You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I can't manage, following the Nix Integration official tutorial, to make it works. Since I use Nix as my daily driver for years, I wonder, it is the documentation that is really misleading? Or is the feature broken, and no one reported it before because there is no user of it?
To Reproduce
I wanted to give Cabal Nix integration a try, so I created a dummy project with a shell.nix that set an environment variable that a Setup.hs will try to read.
shell.nix:
{pkgs ? import<nixpkgs>{}}:
pkgs.mkShell{shellHook="touch NIX_SHELL_HOOK_CALLED";VARIABLE_SET_BY_NIX_SHELL="Hello from Nix shell!";}
Setup.hs:
importDistribution.SimpleimportSystem.Environmentmain::IO()
main =do
x <- getEnv "VARIABLE_SET_BY_NIX_SHELL"putStrLn x
defaultMain
So, on a machine with Cabal and GHC installed (or in a developer shell spawned with nix-shell -p cabal-install ghc), you can build the project with nix-shell --run "cabal build" or the new experimental command nix develop -c cabal build. It works, and the shell.nix does 2 others side effect for debugging: it prints Hello from Nix shell! (it's Setup.hs that reads and displays the ENV variable VARIABLE_SET_BY_NIX_SHELL) on standard output and touch the file NIX_SHELL_HOOK_CALLED.
So, then if I understand well the Nix integration documentation, I could replace the previous commands by just cabal --enable-nix build or cabal --nix=True build, right? Both of that commands will not trigger any of the side effects defined in the shell.nix and so the build will fail:
$ cabal --enable-nix build
Resolving dependencies...
Build profile: -w ghc-9.2.8 -O1
In order, the following will be built (use -v for more details):
- test-0.1.0.0 (exe:test) (first run)
[1 of 1] Compiling Main ( /home/yvan/is-cabal-nix-integration-broken/dist-newstyle/build/x86_64-linux/ghc-9.2.8/test-0.1.0.0/setup/setup.hs, /home/yvan/is-cabal-nix-integration-broken/dist-newstyle/build/x86_64-linux/ghc-9.2.8/test-0.1.0.0/setup/Main.o )
Linking /home/yvan/is-cabal-nix-integration-broken/dist-newstyle/build/x86_64-linux/ghc-9.2.8/test-0.1.0.0/setup/setup ...
setup: VARIABLE_SET_BY_NIX_SHELL: getEnv: does not exist (no environment variable)
Error: cabal: Failed to build test-0.1.0.0. The failure occurred during the
configure step.
Expected behavior cabal --enable-nix build and cabal --nix=True build should have the same behavior as nix-shell --run "cabal build" or nix develop -c cabal build.
System information
$ uname -a
Linux X230 6.1.42 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jul 27 06:50:53 UTC 2023 x86_64 GNU/Linux
$ cabal --version
cabal-install version 3.10.1.0
compiled using version 3.10.1.0 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.8
Additional context
This issue was mentioned in the last “cabal devs fortnightly chat”, and the consensus was to depreciated progressively the feature. I will open a PR with a plan for that! :)
The text was updated successfully, but these errors were encountered:
Describe the bug
I can't manage, following the Nix Integration official tutorial, to make it works. Since I use Nix as my daily driver for years, I wonder, it is the documentation that is really misleading? Or is the feature broken, and no one reported it before because there is no user of it?
To Reproduce
I wanted to give Cabal Nix integration a try, so I created a dummy project with a
shell.nix
that set an environment variable that aSetup.hs
will try to read.shell.nix
:Setup.hs
:So, on a machine with Cabal and GHC installed (or in a developer shell spawned with
nix-shell -p cabal-install ghc
), you can build the project withnix-shell --run "cabal build"
or the new experimental commandnix develop -c cabal build
. It works, and theshell.nix
does 2 others side effect for debugging: it printsHello from Nix shell!
(it'sSetup.hs
that reads and displays the ENV variableVARIABLE_SET_BY_NIX_SHELL
) on standard output and touch the fileNIX_SHELL_HOOK_CALLED
.So, then if I understand well the Nix integration documentation, I could replace the previous commands by just
cabal --enable-nix build
orcabal --nix=True build
, right? Both of that commands will not trigger any of the side effects defined in theshell.nix
and so the build will fail:Expected behavior
cabal --enable-nix build
andcabal --nix=True build
should have the same behavior asnix-shell --run "cabal build"
ornix develop -c cabal build
.System information
Additional context
This issue was mentioned in the last “cabal devs fortnightly chat”, and the consensus was to depreciated progressively the feature. I will open a PR with a plan for that! :)
The text was updated successfully, but these errors were encountered: