When I try to install a new system with a configuration.nix
that references another channel nixos-install fails, even when I pass the location explicitly.
If configuration.nix
contains for example:
# Allows us to use packages from unstable channel
nixpkgs.config = {
allowUnfree = true;
packageOverrides = pkgs: {
unstable = import <nixos-unstable> {
config = config.nixpkgs.config;
};
};
};
Then I get:
[root@nixos:~]# nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
[root@nixos:~]# nixos-install
error: file ‘nixos-unstable’ was not found in the Nix search path (add it using $NIX_PATH or -I), at /mnt/etc/nixos/configuration.nix:17:25
(use ‘--show-trace’ to show detailed location information)
[root@nixos:~]#
Trying with -I
options:
[root@nixos:~]# nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
[root@nixos:~]# nixos-install -I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos-unstable.nixpkgs
error: file ‘nixos-unstable’ was not found in the Nix search path (add it using $NIX_PATH or -I), at /mnt/etc/nixos/configuration.nix:17:25
(use ‘--show-trace’ to show detailed location information)
[root@nixos:~]#
And even:
[root@nixos:~]# nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
[root@nixos:~]# export NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos-unstable/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels/"
[root@nixos:~]# nixos-install -I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos-unstable/nixpkgs
error: file ‘nixos-unstable’ was not found in the Nix search path (add it using $NIX_PATH or -I), at /mnt/etc/nixos/configuration.nix:17:25
(use ‘--show-trace’ to show detailed location information)
[root@nixos:~]#
"x86_64-linux"
Linux 4.9.80, NixOS, 17.09.3008.c831224528c (Hummingbird)
no
yes
nix-env (Nix) 1.11.16
"nixos-unstable-18.03pre128553.8b1cf100cd8, nixos-17.09.3031.d09e425aea3"
/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs
When you use something like import <nixos-unstable>
the label between the brackets refers to the labels such as nixpkgs
and nixos-config
in NIX_PATH
. Assuming you have NixOS stable and unstable channels, have you tried something like this:
[root@nixos:~]# nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
[root@nixos:~]# export NIX_PATH="nixos-unstable=/nix/var/nix/profiles/per-user/root/channels/nixos-unstable/nixpkgs:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels/"
[root@nixos:~]# nixos-install
The idea here is that <nixpkgs>
refers to the channel named _nixos_ (which would be the stable channel) and <nixos-unstable>
refers to the channel named _nixos-unstable_.
Not sure if this is related, but I feel like nixos-install
ignores --option …
flags completely. For example, when I'm trying to speed up the install like that nixos-install --option extra-binary-caches http://my-server:8080 --option require-sigs false
it just ignores it and downloads everything from https://cache.nixos.org
, which is long and expensive (at least for me :disappointed: ). Same options used with nix-env
do work and everything gets downloaded lightning-fast.
That's weird. The source code suggests that --option
gets passed to nix build
.
As a work-around you can build the system directly with nix-build
and then pass that system to nixos-install
to finish the installation. Something like this:
nix-build -I nixos-config=/mnt/etc/nixos/configuration.nix '<nixos>' --option extra-binary-caches http://my-server:8080 --option require-sigs -A system
nixos-install --system ./result
rm ./result
@emmanuelrosa Thank you for the suggestion! It works as expected, but I still wonder if nixos-install
itself could understand options.
@emmanuelrosa Yes, I also looked at the source and thought it would pass the options, but it did not seem to. Thanks for the workaround suggestion at least.
The great thing about NixOS is that if you have a itch -something that just doesn't work right- you don't need anyone's permission to jump in and fix it. And if you get stuck you can always get help on the #nixos IRC channel on freenode.net.
That said, the installer is a critical component which luckily has a comprehensive test suite. Here's how I'd approach fixing this:
nixos-install
extraBuildFlags
array. The rest can go.extraBuildFlags
array; This is where the options are supposed to go.nixos-install
.I won't be working on this issue because it's not my itch. But I'm willing to help with the testing.
I'm trying: nix-build -I nixos-config=/mnt/etc/nixos/configuration.nix '<nixos>' -A system
But this gives me an error of expression does not evaluate to a derivation (or a set or list of those)
?
@chrissound It should probably be <nixpkgs/nixos>
, unless you have nixos
pointing to nixos
directory of nixpkgs
repository in your NIX_PATH
.
@jtojnar thanks! That fixed that issue in particular.
Been struggling with this issue once again, till I realized I forgot to nix-channel --update
after adding the channel.
Most helpful comment
@emmanuelrosa Thank you for the suggestion! It works as expected, but I still wonder if
nixos-install
itself could understand options.