Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 60 additions & 20 deletions nixos/modules/installer/cd-dvd/iso-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
config,
lib,
utils,
pkgs,
...
}:
Expand Down Expand Up @@ -785,7 +786,11 @@ in
# specified on the kernel command line, created in the stage 1
# init script.
"/iso" = lib.mkImageMediaOverride {
device = "/dev/root";
device =
if config.boot.initrd.systemd.enable then
"/dev/disk/by-label/${config.isoImage.volumeID}"
else
"/dev/root";
neededForBoot = true;
noCheck = true;
};
Expand All @@ -794,7 +799,7 @@ in
# image) to make this a live CD.
"/nix/.ro-store" = lib.mkImageMediaOverride {
fsType = "squashfs";
device = "/iso/nix-store.squashfs";
device = "${lib.optionalString config.boot.initrd.systemd.enable "/sysroot"}/iso/nix-store.squashfs";
options = [
"loop"
]
Expand All @@ -809,18 +814,11 @@ in
};

"/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"
];
overlay = {
lowerdir = [ "/nix/.ro-store" ];
upperdir = "/nix/.rw-store/store";
workdir = "/nix/.rw-store/work";
};
};
};

Expand Down Expand Up @@ -882,9 +880,9 @@ in
# 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.kernelParams = lib.optionals (!config.boot.initrd.systemd.enable) [
"boot.shell_on_fail"
"root=LABEL=${config.isoImage.volumeID}"
];

fileSystems = config.lib.isoFileSystems;
Expand All @@ -901,6 +899,44 @@ in
"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
'';
};
};
Comment on lines +905 to +938
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(This is kind of gross, but I realize that doing anything about it is out of scope for this PR.)


# Closures to be copied to the Nix store on the CD, namely the init
# script and the top-level system configuration directory.
isoImage.storeContents = [
Expand Down Expand Up @@ -958,15 +994,19 @@ in
source = "${efiDir}/EFI";
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.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) [
{
source = "${pkgs.memtest86plus}/memtest.bin";
Expand Down
Loading