Files
vms/nix/cache.nix
T
Greg Hellings f99c35b2d5 Convert the cache to golang
In the interest of performance, convert the fetcher and uploader to
golang and use the minio library, rather than repeated calls to the
server with the command line
2024-12-24 00:23:26 -06:00

49 lines
1013 B
Nix

{
writeShellApplication,
active,
distroFile,
buildGoModule,
lib,
go,
packer,
...
}:
let
inherit (builtins) concatStringsSep map;
bin = buildGoModule {
pname = "cache";
version = "0.0.0";
src = ./cache;
vendorHash = "sha256-Mtq6BIlBNxI28eoLPfayov5uUqC4gMK+4ib6VKjyAlU=";
#vendorHash = lib.fakeHash;
meta.mainProgram = "main";
};
in
writeShellApplication {
name = "cache-isos";
runtimeInputs = [
go
packer
];
text =
''
function list_isos {
''
+ (concatStringsSep "\n" (
map (d: ''
url=$(echo var.iso.url | packer console -var-file="${d}" -config-type=hcl2 sources/)
sha=$(echo var.iso.checksum | packer console -var-file="${d}" -config-type=hcl2 sources/)
distro=$(echo var.distro | packer console -var-file="${d}" -config-type=hcl2 sources/)
echo "$url" "$sha" "$distro"
'') (lib.unique (lib.map distroFile active))
))
+ ''
}
list_isos | ${lib.getExe bin}
'';
}