Nixpkgs: Cannot nixos-install using other channels

Created on 22 Feb 2018  Â·  10Comments  Â·  Source: NixOS/nixpkgs

Issue description

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.

Steps to reproduce

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:~]# 

Technical details

  • system: "x86_64-linux"

    • host os: Linux 4.9.80, NixOS, 17.09.3008.c831224528c (Hummingbird)

    • multi-user?: no

    • sandbox: yes

    • version: nix-env (Nix) 1.11.16

    • channels(root): "nixos-unstable-18.03pre128553.8b1cf100cd8, nixos-17.09.3031.d09e425aea3"

    • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs

Most helpful comment

@emmanuelrosa Thank you for the suggestion! It works as expected, but I still wonder if nixos-install itself could understand options.

All 10 comments

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:

  1. Make a copy of nixos-install
  2. Neuter the copy so it prints out the commands it would run, but doesn't actually do anything. The commands of interest are those which use the extraBuildFlags array. The rest can go.
  3. Troubleshoot and get the script to use the extraBuildFlags array; This is where the options are supposed to go.
  4. Add a test (to the suite) which confirms options can be passed in.
  5. Run the test suite; All tests other than the new one should pass because you're proving the current installer ignores the options.
  6. Apply the fix to the real nixos-install.
  7. Run the test suite; All tests should pass.
  8. Submit pull request referencing this issue.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomberek picture tomberek  Â·  3Comments

ghost picture ghost  Â·  3Comments

edolstra picture edolstra  Â·  3Comments

grahamc picture grahamc  Â·  3Comments

ob7 picture ob7  Â·  3Comments