Hi, I wanted to use nh, but it only supports flake based systems, so I switched to using flakes by putting this in /etc/nixos/flake.nix
{
description = "A simple NixOS flake";
inputs = {
# NixOS official package source, using the nixos-24.05 branch here
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
};
outputs = { self, nixpkgs, ... }@inputs: {
# nixosConfigurations.hostname
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
# Import the previous configuration.nix we used,
# so the old configuration file still takes effect
./configuration.nix
];
};
};
}
It seemed to work, but after I eventually rebooted, it would fail like this when I try to rebuild:
$ sudo nixos-rebuild switch --impure
building the system configuration...
error:
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'nixos-system-nixos-add_uv'
whose name attribute is located at /nix/store/l2v78vdd33hvyyy33w9zih2ss60k2yms-source/pkgs/stdenv/generic/make-derivation.nix:333:7
… while evaluating attribute 'buildCommand' of derivation 'nixos-system-nixos-add_uv'
at /nix/store/l2v78vdd33hvyyy33w9zih2ss60k2yms-source/nixos/modules/system/activation/top-level.nix:53:5:
52| passAsFile = [ "extraDependencies" ];
53| buildCommand = systemBuilder;
| ^
54|
(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)
But it works if I specify nixos-config: sudo nixos-rebuild switch -I nixos-config=/etc/nixos/configuration.nix --impure
Checking with set
I see that NIX_PATH used to be this:
NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
Now it is this:
NIX_PATH=/home/alister/.nix-defexpr/channels:nixpkgs=flake:nixpkgs:/nix/var/nix/profiles/per-user/root/channels
If I set it manually like this I can even rebuild using nh:
NIX_PATH=/home/alister/.nix-defexpr/channels:nixpkgs=flake:nixpkgs:/nix/var/nix/profiles/per-user/root/channels:nixos-config=/etc/nixos/configuration.nix
I presume that nh
truly is building from the flake, because if I move configuration.nix
somewhere else and update the flake, then this still gives me a working system:
sudo touch /etc/nixos/configuration.nix
sudo nixos-rebuild switch -I nixos-config=/etc/nixos/configuration.nix --impure
So it seems like there is a check somewhere for nixos-config, even though it is actually not otherwise needed for a flakes build.
Is this a bug?
If not, can anybody advise on whether it all looks and behaves as you would expect?
- Does my
NIX_PATH
look right? Several things about it look wrong to me, but I don’t understand what would be causing them to be wrong. - Should I be adding something to my configuration to set
nixos-config
? Obviously I can resolve my problem by doing that, but I’d prefer not to blindly implement a workaround if something is broken. I haven’t seen this mentioned in the tutorials where I’ve seen thisflake.nix
, or by other people using it on their systems, and my understanding is that if flakes are enablednixos-rebuild
is supposed to look for/etc/nixos/flake.nix
by default, and if it does not exist, look for/etc/nixos/configuration.nix
. It doesn’t make sense to me that I would need to setnixos-config
to/etc/nixos/configuration.nix
if I am using/etc/nixos/flake.nix
, but not if I am using/etc/nixos/configuration.nix
directly… - If so, what would be the recommended thing to add, and where?
- Or should I be looking for some other problem something else?
Thanks.