Skip to content

Commit

Permalink
feat: stabilize the output api
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jun 16, 2023
1 parent 7369f76 commit 37a40b3
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ let
"dir://$out" \
| cat # pipe through cat to force-disable progress bar
'';
in pkgs.runCommand "nix2container-${imageName}.json" { } ''
${nix2containerUtil}/bin/nix2container image-from-dir $out ${dir}
'';
in l.lazyDerivation {
derivation = pkgs.runCommand "nix2container-${imageName}.json" { } ''
${nix2containerUtil}/bin/nix2container image-from-dir $out ${dir}
'';
};

buildLayer = {
# A list of store paths to include in the layer.
Expand Down Expand Up @@ -187,18 +189,20 @@ let
permsFlag = l.optionalString (perms != []) "--perms ${permsFile}";
allDeps = deps ++ copyToRootList;
tarDirectory = l.optionalString (! reproducible) "--tar-directory $out";
layersJSON = pkgs.runCommand "layers.json" {} ''
mkdir $out
${nix2containerUtil}/bin/nix2container ${subcommand} \
$out/layers.json \
${closureGraph allDeps} \
--max-layers ${toString maxLayers} \
${rewritesFlag} \
${permsFlag} \
${tarDirectory} \
${l.concatMapStringsSep " " (l: l + "/layers.json") layers} \
${l.optionalString (ignore != null) "--ignore ${ignore}"}
'';
layersJSON = l.lazyDerivation {
derivation = pkgs.runCommand "layers.json" {} ''
mkdir $out
${nix2containerUtil}/bin/nix2container ${subcommand} \
$out/layers.json \
${closureGraph allDeps} \
--max-layers ${toString maxLayers} \
${rewritesFlag} \
${permsFlag} \
${tarDirectory} \
${l.concatMapStringsSep " " (l: l + "/layers.json") layers} \
${l.optionalString (ignore != null) "--ignore ${ignore}"}
'';
};
in checked { inherit copyToRoot contents; } layersJSON;


Expand Down Expand Up @@ -299,10 +303,16 @@ let
};
fromImageFlag = l.optionalString (fromImage != "") "--from-image ${fromImage}";
layerPaths = l.concatMapStringsSep " " (l: l + "/layers.json") ([customizationLayer] ++ layers);
image = pkgs.runCommand "image-${baseNameOf name}.json"
{
imageName = l.toLower name;
image = l.lazyDerivation {
derivation = pkgs.runCommand "image-${baseNameOf name}.json" ''
${nix2containerUtil}/bin/nix2container image \
$out \
${fromImageFlag} \
${configFile} \
${layerPaths}
'';
passthru = {
imageName = l.toLower name;
imageTag =
if tag != null
then tag
Expand All @@ -313,14 +323,7 @@ let
copyToPodman = copyToPodman image;
copyTo = copyTo image;
};
}
''
${nix2containerUtil}/bin/nix2container image \
$out \
${fromImageFlag} \
${configFile} \
${layerPaths}
'';
};
in checked { inherit copyToRoot contents; } image;

checked = { copyToRoot, contents }:
Expand Down

0 comments on commit 37a40b3

Please sign in to comment.