Merge pull request #230777 from nikstur/systemd-repart-definitions-in-initrd

systemd-repart definitions in initrd
This commit is contained in:
Florian Klink 2023-05-09 13:24:04 +03:00 committed by GitHub
commit 6c9bef6b0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,11 +72,6 @@ in
}; };
config = lib.mkIf (cfg.enable || initrdCfg.enable) { config = lib.mkIf (cfg.enable || initrdCfg.enable) {
# Always link the definitions into /etc so that they are also included in
# the /nix/store of the sysroot during early userspace (i.e. while in the
# initrd).
environment.etc."repart.d".source = definitionsDirectory;
boot.initrd.systemd = lib.mkIf initrdCfg.enable { boot.initrd.systemd = lib.mkIf initrdCfg.enable {
additionalUpstreamUnits = [ additionalUpstreamUnits = [
"systemd-repart.service" "systemd-repart.service"
@ -86,38 +81,44 @@ in
"${config.boot.initrd.systemd.package}/bin/systemd-repart" "${config.boot.initrd.systemd.package}/bin/systemd-repart"
]; ];
contents."/etc/repart.d".source = definitionsDirectory;
# Override defaults in upstream unit. # Override defaults in upstream unit.
services.systemd-repart = { services.systemd-repart = {
# Unset the conditions as they cannot be met before activation because # systemd-repart tries to create directories in /var/tmp by default to
# the definition files are not stored in the expected locations. # store large temporary files that benefit from persistence on disk. In
unitConfig.ConditionDirectoryNotEmpty = [ # the initrd, however, /var/tmp does not provide more persistence than
" " # required to unset the previous value. # /tmp, so we re-use it here.
]; environment."TMPDIR" = "/tmp";
serviceConfig = { serviceConfig = {
# systemd-repart runs before the activation script. Thus we cannot
# rely on them being linked in /etc already. Instead we have to
# explicitly pass their location in the sysroot to the binary.
ExecStart = [ ExecStart = [
" " # required to unset the previous value. " " # required to unset the previous value.
# When running in the initrd, systemd-repart by default searches
# for definition files in /sysroot or /sysusr. We tell it to look
# in the initrd itself.
''${config.boot.initrd.systemd.package}/bin/systemd-repart \ ''${config.boot.initrd.systemd.package}/bin/systemd-repart \
--definitions=/sysroot${definitionsDirectory} \ --definitions=/etc/repart.d \
--dry-run=no --dry-run=no
'' ''
]; ];
}; };
# Because the initrd does not have the `initrd-usr-fs.target` the # systemd-repart needs to run after /sysroot (or /sysuser, but we don't
# upestream unit runs too early in the boot process, before the sysroot # have it) has been mounted because otherwise it cannot determine the
# is available. However, systemd-repart needs access to the sysroot to # device (i.e disk) to operate on. If you want to run systemd-repart
# find the definition files. # without /sysroot, you have to explicitly tell it which device to
# operate on.
after = [ "sysroot.mount" ]; after = [ "sysroot.mount" ];
}; };
}; };
environment.etc = lib.mkIf cfg.enable {
"repart.d".source = definitionsDirectory;
};
systemd = lib.mkIf cfg.enable { systemd = lib.mkIf cfg.enable {
additionalUpstreamSystemUnits = [ additionalUpstreamSystemUnits = [
"systemd-repart.service" "systemd-repart.service"
]; ];
}; };
}; };
} }