diff --git a/pkgs/oizys/src/oizys.nim b/pkgs/oizys/src/oizys.nim index 4ac5557..4fc4b0d 100644 --- a/pkgs/oizys/src/oizys.nim +++ b/pkgs/oizys/src/oizys.nim @@ -59,12 +59,12 @@ hwylCli: flags: name: T string - ? "name of binary cache" - * "oizys" + ? "name/host of binary cache" + * "algiz" service: T string ? "name of cache service" - * "attic" + * "harmonica" jobs: T int ? "jobs when pushing paths" diff --git a/pkgs/oizys/src/oizys/nix.nim b/pkgs/oizys/src/oizys/nix.nim index 621a52f..ba7ec07 100644 --- a/pkgs/oizys/src/oizys/nix.nim +++ b/pkgs/oizys/src/oizys/nix.nim @@ -377,11 +377,52 @@ proc prettyDerivation*(path: string): BbString = drv.name.trunc(maxLen) & " " & drv.hash.bb("faint") +type NixCacheKind = enum + Store ## Nix-serve-ng, Harmonia + Service ## Attic, Cachix + +type NixCache = object + case kind: NixCacheKind + of Store: + host: string + of Service: + exe: string + name: string + + +proc toCache(service: string, name: string): NixCache = + case service + of "harmonica", "nix-serve-ng": + info bbfmt"building and pushing to /nix/store/ host: [b]{name}" + result = NixCache(kind: Store, host: name) + of "attic", "cachix": + info bbfmt"building and pushing to {service} cache: [b]{name}" + if findExe(service) == "": + fatalQuit fmt"is {service} installed?" + result = NixCache(kind: Service, name: name, exe: service) + else: + fatalQuit fmt"unknown cache service: {service}" + +proc pushPathsToCache(cache: NixCache, paths: openArray[string], jobs: int) = + var cmd: string + case cache.kind: + of Service: + cmd.addArgs cache.exe, "push", cache.name, "--jobs", $jobs + cmd.addArgs paths + of Store: + # TODO: how to handle user, this will probably error on remote machine + # Could try using NIX_SSHOPTS='-l daylin' on github actions + cmd.addArgs "nix-copy-closure", "-s", cache.host + cmd.addArgs paths + + let pushErr = runCmd(cmd) + if pushErr != 0: + errorQuit "failed to push build to cache" + proc nixBuildWithCache*(name: string, rest: seq[string], service: string, jobs: int, dry: bool) = ## build individual derivations not cached and push to cache - if findExe(service) == "": fatalQuit fmt"is {service} installed?" - info bbfmt"building and pushing to cache: [b]{name}" + let cache = toCache(service, name) debug "determining missing cache hits" let drvs = getOizysDerivations() @@ -389,9 +430,6 @@ proc nixBuildWithCache*(name: string, rest: seq[string], service: string, jobs: info "nothing to build" quit "exiting...", QuitSuccess - # TODO: fix this so it works with table - # info fmt("need to build {drvs.len} derivations:\n") & drvs.mapIt(prettyDerivation(" " & it.outputs["out"].path)).join("\n") - info fmt("need to build {drvs.len} dervations") for _, drv in drvs: info prettyDerivation(drv.outputs["out"].path) @@ -413,16 +451,7 @@ proc nixBuildWithCache*(name: string, rest: seq[string], service: string, jobs: reportResults(results) if outs.len > 0: - # TODO: push after build not at once? - var cmd = service - cmd.addArg "push" - cmd.addArg name - cmd.addArg "--jobs" - cmd.addArg $jobs - cmd.addArgs outs - let pushErr = runCmd(cmd) - if pushErr != 0: - errorQuit "failed to push build to cache" + pushPathsToCache(cache, outs, jobs) proc getUpdatedLockFile() = info "getting updated flake.lock as updated.lock"