summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Helbling <cole.helbling@determinate.systems>2021-07-28 14:10:02 -0700
committerGraham Christensen <graham@grahamc.com>2022-05-11 13:49:38 -0400
commit530636fb24a8c9111e54071bc2f7f3cb2baa633a (patch)
tree83232302c8ac116a8774046b92cb0b91560c4c3e
parentMerge pull request #172288 from r-ryantm/auto-update/python3.10-dbf (diff)
downloadnixpkgs-530636fb24a8c9111e54071bc2f7f3cb2baa633a.tar.gz
bootspec: init against RFC-0125
-rw-r--r--.github/CODEOWNERS1
-rw-r--r--nixos/modules/system/activation/bootspec.nix50
-rw-r--r--nixos/modules/system/activation/top-level.nix10
3 files changed, 61 insertions, 0 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 28bfe7c1fd55..ecb0f525f8b4 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -71,6 +71,7 @@
/nixos/doc/manual/man-nixos-option.xml @nbp
/nixos/modules/installer/tools/nixos-option.sh @nbp
/nixos/modules/system @dasJ
+/nixos/modules/system/activation/bootspec.nix @grahamc @cole-h
# NixOS integration test driver
/nixos/lib/test-driver @tfc
diff --git a/nixos/modules/system/activation/bootspec.nix b/nixos/modules/system/activation/bootspec.nix
new file mode 100644
index 000000000000..c38f675cea27
--- /dev/null
+++ b/nixos/modules/system/activation/bootspec.nix
@@ -0,0 +1,50 @@
+# 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
+{ config, pkgs, lib, children }:
+let
+ schemas = {
+ v1 = rec {
+ filename = "boot.v1.json";
+ json =
+ pkgs.writeText filename
+ (builtins.toJSON
+ {
+ schemaVersion = 1;
+
+ 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})";
+
+ specialisation = lib.mapAttrs
+ (childName: childToplevel: {
+ bootspec = "${childToplevel}/${filename}";
+ })
+ children;
+ });
+
+ generator = ''
+ ${pkgs.jq}/bin/jq '
+ .toplevel = $toplevel |
+ .init = $init
+ ' \
+ --sort-keys \
+ --arg toplevel "$out" \
+ --arg init "$out/init" \
+ < ${json} \
+ > $out/${filename}
+ '';
+ };
+ };
+in
+{
+ # 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 = schemas.v1.generator;
+}
diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix
index 84f560691fc4..0f03fbf71374 100644
--- a/nixos/modules/system/activation/top-level.nix
+++ b/nixos/modules/system/activation/top-level.nix
@@ -22,6 +22,14 @@ let
"${config.system.boot.loader.kernelFile}";
initrdPath = "${config.system.build.initialRamdisk}/" +
"${config.system.boot.loader.initrdFile}";
+
+ bootSpec = import ./bootspec.nix {
+ inherit
+ config
+ pkgs
+ lib
+ children;
+ };
in ''
mkdir $out
@@ -95,6 +103,8 @@ let
echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies
+ ${bootSpec.writer}
+
${config.system.extraSystemBuilderCmds}
'';