2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-02-02 05:03:45 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
|
|
|
let
|
2016-06-01 10:51:33 +00:00
|
|
|
cfg = config.boot.loader.systemd-boot;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
|
|
|
efi = config.boot.loader.efi;
|
|
|
|
|
2024-04-23 17:49:23 +00:00
|
|
|
# We check the source code in a derivation that does not depend on the
|
|
|
|
# system configuration so that most users don't have to redo the check and require
|
|
|
|
# the necessary dependencies.
|
2024-04-30 15:56:27 +00:00
|
|
|
checkedSource = pkgs.runCommand "systemd-boot" {
|
|
|
|
preferLocalBuild = true;
|
|
|
|
} ''
|
2024-04-23 17:49:23 +00:00
|
|
|
install -m755 -D ${./systemd-boot-builder.py} $out
|
|
|
|
${lib.getExe pkgs.buildPackages.mypy} \
|
|
|
|
--no-implicit-optional \
|
|
|
|
--disallow-untyped-calls \
|
|
|
|
--disallow-untyped-defs \
|
|
|
|
$out
|
|
|
|
'';
|
|
|
|
|
2024-02-01 02:51:12 +00:00
|
|
|
systemdBootBuilder = pkgs.substituteAll rec {
|
2024-07-16 17:43:00 +00:00
|
|
|
name = "systemd-boot";
|
|
|
|
|
2024-04-23 17:49:23 +00:00
|
|
|
src = checkedSource;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
|
|
|
isExecutable = true;
|
|
|
|
|
2023-10-10 08:12:41 +00:00
|
|
|
inherit (pkgs) python3;
|
2016-05-31 14:52:40 +00:00
|
|
|
|
|
|
|
systemd = config.systemd.package;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
2023-11-16 23:48:19 +00:00
|
|
|
bootspecTools = pkgs.bootspec;
|
|
|
|
|
2016-04-24 11:06:04 +00:00
|
|
|
nix = config.nix.package.out;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
2024-08-05 08:48:54 +00:00
|
|
|
timeout = if config.boot.loader.timeout == null then "menu-force" else config.boot.loader.timeout;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
2019-07-23 08:19:17 +00:00
|
|
|
configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit;
|
|
|
|
|
2023-09-04 12:12:24 +00:00
|
|
|
inherit (cfg) consoleMode graceful editor rebootForBitlocker;
|
2018-07-02 16:21:51 +00:00
|
|
|
|
2013-02-21 17:33:54 +00:00
|
|
|
inherit (efi) efiSysMountPoint canTouchEfiVariables;
|
2019-05-05 11:16:19 +00:00
|
|
|
|
2024-02-01 02:51:12 +00:00
|
|
|
bootMountPoint = if cfg.xbootldrMountPoint != null
|
|
|
|
then cfg.xbootldrMountPoint
|
|
|
|
else efi.efiSysMountPoint;
|
|
|
|
|
|
|
|
nixosDir = "/EFI/nixos";
|
|
|
|
|
2022-12-17 23:00:58 +00:00
|
|
|
inherit (config.system.nixos) distroName;
|
|
|
|
|
2023-04-18 08:39:38 +00:00
|
|
|
memtest86 = optionalString cfg.memtest86.enable pkgs.memtest86plus;
|
2021-12-12 11:44:02 +00:00
|
|
|
|
2023-03-19 20:44:31 +00:00
|
|
|
netbootxyz = optionalString cfg.netbootxyz.enable pkgs.netbootxyz-efi;
|
2021-12-12 11:44:39 +00:00
|
|
|
|
2024-02-01 02:51:12 +00:00
|
|
|
checkMountpoints = pkgs.writeShellScript "check-mountpoints" ''
|
|
|
|
fail() {
|
|
|
|
echo "$1 = '$2' is not a mounted partition. Is the path configured correctly?" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
${pkgs.util-linuxMinimal}/bin/findmnt ${efiSysMountPoint} > /dev/null || fail efiSysMountPoint ${efiSysMountPoint}
|
|
|
|
${lib.optionalString
|
|
|
|
(cfg.xbootldrMountPoint != null)
|
|
|
|
"${pkgs.util-linuxMinimal}/bin/findmnt ${cfg.xbootldrMountPoint} > /dev/null || fail xbootldrMountPoint ${cfg.xbootldrMountPoint}"}
|
|
|
|
'';
|
|
|
|
|
2021-12-12 11:44:02 +00:00
|
|
|
copyExtraFiles = pkgs.writeShellScript "copy-extra-files" ''
|
2022-05-02 12:44:55 +00:00
|
|
|
empty_file=$(${pkgs.coreutils}/bin/mktemp)
|
2021-12-12 11:44:02 +00:00
|
|
|
|
|
|
|
${concatStrings (mapAttrsToList (n: v: ''
|
2024-02-01 02:51:12 +00:00
|
|
|
${pkgs.coreutils}/bin/install -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n}
|
|
|
|
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n}
|
2021-12-12 11:44:02 +00:00
|
|
|
'') cfg.extraFiles)}
|
|
|
|
|
|
|
|
${concatStrings (mapAttrsToList (n: v: ''
|
2024-02-01 02:51:12 +00:00
|
|
|
${pkgs.coreutils}/bin/install -Dp "${pkgs.writeText n v}" "${bootMountPoint}/loader/entries/"${escapeShellArg n}
|
|
|
|
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/loader/entries/"${escapeShellArg n}
|
2021-12-12 11:44:02 +00:00
|
|
|
'') cfg.extraEntries)}
|
|
|
|
'';
|
2024-03-03 01:25:36 +00:00
|
|
|
bootCountingTries = cfg.bootCounting.tries;
|
|
|
|
bootCounting = if cfg.bootCounting.enable then "True" else "False";
|
2013-02-02 05:03:45 +00:00
|
|
|
};
|
2021-01-10 13:09:07 +00:00
|
|
|
|
2022-11-14 13:20:58 +00:00
|
|
|
finalSystemdBootBuilder = pkgs.writeScript "install-systemd-boot.sh" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
2024-04-23 17:49:23 +00:00
|
|
|
${systemdBootBuilder} "$@"
|
2022-11-14 13:20:58 +00:00
|
|
|
${cfg.extraInstallCommands}
|
|
|
|
'';
|
2013-02-02 05:03:45 +00:00
|
|
|
in {
|
2016-06-01 10:51:33 +00:00
|
|
|
|
2024-03-03 01:25:36 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ julienmalka ];
|
|
|
|
doc = ./boot-counting.md;
|
|
|
|
};
|
2023-11-04 01:38:11 +00:00
|
|
|
|
2016-06-01 10:51:33 +00:00
|
|
|
imports =
|
|
|
|
[ (mkRenamedOptionModule [ "boot" "loader" "gummiboot" "enable" ] [ "boot" "loader" "systemd-boot" "enable" ])
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
(lib.mkChangedOptionModule
|
|
|
|
[ "boot" "loader" "systemd-boot" "memtest86" "entryFilename" ]
|
|
|
|
[ "boot" "loader" "systemd-boot" "memtest86" "sortKey" ]
|
|
|
|
(config: lib.strings.removeSuffix ".conf" config.boot.loader.systemd-boot.memtest86.entryFilename)
|
|
|
|
)
|
|
|
|
(lib.mkChangedOptionModule
|
|
|
|
[ "boot" "loader" "systemd-boot" "netbootxyz" "entryFilename" ]
|
|
|
|
[ "boot" "loader" "systemd-boot" "netbootxyz" "sortKey" ]
|
|
|
|
(config: lib.strings.removeSuffix ".conf" config.boot.loader.systemd-boot.netbootxyz.entryFilename)
|
|
|
|
)
|
2016-06-01 10:51:33 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options.boot.loader.systemd-boot = {
|
2013-02-02 05:03:45 +00:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
|
|
|
|
type = types.bool;
|
|
|
|
|
2024-01-19 13:01:26 +00:00
|
|
|
description = ''
|
|
|
|
Whether to enable the systemd-boot (formerly gummiboot) EFI boot manager.
|
|
|
|
For more information about systemd-boot:
|
|
|
|
https://www.freedesktop.org/wiki/Software/systemd/systemd-boot/
|
|
|
|
'';
|
2013-02-02 05:03:45 +00:00
|
|
|
};
|
2017-01-21 13:24:26 +00:00
|
|
|
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
sortKey = mkOption {
|
|
|
|
default = "nixos";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The sort key used for the NixOS bootloader entries.
|
|
|
|
This key determines sorting relative to non-NixOS entries.
|
|
|
|
See also https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
|
|
|
|
|
|
|
|
This option can also be used to control the sorting of NixOS specialisations.
|
|
|
|
|
|
|
|
By default, specialisations inherit the sort key of their parent generation
|
|
|
|
and will have the same value for both the sort-key and the version (i.e. the generation number),
|
|
|
|
systemd-boot will therefore sort them based on their file name, meaning that
|
|
|
|
in your boot menu you will have each main generation directly followed by
|
|
|
|
its specialisations sorted alphabetically by their names.
|
|
|
|
|
|
|
|
If you want a different ordering for a specialisation, you can override
|
|
|
|
its sort-key which will cause the specialisation to be uncoupled from its
|
|
|
|
parent generation. It will then be sorted by its new sort-key just like
|
|
|
|
any other boot entry.
|
|
|
|
|
|
|
|
The sort-key is stored in the generation's bootspec, which means that
|
|
|
|
generations keep their sort-keys even if the original definition of the
|
|
|
|
generation was removed from the NixOS configuration.
|
|
|
|
It also means that updating the sort-key will only affect new generations,
|
|
|
|
while old ones will keep the sort-key that they were originally built with.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-21 13:24:26 +00:00
|
|
|
editor = mkOption {
|
|
|
|
default = true;
|
|
|
|
|
|
|
|
type = types.bool;
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
Whether to allow editing the kernel command-line before
|
|
|
|
boot. It is recommended to set this to false, as it allows
|
|
|
|
gaining root access by passing init=/bin/sh as a kernel
|
|
|
|
parameter. However, it is enabled by default for backwards
|
|
|
|
compatibility.
|
2017-01-21 13:42:10 +00:00
|
|
|
'';
|
2017-01-21 13:24:26 +00:00
|
|
|
};
|
2018-07-02 16:21:51 +00:00
|
|
|
|
2024-02-01 02:51:12 +00:00
|
|
|
xbootldrMountPoint = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = ''
|
|
|
|
Where the XBOOTLDR partition is mounted.
|
|
|
|
|
|
|
|
If set, this partition will be used as $BOOT to store boot loader entries and extra files
|
|
|
|
instead of the EFI partition. As per the bootloader specification, it is recommended that
|
|
|
|
the EFI and XBOOTLDR partitions be mounted at `/efi` and `/boot`, respectively.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-06-22 18:10:03 +00:00
|
|
|
configurationLimit = mkOption {
|
2019-07-23 08:19:17 +00:00
|
|
|
default = null;
|
2019-06-22 18:10:03 +00:00
|
|
|
example = 120;
|
2019-07-23 08:19:17 +00:00
|
|
|
type = types.nullOr types.int;
|
2019-06-22 18:10:03 +00:00
|
|
|
description = ''
|
2020-08-07 13:43:58 +00:00
|
|
|
Maximum number of latest generations in the boot menu.
|
2019-07-23 08:19:17 +00:00
|
|
|
Useful to prevent boot partition running out of disk space.
|
|
|
|
|
2020-08-07 13:43:58 +00:00
|
|
|
`null` means no limit i.e. all generations
|
2024-02-01 02:51:12 +00:00
|
|
|
that have not been garbage collected yet.
|
2019-06-22 18:10:03 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-13 00:02:35 +00:00
|
|
|
installDeviceTree = mkOption {
|
|
|
|
default = with config.hardware.deviceTree; enable && name != null;
|
|
|
|
defaultText = ''with config.hardware.deviceTree; enable && name != null'';
|
|
|
|
description = ''
|
|
|
|
Install the devicetree blob specified by `config.hardware.deviceTree.name`
|
|
|
|
to the ESP and instruct systemd-boot to pass this DTB to linux.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-14 13:20:58 +00:00
|
|
|
extraInstallCommands = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
default_cfg=$(cat /boot/loader/loader.conf | grep default | awk '{print $2}')
|
|
|
|
init_value=$(cat /boot/loader/entries/$default_cfg | grep init= | awk '{print $2}')
|
|
|
|
sed -i "s|@INIT@|$init_value|g" /boot/custom/config_with_placeholder.conf
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Additional shell commands inserted in the bootloader installer
|
|
|
|
script after generating menu entries. It can be used to expand
|
|
|
|
on extra boot entries that cannot incorporate certain pieces of
|
|
|
|
information (such as the resulting `init=` kernel parameter).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-07-02 16:21:51 +00:00
|
|
|
consoleMode = mkOption {
|
|
|
|
default = "keep";
|
|
|
|
|
|
|
|
type = types.enum [ "0" "1" "2" "auto" "max" "keep" ];
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
The resolution of the console. The following values are valid:
|
2019-05-13 07:15:17 +00:00
|
|
|
|
2018-07-02 16:21:51 +00:00
|
|
|
- `"0"`: Standard UEFI 80x25 mode
|
|
|
|
- `"1"`: 80x50 mode, not supported by all devices
|
|
|
|
- `"2"`: The first non-standard mode provided by the device firmware, if any
|
|
|
|
- `"auto"`: Pick a suitable mode automatically using heuristics
|
|
|
|
- `"max"`: Pick the highest-numbered available mode
|
|
|
|
- `"keep"`: Keep the mode selected by firmware (the default)
|
|
|
|
'';
|
|
|
|
};
|
2019-05-05 11:16:19 +00:00
|
|
|
|
|
|
|
memtest86 = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
2023-09-11 01:41:14 +00:00
|
|
|
Make Memtest86+ available from the systemd-boot menu. Memtest86+ is a
|
2023-04-18 08:39:38 +00:00
|
|
|
program for testing memory.
|
2019-05-05 11:16:19 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-12-12 11:44:02 +00:00
|
|
|
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
sortKey = mkOption {
|
|
|
|
default = "o_memtest86";
|
2021-12-12 11:44:02 +00:00
|
|
|
type = types.str;
|
|
|
|
description = ''
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
`systemd-boot` orders the menu entries by their sort keys,
|
2021-12-12 11:44:02 +00:00
|
|
|
so if you want something to appear after all the NixOS entries,
|
|
|
|
it should start with {file}`o` or onwards.
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
|
|
|
|
See also {option}`boot.loader.systemd-boot.sortKey`.
|
2021-12-12 11:44:02 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-12 11:44:39 +00:00
|
|
|
netbootxyz = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Make `netboot.xyz` available from the
|
|
|
|
`systemd-boot` menu. `netboot.xyz`
|
|
|
|
is a menu system that allows you to boot OS installers and
|
|
|
|
utilities over the network.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
sortKey = mkOption {
|
|
|
|
default = "o_netbootxyz";
|
2021-12-12 11:44:39 +00:00
|
|
|
type = types.str;
|
|
|
|
description = ''
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
`systemd-boot` orders the menu entries by their sort keys,
|
2021-12-12 11:44:39 +00:00
|
|
|
so if you want something to appear after all the NixOS entries,
|
|
|
|
it should start with {file}`o` or onwards.
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
|
|
|
|
See also {option}`boot.loader.systemd-boot.sortKey`.
|
2021-12-12 11:44:39 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-12 11:44:02 +00:00
|
|
|
extraEntries = mkOption {
|
|
|
|
type = types.attrsOf types.lines;
|
|
|
|
default = {};
|
|
|
|
example = literalExpression ''
|
|
|
|
{ "memtest86.conf" = '''
|
2023-09-11 01:41:14 +00:00
|
|
|
title Memtest86+
|
2023-04-18 08:39:38 +00:00
|
|
|
efi /efi/memtest86/memtest.efi
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
sort-key z_memtest
|
2021-12-12 11:44:02 +00:00
|
|
|
'''; }
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Any additional entries you want added to the `systemd-boot` menu.
|
2024-02-01 02:51:12 +00:00
|
|
|
These entries will be copied to {file}`$BOOT/loader/entries`.
|
2021-12-12 11:44:02 +00:00
|
|
|
Each attribute name denotes the destination file name,
|
|
|
|
and the corresponding attribute value is the contents of the entry.
|
|
|
|
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
To control the ordering of the entry in the boot menu, use the sort-key
|
|
|
|
field, see
|
|
|
|
https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
|
|
|
|
and {option}`boot.loader.systemd-boot.sortKey`.
|
2021-12-12 11:44:02 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraFiles = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = {};
|
|
|
|
example = literalExpression ''
|
2023-04-18 08:39:38 +00:00
|
|
|
{ "efi/memtest86/memtest.efi" = "''${pkgs.memtest86plus}/memtest.efi"; }
|
2021-12-12 11:44:02 +00:00
|
|
|
'';
|
|
|
|
description = ''
|
2024-02-01 02:51:12 +00:00
|
|
|
A set of files to be copied to {file}`$BOOT`.
|
2021-12-12 11:44:02 +00:00
|
|
|
Each attribute name denotes the destination file name in
|
2024-02-01 02:51:12 +00:00
|
|
|
{file}`$BOOT`, while the corresponding
|
2021-12-12 11:44:02 +00:00
|
|
|
attribute value specifies the source file.
|
|
|
|
'';
|
2019-05-05 11:16:19 +00:00
|
|
|
};
|
2021-09-26 15:54:36 +00:00
|
|
|
|
|
|
|
graceful = mkOption {
|
|
|
|
default = false;
|
|
|
|
|
|
|
|
type = types.bool;
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
Invoke `bootctl install` with the `--graceful` option,
|
|
|
|
which ignores errors when EFI variables cannot be written or when the EFI System Partition
|
|
|
|
cannot be found. Currently only applies to random seed operations.
|
|
|
|
|
|
|
|
Only enable this option if `systemd-boot` otherwise fails to install, as the
|
|
|
|
scope or implication of the `--graceful` option may change in the future.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-03-03 01:25:36 +00:00
|
|
|
bootCounting = {
|
|
|
|
enable = mkEnableOption "automatic boot assessment";
|
|
|
|
tries = mkOption {
|
|
|
|
default = 3;
|
|
|
|
type = types.int;
|
|
|
|
description = "number of tries each entry should start with";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-09-04 12:12:24 +00:00
|
|
|
rebootForBitlocker = mkOption {
|
|
|
|
default = false;
|
|
|
|
|
|
|
|
type = types.bool;
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
Enable *EXPERIMENTAL* BitLocker support.
|
|
|
|
|
|
|
|
Try to detect BitLocker encrypted drives along with an active
|
|
|
|
TPM. If both are found and Windows Boot Manager is selected in
|
|
|
|
the boot menu, set the "BootNext" EFI variable and restart the
|
|
|
|
system. The firmware will then start Windows Boot Manager
|
|
|
|
directly, leaving the TPM PCRs in expected states so that
|
|
|
|
Windows can unseal the encryption key.
|
|
|
|
'';
|
|
|
|
};
|
2013-02-02 05:03:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
2024-02-01 02:51:12 +00:00
|
|
|
{
|
|
|
|
assertion = (hasPrefix "/" efi.efiSysMountPoint);
|
2024-06-18 18:30:16 +00:00
|
|
|
message = "The ESP mount point '${toString efi.efiSysMountPoint}' must be an absolute path";
|
2024-02-01 02:51:12 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.xbootldrMountPoint == null || (hasPrefix "/" cfg.xbootldrMountPoint);
|
2024-06-18 18:30:16 +00:00
|
|
|
message = "The XBOOTLDR mount point '${toString cfg.xbootldrMountPoint}' must be an absolute path";
|
2024-02-01 02:51:12 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.xbootldrMountPoint != efi.efiSysMountPoint;
|
2024-06-18 18:30:16 +00:00
|
|
|
message = "The XBOOTLDR mount point '${toString cfg.xbootldrMountPoint}' cannot be the same as the ESP mount point '${toString efi.efiSysMountPoint}'";
|
2024-02-01 02:51:12 +00:00
|
|
|
}
|
2013-02-02 05:03:45 +00:00
|
|
|
{
|
2013-03-03 22:48:33 +00:00
|
|
|
assertion = (config.boot.kernelPackages.kernel.features or { efiBootStub = true; }) ? efiBootStub;
|
2013-02-02 05:03:45 +00:00
|
|
|
message = "This kernel does not support the EFI boot stub";
|
|
|
|
}
|
2024-06-13 00:02:35 +00:00
|
|
|
{
|
|
|
|
assertion = cfg.installDeviceTree -> config.hardware.deviceTree.enable -> config.hardware.deviceTree.name != null;
|
|
|
|
message = "Cannot install devicetree without 'config.hardware.deviceTree.enable' enabled and 'config.hardware.deviceTree.name' set";
|
|
|
|
}
|
2021-12-12 11:44:02 +00:00
|
|
|
] ++ concatMap (filename: [
|
|
|
|
{
|
|
|
|
assertion = !(hasInfix "/" filename);
|
|
|
|
message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries within folders are not supported";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = hasSuffix ".conf" filename;
|
|
|
|
message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries must have a .conf file extension";
|
|
|
|
}
|
|
|
|
]) (builtins.attrNames cfg.extraEntries)
|
|
|
|
++ concatMap (filename: [
|
|
|
|
{
|
|
|
|
assertion = !(hasPrefix "/" filename);
|
|
|
|
message = "boot.loader.systemd-boot.extraFiles.${lib.strings.escapeNixIdentifier filename} is invalid: paths must not begin with a slash";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = !(hasInfix ".." filename);
|
|
|
|
message = "boot.loader.systemd-boot.extraFiles.${lib.strings.escapeNixIdentifier filename} is invalid: paths must not reference the parent directory";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = !(hasInfix "nixos/.extra-files" (toLower filename));
|
|
|
|
message = "boot.loader.systemd-boot.extraFiles.${lib.strings.escapeNixIdentifier filename} is invalid: files cannot be placed in the nixos/.extra-files directory";
|
|
|
|
}
|
|
|
|
]) (builtins.attrNames cfg.extraFiles);
|
2013-02-02 05:03:45 +00:00
|
|
|
|
2014-04-30 09:41:39 +00:00
|
|
|
boot.loader.grub.enable = mkDefault false;
|
|
|
|
|
2017-04-02 18:51:09 +00:00
|
|
|
boot.loader.supportsInitrdSecrets = true;
|
|
|
|
|
2021-12-12 11:44:02 +00:00
|
|
|
boot.loader.systemd-boot.extraFiles = mkMerge [
|
|
|
|
(mkIf cfg.memtest86.enable {
|
2023-04-18 08:39:38 +00:00
|
|
|
"efi/memtest86/memtest.efi" = "${pkgs.memtest86plus.efi}";
|
2021-12-12 11:44:02 +00:00
|
|
|
})
|
2021-12-12 11:44:39 +00:00
|
|
|
(mkIf cfg.netbootxyz.enable {
|
|
|
|
"efi/netbootxyz/netboot.xyz.efi" = "${pkgs.netbootxyz-efi}";
|
|
|
|
})
|
2021-12-12 11:44:02 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
boot.loader.systemd-boot.extraEntries = mkMerge [
|
|
|
|
(mkIf cfg.memtest86.enable {
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
"memtest86.conf" = ''
|
2023-09-11 01:41:14 +00:00
|
|
|
title Memtest86+
|
2023-04-18 08:39:38 +00:00
|
|
|
efi /efi/memtest86/memtest.efi
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
sort-key ${cfg.memtest86.sortKey}
|
2021-12-12 11:44:02 +00:00
|
|
|
'';
|
|
|
|
})
|
2021-12-12 11:44:39 +00:00
|
|
|
(mkIf cfg.netbootxyz.enable {
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
"netbootxyz.conf" = ''
|
2021-12-12 11:44:39 +00:00
|
|
|
title netboot.xyz
|
|
|
|
efi /efi/netbootxyz/netboot.xyz.efi
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
sort-key ${cfg.netbootxyz.sortKey}
|
2021-12-12 11:44:39 +00:00
|
|
|
'';
|
|
|
|
})
|
2021-12-12 11:44:02 +00:00
|
|
|
];
|
|
|
|
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
boot.bootspec.extensions."org.nixos.systemd-boot" = {
|
|
|
|
inherit (config.boot.loader.systemd-boot) sortKey;
|
2024-06-13 00:02:35 +00:00
|
|
|
devicetree = lib.mkIf cfg.installDeviceTree "${config.hardware.deviceTree.package}/${config.hardware.deviceTree.name}";
|
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by
file name (in decreasing order, so starting at the end of the alphabet!),
without taking any other fields into account (see
[the boot loader specification reference][1]).
Moreover, entries without a sort-key are always ordered after all
entries with a sort-key, so by not adding a sort-key to the NixOS ones,
we cannot add a sort-key to any other entry while keeping it below the
NixOS entries.
So currently we have options to set the file names for additional entries like
memtest and netbootxyz.
However, as mentioned above, the sorting by file name is not very intuitive and
actually sorts in the opposite order of what is currently mentioned in the option
descriptions.
With this commit, we set a configurable sort-key on all NixOS entries,
and add options for setting the sort-keys for the memtest and netbootxyz
entries.
The sorting by sort-key is more intuitive (it starts at the start of the
alphabet) and also takes into account the machine-id and version for entries
with identical sort-keys.
We use a bootspec extension to store the sort keys, which allows us to
redefine the sort key for individual specialisations without needing any
special casing.
[1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
2024-01-24 17:15:28 +00:00
|
|
|
};
|
|
|
|
|
2013-02-02 05:03:45 +00:00
|
|
|
system = {
|
2022-11-14 13:20:58 +00:00
|
|
|
build.installBootLoader = finalSystemdBootBuilder;
|
2013-02-02 05:03:45 +00:00
|
|
|
|
2016-06-01 10:51:33 +00:00
|
|
|
boot.loader.id = "systemd-boot";
|
2013-02-02 05:03:45 +00:00
|
|
|
|
|
|
|
requiredKernelConfig = with config.lib.kernelConfig; [
|
|
|
|
(isYes "EFI_STUB")
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|