Hey @domenkozar, that’s great stuff
I’m feeling ready to start migrating my flakes to devenv. I find myself often copy pasting my flakes into github projects I download and modifying them to fit the project environment (even contributing them back sometimes, right @turion )
It would be great to have stack and cabal examples as well as migration steps from cabal2nix or haskell4nix.
As I’m going through my first attempt to use devenv
right now on this project, maybe it’s helpful if I go through this and report my thoughts and difficulties?
The project has a very simple stack.yaml
and I bumped into a difficult error (I know you’re fundraising for improving errors in nix, and I wish that effort the very best). I just ran devenv init
in the folder and added languages.haskell.enable = true;
and when I ran stack build
I got this error:
error:
… while calling the 'derivationStrict' builtin
at //builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'myEnv'
whose name attribute is located at /nix/store/dbfxzxrxf82zxql89ywnprg0dbbmxy69-nixos-20.09.3301.42809feaa9f/nixos/pkgs/build-support/trivial-builders.nix:7:7
… while evaluating attribute 'LD_LIBRARY_PATH' of derivation 'myEnv'
at «string»:1:411:
1| with (import <nixpkgs> {}); let inputs = [haskell.compiler.ghc925 git gcc gmp]; libPath = lib.makeLibraryPath inputs; stackExtraArgs = lib.concatMap (pkg: [ ''--extra-lib-dirs=${lib.getLib pkg}/lib'' ''--extra-include-dirs=${lib.getDev pkg}/include'' ]) inputs; in runCommand ''myEnv'' { buildInputs = lib.optional stdenv.isLinux glibcLocales ++ inputs; STACK_PLATFORM_VARIANT=''nix''; STACK_IN_NIX_SHELL=1; LD_LIBRARY_PATH = libPath;STACK_IN_NIX_EXTRA_ARGS = stackExtraArgs; LANG="en_US.UTF-8";} ""
| ^
error: attribute 'ghc925' missing
at «string»:1:43:
1| with (import <nixpkgs> {}); let inputs = [haskell.compiler.ghc925 git gcc gmp]; libPath = lib.makeLibraryPath inputs; stackExtraArgs = lib.concatMap (pkg: [ ''--extra-lib-dirs=${lib.getLib pkg}/lib'' ''--extra-include-dirs=${lib.getDev pkg}/include'' ]) inputs; in runCommand ''myEnv'' { buildInputs = lib.optional stdenv.isLinux glibcLocales ++ inputs; STACK_PLATFORM_VARIANT=''nix''; STACK_IN_NIX_SHELL=1; LD_LIBRARY_PATH = libPath;STACK_IN_NIX_EXTRA_ARGS = stackExtraArgs; LANG="en_US.UTF-8";} ""
| ^
Did you mean ghc865?
A thought: the fact that the devenv
dev shell is --impure
worries me a bit, as I don’t know if something from my system environment is interfering here. That’s a worry I don’t usually have with nix develop
and that’s a pretty big one. Also I installed devenv
on my nixos machine via home manager (passing the flake through to home.packages
, which wasn’t completely obvious) so I’m also wondering now if I messed that up.
I tried to add languages.haskell.package = pkgs.haskell.compiler.ghc925;
not really believing it would do anything, and indeed it didn’t. So I find myself having to dropdown into nix to troubleshoot.
My assumption reading the last message in the stack trace is that the haskell.compiler.ghc925
could be coming from devenv
itself, or from stack
trying to do something smart with its nix integration. That’s the point where I tried to go the the devenv examples but came up empty.
Ah ha, I feel lucky. I got to this issue in a search and two clicks
A thought: I haven’t been immersed in nix/haskell dev in a few months, so I have a lot of context to reload here. Also I tended to migrate away from stack and towards cabal, so I’m having flashbacks of how actually quite difficult haskell dev setup is.
So now I think I should try to disable nix integration in stack.
nix:
enable: false
Yeah not quite:
> stack build
I don't know how to install GHC on your system configuration, please install manually
x> ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.5
> which ghc
/nix/store/fyl847yw1p7n3nll9jbcj1cg4y09wdxl-devenv-profile/bin/ghc
I feel tempted to change my nix channels given the github issue, but that would be too much of a defeat. A bit of jogging my memory and I’m thinking I should be able to pass the GHC path to stack. A bit of googling later, I’m realising there’s system-ghc: true
.
Victory!
> stack exec -- which ghc
/nix/store/lnxk3fmylchldhcs6hpbwx8bp9jjcp6w-ghc-9.2.5/bin/ghc
> stack build
[1 of 2] Compiling Main ( /home/jun/.stack/setup-exe-src/setup-Z6RU0evB.hs, /home/jun/.stack/setup-exe-src/setup-Z6RU0evB.o )
[2 of 2] Compiling StackSetupShim ( /home/jun/.stack/setup-exe-src/setup-shim-Z6RU0evB.hs, /home/jun/.stack/setup-exe-src/setup-shim-Z6RU0evB.o )
Linking /home/jun/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_Z6RU0evB_3.6.3.0_ghc-9.2.5 ...
Hope my developer experience was a little bit useful, I’m not sure if I landed on the “correct devenv way” but at least I can build the project.
TLDR; For me, adding this to the project’s stack.yaml
did it:
nix:
enable: false
system-ghc: true
A parting thought: I would have preferred if devenv init
picked up the fact that it’s a haskell project, and also didn’t create a devenv.yaml
file (since it’s using the default input flake anyway) given that project root folder get quite bloated these days.
Cheers,
Jun