Unverified Commit 3f1f20b2 authored by WilliButz's avatar WilliButz
Browse files

nixos/repart-image: pass partition attrs to builder instead of JSON file

Having access to the original Nix partition definitions in the builder
should make it a bit easier to manipulate them and still provide access
to the manipulated results.
parent 23887af5
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
, imageFileBasename
, compression
, fileSystems
, partitionsJSON
, finalPartitions
, split
, seed
, definitionsDirectory
@@ -110,7 +110,9 @@ in

  env = mkfsEnv;

  inherit partitionsJSON definitionsDirectory;
  inherit finalPartitions definitionsDirectory;

  partitionsJSON = builtins.toJSON finalAttrs.finalPartitions;

  # relative path to the repart definitions that are read by systemd-repart
  finalRepartDefinitions = "repart.d";
@@ -136,7 +138,7 @@ in
  patchPhase = ''
    runHook prePatch

    amendedRepartDefinitionsDir=$(${amendRepartDefinitions} $partitionsJSON $definitionsDirectory)
    amendedRepartDefinitionsDir=$(${amendRepartDefinitions} <(echo "$partitionsJSON") $definitionsDirectory)
    ln -vs $amendedRepartDefinitionsDir $finalRepartDefinitions

    runHook postPatch
+8 −10
Original line number Diff line number Diff line
@@ -163,21 +163,19 @@ in
          createEmpty = false;
        }).overrideAttrs
          (
            finalAttrs: previousAttrs:
            let
              copyUki = "CopyFiles=${config.system.build.uki}/${config.system.boot.loader.ukiFile}:${cfg.ukiPath}";
            in
            {
            finalAttrs: previousAttrs: {
              # add entry to inject UKI into ESP
              finalPartitions = lib.recursiveUpdate previousAttrs.finalPartitions {
                ${cfg.partitionIds.esp}.contents = {
                  "${cfg.ukiPath}".source = "${config.system.build.uki}/${config.system.boot.loader.ukiFile}";
                };
              };

              nativeBuildInputs = previousAttrs.nativeBuildInputs ++ [
                pkgs.systemdUkify
                verityHashCheck
              ];

              postPatch = ''
                # add entry to inject UKI into ESP
                echo '${copyUki}' >> $finalRepartDefinitions/${cfg.partitionIds.esp}.conf
              '';

              preBuild = ''
                # check that we build the final image with the same intermediate image for
                # which the injected UKI was built by comparing the UKI cmdline with the repart output
+2 −4
Original line number Diff line number Diff line
@@ -318,14 +318,12 @@ in
          format
          (lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) cfg.finalPartitions);

        partitionsJSON = pkgs.writeText "partitions.json" (builtins.toJSON cfg.finalPartitions);

        mkfsEnv = mkfsOptionsToEnv cfg.mkfsOptions;
      in
      pkgs.callPackage ./repart-image.nix {
        systemd = cfg.package;
        inherit (cfg) name version imageFileBasename compression split seed sectorSize;
        inherit fileSystems definitionsDirectory partitionsJSON mkfsEnv;
        inherit (cfg) name version imageFileBasename compression split seed sectorSize finalPartitions;
        inherit fileSystems definitionsDirectory mkfsEnv;
      };

    meta.maintainers = with lib.maintainers; [ nikstur willibutz ];