mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/systemd-boot: autoformat
This commit is contained in:
parent
568bfef547
commit
548206583d
2 changed files with 380 additions and 255 deletions
|
@ -1,4 +1,9 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
with lib;
|
||||
|
||||
|
@ -10,9 +15,12 @@ let
|
|||
# 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.
|
||||
checkedSource = pkgs.runCommand "systemd-boot" {
|
||||
checkedSource =
|
||||
pkgs.runCommand "systemd-boot"
|
||||
{
|
||||
preferLocalBuild = true;
|
||||
} ''
|
||||
}
|
||||
''
|
||||
install -m755 -D ${./systemd-boot-builder.py} $out
|
||||
${lib.getExe pkgs.buildPackages.mypy} \
|
||||
--no-implicit-optional \
|
||||
|
@ -44,13 +52,17 @@ let
|
|||
|
||||
configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit;
|
||||
|
||||
inherit (cfg) consoleMode graceful editor rebootForBitlocker;
|
||||
inherit (cfg)
|
||||
consoleMode
|
||||
graceful
|
||||
editor
|
||||
rebootForBitlocker
|
||||
;
|
||||
|
||||
inherit (efi) efiSysMountPoint canTouchEfiVariables;
|
||||
|
||||
bootMountPoint = if cfg.xbootldrMountPoint != null
|
||||
then cfg.xbootldrMountPoint
|
||||
else efi.efiSysMountPoint;
|
||||
bootMountPoint =
|
||||
if cfg.xbootldrMountPoint != null then cfg.xbootldrMountPoint else efi.efiSysMountPoint;
|
||||
|
||||
nixosDir = "/EFI/nixos";
|
||||
|
||||
|
@ -66,23 +78,27 @@ let
|
|||
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}"}
|
||||
${lib.optionalString (cfg.xbootldrMountPoint != null)
|
||||
"${pkgs.util-linuxMinimal}/bin/findmnt ${cfg.xbootldrMountPoint} > /dev/null || fail xbootldrMountPoint ${cfg.xbootldrMountPoint}"
|
||||
}
|
||||
'';
|
||||
|
||||
copyExtraFiles = pkgs.writeShellScript "copy-extra-files" ''
|
||||
empty_file=$(${pkgs.coreutils}/bin/mktemp)
|
||||
|
||||
${concatStrings (mapAttrsToList (n: v: ''
|
||||
${concatStrings (
|
||||
mapAttrsToList (n: v: ''
|
||||
${pkgs.coreutils}/bin/install -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n}
|
||||
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n}
|
||||
'') cfg.extraFiles)}
|
||||
'') cfg.extraFiles
|
||||
)}
|
||||
|
||||
${concatStrings (mapAttrsToList (n: v: ''
|
||||
${concatStrings (
|
||||
mapAttrsToList (n: v: ''
|
||||
${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}
|
||||
'') cfg.extraEntries)}
|
||||
'') cfg.extraEntries
|
||||
)}
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -91,20 +107,58 @@ let
|
|||
${systemdBootBuilder}/bin/systemd-boot "$@"
|
||||
${cfg.extraInstallCommands}
|
||||
'';
|
||||
in {
|
||||
in
|
||||
{
|
||||
|
||||
meta.maintainers = with lib.maintainers; [ julienmalka ];
|
||||
|
||||
imports =
|
||||
[ (mkRenamedOptionModule [ "boot" "loader" "gummiboot" "enable" ] [ "boot" "loader" "systemd-boot" "enable" ])
|
||||
imports = [
|
||||
(mkRenamedOptionModule
|
||||
[
|
||||
"boot"
|
||||
"loader"
|
||||
"gummiboot"
|
||||
"enable"
|
||||
]
|
||||
[
|
||||
"boot"
|
||||
"loader"
|
||||
"systemd-boot"
|
||||
"enable"
|
||||
]
|
||||
)
|
||||
(lib.mkChangedOptionModule
|
||||
[ "boot" "loader" "systemd-boot" "memtest86" "entryFilename" ]
|
||||
[ "boot" "loader" "systemd-boot" "memtest86" "sortKey" ]
|
||||
[
|
||||
"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" ]
|
||||
[
|
||||
"boot"
|
||||
"loader"
|
||||
"systemd-boot"
|
||||
"netbootxyz"
|
||||
"entryFilename"
|
||||
]
|
||||
[
|
||||
"boot"
|
||||
"loader"
|
||||
"systemd-boot"
|
||||
"netbootxyz"
|
||||
"sortKey"
|
||||
]
|
||||
(config: lib.strings.removeSuffix ".conf" config.boot.loader.systemd-boot.netbootxyz.entryFilename)
|
||||
)
|
||||
];
|
||||
|
@ -218,7 +272,15 @@ in {
|
|||
consoleMode = mkOption {
|
||||
default = "keep";
|
||||
|
||||
type = types.enum [ "0" "1" "2" "5" "auto" "max" "keep" ];
|
||||
type = types.enum [
|
||||
"0"
|
||||
"1"
|
||||
"2"
|
||||
"5"
|
||||
"auto"
|
||||
"max"
|
||||
"keep"
|
||||
];
|
||||
|
||||
description = ''
|
||||
The resolution of the console. The following values are valid:
|
||||
|
@ -283,7 +345,7 @@ in {
|
|||
|
||||
extraEntries = mkOption {
|
||||
type = types.attrsOf types.lines;
|
||||
default = {};
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{ "memtest86.conf" = '''
|
||||
title Memtest86+
|
||||
|
@ -306,7 +368,7 @@ in {
|
|||
|
||||
extraFiles = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = {};
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{ "efi/memtest86/memtest.efi" = "''${pkgs.memtest86plus}/memtest.efi"; }
|
||||
'';
|
||||
|
@ -352,7 +414,8 @@ in {
|
|||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [
|
||||
assertions =
|
||||
[
|
||||
{
|
||||
assertion = (hasPrefix "/" efi.efiSysMountPoint);
|
||||
message = "The ESP mount point '${toString efi.efiSysMountPoint}' must be an absolute path";
|
||||
|
@ -370,10 +433,14 @@ in {
|
|||
message = "This kernel does not support the EFI boot stub";
|
||||
}
|
||||
{
|
||||
assertion = cfg.installDeviceTree -> config.hardware.deviceTree.enable -> config.hardware.deviceTree.name != null;
|
||||
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";
|
||||
}
|
||||
] ++ concatMap (filename: [
|
||||
]
|
||||
++ concatMap (filename: [
|
||||
{
|
||||
assertion = !(hasInfix "/" filename);
|
||||
message = "boot.loader.systemd-boot.extraEntries.${lib.strings.escapeNixIdentifier filename} is invalid: entries within folders are not supported";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ system ? builtins.currentSystem,
|
||||
config ? {},
|
||||
pkgs ? import ../.. { inherit system config; }
|
||||
{
|
||||
system ? builtins.currentSystem,
|
||||
config ? { },
|
||||
pkgs ? import ../.. { inherit system config; },
|
||||
}:
|
||||
|
||||
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||
|
@ -16,7 +17,13 @@ let
|
|||
system.switch.enable = true;
|
||||
};
|
||||
|
||||
commonXbootldr = { config, lib, pkgs, ... }:
|
||||
commonXbootldr =
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
diskImage = import ../lib/make-disk-image.nix {
|
||||
inherit config lib pkgs;
|
||||
|
@ -85,7 +92,10 @@ in
|
|||
{
|
||||
basic = makeTest {
|
||||
name = "systemd-boot";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer julienmalka ];
|
||||
meta.maintainers = with pkgs.lib.maintainers; [
|
||||
danielfullmer
|
||||
julienmalka
|
||||
];
|
||||
|
||||
nodes.machine = common;
|
||||
|
||||
|
@ -117,9 +127,12 @@ in
|
|||
virtualisation.useSecureBoot = true;
|
||||
};
|
||||
|
||||
testScript = let
|
||||
testScript =
|
||||
let
|
||||
efiArch = pkgs.stdenv.hostPlatform.efiArch;
|
||||
in { nodes, ... }: ''
|
||||
in
|
||||
{ nodes, ... }:
|
||||
''
|
||||
machine.start(allow_reboot=True)
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
|
@ -141,7 +154,9 @@ in
|
|||
|
||||
nodes.machine = commonXbootldr;
|
||||
|
||||
testScript = { nodes, ... }: ''
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
''
|
||||
${customDiskImage nodes}
|
||||
|
||||
machine.start()
|
||||
|
@ -164,9 +179,14 @@ in
|
|||
# Check that specialisations create corresponding boot entries.
|
||||
specialisation = makeTest {
|
||||
name = "systemd-boot-specialisation";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ lukegb julienmalka ];
|
||||
meta.maintainers = with pkgs.lib.maintainers; [
|
||||
lukegb
|
||||
julienmalka
|
||||
];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
specialisation.something.configuration = {
|
||||
boot.loader.systemd-boot.sortKey = "something";
|
||||
|
@ -179,14 +199,18 @@ in
|
|||
# the correct contents.
|
||||
boot.loader.systemd-boot.installDeviceTree = pkgs.stdenv.hostPlatform.isAarch64;
|
||||
hardware.deviceTree.name = "dummy.dtb";
|
||||
hardware.deviceTree.package = lib.mkForce (pkgs.runCommand "dummy-devicetree-package" { } ''
|
||||
hardware.deviceTree.package = lib.mkForce (
|
||||
pkgs.runCommand "dummy-devicetree-package" { } ''
|
||||
mkdir -p $out
|
||||
cp ${pkgs.emptyFile} $out/dummy.dtb
|
||||
'');
|
||||
''
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
testScript = { nodes, ... }: ''
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
''
|
||||
machine.start()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
|
@ -199,7 +223,8 @@ in
|
|||
machine.succeed(
|
||||
"grep 'sort-key something' /boot/loader/entries/nixos-generation-1-specialisation-something.conf"
|
||||
)
|
||||
'' + pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isAarch64 ''
|
||||
''
|
||||
+ pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isAarch64 ''
|
||||
machine.succeed(
|
||||
r"grep 'devicetree /EFI/nixos/[a-z0-9]\{32\}.*dummy' /boot/loader/entries/nixos-generation-1-specialisation-something.conf"
|
||||
)
|
||||
|
@ -209,9 +234,14 @@ in
|
|||
# Boot without having created an EFI entry--instead using default "/EFI/BOOT/BOOTX64.EFI"
|
||||
fallback = makeTest {
|
||||
name = "systemd-boot-fallback";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer julienmalka ];
|
||||
meta.maintainers = with pkgs.lib.maintainers; [
|
||||
danielfullmer
|
||||
julienmalka
|
||||
];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.efi.canTouchEfiVariables = mkForce false;
|
||||
};
|
||||
|
@ -235,7 +265,10 @@ in
|
|||
|
||||
update = makeTest {
|
||||
name = "systemd-boot-update";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ danielfullmer julienmalka ];
|
||||
meta.maintainers = with pkgs.lib.maintainers; [
|
||||
danielfullmer
|
||||
julienmalka
|
||||
];
|
||||
|
||||
nodes.machine = common;
|
||||
|
||||
|
@ -270,11 +303,15 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
memtest86 = with pkgs.lib; optionalAttrs (meta.availableOn { inherit system; } pkgs.memtest86plus) (makeTest {
|
||||
memtest86 =
|
||||
with pkgs.lib;
|
||||
optionalAttrs (meta.availableOn { inherit system; } pkgs.memtest86plus) (makeTest {
|
||||
name = "systemd-boot-memtest86";
|
||||
meta.maintainers = with maintainers; [ julienmalka ];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.memtest86.enable = true;
|
||||
};
|
||||
|
@ -289,7 +326,9 @@ in
|
|||
name = "systemd-boot-netbootxyz";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.netbootxyz.enable = true;
|
||||
};
|
||||
|
@ -304,7 +343,9 @@ in
|
|||
name = "systemd-boot-memtest-sortkey";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.memtest86.enable = true;
|
||||
boot.loader.systemd-boot.memtest86.sortKey = "apple";
|
||||
|
@ -321,12 +362,16 @@ in
|
|||
name = "systemd-boot-entry-filename-xbootldr";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ sdht0 ];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ commonXbootldr ];
|
||||
boot.loader.systemd-boot.memtest86.enable = true;
|
||||
};
|
||||
|
||||
testScript = { nodes, ... }: ''
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
''
|
||||
${customDiskImage nodes}
|
||||
|
||||
machine.start()
|
||||
|
@ -342,7 +387,9 @@ in
|
|||
name = "systemd-boot-extra-entries";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.extraEntries = {
|
||||
"banana.conf" = ''
|
||||
|
@ -361,7 +408,9 @@ in
|
|||
name = "systemd-boot-extra-files";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];
|
||||
|
||||
nodes.machine = { pkgs, lib, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.extraFiles = {
|
||||
"efi/fruits/tomato.efi" = pkgs.netbootxyz-efi;
|
||||
|
@ -381,7 +430,9 @@ in
|
|||
nodes = {
|
||||
inherit common;
|
||||
|
||||
machine = { pkgs, nodes, ... }: {
|
||||
machine =
|
||||
{ pkgs, nodes, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.extraFiles = {
|
||||
"efi/fruits/tomato.efi" = pkgs.netbootxyz-efi;
|
||||
|
@ -394,17 +445,22 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
with_netbootxyz = { pkgs, ... }: {
|
||||
with_netbootxyz =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
boot.loader.systemd-boot.netbootxyz.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = { nodes, ... }: let
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
let
|
||||
originalSystem = nodes.machine.system.build.toplevel;
|
||||
baseSystem = nodes.common.system.build.toplevel;
|
||||
finalSystem = nodes.with_netbootxyz.system.build.toplevel;
|
||||
in ''
|
||||
in
|
||||
''
|
||||
machine.succeed("test -e /boot/efi/fruits/tomato.efi")
|
||||
machine.succeed("test -e /boot/efi/nixos/.extra-files/efi/fruits/tomato.efi")
|
||||
|
||||
|
@ -438,7 +494,9 @@ in
|
|||
|
||||
nodes = {
|
||||
inherit common;
|
||||
machine = { pkgs, nodes, ... }: {
|
||||
machine =
|
||||
{ pkgs, nodes, ... }:
|
||||
{
|
||||
imports = [ common ];
|
||||
|
||||
# These are configs for different nodes, but we'll use them here in `machine`
|
||||
|
@ -448,7 +506,8 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
testScript = { nodes, ... }:
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
let
|
||||
baseSystem = nodes.common.system.build.toplevel;
|
||||
in
|
||||
|
@ -461,8 +520,7 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
no-bootspec = makeTest
|
||||
{
|
||||
no-bootspec = makeTest {
|
||||
name = "systemd-boot-no-bootspec";
|
||||
meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue