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
25 changes: 12 additions & 13 deletions nixos/modules/system/boot/systemd-units.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
runCommand "systemd-units" { } ''
set -euo pipefail
mkdir $out
(cd ${systemd}/example/systemd; find . -type f) | while read -r f; do
(cd ${systemd}/example/systemd; find . -type f -o -type l) | while read -r f; do
mkdir -p $out/$(dirname "$f")
cp "${systemd}/example/systemd/$f" "$out/$f"
cp -d "${systemd}/example/systemd/$f" "$out/$f"
done

# TODO: I believe much of this can be fixed by using -type l and cp -d above,
# but that brings a lot more units with a lot more problems.
mkdir $out/system/initrd.target.wants
ln -s ../systemd-udevd.service $out/system/initrd.target.wants/systemd-udevd.service
ln -s ../systemd-modules-load.service $out/system/initrd.target.wants/systemd-modules-load.service
ln -s ../systemd-journald.service $out/system/initrd.target.wants/systemd-journald.service
ln -s ../systemd-ask-password-console.service $out/system/initrd.target.wants/systemd-ask-password-console.service
ln -s ../systemd-vconsole-setup.service $out/system/initrd.target.wants/systemd-vconsole-setup.service
ln -s ../systemd-udev-settle.service $out/system/initrd.target.wants/systemd-udev-settle.service
ln -s ../systemd-udev-trigger.service $out/system/initrd.target.wants/systemd-udev-trigger.service
mkdir $out/system/sysinit.target.wants
ln -s ../cryptsetup.target $out/system/sysinit.target.wants

# For some reason, running 'udevadm info --cleanup-db' in initrd causes
# LUKS devices to get SYSTEMD_READY=0 in stage 2 (but not other devices)
# which prevents LUKS encrypted file systems from being mounted in stage 2.
rm $out/system/initrd-udevadm-cleanup-db.service

ln -s ../plymouth-start.service $out/system/initrd.target.wants/plymouth-start.service

rm $out/system/proc-sys-fs-binfmt_misc.automount
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a good advice of developers when to add a line here? Previously units were opt-in and now we have some list of units that we don't want anymore.

For example I could see why we want the random seed in the initrd when unlocking the system using some network interaction that requires cryptography.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These services were simply the ones that created errors during boot. I didn't spend much time trying to figure out why they caused errors.

rm $out/system/systemd-random-seed.service
rm $out/system/systemd-update-utmp.service
rm $out/system/systemd-update-done.service
rm $out/system/systemd-sysctl.service
rm $out/system/systemd-hwdb-update.service

rm $out/system/default.target
ln -s initrd.target $out/system/default.target

${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: u: ''
Expand Down