NixOS packages are not upgrading even though I am certainly configured to 'unstable' system state

My NixOS is out of date and I can’t upgrade it. I have a hunch the issue is related to the way I am handling my configuration.nix. I’ve tried to symbolically link my etc nixos directory to a location inside my home user directory. I am doing something wrong but I am not sure what exactly.

Here is the output of:

$ uname -a
Linux nixoslaptop 6.6.69 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jan  2 09:32:11 UTC 2025 x86_64 GNU/Linux

As you can see, I am running Linux v6.6.69. This shouldn’t be the case because search.nixos.org when looking up linux, the unstable branch expects v6.12.12. Also take note the last build date from uname above shows “January 2nd 2025” which means the kernel I am running is over 1 month old.

I am indeed on unstable and not 24.11 as you can see with this output here:

$ sudo nix-channel --list
nixos https://channels.nixos.org/nixos-unstable

Here is where I think the issue is:

Basic switch output
$ sudo nixos-rebuild switch
error:
       … while calling the 'seq' builtin
         at /nix/store/apfqvr9kddcl6fscjvb92p4xdrqzcwk0-source/lib/modules.nix:334:18:
          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       … while evaluating a branch condition
         at /nix/store/apfqvr9kddcl6fscjvb92p4xdrqzcwk0-source/lib/modules.nix:273:9:
          272|       checkUnmatched =
          273|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
             |         ^
          274|           let

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: access to absolute path '/home' is forbidden in pure evaluation mode (use '--impure' to override)

Similarly:

Just switch with upgrade
$ sudo nixos-rebuild switch --upgrade
unpacking 1 channels...
error:
       … while calling the 'seq' builtin
         at /nix/store/apfqvr9kddcl6fscjvb92p4xdrqzcwk0-source/lib/modules.nix:334:18:
          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       … while evaluating a branch condition
         at /nix/store/apfqvr9kddcl6fscjvb92p4xdrqzcwk0-source/lib/modules.nix:273:9:
          272|       checkUnmatched =
          273|         if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
             |         ^
          274|           let

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: access to absolute path '/home' is forbidden in pure evaluation mode (use '--impure' to override)

So I resolved to appending --impure to the end of my command when I invoke switch:

The output for the command I usually use
$ sudo nixos-rebuild switch --upgrade --impure
unpacking 1 channels...
building the system configuration...
evaluation warning: The option `hardware.pulseaudio' defined in `/nix/store/0agswvb80frv1qqbq32ng1qz15bc7w87-source/configuration.nix' has been renamed to `services.pulseaudio'.
activating the configuration...
setting up /etc...
reloading user units for evangelist...
restarting sysinit-reactivation.target
the following new units were started: NetworkManager-dispatcher.service, sysinit-reactivation.target, systemd-tmpfiles-resetup.service

As you can see in the output, the traceback shows work is being done but before and after, the packages remain the same - - everything is out dated. What might you people recommend I try next? How can I better handle my /etc/nixos/configuration.nix?

Even when running upgrade along with impure, work is being done but my system packages remain out of date.

Even with upgrade and impure, here is the output
$ sudo nixos-rebuild switch --upgrade --impure
[sudo] password for evangelist: 
unpacking 1 channels...
building the system configuration...
evaluation warning: The option `hardware.pulseaudio' defined in `/nix/store/0agswvb80frv1qqbq32ng1qz15bc7w87-source/configuration.nix' has been renamed to `services.pulseaudio'.
activating the configuration...
setting up /etc...
reloading user units for evangelist...
restarting sysinit-reactivation.target
the following new units were started: NetworkManager-dispatcher.service

Here is my latest configuration.nix hosted on GitHub. There are a few things to notice. I initialized the repo on January 4th which matches the age of my kernel. As you can see, I have added multiple packages iteratively and progressively over time. When I do and run $ sudo nixos-rebuild switch --upgrade –impure the NixOS package manager installs the packages. It’s just all prior packages remain obsolete and aren’t being upgraded along with the new packages I am adding. It’s also worth pointing out that at line 240 I have correctly specified `system.stateVersion = “unstable”;

Please note: I realize my configuration.nix on GitHub is a disaster currently. I intend on reorganizing and modularizing it next. Then I am going to learn Flakes.

you’ve run sudo nix-channel --update before trying your rebuild, yes?

I took a peek at the manual page for nixos-rebuild and here’s what it says about --upgrade flag:

  --upgrade, --upgrade-all
           Update the root user's channel named ‘nixos’ before rebuilding the system.

           In addition to the ‘nixos’ channel, the root user's channels which have a file named ‘.update-on-nixos-rebuild’ in their base directory will also be updated.

           Passing --upgrade-all updates all of the root user's channels.

system.stateVersion should stay at the NixOS version you installed originally, e.g. “24.11”. “unstable” is not a valid value.

Other than that, everything looks alright to me, but I am not familiar with non-flake setups. However, the error about “pure evaluation mode” sounds like a flake may be involved. Are you sure that there is no flake in /etc/nixos?

3 Likes

The comment in your config explains why it is important to keep it at the initial value, by the way: nixoslaptop-configs/configuration.nix at 7fa0e855fabece12b77ed3e604def3fceb846627 · enoren5/nixoslaptop-configs · GitHub

1 Like

Thank you both @Fitis and @TLATER for highlighting the importance of keeping this value unchanged. I reverted unstable back to the original 24.11.

This is a key observation. I checked /etc/nixos and you are right that there were two flake files. I removed them.

Next I went to run: $ sudo nixos-rebuild switch --upgrade-all (as per @rjpc and the official docs) and am getting this new traceback:

Still can't build due to this flakes error
$ sudo nixos-rebuild switch --upgrade-all
[sudo] password for evangelist: 
unpacking 1 channels...
unpacking 1 channels...
error:
       … while calling the 'import' builtin
         at «string»:1:6:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |      ^

       … while realising the context of a path

       … while calling the 'findFile' builtin
         at «string»:1:13:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |             ^

       error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
building Nix...
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
/tmp/nixos-rebuild.72ZkhG/nix
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
building the system configuration...
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it

I have this issue because I am relatively new to NixOS and jumped into learning about Flakes too soon. I began following ryan4yin’s Unofficial Flakes Book but after getting a few modules in, I realized I was not ready. I tried to backout by restoring the changes I made and now I am still dealing with a semi-broken nix package manager.

Given the traceback above, how do I tell nixpkgs to rebuild my system without the flakes error?

Looks like there’s still some flake involved - the error seems to say rebuild run into a flake & couldn’t build it.

FWIW it’s relatively simple to switch into a flake. The following flake.nix should work. Mind you, writing this by hand, watch your step.

{
  description = "My NixOS configuration";
  outputs = { nixpkgs, ...}: {
    nixosConfigurations.nixoslaptop = nixpgks.lib.nixosSystem {
      system = "x86_64-linux"; # Wild guess
      modules = [
        ./configuration.nix
      ];
    };
  };
}

This would take the current unstable nixpkgs & allow you to keep your config as-is. Though it would also pin nixpkgs at the point you’ve first run it and --upgrade would no longer work. The quickest (and not really recommended) way to upgrade would be to delete flake.lock and let it be regenerated.

That being said, not sure if that’s the setup I’d consider using, unless trying to get out of a pinch.

I don’t think you should be forced to switch to an experimental feature (flakes) if you’ve no interest in it.

Can you list out the contents of /etc/nixos:

ls -al /etc/nixos

And the contents of NIX_PATH:

sudo printenv NIX_PATH

And are you using a custom nixos-rebuild script?

4 Likes

As per your request @waffle8946:

$ sudo printenv NIX_PATH
nixpkgs=flake:nixpkgs:/nix/var/nix/profiles/per-user/root/channels
$ pwd
/etc/nixos
$ ls -la
total 12
drwxr-xr-x  2 root root 4096 Feb  5 18:13 .
drwxr-xr-x 39 root root 4096 Feb  4 18:53 ..
lrwxrwxrwx  1 root root   54 Jan  4 02:41 configuration.nix -> /home/evangelist/nixoslaptop-configs/configuration.nix
lrwxrwxrwx  1 root root   63 Jan  4 02:55 hardware-configuration.nix -> /home/evangelist/nixoslaptop-configs/hardware-configuration.nix
$

I am not sure what you mean by custom rebuild script. May you elaborate a little further?

The only configuration.nix I am using is the one in my GitHub repo linked to in my OP and the only command I am using right now to rebuild my system is: $ sudo nixos-rebuild switch --upgrade-all No custom script with extra paramaters.

And here’s the culprit:
Your NIX_PATH makes <nixpkgs> refer to a flake.

Could you try setting

NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels

and rebuilding?

2 Likes

Thank you @Torinthiel. We’re making progress. I need to reset my NIX_PATH environment variable. I suppose you provided what is required but being the NixOS novice that I am, I am still struggling to export this variable properly. Here is what I have tried so far without success:

$ sudo export NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels 
sudo: export: command not found
$ sudo export NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels"
sudo: export: command not found

Even if one of those exports succeeded, the environemnt variable would only be valid for the shell’s session. So that is not really what I need. I even tried running the exports without sudo. While the shell didn’t give me sudo related pushback, running the rebuild upgrade commands still showed the same flakes error.

I gather NixOS is an operating system expressed as code, so the right way to universally apply an enviornment variable system wide would be inside configuration.nix or elsewhere. I used the NixOS search tool and found the entry for evaluating environment variable expressions. To this end I tried adding:

environment.variables = {
   NIX_PATH = "nixpkgs=/nix/var/nix/profiles/per-user/root/channels";
   }

…to my configuration.nix and ran the rebuild command. No dice. Furher guidance is welcome.

You have two ways to proceed. Both should be equivalent.

Either run

sudo -i
export NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels 
nixos-rebuild switch --upgrade all

sudo -i drops you in root shell, where you can normally run other two. As you’ve noted, running export with sudo won’t do much as it’ll work only in the now-defunct session.

The other way would be
sudo NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels nixos-rebuild switch --upgrade all as a single command.
This one uses less-known (ba)sh feature that assignments preceeding command are valid for that command (and not after that), so an export is not necessary.

Either way, it should be fine after you rebuild your system. The NIX_PATH setting that was causing problems came from the fact that you’ve rebuilt your system using flake, and would be gone once you rebuld w/o flakes.

The reason setting environment.variables in configuration.nix didn’t work is that it would only take effect after you rebuilt. But please remove it, it’ll conflict with what nixos is doing by default. And while it would work for now, it’d probably hit you when you’ve forgotten about it (like your stray flake files in the first place).

Credit for solving the issue goes to @waffle8946, he found the correct thing to check, while at the same time resisting my attempt to force you into flake-world, which wouldn’t really help here (and I agree that forcing you into it was a bad idea).

And the 'custom nixos-rebuild scriptwas (I think) whether you are using plainnixos-rebuild` or some kind of wrapper/reimplementation (that would add to places that needed checking).

Either way, if anything more appears I’ll try to answer in a few hours, right now it’s bedtime in my area :wink:

1 Like

I appreciate your patience and the careful thought you have put in these responses.

I have tried both sets of commands. They both show different errors and a flakes issue persists. Here they are:

First suggestion
$ sudo -i

# export NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels 
nixos-rebuild switch --upgrade-all   
unpacking 1 channels...
unpacking 1 channels...
error: attribute 'system' missing
       at «string»:1:33:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |                                 ^
building Nix...
error: attribute 'nix' in selection path 'config.nix.package.out' not found
error: opening file '/nix/store/bjr17hv9r2fqk5g13wm8ij5rlddgl5ny-user-environment/default.nix': No such file or directory
error: file 'nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)
/tmp/nixos-rebuild.CHQkKS/nix
building the system configuration...
error: expression does not evaluate to a derivation (or a set or list of those)
#
Second suggestion
$ sudo NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels nixos-rebuild switch --upgrade-all
unpacking 1 channels...
unpacking 1 channels...
error:
       … while calling the 'import' builtin
         at «string»:1:6:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |      ^

       … while realising the context of a path

       … while calling the 'findFile' builtin
         at «string»:1:13:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |             ^

       error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
building Nix...
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
/tmp/nixos-rebuild.FtUBIg/nix
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
building the system configuration...
error: experimental Nix feature 'flakes' is disabled; add '--extra-experimental-features flakes' to enable it
$

Noted. I made the change to my configuration.nix but stashed the changes effectively removing those lines.

It’s bed time for me too now. I will be back tomorrow when I can. Hopefully you @Torinthiel or another forum member can jump in here and advise on some things we can try next.

Fine. The second message is identical to what you got previously and it triggers yet another less-known behaviour. I didn’t know sudo is interpretting those and not handing over to bash. Which means that standard user setup later overrides it. Learned something new today. :slight_smile:

As for the first, I’m lost. I need to stop pretending I know what’s happening and try to reproduce your issue. Or allow someoneelseto step in.

@enoren5 I think I get it now, hopefully one last try.

Please try

sudo -i
export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels 
nixos-rebuild switch --upgrade-all   

This is almost as before - the last two commands need to be entered in the root shell that sudo -i gives. The only difference is removed nixpkgs= from NIX_PATH. That’s because the /nix/var/nix/profiles/per-user/root/channels dir already contains nixpkgs subdir (or so it does during my experiments), so it’s unnecessary to give it twice.

If that fails, please also give result of ls -l /nix/var/nix/profiles/per-user/root/channels/ (mind the / at end, it’s important), and we’ll try to debug it further.

2 Likes

Still not quite where we want to be. We are now getting related but I think different output. Rather than complaining about flakes, we are now seeing errors involving NixOS environment variables. So I think we are on the right track at least. Thank you for your insight and patience so far @Torinthiel

Here is the latest - -

New recommended command
$ sudo -i
[sudo] password for evangelist: 
root@nixoslaptop:~/ > export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels 
root@nixoslaptop:~/ > nixos-rebuild switch --upgrade-all   
unpacking 1 channels...
unpacking 1 channels...
error:
       … while calling the 'import' builtin
         at «string»:1:6:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |      ^

       … while realising the context of a path

       … while calling the 'findFile' builtin
         at «string»:1:13:
            1| with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild
             |             ^

       error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)
building Nix...
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
error: file 'nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)
/tmp/nixos-rebuild.IUBb6K/nix
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
building the system configuration...
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)
Follow up suggested command
root@nixoslaptop:~/ > ls -l /nix/var/nix/profiles/per-user/root/channels/
total 4
lrwxrwxrwx 1 root root 60 Dec 31  1969 manifest.nix -> /nix/store/mk4vvia5jfslz6irdqj7g11r636vlmsa-env-manifest.nix
lrwxrwxrwx 1 root root 55 Dec 31  1969 nixos -> /nix/store/f5asbabknqlhipxigbax2d5vpk7qm5q1-nixos/nixos
root@nixoslaptop:~/ > 

I’m beginning to wonder how it has worked in the first place (before you somehow switched to flakes) , which probably means I’m wrong somewhere.
You see, your channels (as given by the last command’s output and also output from nixos-channel - - list from your 1st post) has proper nixos channel, but under name ‘nixos’, while it should be ‘nixpkgs’.

I’ve even double-checked that, while default installation manual mentions nothing, one for installing from different linux (NixOS Manual) has an explicit step

nix-channel --add https://nixos.org/channels/nixos-<version> nixpkgs

that registers the nixos channel under (local) name nixpkgs.

That being said, if you still want to follow my advice (I won’t be offended if you don’t), I would run nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs
just before running nixos-rebuild (after sudo & export NIX_PATH).
Keep in mind that this will leave you with tracking the same channel twice, under two different local names. No big harm done, we should be able to clean this up after we deal with nixos-rebuild failing.

I am not quite sure if I understood the order in which all the new set of commands should be entered, but here is the latest:

root@nixoslaptop:~/ > export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels       
root@nixoslaptop:~/ > nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs
root@nixoslaptop:~/ > nixos-rebuild switch --upgrade-all                                 
error: filesystem error: read_symlink: No such file or directory [/nix/var/nix/profiles/per-user/root/channels/nixpkgs]
root@nixoslaptop:~/ > 

I asked Gemini AI this question:

What does this error mean?
root@nixoslaptop:~/ > nixos-rebuild switch --upgrade-all
error: filesystem error: read_symlink: No such file or directory [/nix/var/nix/profiles/per-user/root/channels/nixpkgs]

Here was its response:

That error message is telling you that NixOS can’t find the nixpkgs channel at the path it’s expecting: /nix/var/nix/profiles/per-user/root/channels/nixpkgs. This usually means one of the following:

  1. No nixpkgs Channel Added: You haven’t added the nixpkgs channel yet. This is the most likely cause.
  2. Incorrect Path: The path /nix/var/nix/profiles/per-user/root/channels/nixpkgs is the default location, but it’s possible (though less common) that your nixpkgs channel is installed somewhere else.
  3. Permissions Issues (Less Likely): It’s possible (but less probable) that there’s a permissions problem preventing Nix from accessing that directory.
  4. Corrupted Nix Installation (Rare): In very rare cases, a corrupted Nix installation could cause this.

There was more to it. I hope the issue I have is not #4.

When I log out of the native root enviornment and return as a regular user and begin using sudo again, below is a sample of some of the output I am receiving now.

$ sudo nix-channel --update nixos-unstable
[sudo] password for evangelist: 
error: filesystem error: read_symlink: No such file or directory [/nix/var/nix/profiles/per-user/root/channels/nixpkgs]

$ sudo nixos-rebuild switch --upgrade-all
error: filesystem error: read_symlink: No such file or directory [/nix/var/nix/profiles/per-user/root/channels/nixos-unstable]

$ sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable

$ sudo nix-channel --update nixos-unstable
error: filesystem error: read_symlink: No such file or directory [/nix/var/nix/profiles/per-user/root/channels/nixpkgs]

$ sudo nixos-rebuild switch --upgrade-all
error: filesystem error: read_symlink: No such file or directory [/nix/var/nix/profiles/per-user/root/channels/nixos-unstable]

$ sudo nix-channel --list
[sudo] password for evangelist: 
nixos https://channels.nixos.org/nixos-unstable
nixos-unstable https://nixos.org/channels/nixos-unstable
nixpkgs https://nixos.org/channels/nixos-unstable

The order of commands was exactly what I had in mind (that doesn’t say it was correct :wink: though). I had anticipated --upgrade-all to nixos rebuild would update it before using, and I’m proven wrong. Hopefully what you see is a variant of #1, namely channel is added but not updated. Try running sudo nix-channel --update without additional arguments. If it works (I relly hope so, and I had similar error message when updating a single channel when others were missing), go on with the previous sudo/export NIX_PATH/nixos-rebuild dance. No need to use nix-channel --add again.

1 Like