From 6c0e4e892ff70b2875da3fd04e37b7fe3019850d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 16 May 2022 16:14:08 -0400 Subject: [PATCH] nixos/activation/bootspec: embed the entire contents of specialisation's bootspecs into the parent See: https://github.com/NixOS/rfcs/pull/125#discussion_r871222614 --- nixos/modules/system/activation/bootspec.nix | 38 +++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/nixos/modules/system/activation/bootspec.nix b/nixos/modules/system/activation/bootspec.nix index c38f675cea27..f14ec65137f3 100644 --- a/nixos/modules/system/activation/bootspec.nix +++ b/nixos/modules/system/activation/bootspec.nix @@ -19,25 +19,29 @@ let 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} - ''; + generator = + let + specialisationLoader = (lib.mapAttrsToList + (childName: childToplevel: lib.escapeShellArgs [ "--slurpfile" childName "${childToplevel}/${filename}" ]) + children); + in + '' + ${pkgs.jq}/bin/jq ' + .toplevel = $toplevel | + .init = $init + ' \ + --sort-keys \ + --arg toplevel "$out" \ + --arg init "$out/init" \ + < ${json} \ + | ${pkgs.jq}/bin/jq \ + --sort-keys \ + '.specialisation = ($ARGS.named | map_values(. | first))' \ + ${lib.concatStringsSep " " specialisationLoader} \ + > $out/${filename} + ''; }; }; in