首页 > 解决方案 > 如何将 ghcide 添加到 shell.nix

问题描述

我有一个 Haskell Cabal 项目。我一直在使用cabal2nix构建它。因此我有 3 个 nix 文件:

最近决定使用ghcide搭建 vscode 开发环境。在描述中它说

包括pkgs.haskellPackages.ghcide在你的项目shell.nix中......

无需进一步解释。听起来这应该很容易,但我不知道怎么做。我该怎么做?

标签: haskellcabalnix

解决方案


shell.nix使用shellFor功能。它在包集中而不是haskell.lib. 基于https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/make-package-set.nix上的 shellFor 内联文档中的示例,我已重命名为all-packages.nix添加了一个 let 绑定它在shell.nix并添加ghcide

    # Returns a derivation whose environment contains a GHC with only
    # the dependencies of packages listed in `packages`, not the
    # packages themselves. Using nix-shell on this derivation will
    # give you an environment suitable for developing the listed
    # packages with an incremental tool like cabal-install.
    # In addition to the "packages" arg and "withHoogle" arg, anything that
    # can be passed into stdenv.mkDerivation can be included in the input attrset
    #
    #     # all-packages.nix
    #     with import <nixpkgs> {};
    #     haskellPackages.extend (haskell.lib.packageSourceOverrides {
    #       frontend = ./frontend;
    #       backend = ./backend;
    #       common = ./common;
    #     })
    #
    #     # shell.nix
    #     let pkgs = import <nixpkgs> {};
    #         allPackages = import ./all-packages.nix;
    #     in
    #     allPackages.shellFor {
    #       packages = p: [p.frontend p.backend p.common];
    #       withHoogle = true;
    #       buildInputs = [ allPackages.ghcide ];
    #     }
    #
    #     -- cabal.project
    #     packages:
    #       frontend/
    #       backend/
    #       common/
    #
    #     bash$ nix-shell --run "cabal new-build all"
    #     bash$ nix-shell --run "python"


推荐阅读