nixos/iso-image: Support systemd initrd (#291750)

Emily 46aad760 ea6374f0

Changed files
+60 -20
nixos
modules
installer
cd-dvd
+60 -20
nixos/modules/installer/cd-dvd/iso-image.nix
···
{
config,
lib,
pkgs,
...
}:
···
# specified on the kernel command line, created in the stage 1
# init script.
"/iso" = lib.mkImageMediaOverride {
-
device = "/dev/root";
neededForBoot = true;
noCheck = true;
};
···
# image) to make this a live CD.
"/nix/.ro-store" = lib.mkImageMediaOverride {
fsType = "squashfs";
-
device = "/iso/nix-store.squashfs";
options = [
"loop"
]
···
};
"/nix/store" = lib.mkImageMediaOverride {
-
fsType = "overlay";
-
device = "overlay";
-
options = [
-
"lowerdir=/nix/.ro-store"
-
"upperdir=/nix/.rw-store/store"
-
"workdir=/nix/.rw-store/work"
-
];
-
depends = [
-
"/nix/.ro-store"
-
"/nix/.rw-store/store"
-
"/nix/.rw-store/work"
-
];
};
};
···
# UUID of the USB stick. It would be nicer to write
# `root=/dev/disk/by-label/...' here, but UNetbootin doesn't
# recognise that.
-
boot.kernelParams = [
-
"root=LABEL=${config.isoImage.volumeID}"
"boot.shell_on_fail"
];
fileSystems = config.lib.isoFileSystems;
···
"overlay"
];
# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
isoImage.storeContents = [
···
target = "/EFI";
}
{
-
source = (pkgs.writeTextDir "grub/loopback.cfg" "source /EFI/BOOT/grub.cfg") + "/grub";
-
target = "/boot/grub";
-
}
-
{
source = config.isoImage.efiSplashImage;
target = "/EFI/BOOT/efi-background.png";
}
]
++ lib.optionals (config.boot.loader.grub.memtest86.enable && config.isoImage.makeBiosBootable) [
···
{
config,
lib,
+
utils,
pkgs,
...
}:
···
# specified on the kernel command line, created in the stage 1
# init script.
"/iso" = lib.mkImageMediaOverride {
+
device =
+
if config.boot.initrd.systemd.enable then
+
"/dev/disk/by-label/${config.isoImage.volumeID}"
+
else
+
"/dev/root";
neededForBoot = true;
noCheck = true;
};
···
# image) to make this a live CD.
"/nix/.ro-store" = lib.mkImageMediaOverride {
fsType = "squashfs";
+
device = "${lib.optionalString config.boot.initrd.systemd.enable "/sysroot"}/iso/nix-store.squashfs";
options = [
"loop"
]
···
};
"/nix/store" = lib.mkImageMediaOverride {
+
overlay = {
+
lowerdir = [ "/nix/.ro-store" ];
+
upperdir = "/nix/.rw-store/store";
+
workdir = "/nix/.rw-store/work";
+
};
};
};
···
# UUID of the USB stick. It would be nicer to write
# `root=/dev/disk/by-label/...' here, but UNetbootin doesn't
# recognise that.
+
boot.kernelParams = lib.optionals (!config.boot.initrd.systemd.enable) [
"boot.shell_on_fail"
+
"root=LABEL=${config.isoImage.volumeID}"
];
fileSystems = config.lib.isoFileSystems;
···
"overlay"
];
+
boot.initrd.systemd = lib.mkIf config.boot.initrd.systemd.enable {
+
emergencyAccess = true;
+
+
# Most of util-linux is not included by default.
+
initrdBin = [ config.boot.initrd.systemd.package.util-linux ];
+
services.copytoram = {
+
description = "Copy ISO contents to RAM";
+
requiredBy = [ "initrd.target" ];
+
before = [
+
"${utils.escapeSystemdPath "/sysroot/nix/.ro-store"}.mount"
+
"initrd-switch-root.target"
+
];
+
unitConfig = {
+
RequiresMountsFor = "/sysroot/iso";
+
ConditionKernelCommandLine = "copytoram";
+
};
+
serviceConfig = {
+
Type = "oneshot";
+
RemainAfterExit = true;
+
};
+
path = [
+
pkgs.coreutils
+
config.boot.initrd.systemd.package.util-linux
+
];
+
script = ''
+
device=$(findmnt -n -o SOURCE --target /sysroot/iso)
+
fsSize=$(blockdev --getsize64 "$device" || stat -Lc '%s' "$device")
+
mkdir -p /tmp-iso
+
mount --bind --make-private /sysroot/iso /tmp-iso
+
umount /sysroot/iso
+
mount -t tmpfs -o size="$fsSize" tmpfs /sysroot/iso
+
cp -r /tmp-iso/* /sysroot/iso/
+
umount /tmp-iso
+
rm -r /tmp-iso
+
'';
+
};
+
};
+
# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
isoImage.storeContents = [
···
target = "/EFI";
}
{
source = config.isoImage.efiSplashImage;
target = "/EFI/BOOT/efi-background.png";
+
}
+
]
+
++ lib.optionals (config.isoImage.makeEfiBootable && !config.boot.initrd.systemd.enable) [
+
# http://www.supergrubdisk.org/wiki/Loopback.cfg
+
# This feature will be removed, and thus is not supported by systemd initrd
+
{
+
source = (pkgs.writeTextDir "grub/loopback.cfg" "source /EFI/BOOT/grub.cfg") + "/grub";
+
target = "/boot/grub";
}
]
++ lib.optionals (config.boot.loader.grub.memtest86.enable && config.isoImage.makeBiosBootable) [