I just updated to the latest nixos-18.03 channel, rebuilt NixOS, and then ran nix-collect-garbage - and I found that my user profile was gone.
chris@renzo ~ ❯❯❯ ls .nix-profile/
ls: cannot access '.nix-profile/': No such file or directory
chris@renzo ~ ❯❯❯ readlink .nix-profile
.nix-profile-1-link
chris@renzo ~ ❯❯❯ readlink .nix-profile-1-link
.nix-profile-1-link-23-link
chris@renzo ~ ❯❯❯ readlink .nix-profile-1-link-23-link
/nix/store/39cvrvzirh2r1xs65pz1x9pi94x384qj-user-environment
chris@renzo ~ ❯❯❯ ll /nix/store/39cvrvzirh2r1xs65pz1x9pi94x384qj-user-environment
ls: cannot access '/nix/store/39cvrvzirh2r1xs65pz1x9pi94x384qj-user-environment': No such file
or directory
When I install something with nix-env, it comes back, but if I run nix-collect-garbage, it deletes it again.
chris@renzo ~ ❯❯❯ nix --version
nix (Nix) 2.0
Any idea where all these numbered ~/.nix-profile-...-link-... symlinks are coming from? There's a dozen or so. On my other NixOS machine with (as far as I know) the same setup, I don't have them.
User profiles are supposed to be in /nix/var/nix/profiles anything in there is a gcroot.
It looks like something weird happened when your user profile was created (generation 1) causing nix-env to use ~/.nix-profile-1-link as your profile instead of /nix/var/nix/profiles/per-user/foo/profile. I seem to recall some other people ending up in a similar state but can't remember why. Do you see any other profiles in the per-user dir?
Found this in my irc logs https://botbot.me/freenode/nixos/2017-01-29/?msg=80116278&page=3
I deleted all the nix-profile symlinks in my home directory, and now everything seems back to normal.
chris@renzo ~ ❯❯❯ ls -la | grep profile
lrwxrwxrwx 1 chris users 44 Apr 12 17:13 .nix-profile -> /nix/var/nix/profiles/per-user/chris/profile
So now the question is... How in the world did I get into that state? I've never manually touched any of those links, so surely it's something that a nix command did.
Hey I had exactly the same issue today interestingly enough.
I've installed nix pretty recently (when nix 2.0 came out) through the installer script on the website. on Arch Linux.
nix-store --gc
deleted everything.
I also have the spurious .nix-profile-1-link file
❯ ls -al | grep nix-pr
lrwxrwxrwx 1 arian users 19 May 7 13:33 .nix-profile -> .nix-profile-1-link
lrwxrwxrwx 1 arian users 60 May 7 13:33 .nix-profile-1-link -> /nix/store/zflrin4jx05kpyiqp0bzqdxmay1rbj4k-user-environment
I fixed it by doing:
ln -s /nix/var/nix/profiles/per-user/arian/profile /home/arian/.nix-profile
```
The creation of ".nix-profile-*-link"s has happened to others in the past:
I wonder if some uncommon command (executed in "unusual" conditions, perhaps) could cause this?
Bouncing through the code nothing jumps out, but it's very strange....
something makes those links! :)
If not nix, then perhaps some other tools/scripts/etc.?
@chris-martin
Conceivably caused by something like this: 07d2c6d213660e178fcdf128ea6f1f36d9d8a85d ? Or maybe using NFS or NTFS(-3g)?
Only bits that create/modify these links would be in Nix itself, installer scripts, and I think some NixOS shell init? Are there others?
Alternatively maybe there's a way to "catch" this before it becomes problematic, and if it's not easy to do so without limiting usage perhaps emit a warning if profiles aren't gc roots or something?
https://github.com/NixOS/nix/blob/966407bcf1cf86de508b20fef43cffb81d8a87dc/src/nix-env/nix-env.cc#L1416 is curious -- although AFAICT never problematic -- since absPath is being told to resolve the path relative to $HOME is it's relative. But it isn't, unless.. $HOME doesn't start with "/"? Bah anyway just caught my eye.....
Hmm, okay so I came up with a way to cause this sort of thing, does it seem likely to be something folks do?
$ ls -l .nix-profile*
lrwxrwxrwx 1 will users 43 May 20 15:38 .nix-profile -> /nix/var/nix/profiles/per-user/will/profile
$ # THIS COMMAND IS INTENDED TO CAUSE PROBLEMS, BE CAREFUL
$ nix-env -p $HOME/.nix-profile -iA nixos.bash
$ ls -l .nix-profile*
lrwxrwxrwx 1 will users 19 May 20 15:39 .nix-profile -> .nix-profile-1-link
lrwxrwxrwx 1 will users 60 May 20 15:39 .nix-profile-1-link -> /nix/store/3y1fsybz15d7x36475n9qjgjmz09hf7d-user-environment
$ # Fix
$ nix-env -S /nix/var/nix/profiles/per-user/$USER/profile
Maybe?
@dtzWill running nix-env -p $HOME/.nix-profile -iA nixos.bash does not seem like the type of command that I have run, no.
I've got these links as well on macOS

I feel like multi-user is causing unnecessary complexity on my macOS machine. Depending on whether I run with sudo or not, different stuff happens - different packages get picked up, etc. Might be unrelated; would like to do a single-user install but wasn't entirely clear on that. I have messed around with sudo -H nix-env ... not sure it made much sense (I don't commonly use the -H flag so not real good on its details) but was experimenting with how sudo acted differently.
If it helps, this is every nix command I have ever executed on my machine:
❯ cat ~/.histfile | grep '^nix' | sort | uniq
nix
nix-buiild
nix-builc -f libsignal-protocol-c.nix
nix build
nix build
nix-build
nix-build -A haskellPackages.generics-mrsop
nix-build -A haskellPackages.generics-mrsop-diff
nix-build -A haskellPAckages.generics-mrsop-diff
nix-build --arg nixpkgs 'import ../../.'
nix-build --argstr compiler ghcHEAD
nix-build --attr generics-mrsop release.nix
nix-build --attr generics-mrsop release.nix --verbose
nix-build --attr nixpkgs './../..'
nix-build --attr nixpkgs './..'
nix-build --attr nixpkgs '{}'
nix-build --attr nixpkgs './../..' --trace
nix-build --build-repeat 5 -K
nix-build --check
nix-build --check -f libsignal-protocol-c.nix
nix-build --check lol.nix
nix-build default.nix
nix build -f ./default.nix
nix build -f ./default.nix nginx
nix build -f default.nix ocesql
nix build -f libsignal-protocol-c.nix
nix build -f lol.nix
nix build -f lol.nix .
nix-build -f lol.nix --chck
nix build -f lol.nix --check
nix-build -f lol.nix --check
nix-build ../generics-mrsop/../../default.nix -A haskellPackages.generics-mrsop-diff
nix build --help
nix-build --help
nix build --help --keep-failed
nix build --help --keep-failed -f libsignal-protocol-c.nix
nix-build -K
nix build --logs
nix build lol.nix
nix-build lol.nix --check
nix-build --no-out-link
nix-build --no-out-links
nix build ocesql
nix-build --option build-repeat 2 -K
nix-build --option build-repeat 2 -K -j4
nix-build --option build-repeat 5
nix-build --option build-repeat 5 -K
nix-build release.nix
nix-build release.nix -A generics-mrsop
nix-build release.nix --attr generics-mrsop
nix-build --show-trace
nix-build --trace --arg nixpkgs './../..'
nix-build --trace --arg nixpkgs 'import ../../.'
nix-build --trace --attr nixpkgs './../..'
nix build -v
nix build -vvv
nix-channel
nix-channel --add https://nixos.org/channels/nixos-18.03
nix-channel --add https://nixos.org/channels/nixos-18.03 nixpkgs
nix-channel --help
nix-channel --list
nix-channel --remove nixos-18.03
nix-channel set-url
nix-channel update
nix-channel --update
nix config
nix copy
nix copy --from http://localhost:8000
nix copy --hel
nix copy --help
nix copy-sigs --help
nix copy --to
nix copy --to file:///tmp/cache
nix copy --to file:///tmp/cache /home/arian/.nix-profile/bin/stack
nix copy --to --help
nix copy --to s3:// --help
nix copy --to s3://x
nix-daemon
nix dump-path
nix dump-path -f <nixpkgs> stack
nix dump-path -f '<nixpkgs>' stack
nix dump-path -f '<nixpkgs>' stack > stack.nar
nix dump-path --help
nix dump-path -I <nixpkgs> stack
nix edit nixpkgs.nginx
nix-env
nix-env -f '(import .default.nix).env'
nix-env -f '<nixpkgs>' -iA curl.devdoc
nix-env -iA curl.devdoc
nix-env -iA curl.doc
nix-env -iA 'elmPackages.elm'
nix-env -iA elmPackages.elm
nix-env -iA haskellngPackages.cabal-install
nix-env -iA "haskellPackages.cabal-install"
nix-env -iA haskellPackages.cabal-install
nix-env -iA libcurl.doc
nix-env -iA 'nixos.elmPackages.elm'
nix-env -iA 'nixpkgs.elmPackages.elm'
nix-env -iA 'nixpkgs.elmPackages.elm' -j8
nix-env -iA "nixpkgs.haskellPackages.cabal-install"
nix-env -iA nixpkgs.haskellPackages.ghcid
nix-env -iA nixpkgs.haskellPackages.idris
nix-env -iA 'pkgs.elmPackages.elm'
nix-env -iA pkgs.libcurl.doc
nix-env -i cabal
nix-env -i cabal2nix
nix-env -i elmPackages.elm
nix-env -i elmPackages.elm-compiler
nix-env -i ghcid
nix-env -i haskellPackages.cabal-install
nix-env -i nix
nix-env -i stack
nix-env '<nixpkgs>' -iA curl.devdoc
nix-env -qaP elm
nix eval
nix eval -f lol.nix
nix eval -f lol.nix
nix eval -f lol.nix -
nix eval -f lol.nix o
nix eval -f lol.nix x
nix eval --help
nix eval '(import ./lol.nix)'
nix eval 'import lol.nix;\
nix eval 'import lol.nix'
nix eval '(import ./lol.nix).drvPath'
nix-hash
nix-hash .
nix-hash lol
nix --help
nix-instantiate default.nix
nix-instantiate overlay.nix
nix ls-nar
nix ls-nar stack.nar
nix ls-nar stack.nar /
nix ls-nar stack.nar /bin
nix ls-nar stack.nar /bin/
nix ls-nar stack.nar /bin/stack
nix ls-nar stack.nar --help
nix ls-store
nix path-info
nix path-info --help
nix path-info --sigs
nix-prefetch-url
nix-prefetch-url --unpack
nix repl
nix-repl
nix-repl <nixpkgs>
nix-repl '<nixpkgs>'
nix rpel
nix-rpel
nix run
nix run carnix
nix run dotnet
nix run dotnet-sdk
nix run --help
nix run --hlep
nix run niginx
nix run nixpkg.nginx
nix run nixpkgs.cabal2nix
nix run nixpkgs.cabal-install
nix run nixpkgs.carnix
nix run nixpkgs.dotnet-sdk
nix run nixpkgs.gprolog
nix run nixpkgs.haskellPackages.cabal-install
nix run nixpkgs.hello -c
nix run nixpkgs.hello -c hello
nix run nixpkgs.hello -c hello --greeting "Hi"
nix run nixpkgs.hello -c hello --greeting yo
nix run nixpkgs.hello -c hello --greeting 'yo there'
nix run nixpkgs.hello -c hello --greeting yo there
nix run nixpkgs.hello -c hello --help "Hi"
nix run nixpkgs.hello -c hello -t
nix run nixpkgs.hello -c hello -v
nix run nixpkgs.mksquashfs
nix run nixpkgs.nginx
nix run nixpkgs.nginx -c nginx
nix run nixpkgs.nginx -c nginx --
nix run nixpkgs.nginx -c nginx --help
nix run nixpkgs.nginx -c nginx -p .
nix run nixpkgs.nginx -c nginx -p . -c nginx.conf
nix run nixpkgs.pandoc
nix run nixpkgs.prolog
nix run nixpkgs.squashfs
nix run nixpkgs.squashfsTools
nix run -p pandoc
nix search
nix search agda
nix search biber
nix search bison
nix search busybox
nix search dotnet-sdk
nix search echo
nix search ehco
nix search flex
nix search --help
nix search latexmk
nix search libpq
nix search ocesql
nix search postgresql
nix search postgresql.dev
nix search prolog
nix search squashfs
nix search yacc
nix-serve
nix shell
nix-shell
nix-shell
nix-shell -A env
nix-shell -A haskellPackages.exceptions.env
nix-shell -A haskellPackages.generics-mrsop
nix-shell -A haskellPackages.generics-mrsop-diff
nix-shell -A haskellPackages.generics-mrsop-diff.env
nix-shell -A haskellPackages.generics-mrsop-diff.env --help
nix-shell -A haskellPackages.generics-mrsop.env
nix-shell -A haskellPackages.servant.env
nix-shell -A ocesql
nix-shell -A oscesql
nix-shell -A oscesql -f default.nix
nix-shell -A recipes
nix-shell --arg compiler ghcHEAD
nix-shell --argstr compiler ghcHEAD
nix-shell --attr env
nix-shell --attr env default.nix
nix-shell --attr generics-mrsop-diff.env release.nix
nix-shell --attr generics-mrsop-diff release.nix
nix-shell --attr generics-mrsop.env release.nix
nix-shell -[ curl.doc
nix-shell default.nix
nix-shell default.nix
nix-shell default.nix --attr env
nix-shell default.nix --run 'cabal configure'
nix-shell elmPackages.elm
nix-shell -f default.nix
nix-shell -f default.nix --attr env
nix-shell -f '(import .default.nix).env'
nix-shell --help
nix-shell --help
nix-shell -j4 --cores 2 --argstr compiler ghcHEAD
nix-shell l
nix-shell '<nixpkgs>' -A haskellPackages.containers.env
nix-shell '<nixpkgs>' -A haskellPackages.exceptions.env
nix-shell '<nixpkgs>' -A haskellPackages.servant.env
nix-shell '<nixpkgs'> -A haskellPackages.servant.env
nix-shell '<nixpkgs>' -A haskellPackages.unordered-\containers.env
nix-shell '<nixpkgs>' -A haskellPackages.unordered-containers.env
nix-shell ocesql
nix-shell ocesql
nix-shell overlay.nix -A haskellPackages.generics-mrsop-diff.env
nix-shell -p agda
nix-shell -p agda.Agda
nix-shell -p agda.Agda.env
nix-shell -p agda.Agda.venv
nix-shell -p curl.devdoc
nix-shell -p curl.doc
nix-shell -p diffoscope
nix-shell -p diffoscope --cmd="./build.sh"
nix-shell -p diffoscope --run "./build.sh"
nix-shell -p 'elmPackages.elm'
nix-shell -p 'elmPackages.elm' -j8
nix-shell -p ghc
nix-shell -p haskell.compiler.ghcHEAD
nix-shell -p haskell.ghcHEAD
nix-shell -p haskellPackages.agda
nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [ pkgs.safe-money ])"
nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [ pkgs.safe-money pkgs.generics-sop ])"
nix-shell -p haskellPackages.lhs2tex
nix-shell -p haskellPackages.lhs2TeX
nix-shell -p 'haskellPackages.safe-money'
nix-shell -p lhs2TeX
nix-shell -p nixpkgs.haskell.compiler.ghcHEAD
nix-shell -p 'nixpkgs.haskellPackages.safe-money'
nix-shell release.nix
nix-shell release.nix --attr generics-mrsop
nix-shell --shell
nix-shell shell.nix
nix-shell --show-trace
nix show-config
nix show-derivation
nix show-derivation -f "lol.nix"
nix show-derivation lol.nix
nix show-derivation nixpkgs.nginx
nix show-derivation nixpkgs.nginx | grep gd
nix show-derivation pkgs.nginx
nix sign-path
nix sign-path --help
nix sign-paths
nix sign-paths --help
nix sign-paths -k foo.key
nix sign-paths -k foo.pub
nix-store
nix-store -d
nix-store --gc
nix-store --generate-binary-cache-key
nix-store --generate-binary-cache-key foo foo.key foo.pub
nix-store --generate-binary-cache-key foo foo.pub foo.key
nix-store --generate-binary-cache-key --help
nix-store --help
nix-store -q
nix-store -q --hlep
nix-store -q $(nix-instantiate)
nix-store -r $(nix-instantiate)
nix ubild
nix upgrade-nix
nix why-depends
nix why-depends --help
nix why-depends nginx fontconfig
nix why-depends nixpkgs.nginx nixpkgs.dejavu-fonts
nix why-depends nixpkgs.nginx nixpkgs.fontconfig
nix why-depends nixpkgs.nginx nixpkgs.font-config
nix why-depends nixpkgs.nginx nixpkgs.font-config'
Awesome, TYVM. Looking through this led me to investigate a few things and I have another explanation (that should probably become its own issue!):
The following reasonable set of behaviors cause the generation of borked profile links, which lead to having profile generations not GC roots.
This "works" on NixOS as well!
$ nix-env -iA nixpkgs.nix (or $ nix-env -iA nixos.nix on NixOS)nix upgrade-nix (let it find the profile to update)"upgrade-nix" will find profile to use by what's on PATH, and end up executing essentially the equivalent of what I suggested earlier (nix-env -p $HOME/.nix-profile).
Does that seem like something you might've done (your history shows nix upgrade-nix but do you think you had a copy of nix installed in your user profile, etc.?)?
Same question for you @chris-martin?
I did have Nix installed in my user profile at various times, and I believe I did run nix upgrade-nix at some point around the time this bug occurred, so that sounds like a great guess.
@dtzWill your hypothesis is 100% right:
I cannow 100% reproduce this issue on a new machine with the following commands:
$ curl https://nixos.org/nix/install | sh
$ nix-env -i nix
$ nix upgrade-nix
$ ls -al ~
-rw-r--r-- 1 arian users 52 Apr 25 13:06 .nix-channels
drwxr-xr-x 1 arian users 42 May 7 13:31 .nix-defexpr
lrwxrwxrwx 1 arian users 19 May 26 11:50 .nix-profile -> .nix-profile-1-link
lrwxrwxrwx 1 arian users 60 May 26 11:50 .nix-profile-1-link -> /nix/store/gw0lfkqwblnzdgy8cw37p3cnx45s42lb-user-environment
$ nix-store --gc
... and everything is thrown away
I ran into a similar issue, though I don't see that I've installed nix into a profile. I'm still pretty new to this, so it's totally possible that I did and can't find where I did it :).
If I run these commands, it breaks the install:
$ nix --version
nix (Nix) 2.0
$ nix upgrade-nix
[0.0 MiB DL]replacing old 'nix-2.0'
installing 'nix-2.0.4'
building '/nix/store/534zgisvk2vv2qkww3kdwl50vjrjxn53-user-environment.drv'...
created 29 symlinks in user environment
[0.0 MiB DL]
$ ls -ahl ~/.nix-profile*
lrwxrwxrwx 1 joneshf users 19 Jul 31 06:45 /home/joneshf/.nix-profile -> .nix-profile-1-link
lrwxrwxrwx 1 joneshf users 60 Jul 31 06:45 /home/joneshf/.nix-profile-1-link -> /nix/store/sd5s0l3f49ry8ahy8f2k6k387wnyf1cp-user-environment
$ nix-collect-garbage
finding garbage collector roots...
deleting garbage...
deleting '/nix/store/534zgisvk2vv2qkww3kdwl50vjrjxn53-user-environment.drv'
deleting '/nix/store/sd5s0l3f49ry8ahy8f2k6k387wnyf1cp-user-environment'
deleting '/nix/store/qip2ypc9nxnzaxwr1g5wfz0arnsj0m5r-env-manifest.nix'
deleting '/nix/store/trash'
deleting unused links...
note: currently hard linking saves -0.00 MiB
3 store paths deleted, 0.11 MiB freed
$ nix --version
zsh: command not found: nix
In similar fashion, here are the nix commands in my history file:
nix commands
$ cut -f2 -d';' ~/.zsh_history | grep '^nix' | sort | uniq
nix
nix-bazel
nix-build
nix-build -A
nix-build -A ./default.nix
nix-build -A default.nix
nix-build -A dhall-json release.nix
nix-build -A hel
nix-build -A helaslkjdaslkd
nix-build -A hello
nix-build -A hello-2.1.1
nix-build -A hello-2.1.2
nix-build -A hello.nix
nix-build --attr dhall-json release.nix
nix-build --attr dhall-json --show-trace release.nix
nix-build --attr project1 release0.nix
nix-build --attr project1 release-text.nix
nix-build default.nix
nix-build -E '(import {}).callPackage'
nix-build -E '(import {}).callPackage ./default.nix {}'
nix-build -E '(import {}).callPackage ./hello-2.1.1.nix {}'
nix-build --help
nix-build release0.nix
nix-build release2.nix
nix-build release-text.nix
nix-build --version
nix-channel
nix-channel --add http://nixos.org/channels/nixpkgs nixpkgs
nix-channel --add http://nixos.org/channels/nixpkgs-unstable unstable
nix-channel --add https://nixos.org/channels/nixos-18.03 nixpkgs
nix-channel --add https://nixos.org/channels/nixpkgs-unstable unstable
nix-channel --help
nix-channel list
nix-channel --list
nix-channel --list-generations
nix-channel --remove nixpkgs
nix-channel --rollback
nix-channel --update
nix-channel --version
nix-collect-garbage
nix-env
nix-env -e hello
nix-env -f "<nixpkgs>" -iA cabal2nix\
nix-env -f "<nixpkgs>" -iA cabal-install\
nix-env -f "<nixpkgs>" -iA nix-prefetch-git\
nix-env --help
nix-env -i hello
nix-env -i npm
nix-env --install --attr unstable.dhall
nix-env --install --attr unstable.dhall-json
nix-env --install --attr unstable.gephi
nix-env --install dhall-0.15.1
nix-env --install dhall-1.15.1
nix-env --list-generations
nix-env -q
nix-env -qa
nix-env -qa elm
nix-env -q elm
nix-env -qs
nix-env --query --available --attr-path dhall-format
nix-env --query --available --attr-path dhall-json
nix-env --query --available --attr-path gephi
nix-env --query --available --attr-path haddock
nix-env --query --available --attr-path unstable.haddock
nix-env --query --available --attr-path xdot
nix-env --query --available dhall
nix-env --query --available dhall-json
nix-env --query --available --help dhall-json
nix-env --query dhall
nix-env --query dhall-text
nix-env --query dhall-to-text
nix-env --uninstall cabal
nix-env --uninstall cabal-install
nix-env --uninstall gephi
nix-env --uninstall unstable.gephi
nix-env --version
nix --help
nix-install
nix-make
nix --query --available dhall
nix-shell
nix-shell -A env default.nix
nix-shell --attr env release0.nix
nix-shell default.nix
nix-shell dhall-1.15.1
nix-shell --help
nix-shell --list-generations
nix-shell --packages dhall
nix-shell --packages dhall-1.15.1
nix-shell -p elm-make --run 'elm-make --version'
nix-shell -p elmPackages.elm --run 'elm-make --help'
nix-shell -p elmPackages.elm --run 'elm-make --version'
nix-shell -p elmPackages --run 'elm-make --version'
nix-shell -p elm --run 'elm-make --version'
nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [])"
nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [pkgs.mtl])"
nix-shell -p hello
nix-shell -p node
nix-shell -p nodejs-4_x --run 'npm --version'
nix-shell -p nodejs-6_x --run 'npm --version'
nix-shell -p nodejs --run 'npm --version'
nix-shell -p node --run 'npm --version'
nix-shell -p npm
nix-shell -p npm --run 'npm --version'
nix-shell -p npm --run 'npm --version' --show-trace
nix-shell -p ruby --run 'elm-make --help'
nix-shell -p ruby --run 'irb --version'
nix-shell -p ruby --run 'ruby --version'
nix-shell -qa elm
nix-shell release0.nix
nix-shell --rollback
nix-stack
nix upgrade-nix
nix --version
Am I running into the same problem (and can't see where I've installed nix into a profile), or is this something different and I should make a new issue?
~/.nix-profile must point to a subdirectory of /nix/var/nix/profiles
if it does not, then nix will GC the entire profile on you
This was fixed in Nix 2.1 under https://github.com/NixOS/nix/issues/2175
Thanks for the hint, @arianvp. For anyone else encountering this issue right now and wanting a working solution, the full sequence of commands you should run is:
curl https://nixos.org/nix/install | sh
rm -i ~/.nix-profile*
ln -s /nix/var/nix/profiles/per-user/$(whoami)/profile ~/.nix-profile
I didn't know about the "fix" here, but even with the newest installer (tested today), I do not have /nix/var/nix/profiles/per-user/$(whoami)/profile generated by the installer or any other step. All I have in a new installation is ~/.nix-profile which points to ~/.nix-profile-1-link which points to /nix/store/hash-user-environment on a new installation. This causes nix-store --gc to delete everything, including the nix binary.
I got error: not an absolute path: '.nix-profile-1-link' when I try nix upgrade-nix in my windows ubuntu WSL. Does this relate to the issue?
@justinwoo @Rizary On 2018 Dec 5, I ran nix upgrade-nix to move from version 2.0.4 to 2.1.3. When I tried that again just now to move to 2.2.1, I got the dreaded:
error: not an absolute path: '.nix-profile-1-link'
Notice:
colin@yumi ~> la .nix-profile
lrwxrwxrwx 1 colin colin 19 Dec 5 14:55 .nix-profile -> .nix-profile-1-link/
colin@yumi ~> la .nix-profile-1-link
lrwxrwxrwx 1 colin colin 60 Dec 5 14:55 .nix-profile-1-link -> /nix/store/w66w1sgs1qj6cfcqp7ads8qavdys642l-user-environment/
Also strange is that the Nix manual advertises a completely different way to upgrade Nix.
The plot thickens. I just tried:
nix-channel --update
nix-env -iA nixpkgs.nix
as advertised in the manual, which gives me Nix 2.2 (although not 2.2.1 for some reason), and the following in my ~:
lrwxrwxrwx 1 colin colin 19 Dec 5 14:55 .nix-profile -> .nix-profile-1-link/
lrwxrwxrwx 1 colin colin 26 Mar 12 10:15 .nix-profile-1-link -> .nix-profile-1-link-1-link/
lrwxrwxrwx 1 colin colin 60 Mar 12 10:15 .nix-profile-1-link-1-link -> /nix/store/vjjrnk4vd80f3hmymdn1dv7xizciwg4r-user-environment/
They're multiplying.
Alright, I've gotten it. For the afflicted, here are the steps. This assumes that ls /nix/var/nix/profiles/per-user/YOU/ has NO profile* symlinks in it!
/nix/...ls -la ~ | grep nix-profile
This will tell you the true location of your most current Nix store, something like /nix/store/vjjrnk4vd80f3hmymdn1dv7xizciwg4r-user-environment
Now write the proper links:
cd /nix/var/nix/profiles/per-user/YOU/
ln -s /nix/store/vjjrnk4vd80f3hmymdn1dv7xizciwg4r-user-environment profile-1-link
ln -s profile-1-link profile
.nix-profile* symlinks in ~cd ~
rm .nix-profile # Don't include the trailing slash!
rm .nix-profile-1-link
# ... and so on
~/.nix-profile symlinkln -s /nix/var/nix/profiles/per-user/YOU/profile .nix-profile
And you should see output like the following:
colin@yumi ~> nix upgrade-nix
[29 copied (68.0 MiB), 16.1 MiB DL]
replacing old 'nix-2.2'
installing 'nix-2.2'
building '/nix/store/2xzdqa6c1kjw5a5pp1vw05d1gnnj3j73-user-environment.drv'...
created 6 symlinks in user environment
upgrade to version 2.2 done
colin@yumi ~> ls -la | grep nix-profile
lrwxrwxrwx 1 colin colin 44 Mar 12 10:31 .nix-profile -> /nix/var/nix/profiles/per-user/colin/profile
colin@yumi ~> cd /nix/var/nix/profiles/per-user/colin/
colin@yumi /n/v/n/p/p/colin> ls
channels@ channels-1-link@ channels-2-link@ profile@ profile-1-link@ profile-2-link@
Notice that the links got incremented correctly within /nix/..., but importantly not in your ~.
Good luck!
Thanks @fosskers, this fixed my desktop from constantly wiping itself. I'll try this on my latpop later this week. I hope you put this somewhere more easily found via Google with various keywords.
I can fire it on my personal blog.
I tried this same fix on my laptop, but unfortunately my ~/.nix-profile goes right back to referring to symlinks in ~/.nix-profile-1-link and so on, which then still causes everything to be deleted by nix-collect-garbage. This also means that after I run nix upgrade-nix, if I then generate a new profile, I cannot run nix upgrade-nix again as I get this:
[bash:~] $ nix upgrade-nix
error: not an absolute path: '.nix-profile-1-link'
@justinwoo same as what I was seeing here eh: https://github.com/NixOS/nix/issues/2070#issuecomment-472093170
What's your current nix --version? Maybe if we can at least get you to 2.2 first, the problem might go away.
Suggestion:
nix-channel --update; nix-env -iA nixpkgs.nixnix --version should now say 2.2 (and your symlinks will probably be funky still)nix upgrade-nixRight, I tried with the latest reporting 2.2 and all but it still didn't work, even after manually setting the symlink again.
@justinwoo can you paste in the output of:
ls -la ~ | grep nix-profile
ls -la /nix/var/nix/profiles/per-user/YOU/ | grep profile
@justinwoo same as what I was seeing here eh: #2070 (comment)
What's your current
nix --version? Maybe if we can at least get you to2.2first, the problem might go away.Suggestion:
- Do
nix-channel --update; nix-env -iA nixpkgs.nixnix --versionshould now say2.2(and your symlinks will probably be funky still)- Repeat the other steps
- Try a
nix upgrade-nix
this works, but before doing the other steps, make sure to delete all profile* in /nix/var/nix/profiles/per-user/YOU/
trying with my wsl and it works.
Not particularly useful after the fact, but a warning for this problem was also added to nix doctor.
$ nix doctor
Store uri: local
Warning: found profiles outside of /nix/var/nix/profiles.
The generation this profile points to might not have a gcroot and could be
garbage collected, resulting in broken symlinks.
/home/foo/.nix-profile/bin
Most helpful comment
I fixed it by doing:
```