I’ve been migrating my nixos config from channels to flakes and I think I’m ready to flip the switch.
However, one thing that concerned me when testing is that I couldn’t revert to using channels without rebooting into an older system build.
If I switch to flakes, nix-collect-garbage -d
, and want to switch back to channels, is there any way of doing it? Or am I stuck with flakes at that point? Thanks!
nix-collect-garbage
does not remove channels themselves so it should just work.
If you removed them, you can just add e.g. nixos-unstable
back using appropriate nix-channel
command (nix-channel --add
as root
, and do not forget nix-channel --update
afterwards).
One complication might be if you also unset NIX_PATH
(e.g. with nix.nixPath
option). Then you will need to pass the default values of the option to nixos-rebuild
using -I
flags or NIX_PATH
environment variable, or it will not be able to find Nixpkgs.
1 Like
I didn’t actually remove channels at all when testing, I just added flake.nix and rebuilt (in /etc/nixos, and I built a user-specific profile from a second one).
In both cases, removing the flake files and rebuilding (nixos-rebuild or nix-env -iA) without them errored out.
The profiles managed with nix profile
are not backwards compatible. I forgot about that since I avoid imperative package management.
The only other reason why nixos-rebuild
could fail that comes to mind is that you updated the Nixpkgs input and changed the NixOS config in a backwards incompatible way. Then it would not work with older version of Nixpkgs from a channel.
But it is really impossible to tell without a concrete error message.
Thanks, that link answers my question for nix-env
, do you have any idea about nixos-rebuild
?
Without a concrete error message, only the stuff mentioned above.
Error message when trying to revert to nixos-rebuild
with channels:
❯❯❯ sudo nixos-rebuild switch
error:
… while evaluating the attribute 'config'
at /nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source/lib/modules.nix:322:9:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
… while calling the 'seq' builtin
at /nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source/lib/modules.nix:322:18:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
(stack trace truncated; use '--show-trace' to show the full trace)
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)
at «none»:0: (source not available)
building Nix...
error:
… while evaluating the attribute 'config'
at /nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source/lib/modules.nix:322:9:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
… while calling the 'seq' builtin
at /nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source/lib/modules.nix:322:18:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
(stack trace truncated; use '--show-trace' to show the full trace)
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)
at «none»:0: (source not available)
building the system configuration...
error:
… while evaluating the attribute 'config.system.build.toplevel'
at /nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source/lib/modules.nix:322:9:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
… while calling the 'seq' builtin
at /nix/store/qgbn0imyridkb9527v6gnv6z3jzzprb9-source/lib/modules.nix:322:18:
321| options = checked options;
322| config = checked (removeAttrs config [ "_module" ]);
| ^
323| _module = checked (config._module);
(stack trace truncated; use '--show-trace' to show the full trace)
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)
at «none»:0: (source not available)
You either need to put your config’s entrypoint in /etc/nixos/configuration.nix
, or specify what the entrypoint is (using nixos-config
in NIX_PATH
, as the error instructs).
Config is at /etc/nixos/configuration.nix
(as before). I suspect it errors because it is expecting flake.nix
not configuration.nix
?
There is no default configuration path – NixOS relies on NIX_PATH
if NIXOS_CONFIG
environment variable is not set. But even if you set it, you might still not be using Nixpkgs from channels as mentioned above:
Thanks to everyone for their help, I’ve tested this out now:
-
Removing $XDG_STATE_HOME/nix/profiles/profile
let me revert to nix-env with no obvious problems (as per the above link nix profile - Nix Reference Manual). ![:sparkles: :sparkles:](https://discourse.nixos.org/images/emoji/twitter/sparkles.png?v=12)
-
However, noting $NIX_PATH before sudo nixos-rebuild switch
ing with flakes, then removing flake.nix
and calling the command again but manually setting $NIX_PATH didn’t let me revert to channels. I tried
-
NIX_PATH=... sudo nixos-rebuild switch
,
-
sudo NIX_PATH=... nixos-rebuild switch
, and
-
sudo nixos-rebuild -I ... swicth
,
but none of these worked—I got the same file 'nixos-config' was not found
error as above.
Weirdly I get warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
, even though all those files are clearly there when I check manually.
Ok, the incantation that works for nixos-rebuild is sudo nixos-rebuild switch -I nixos-config=/etc/nixos/configuration.nix
. Thanks to everyone for their help in solving this!
2 Likes