Nix GC command breaks nix completely
What happened?
Found that my nix installation had snowballed to 15gb (I only have a single project using devbox).
Found the documentation how-do-i-clean-up-unused-packages-from-the-nix-store
Ran devbox run -- nix store gc
Then (after several attempts at different combinations and a couple of web searches) finally found that the command I really wanted was devbox run -- nix store gc --extra-experimental-features nix-command
Even with a fresh install of nix and the devbox.json below, I get the message:
16 store paths deleted, 343.42 MiB freed
After exiting the shell, attempting devbox shell produces the following error
Error: Unable to find nix startup file. If /nix directory exists it's possible the installation did not complete successfully. Follow instructions at https://nixos.org/download.html for manual install.
Steps to reproduce
- Start with a fresh installation of devbox / nix
-
devbox shellor similar to install required packages -
devbox run -- nix store gc --extra-experimental-features nix-command - Exit the devbox shell
- Attempt to re-enter the devbox shell.
Command
run, shell
devbox.json
{
"packages": [
"git@latest"
]
}
Devbox version
0.9.1
Nix version
nix (Nix) 2.18.1
What system does this bug occur on?
Linux (x86-64)
Debug logs
❯ DEVBOX_DEBUG=1 devbox shell
2024/02/27 09:22:26 findProjectDir: path is
2024/02/27 09:22:26 finding devbox config in dir: /home/matthew/projects/third_party/devboxplay
2024/02/27 09:22:26 findProjectDir: path is
2024/02/27 09:22:26 finding devbox config in dir: /home/matthew/projects/third_party/devboxplay
Error: Unable to find nix startup file. If /nix directory exists it's possible the installation did not complete successfully. Follow instructions at https://nixos.org/download.html for manual install.
2024/02/27 09:22:26
ExecutionID:a2fe6425a3684e24b568cf5d2c1a3dcd
Unable to find nix startup file. If /nix directory exists it's possible the installation did not complete successfully. Follow instructions at https://nixos.org/download.html for manual install.
go.jetpack.io/devbox/internal/boxcli/usererr.New
go.jetpack.io/devbox/internal/boxcli/usererr/usererr.go:29
go.jetpack.io/devbox/internal/nix.SourceNixEnv
go.jetpack.io/devbox/internal/nix/source.go:45
go.jetpack.io/devbox/internal/nix.EnsureNixInstalled
go.jetpack.io/devbox/internal/nix/install.go:140
go.jetpack.io/devbox/internal/boxcli.ensureNixInstalled
go.jetpack.io/devbox/internal/boxcli/setup.go:51
github.com/spf13/cobra.(*Command).execute
github.com/spf13/[email protected]/command.go:968
github.com/spf13/cobra.(*Command).ExecuteC
github.com/spf13/[email protected]/command.go:1115
github.com/spf13/cobra.(*Command).Execute
github.com/spf13/[email protected]/command.go:1039
go.jetpack.io/devbox/internal/boxcli/midcobra.(*midcobraExecutable).Execute
go.jetpack.io/devbox/internal/boxcli/midcobra/midcobra.go:61
go.jetpack.io/devbox/internal/boxcli.Execute
go.jetpack.io/devbox/internal/boxcli/root.go:113
go.jetpack.io/devbox/internal/boxcli.Main
go.jetpack.io/devbox/internal/boxcli/root.go:136
main.main
./main.go:11
runtime.main
runtime/proc.go:267
runtime.goexit
runtime/asm_amd64.s:1650
2024/02/27 09:22:26 findProjectDir: path is
2024/02/27 09:22:26 finding devbox config in dir: /home/matthew/projects/third_party/devboxplay
I'm having trouble reproducing this one. Do you mind telling me if any of the following paths exist on your system?
ls -l \
"/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" \
"$HOME/.nix-profile/etc/profile.d/nix.sh" \
"$HOME/.local/state/nix/profile/etc/profile.d/nix.sh" \
"$HOME/.local/state/nix/profiles/profile/etc/profile.d/nix.sh"
What's the output of nix --version --debug?
Do you see something like the following in /etc/bash.bashrc or /etc/profile.d/nix.sh?
# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix
Also, if you add a verbose flag does it tell you which paths are being removed?
devbox run -- nix store gc --verbose --extra-experimental-features nix-command
Thanks!
❯ ls -l "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" "$HOME/.nix-profile/etc/profile.d/nix.sh" "$HOME/.local/state/nix/profile/etc/profile.d/nix.sh" "$HOME/.local/state/nix/profiles/profile/etc/profile.d/nix.sh"
ls: cannot access '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh': No such file or directory
ls: cannot access '/home/matthew/.local/state/nix/profile/etc/profile.d/nix.sh': No such file or directory
-r--r--r-- 1 matthew matthew 2880 Jan 1 1970 /home/matthew/.local/state/nix/profiles/profile/etc/profile.d/nix.sh
-r--r--r-- 1 matthew matthew 2880 Jan 1 1970 /home/matthew/.nix-profile/etc/profile.d/nix.sh
Nix version:
❯ nix --version --debug
nix (Nix) 2.18.1
System type: x86_64-linux
Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux, x86_64-v4-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/matthew/.config/nix/nix.conf:/etc/xdg/xdg-cinnamon/nix/nix.conf:/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/azvn85cras6xv4z5j85fiy406f24r1q0-nix-2.18.1/share
❯ cat /etc/nix/nix.conf
cat: /etc/nix/nix.conf: No such file or directory
Nothing nix related in /etc/ - sudo grep -ir nix /etc/bash* /etc/profile* gave no results
And with verbose flag:
projects/third_party/devboxplay via impure
❯ devbox run -- nix store gc --verbose --extra-experimental-features nix-command
finding garbage collector roots...
deleting garbage...
deleting '/nix/store/ys6g8wvr5rwxyfqrlvwd7vipj9ysqn70-nss-cacert-3.92'
deleting '/nix/store/hzx954rnda4k348rb4wvqbdzp9z0ynjy-user-environment.drv'
deleting '/nix/store/8xl4kcn7lgaa9chyqwjjsd7xbq842hml-user-environment'
deleting '/nix/store/qa5v8vixm2z468nw49wcvgqiq61dlg8s-env-manifest.nix'
deleting '/nix/store/9kbkm00saz41sxfs6bxmvkb9k4qk495y-nixpkgs-unstable'
deleting '/nix/store/sn54r0d8p033g71s08nhsabhwhl07f5d-source'
deleting '/nix/store/b319178j5b2c7i9xvpnik81881jy11fj-source'
deleting '/nix/store/j0jlb33bm31w347w43051hbffgh616jr-source'
deleting '/nix/store/q9kr7w9lb4b7kxb9p647qzxarjrbr8x0-nix-shell.drv'
deleting unused links...
note: currently hard linking saves 0.00 MiB
9 store paths deleted, 133.72 MiB freed
❯
exit
❯ devbox shell
Error: Unable to find nix startup file. If /nix directory exists it's possible the installation did not complete successfully. Follow instructions at https://nixos.org/download.html for manual install.