diff --git a/nixos/modules/system/boot/loader/generic-extlinux-compatible/default.nix b/nixos/modules/system/boot/loader/generic-extlinux-compatible/default.nix index 2b75707ad99ed..797f0d81f14ca 100644 --- a/nixos/modules/system/boot/loader/generic-extlinux-compatible/default.nix +++ b/nixos/modules/system/boot/loader/generic-extlinux-compatible/default.nix @@ -54,6 +54,30 @@ in ''; }; + mirroredBoots = mkOption { + default = [ { path = "/boot"; } ]; + example = [ + { path = "/boot1"; } + { path = "/boot2"; } + ]; + description = '' + Mirror the boot configuration to multiple paths. + ''; + + type = with types; listOf (submodule { + options = { + path = mkOption { + example = "/boot1"; + type = types.str; + description = '' + The path to the boot directory where the extlinux-compatible + configuration files will be written. + ''; + }; + }; + }); + }; + populateCmd = mkOption { type = types.str; readOnly = true; @@ -72,11 +96,27 @@ in builderArgs = "-g ${toString cfg.configurationLimit} -t ${timeoutStr}" + lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}" + lib.optionalString (!cfg.useGenerationDeviceTree) " -r"; + installBootLoader = pkgs.writeScript "install-extlinux-conf.sh" ('' + #!${pkgs.runtimeShell} + set -e + '' + flip concatMapStrings cfg.mirroredBoots (args: '' + ${builder} ${builderArgs} -d '${args.path}' -c "$@" + '')); in mkIf cfg.enable { - system.build.installBootLoader = "${builder} ${builderArgs} -c"; + system.build.installBootLoader = installBootLoader; system.boot.loader.id = "generic-extlinux-compatible"; boot.loader.generic-extlinux-compatible.populateCmd = "${populateBuilder} ${builderArgs}"; + + assertions = [ + { + assertion = cfg.mirroredBoots != [ ]; + message = '' + You must not remove all elements from option 'boot.loader.generic-extlinux-compatible.mirroredBoots', + otherwise the system will not be bootable. + ''; + } + ]; }; }