Improve variant builder

This commit is contained in:
Surma
2024-09-08 11:07:02 +01:00
parent aa7b284e65
commit dfc9b36b6e

View File

@@ -15,6 +15,7 @@
webp-src, webp-src,
}: }:
let let
packageVariants = { packageVariants = {
base = { base = {
simd = false; simd = false;
@@ -23,6 +24,7 @@
simd = true; simd = true;
}; };
}; };
in in
flake-utils.lib.eachDefaultSystem ( flake-utils.lib.eachDefaultSystem (
system: system:
@@ -93,34 +95,26 @@
''; '';
dontFixup = true; dontFixup = true;
}; };
"install-${name}" = writeShellScriptBin "install.sh" ''
${pkgs.coreutils}/bin/mkdir -p wasm_build/${name}
${pkgs.rsync}/bin/rsync --chmod=u+w -r ${
self.packages.${system}."webp-squoosh-${name}"
}/* wasm_build/${name}
'';
}; };
packages = lib.foldl (acc: v: acc//v) {} (lib.mapAttrsToList packageVariantBuilder packageVariants); packages = lib.foldl (acc: v: acc//v) {} (lib.mapAttrsToList packageVariantBuilder packageVariants);
joinLines = lines: lib.foldl (text: line: text + line) "" lines; defaultPackage = let
variants = lib.mapAttrs (name: opts: packages."webp-squoosh-${name}") packageVariants;
globalInstallerCode = joinLines (lib.lists.map (variantName: '' copyCommands = lib.concatLines (lib.mapAttrsToList (name: path: "cp -r ${path} $out/${name}") variants);
${self.packages.${system}."install-${variantName}"}/bin/install.sh in
'') (lib.attrNames packageVariants)); stdenv.mkDerivation {
name = "all-variants";
phases = ["buildPhase"];
buildPhase = ''
mkdir -p $out;
${copyCommands}
'';
};
in in
{ mkInstallable {
packages = packages // { packages = packages // {default = defaultPackage;};
installScript = writeShellScriptBin "install.sh" globalInstallerCode;
};
apps = {
install = {
type = "app";
program = "${self.packages.${system}.installScript}/bin/install.sh";
};
};
} }
); );
} }