arianvp / server-optimised-nixos

MIT License
76 stars 0 forks source link

Allow config activation in initrd #4

Open arianvp opened 4 years ago

arianvp commented 4 years ago

initrd should be able to get a NixOS config and nixos-install it to /sysroot before switch-root'ing to stage-2.

Initrd could use kernel parameter pointing to the configuration file; e.g.:

rd.nixos.systemConfig=https://arianvp.me/config.nix 

or a derivation:

rd.nixos.systemConfig=/nix/store/asdhkqhdequehyiqu-systemConfig.drv

or an output path (which must be substitutable by a cache, or already exist on /sysroot/nix/store):

rd.nixos.systemConfig=/nix/store/asdhkqhdequehyiqu-systemConfig

In the future; we might want to support Cloud metadata services through github.com/coreos/afterburn and allow user-data too.

Mechanism wil be implemented through a systemd-generator that orders a unit doing the realisation at the correct time in boot process (just after /sysroot is mounted).

See man bootup

arianvp commented 4 years ago

Something like this would work:

result=$(nix-build --store /sysroot --no-out-link @systemConfig@)
nixos-install --no-channel-copy --system $result --root /sysroot
arianvp commented 4 years ago

Pointing to a flake would also be an interesting option :)