Open traleig1 opened 8 months ago
@traleig1, thanks for reporting. While I try to work out what is going on, I note that the default value for add-gc-roots
is false
(https://docs.haskellstack.org/en/stable/yaml_configuration/#nix), so this will only affect people who have expressly set add-gc-roots: true
. There is also some documentation at: https://docs.haskellstack.org/en/stable/nix_integration/#non-project-specific-configuration.
Its effect is at Stack.Nix.runShellAndExit
:
fullArgs = concat
[ [ "--pure" | pureShell ]
, if addGCRoots -- <<<< True if add-gc-roots is true
then [ "--indirect"
, "--add-root"
, toFilePath
(configWorkDir config)
F.</> "nix-gc-symlinks"
F.</> "gc-root"
]
else []
, map T.unpack (nixShellOptions (configNix config))
, nixopts
, ["--run", unwords (cmnd:"$STACK_IN_NIX_EXTRA_ARGS":args')]
-- Using --run instead of --command so we cannot end up in the
-- nix-shell if stack build is Ctrl-C'd
]
...
exec "nix-shell" fullArgs
Re --add-root
:
--indirect
and --add-root
are not documented in the nix-shell
manpage)@traleig1, I am not a Nix user. Should I understand from the above links that it is nix-store
(and not nix-shell
) that should be run with the --add-root
option?
I note that the default value for
add-gc-roots
isfalse
Yes - I initially hadn't realized that I had it set in my ~/.stack/config.yaml
, so went back and edited the issue to clarify that.
Should I understand from the above links that it is
nix-store
(and notnix-shell
) that should be run with the--add-root
option?
I'm not sure; I've never had a need to work with the nix-store
command directly - the usual workflow is to just use nix-build
to package things up, and that handles copying to the nix store via nix-store
/nix-instantiate
under the hood. Here it looks like stack already has the .stack-work/nix-gc-symlinks/gc-root
directory ready, and it's adding the gc roots when it creates the environment it runs in via nix-shell
. Seems to me like it could probably be done by calling nix-store
separately/explicitly, but I'm definitely out of my league here.
Judging from the documentation for nix-shell it looks like the intention is for nix-shell
to pass extra flags down to nix-store
itself, which would imply that it should work as-is. I'm struggling to find evidence of support for the flag being explicitly removed, so unless the documentation is out of date, it's possible this is a bug on their end.
@traleig1, 'bug at their end' is also my current hypothesis. I'll raise an issue there.
General summary
Attempting to build projects using Nix on NixOS while
add-gc-roots
is enabled produces the following, as also described in https://github.com/haskell/cabal/issues/9146:Workaround is to add
add-gc-roots: false
tostack.yaml
.Steps to reproduce
flake.lock
:flake.nix
:~/.stack/config.yaml
:stack.yaml
Expected
Stack should begin attempting to build.
Actual
Stack immediately fails. Running with
--verbose
:Running via
nix develop
produces roughly the same, just with a much longer $PATH.Stack version
Method of installation
nix-env
/nix develop
Platform