2021-07-28 23:10:02 +02:00
|
|
|
# Note that these schemas are defined by RFC-0125.
|
|
|
|
# This document is considered a stable API, and is depended upon by external tooling.
|
|
|
|
# Changes to the structure of the document, or the semantics of the values should go through an RFC.
|
|
|
|
#
|
|
|
|
# See: https://github.com/NixOS/rfcs/pull/125
|
2022-11-30 17:55:41 +01:00
|
|
|
{ config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, ...
|
|
|
|
}:
|
2021-07-28 23:10:02 +02:00
|
|
|
let
|
2022-11-30 17:55:41 +01:00
|
|
|
cfg = config.boot.bootspec;
|
|
|
|
children = lib.mapAttrs (childName: childConfig: childConfig.configuration.system.build.toplevel) config.specialisation;
|
2021-07-28 23:10:02 +02:00
|
|
|
schemas = {
|
|
|
|
v1 = rec {
|
2022-11-30 17:55:41 +01:00
|
|
|
filename = "boot.json";
|
2021-07-28 23:10:02 +02:00
|
|
|
json =
|
|
|
|
pkgs.writeText filename
|
|
|
|
(builtins.toJSON
|
2022-11-30 17:55:41 +01:00
|
|
|
{
|
|
|
|
v1 = {
|
2021-07-28 23:10:02 +02:00
|
|
|
kernel = "${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}";
|
|
|
|
kernelParams = config.boot.kernelParams;
|
|
|
|
initrd = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
|
|
|
|
initrdSecrets = "${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets";
|
|
|
|
label = "NixOS ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})";
|
2022-11-30 17:55:41 +01:00
|
|
|
|
|
|
|
inherit (cfg) extensions;
|
|
|
|
};
|
|
|
|
});
|
2021-07-28 23:10:02 +02:00
|
|
|
|
2022-05-16 22:14:08 +02:00
|
|
|
generator =
|
|
|
|
let
|
|
|
|
specialisationLoader = (lib.mapAttrsToList
|
2022-11-30 15:08:37 +01:00
|
|
|
(childName: childToplevel: lib.escapeShellArgs [ "--slurpfile" childName "${childToplevel}/bootspec/${filename}" ])
|
2022-05-16 22:14:08 +02:00
|
|
|
children);
|
|
|
|
in
|
|
|
|
''
|
2022-05-18 21:46:29 +02:00
|
|
|
mkdir -p $out/bootspec
|
|
|
|
|
2022-05-16 22:14:08 +02:00
|
|
|
${pkgs.jq}/bin/jq '
|
2022-11-30 17:55:41 +01:00
|
|
|
.v1.toplevel = $toplevel |
|
|
|
|
.v1.init = $init
|
2022-05-16 22:14:08 +02:00
|
|
|
' \
|
|
|
|
--sort-keys \
|
|
|
|
--arg toplevel "$out" \
|
|
|
|
--arg init "$out/init" \
|
|
|
|
< ${json} \
|
|
|
|
| ${pkgs.jq}/bin/jq \
|
|
|
|
--sort-keys \
|
2022-11-30 17:55:41 +01:00
|
|
|
'.v1.specialisation = ($ARGS.named | map_values(. | first | .v1))' \
|
2022-05-16 22:14:08 +02:00
|
|
|
${lib.concatStringsSep " " specialisationLoader} \
|
2022-05-18 21:46:29 +02:00
|
|
|
> $out/bootspec/${filename}
|
2022-05-16 22:14:08 +02:00
|
|
|
'';
|
2022-11-30 17:55:41 +01:00
|
|
|
|
|
|
|
validator = pkgs.writeCueValidator ./bootspec.cue {
|
|
|
|
document = "Document"; # Universal validator for any version as long the schema is correctly set.
|
|
|
|
};
|
2021-07-28 23:10:02 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2022-11-30 17:55:41 +01:00
|
|
|
options.boot.bootspec = {
|
|
|
|
enable = lib.mkEnableOption "Enable generation of RFC-0125 bootspec in $system/bootspec, e.g. /run/current-system/bootspec";
|
|
|
|
extensions = lib.mkOption {
|
|
|
|
type = lib.types.attrs;
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
# This will be run as a part of the `systemBuilder` in ./top-level.nix. This
|
|
|
|
# means `$out` points to the output of `config.system.build.toplevel` and can
|
|
|
|
# be used for a variety of things (though, for now, it's only used to report
|
|
|
|
# the path of the `toplevel` itself and the `init` executable).
|
|
|
|
writer = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = schemas.v1.generator;
|
|
|
|
};
|
|
|
|
validator = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = schemas.v1.validator;
|
|
|
|
};
|
|
|
|
filename = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = schemas.v1.filename;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf (cfg.enable) {
|
|
|
|
warnings = [
|
|
|
|
''RFC-0125 is not merged yet, this is a feature preview of bootspec.
|
2022-11-30 18:12:13 +01:00
|
|
|
The schema is not definitive and features are not guaranteed to be stable until RFC-0125 is merged.
|
2022-11-30 17:55:41 +01:00
|
|
|
See:
|
|
|
|
- https://github.com/NixOS/nixpkgs/pull/172237 to track merge status in nixpkgs.
|
|
|
|
- https://github.com/NixOS/rfcs/pull/125 to track RFC status.
|
|
|
|
''
|
|
|
|
];
|
|
|
|
};
|
2021-07-28 23:10:02 +02:00
|
|
|
}
|