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

fix(#5008): "Invalid option --internal-re-exec-version" error when using "nix" with options "enable: true", "pure: true", "shell-file: .." -> prevent entering "nix-shell --pure" recursively by exporting STACK_IN_NIX_SHELL properly #5131

Closed
wants to merge 2 commits into from

Conversation

srghma
Copy link

@srghma srghma commented Dec 25, 2019

fixes ##5008

I've run this on srghma/generate-all-tests@50630d2

here is the output

$ ~/projects/stack/.stack-work/dist/x86_64-linux-nix/Cabal-2.0.1.0/build/stack/stack build --verbose
Version 2.2.0, Git revision 602253507622b55ca627bf22a66e5874182e7345 (dirty) (7902 commits) PRE-RELEASE x86_64 hpack-0.31.2
2019-12-26 11:29:33.749556: [debug] Checking for project config at: /home/srghma/projects/generate-all-tests/stack.yaml
2019-12-26 11:29:33.749814: [debug] Loading project config file stack.yaml
2019-12-26 11:29:33.757926: [debug] SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2019-12-25 09:29:33.757888904 UTC]
2019-12-26 11:29:33.758500: [debug] Using package location completions from a lock file
2019-12-26 11:29:33.766725: [debug] Loaded snapshot from Pantry database.
2019-12-26 11:29:33.877276: [debug] Running hpack on /home/srghma/projects/generate-all-tests/package.yaml
2019-12-26 11:29:33.880535: [debug] hpack output unchanged in /home/srghma/projects/generate-all-tests/generate-all-tests.cabal
2019-12-26 11:29:33.896857: [debug] Migration executed: CREATE TABLE "config_cache"("id" INTEGER PRIMARY KEY,"directory" VARCHAR NOT NULL DEFAULT (hex(randomblob(16))),"type" VARCHAR NOT NULL,"pkg_src" VARCHAR NOT NULL,"active" BOOLEAN NOT NULL,"path_env_var" VARCHAR NOT NULL,"haddock" BOOLEAN NOT NULL DEFAULT 0,CONSTRAINT "unique_config_cache" UNIQUE ("directory","type"))
2019-12-26 11:29:33.897105: [debug] Migration executed: CREATE TABLE "config_cache_dir_option"("id" INTEGER PRIMARY KEY,"config_cache_id" INTEGER NOT NULL REFERENCES "config_cache","index" INTEGER NOT NULL,"option" VARCHAR NOT NULL,CONSTRAINT "unique_config_cache_dir_option" UNIQUE ("config_cache_id","index"))
2019-12-26 11:29:33.897234: [debug] Migration executed: CREATE TABLE "config_cache_no_dir_option"("id" INTEGER PRIMARY KEY,"config_cache_id" INTEGER NOT NULL REFERENCES "config_cache","index" INTEGER NOT NULL,"option" VARCHAR NOT NULL,CONSTRAINT "unique_config_cache_no_dir_option" UNIQUE ("config_cache_id","index"))
2019-12-26 11:29:33.897339: [debug] Migration executed: CREATE TABLE "config_cache_dep"("id" INTEGER PRIMARY KEY,"config_cache_id" INTEGER NOT NULL REFERENCES "config_cache","ghc_pkg_id" VARCHAR NOT NULL,CONSTRAINT "unique_config_cache_dep" UNIQUE ("config_cache_id","ghc_pkg_id"))
2019-12-26 11:29:33.897435: [debug] Migration executed: CREATE TABLE "config_cache_component"("id" INTEGER PRIMARY KEY,"config_cache_id" INTEGER NOT NULL REFERENCES "config_cache","component" BLOB NOT NULL,CONSTRAINT "unique_config_cache_component" UNIQUE ("config_cache_id","component"))
2019-12-26 11:29:33.897980: [debug] PATH is: Just "/home/srghma/.gem/ruby/2.4.0/bin:/home/srghma/.node_modules/bin:/home/srghma/bin:/run/wrappers/bin:/home/srghma/.nix-profile/bin:/etc/profiles/per-user/srghma/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:./node_modules/.bin"
2019-12-26 11:29:33.898159: [debug] Using a nix-shell environment from file: /home/srghma/projects/generate-all-tests/stack-shell.nix
2019-12-26 11:29:33.898535: [debug] Run process: /run/current-system/sw/bin/nix-shell /home/srghma/projects/generate-all-tests/stack-shell.nix --arg ghc "with (import <nixpkgs> {}); haskell.compiler.ghc865" --run "export STACK_IN_NIX_SHELL=1;  '/home/srghma/projects/stack/.stack-work/dist/x86_64-linux-nix/Cabal-2.0.1.0/build/stack/stack' $STACK_IN_NIX_EXTRA_ARGS '--internal-re-exec-version=2.2.0' 'build' '--verbose'"

@qrilka
Copy link
Contributor

qrilka commented Dec 26, 2019

@srghma this variable should be set in

,T.pack inNixShellEnvVar <> "=1; "
, if you have a shell file then I suppose you should set this variable in that file.
Though the intended semantics wasn't documented anywhere so it's not quite clear.

…on" error when using "nix" with options "enable: true", "pure: true", "shell-file: .." -> prevent entering "nix-shell --pure" recursively by exporting STACK_IN_NIX_SHELL properly
@srghma
Copy link
Author

srghma commented Dec 26, 2019

this variable should be set in

updated, tnx

if you have a shell file then I suppose you should set this variable in that file

yes, I have mentioned that this is one of possible ways to overcome this issue #5008 (comment)

@qrilka
Copy link
Contributor

qrilka commented Feb 4, 2020

@srghma I think it would be good to remove setting inNixShellEnvVar twice in case when shell file is not used. After that we could merge this.
If you have time it would help if you could add a simple integration test with a shell.nix

@srghma
Copy link
Author

srghma commented Feb 4, 2020

twice in case when shell file is not used

what do you mean?

@qrilka
Copy link
Contributor

qrilka commented Feb 4, 2020

See line

,T.pack inNixShellEnvVar <> "=1; "
- it sets the same variable but using nix, not shell

@srghma
Copy link
Author

srghma commented Feb 4, 2020

ah, you want me to change

                           ,["--run", unwords ("export " <> inNixShellEnvVar <> "=1; ":cmnd:"$STACK_IN_NIX_EXTRA_ARGS":args')]

to something like

let exportInNixShellEnvVarIfShellFileIsUsed = if isJust mshellFile then "export " <> inNixShellEnvVar <> "=1; " else ""
....
                           ,["--run", exportInNixShellEnvVarIfShellFileIsUsed. unwords (cmnd:"$STACK_IN_NIX_EXTRA_ARGS":args')]

@qrilka
Copy link
Contributor

qrilka commented Feb 4, 2020

@srghma just dropping that line 79 would be enough if we need to set this var anyway

…on" error when using "nix" with options "enable: true", "pure: true", "shell-file: .." -> dont set inNixShellEnvVar second time if shell.nix is not used
@srghma
Copy link
Author

srghma commented Feb 4, 2020

added

@qrilka
Copy link
Contributor

qrilka commented Feb 4, 2020

Thanks, let's now wait for CI to pass.

@qrilka
Copy link
Contributor

qrilka commented Feb 5, 2020

Thanks for your efforts @srghma but I think now I understand Nix integration a bit better and it looks like I was wrong in my previous ideas and this PR isn't actually need. As it's said in the docs you need to use buildStackProject from nixpkgs as it adds details needed for a proper integration between Stack and Nix. As for the STACK_IN_NIX_SHELL variable, it gets set in https://github.com/NixOS/nixpkgs/blob/713a45ecf79a4b4c632819f1c898d3e66c77bdd2/pkgs/development/haskell-modules/generic-stack-builder.nix#L28

@srghma
Copy link
Author

srghma commented Feb 6, 2020

ok, agree, thanks to you too

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

Successfully merging this pull request may close these issues.

2 participants