Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: initrd: Use systemd #120015

Closed
41 changes: 34 additions & 7 deletions nixos/modules/virtualisation/qemu-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,32 @@ in
# configuration, where the regular value for the `fileSystems'
# attribute should be disregarded for the purpose of building a VM
# test image (since those filesystems don't exist in the VM).
fileSystems = mkVMOverride (
fileSystems = let
roStore = {
device = "store";
fsType = "9p";
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ] ++ lib.optional (cfg.msize != null) "msize=${toString cfg.msize}";
neededForBoot = true;
};
in mkVMOverride (
cfg.fileSystems //
{ "/".device = cfg.bootDevice;
${if cfg.writableStore then "/nix/.ro-store" else "/nix/store"} =
{ device = "store";
fsType = "9p";
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ] ++ lib.optional (cfg.msize != null) "msize=${toString cfg.msize}";
neededForBoot = true;
{ "/" =
{ device = cfg.bootDevice;
autoFormat = true;
fsType = "ext4";
};
"/nix/store" = if !cfg.writableStore then roStore else {
device = "overlay";
fsType = "overlay";
options = [
"lowerdir=/sysroot/nix/.ro-store"
"upperdir=/sysroot/nix/.rw-store/store"
"workdir=/sysroot/nix/.rw-store/work"
"x-systemd.wants=rw-store.service"
"x-systemd.after=rw-store.service"
];
};
"/nix/.ro-store" = mkIf cfg.writableStore roStore;
"/tmp" = mkIf config.boot.tmpOnTmpfs
{ device = "tmpfs";
fsType = "tmpfs";
Expand Down Expand Up @@ -714,6 +731,16 @@ in
noCheck = true; # fsck fails on a r/o filesystem
};
});
boot.initrd.extraUnits."rw-store.service" = lib.mkIf cfg.writableStore (pkgs.writeText "rw-store.service" ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use our regular systemd unit generation for this? It is a trivial unit yet doesn't allow any composition (without adding a unit named rw-store.service.d/overrides.conf or such?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this, but I wasn't 100% sure if that would be too much. I'll look into it...

[Unit]
Before=sysroot-nix-store.mount
RequiresMountsFor=/sysroot/nix/.rw-store /sysroot/nix/.ro-store
DefaultDependencies=no
[Service]
ExecStart=${pkgs.coreutils}/bin/mkdir -p -m 0755 /sysroot/nix/.rw-store/store /sysroot/nix/.rw-store/work /sysroot/nix/.ro-store /sysroot/nix/store
Type=oneshot
RemainAfterExit=yes
'');

swapDevices = mkVMOverride [ ];
boot.initrd.luks.devices = mkVMOverride {};
Expand Down