无法在Nix中使用haskell-language-server-9.14.1
我想用Nix进行Haskell开发。我想使用GHC版本为9.14.1的 Haskell和 haskell-language-server。以下是我的 toolchain 设置 -
{
"haskell.toolchain" : {
"hls" : "2.14.0.0",
"cabal" : "3.16.1.0",
"stack" : "3.9.3",
"ghc" : "9.14.1"
}
}
下面是 flake.nix -
{
description = "Haskell development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
hs = pkgs.haskell.packages.ghc914;
in
{
devShells.${system}.default = hs.shellFor {
packages = p: [];
buildInputs = with pkgs; [
hs.cabal-install
hs.cabal2nix
hs.haskell-language-server
hs.hlint
hs.fourmolu
];
withHoogle = true;
};
};
}
当我运行 nix develop --show-trace 命令时,出现如下错误 -
> nix develop --show-trace
> error: Cannot build '/nix/store/1pksbmb57m8i1pf4rkpslh2bgfs9vb5d-algebraic-graphs-0.7.drv'.
> Reason: builder failed with exit code 1.
> Output paths:
> /nix/store/ji822jcswiwx4f2cdqxmwp3mxlmf2cyg-algebraic-graphs-0.7-doc
> /nix/store/xb09n97iybvlba3xsafpbym00qjriq74-algebraic-graphs-0.7
> Last 25 log lines:
> > Running phase: setupCompilerEnvironmentPhase
> > Build with /nix/store/gz2pxgdr7np2rh5fhwy9vamrcckbqhv1-ghc-9.14.1.
> > Running phase: unpackPhase
> > unpacking source archive /nix/store/gfjyfw1hcshbfclk91difmkphwib8nbd-algebraic-graphs-0.7.tar.gz
> > source root is algebraic-graphs-0.7
> > setting SOURCE_DATE_EPOCH to timestamp 1655769405 of file "algebraic-graphs-0.7/test/Data/Graph/Test/Typed.hs"
> > Running phase: patchPhase
> > Replace Cabal file with edited version from mirror://hackage/algebraic-graphs-0.7/revision/3.cabal.
> > applying patch /nix/store/fgaciccwb2z0jmfhs30a1vq03azpd9qd-algebraic-graphs-0.7-allow-inspection-testing-0.6.patch
> > patching file algebraic-graphs.cabal
> > Running phase: compileBuildDriverPhase
> > setupCompileFlags: -package-db=/build/tmp.gQ8yAKB2G1/setup-package.conf.d -threaded
> > [1 of 2] Compiling Main ( Setup.hs, /build/tmp.gQ8yAKB2G1/Main.o )
> > [2 of 2] Linking Setup
> > Running phase: updateAutotoolsGnuConfigScriptsPhase
> > Running phase: configurePhase
> > configureFlags: --verbose --prefix=/nix/store/xb09n97iybvlba3xsafpbym00qjriq74-algebraic-graphs-0.7 --libdir=$prefix/lib/$compiler/lib --libsubdir=$abi/$libname --docdir=/nix/store/ji822jcswiwx4f2cdqxmwp3mxlmf2cyg-algebraic-graphs-0.7-doc/share/doc/algebraic-graphs-0.7 --with-gcc=gcc --package-db=/build/tmp.gQ8yAKB2G1/package.conf.d --ghc-option=-j4 --ghc-option=+RTS --ghc-option=-A64M --ghc-option=-RTS --enable-library-profiling --profiling-detail=exported-functions --disable-profiling --enable-shared --disable-coverage --enable-static --disable-executable-dynamic --enable-tests --disable-benchmarks --enable-library-vanilla --disable-library-for-ghci --enable-split-sections --enable-library-stripping --enable-executable-stripping --ghc-option=-fobject-determinism --ghc-option=-haddock --extra-lib-dirs=/nix/store/wl2nw5l4x4dg6kclbgpq7v9212i1s6cy-ncurses-6.6/lib --extra-lib-dirs=/nix/store/2zs4bbi72plfm8j6zxf1js4f3yc4yzwy-libffi-3.5.2/lib --extra-lib-dirs=/nix/store/qhmqdg27kcrlkl8ida6d5hiacw0y8d21-elfutils-0.194/lib --extra-lib-dirs=/nix/store/y56aqb1m3y5davn6hsv4jfbml78qw4mv-gmp-with-cxx-6.3.0/lib --extra-lib-dirs=/nix/store/wjfhh11sfcdf97mvg7hbxickybxzk850-numactl-2.0.18/lib --extra-lib-dirs=/nix/store/gz2pxgdr7np2rh5fhwy9vamrcckbqhv1-ghc-9.14.1/lib
> > Using Parsec parser
> > Configuring algebraic-graphs-0.7...
> > Error: [Cabal-8010]
> > Encountered missing or private dependencies:
> > containers >=0.5.5.1 && <0.8 (installed: 0.8)
> > CallStack (from HasCallStack):
> > dieWithException, called at libraries/Cabal/Cabal/src/Distribution/Simple/Configure.hs:1620:11 in Cabal-3.16.0.0-4c08:Distribution.Simple.Configure
> >
> For full logs, run:
> nix log /nix/store/1pksbmb57m8i1pf4rkpslh2bgfs9vb5d-algebraic-graphs-0.7.drv
> error: Cannot build '/nix/store/016jr78gvqkyxaqb3pc015w5v1j6jz5d-hiedb-0.7.0.0.drv'.
> Reason: 1 dependency failed.
> Output paths:
> /nix/store/78yrisw3l6xfdgfgpp5i740d748fx2mf-hiedb-0.7.0.0-doc
> /nix/store/v3m1mbhb4hk7qm68y8g6qw6cn8a3fcwc-hiedb-0.7.0.0
> error: Build failed due to failed dependency
> error: Cannot build '/nix/store/jlixhp5i59nv5gai7pd7ap0rdjwc6ha5-ghcide-2.13.0.0.drv'.
> Reason: 1 dependency failed.
> Output paths:
> /nix/store/jpqy0q1453l5algd1is2gykx38pq186c-ghcide-2.13.0.0-doc
> /nix/store/kgs7l0gwpmi3rxvzkg3cczc4644bvwbv-ghcide-2.13.0.0
> error: Cannot build '/nix/store/hkkr2gf1aviw2z15dbhjxjvdncf5mg4b-haskell-language-server-2.13.0.0.drv'.
> Reason: 1 dependency failed.
> Output paths:
> /nix/store/xw3g83qabpi03y7n1vnp14wqnhrs5cnf-haskell-language-server-2.13.0.0
> error: Build failed due to failed dependency
> error: Cannot build '/nix/store/yn2n10bs4r7r870j2jkyv0bcsmg73w9v-ghc-shell-for-packages-0-env.drv'.
> Reason: 1 dependency failed.
> Output paths:
> /nix/store/4c01v7nkkwr2h6ksay11zsj5dlqrklhb-ghc-shell-for-packages-0-env
> error: Build failed due to failed dependency
>
我该如何修复这个错误。我想使用ghc-9.14.x,因为haskell-debugger仅支持GHC版本高于9.14.x。
解决方案
以下回答帮助解决了这个问题 -
{
description = "Haskell dev (GHC 9.14.1 + Cabal + HLS)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/haskell-updates";
};
outputs = { self, nixpkgs }:
let
system = "aarch64-darwin";
pkgs = import nixpkgs { inherit system; };
hs = pkgs.haskell.packages.ghc914;
# Building Cabal/HLS from nixpkgs on GHC 9.14.1 currently fails on aarch64-darwin
# (stale Hackage bounds, then a GHC codegen panic). Use official bindists instead.
cabal-install = pkgs.stdenv.mkDerivation {
pname = "cabal-install";
version = "3.16.1.0";
src = pkgs.fetchurl {
url = "https://downloads.haskell.org/~cabal/cabal-install-3.16.1.0/cabal-install-3.16.1.0-aarch64-darwin.tar.xz";
hash = "sha256-4C9FYfvOcrGYo8bIG58hH5x8v0DAc/jy7ln4Nd0d1QI=";
};
nativeBuildInputs = [ pkgs.xz ];
unpackPhase = "xzcat $src | tar xf -";
installPhase = ''
mkdir -p $out/bin
install -m755 cabal $out/bin/cabal
'';
};
haskell-language-server = pkgs.stdenv.mkDerivation {
pname = "haskell-language-server";
version = "2.14.0.0";
src = pkgs.fetchurl {
url = "https://downloads.haskell.org/~hls/haskell-language-server-2.14.0.0/haskell-language-server-2.14.0.0-aarch64-apple-darwin.tar.xz";
hash = "sha256-k0zo2C71OsL2SdvQU11NnAWdjiqQxx6kG5eSngD25GI=";
};
nativeBuildInputs = [ pkgs.xz ];
dontConfigure = true;
dontBuild = true;
unpackPhase = "xzcat $src | tar xf -";
sourceRoot = "haskell-language-server-2.14.0.0";
installPhase = ''
mkdir -p $out/bin $out/lib
cp -r lib/* $out/lib/
cp -r bin/* $out/bin/
# The upstream wrapper binary is built with GHC 9.10.3, so bare `--version`
# reports 9.10.3 even though project mode selects 9.14.1 via cabal/hie-bios.
mv $out/bin/haskell-language-server-wrapper $out/bin/haskell-language-server-wrapper-bin
cat > $out/bin/haskell-language-server-wrapper <<'EOF'
#!${pkgs.bash}/bin/bash
set -euo pipefail
real="$(dirname "$0")/haskell-language-server-wrapper-bin"
case "''${1:-}" in
--version)
echo "haskell-language-server version: 2.14.0.0 (GHC: 9.14.1) (PATH: $0)"
;;
--numeric-version)
echo "2.14.0.0"
;;
*)
exec "$real" "$@"
;;
esac
EOF
chmod +x $out/bin/haskell-language-server-wrapper
'';
};
fourmolu = pkgs.stdenv.mkDerivation {
pname = "fourmolu";
version = "0.20.0.0";
src = pkgs.fetchurl {
url = "https://github.com/fourmolu/fourmolu/releases/download/v0.20.0.0/fourmolu-0.20.0.0-darwin-arm64.zip";
hash = "sha256-raI9mgo3DURn5zEPcp/vO/9u5SfTLmK1w36mbmiL89o=";
};
nativeBuildInputs = [ pkgs.unzip ];
dontConfigure = true;
dontBuild = true;
unpackPhase = "unzip $src";
sourceRoot = "fourmolu-0.20.0.0-darwin-arm64";
installPhase = ''
mkdir -p $out/bin
install -m755 fourmolu $out/bin/fourmolu
'';
};
runtimeLibs = pkgs.lib.makeLibraryPath [
pkgs.gmp
pkgs.zlib
pkgs.ncurses
pkgs.libffi
];
in
{
devShells.${system}.default = pkgs.mkShell {
packages = [
hs.ghc
cabal-install
haskell-language-server
hs.cabal2nix
pkgs.hlint
fourmolu
];
withHoogle = true;
shellHook = ''
export DYLD_LIBRARY_PATH="${runtimeLibs}''${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
'';
};
};
}
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。