1 { config, lib, pkgs, ... }:
6 blCfg = config.boot.loader;
7 dtCfg = config.hardware.deviceTree;
8 cfg = blCfg.generic-extlinux-compatible;
10 timeoutStr = if blCfg.timeout == null then "-1" else toString blCfg.timeout;
12 # The builder used to write during system activation
13 builder = import ./extlinux-conf-builder.nix { inherit pkgs; };
14 # The builder exposed in populateCmd, which runs on the build architecture
15 populateBuilder = import ./extlinux-conf-builder.nix { pkgs = pkgs.buildPackages; };
19 boot.loader.generic-extlinux-compatible = {
24 Whether to generate an extlinux-compatible configuration file
25 under `/boot/extlinux.conf`. For instance,
26 U-Boot's generic distro boot support uses this file format.
28 See [U-boot's documentation](https://u-boot.readthedocs.io/en/latest/develop/distro.html)
33 useGenerationDeviceTree = mkOption {
37 Whether to generate Device Tree-related directives in the
38 extlinux configuration.
40 When enabled, the bootloader will attempt to load the device
41 tree binaries from the generation's kernel.
43 Note that this affects all generations, regardless of the
44 setting value used in their configurations.
48 configurationLimit = mkOption {
53 Maximum number of configurations in the boot menu.
57 mirroredBoots = mkOption {
58 default = [ { path = "/boot"; } ];
64 Mirror the boot configuration to multiple paths.
67 type = with types; listOf (submodule {
73 The path to the boot directory where the extlinux-compatible
74 configuration files will be written.
81 populateCmd = mkOption {
85 Contains the builder command used to populate an image,
86 honoring all options except the `-c <path-to-default-configuration>`
88 Useful to have for sdImage.populateRootCommands
96 builderArgs = "-g ${toString cfg.configurationLimit} -t ${timeoutStr}"
97 + lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}"
98 + lib.optionalString (!cfg.useGenerationDeviceTree) " -r";
99 installBootLoader = pkgs.writeScript "install-extlinux-conf.sh" (''
100 #!${pkgs.runtimeShell}
102 '' + flip concatMapStrings cfg.mirroredBoots (args: ''
103 ${builder} ${builderArgs} -d '${args.path}' -c "$@"
107 system.build.installBootLoader = installBootLoader;
108 system.boot.loader.id = "generic-extlinux-compatible";
110 boot.loader.generic-extlinux-compatible.populateCmd = "${populateBuilder} ${builderArgs}";
114 assertion = cfg.mirroredBoots != [ ];
116 You must not remove all elements from option 'boot.loader.generic-extlinux-compatible.mirroredBoots',
117 otherwise the system will not be bootable.