Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Nix integration broken? #9165

Closed
yvan-sraka opened this issue Aug 8, 2023 · 1 comment
Closed

Is Nix integration broken? #9165

yvan-sraka opened this issue Aug 8, 2023 · 1 comment

Comments

@yvan-sraka
Copy link
Collaborator

yvan-sraka commented Aug 8, 2023

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:
import Distribution.Simple
import System.Environment

main :: 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! :)

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Aug 8, 2023

Hey! It has never worked with v2 commands (which is what you you get when you say cabal build these days). Probably a dup of #6444.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants