1 # Note that these schemas are defined by RFC-0125.
2 # This document is considered a stable API, and is depended upon by external tooling.
3 # Changes to the structure of the document, or the semantics of the values should go through an RFC.
5 # See: https://github.com/NixOS/rfcs/pull/125
13 cfg = config.boot.bootspec;
14 children = lib.mapAttrs (
15 childName: childConfig: childConfig.configuration.system.build.toplevel
16 ) config.specialisation;
17 hasAtLeastOneInitrdSecret = lib.length (lib.attrNames config.boot.initrd.secrets) > 0;
20 filename = "boot.json";
21 json = pkgs.writeText filename (
23 # Merge extensions first to not let them shadow NixOS bootspec data.
27 "org.nixos.bootspec.v1" =
29 system = config.boot.kernelPackages.stdenv.hostPlatform.system;
30 kernel = "${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}";
31 kernelParams = config.boot.kernelParams;
32 label = "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})";
34 // lib.optionalAttrs config.boot.initrd.enable {
35 initrd = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
37 // lib.optionalAttrs hasAtLeastOneInitrdSecret {
38 initrdSecrets = "${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets";
46 # NOTE: Be careful to not introduce excess newlines at the end of the
47 # injectors, as that may affect the pipes and redirects.
49 # Inject toplevel and init into the bootspec.
50 # This can only be done here because we *cannot* depend on $out
51 # referring to the toplevel, except by living in the toplevel itself.
54 "${pkgs.buildPackages.jq}/bin/jq"
56 ."org.nixos.bootspec.v1".toplevel = $toplevel |
57 ."org.nixos.bootspec.v1".init = $init
62 "${placeholder "out"}"
65 "${placeholder "out"}/init"
69 # We slurp all specialisations and inject them as values, such that
70 # `.specialisations.${name}` embeds the specialisation's bootspec
72 specialisationInjector =
74 specialisationLoader = (
76 childName: childToplevel:
80 "${childToplevel}/${filename}"
86 "${pkgs.buildPackages.jq}/bin/jq"
88 ''."org.nixos.specialisation.v1" = ($ARGS.named | map_values(. | first))''
90 + " ${lib.concatStringsSep " " specialisationLoader}";
92 "${toplevelInjector} | ${specialisationInjector} > $out/${filename}";
94 validator = pkgs.writeCueValidator ./bootspec.cue {
95 document = "Document"; # Universal validator for any version as long the schema is correctly set.
101 options.boot.bootspec = {
103 lib.mkEnableOption "the generation of RFC-0125 bootspec in $system/boot.json, e.g. /run/current-system/boot.json"
108 enableValidation = lib.mkEnableOption ''
109 the validation of bootspec documents for each build.
110 This will introduce Go in the build-time closure as we are relying on [Cuelang](https://cuelang.org/) for schema validation.
111 Enable this option if you want to ascertain that your documents are correct
114 extensions = lib.mkOption {
115 # NOTE(RaitoBezarius): this is not enough to validate: extensions."osRelease" = drv; those are picked up by cue validation.
116 type = lib.types.attrsOf lib.types.anything; # <namespace>: { ...namespace-specific fields }
119 User-defined data that extends the bootspec document.
121 To reduce incompatibility and prevent names from clashing
122 between applications, it is **highly recommended** to use a
123 unique namespace for your extensions.
127 # This will be run as a part of the `systemBuilder` in ./top-level.nix. This
128 # means `$out` points to the output of `config.system.build.toplevel` and can
129 # be used for a variety of things (though, for now, it's only used to report
130 # the path of the `toplevel` itself and the `init` executable).
131 writer = lib.mkOption {
133 default = schemas.v1.generator;
136 validator = lib.mkOption {
138 default = schemas.v1.validator;
141 filename = lib.mkOption {
143 default = schemas.v1.filename;