Open falsifian opened 4 years ago
The logic in the perl script to choose which devices get included in hardware-configuration is pretty rudimentary, it just excludes files and zram devices, and includes everything else. The only robust way I can think of to selectively exclude block devices would be for the nixos derivation to produce a list of devices that should be skipped, instead of trying to decide in the perl script.
For example, what if every swapDevices
entry had a property autoGenerated
which defaults to false, but all the swap entries in hardware-configuration.nix would have this set to true. On every rebuild, nix could produce a list at sw/share/nixos/manualy-configured-swap-devices
which contains all the devices with autoGenerated=false
, and the perl script would just skip these.
Since the UUID of randomly encrypted devices is not known at build time, but the /dev/mapper/*
path is, the nix derivation could add the latter to the blacklist, and the perl script could be modified to prefer the /dev/mapper/*
form over the /dev/disk/by-uuid/*
form, unless anyone knows of a case where that would cause problems.
@buckley310 Sounds good as far as I can tell.
I still think it would be simpler to put filesystems and swap in configuration.nix
rather than hardware-configuration.nix
, so that nixos-generate-config
just doesn't touch that stuff after the initial install. But maybe there's a reason I'm not thinking of for having it the way it is.
This took less effort than i expected. I'm working on it here https://github.com/buckley310/nixpkgs/tree/swap-tracking Still need to test it some more...
i think the reason filesystems go in the hardware config is so that its technically possible to have everything except the hardware config shared across multiple machines, but I'm not totally sure. I don't use it that way.
Thanks for working on that. I'm not currently running the NixOS installation where I encountered that problem, but will keep your WIP in mind if I boot that up again.
I marked this as stale due to inactivity. → More info
Describe the bug My swap devices are encrypted with random keys, using
swapDevices.*.randomEncryption.enable = true
.When I run
nixos-generate-config
, I get something like this inhardware-configuration.nix
:The trouble is, those uuids won't exist on the next boot (I think they're different every time), so NixOS hangs for 90 seconds during boot waiting for them to appear.
I know of three workarounds:
hardware-configuration.nix
to remove them. But I'm not supposed to edit that file, according to the comment at the top.lib.mkForce
inconfiguration.nix
to override theswapDevices
fromhardware-configuration.nix
. But this breakszramSwap
: see https://github.com/NixOS/nixpkgs/issues/86061nixos-generate-config
has a--no-filesystems
option. I haven't tried it yet, but I assume it will fix my problem.To Reproduce
randomEncryption
. For example, myconfiguration.nix
is posted here. To properly reproduce the problem, you should leave outmkForce
from theswapDevices
attribute (I put that in as a workaround.)randomEncryption
enabled, run nixos-generate-config. Observe theswapDevices
entry inhardware-configuration.nix
pointing to ephemeral UUIDs.nixos-rebuild boot
and reboot, and you didn't use themkForce
workaround, then you should see the system hang for 90s on boot waiting for those old ephemeral UUIDs to appear.Expected behavior
nixos-generate-config
should not add the swap devices tohardware-configuration.nix
.(Why do filesystems and swap devices go into
hardware-configuration.nix
rather thanconfiguration.nix
? It seems like it's useful to have those automated the first time I install NixOS, but I can't think of a reason I'd wantnixos-generate-config
to change them on its own later. Havingnixos-generate-config
put them inconfiguration.nix
would achieve the behaviour I want, which is to not mess with them after installation.)Notify maintainers Picking on two people who authered recent-ish commits in
nixos-generate-config.pl
: @bjornfor @buckley310Metadata Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result."x86_64-linux"
Linux 5.4.33, NixOS, 20.03.1445.95b9c99f6d0 (Markhor)
yes
yes
nix-env (Nix) 2.3.4
""
"nixos-20.03.1445.95b9c99f6d0"
/nix/var/nix/profiles/per-user/root/channels/nixos
Maintainer information: