diff --git a/flake.nix b/flake.nix index e51bf0e..e5a9eb3 100644 --- a/flake.nix +++ b/flake.nix @@ -49,12 +49,14 @@ nixConfig = { extra-substituters = [ + "https://attic.dayl.in/oizys" "https://hyprland.cachix.org" "https://nixpkgs-wayland.cachix.org" "https://daylin.cachix.org" # "https://cache.lix.systems" ]; extra-trusted-public-keys = [ + "oizys:DSw3mwVMM/Y+PXSVpkDlU5dLwlORuiJRGPkwr5INSMc=" "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=" "daylin.cachix.org-1:fLdSnbhKjtOVea6H9KqXeir+PyhO+sDSPhEW66ClE/k=" diff --git a/hosts/othalan/pkgs.nix b/hosts/othalan/pkgs.nix index 7645b27..529c505 100644 --- a/hosts/othalan/pkgs.nix +++ b/hosts/othalan/pkgs.nix @@ -10,5 +10,6 @@ graphviz typst charm-freeze + attic-client ]); } diff --git a/pkgs/oizys/src/oizys.nim b/pkgs/oizys/src/oizys.nim index 4d371a4..69f36b2 100644 --- a/pkgs/oizys/src/oizys.nim +++ b/pkgs/oizys/src/oizys.nim @@ -1,5 +1,5 @@ ## nix begat oizys -import std/[os, tables, sequtils, strformat, strutils] +import std/[os, osproc, tables, sequtils, strformat, strutils] import hwylterm, hwylterm/[cligen, logging] import oizys/[context, github, nix, overlay, logging] @@ -53,9 +53,9 @@ overlay: ## nix build nixBuild(minimal, rest) - proc cache(minimal: bool = false, name: string = "daylin") = - ## build and push to cachix - nixBuildWithCache(minimal, name, rest) + proc cache(name: string = "oizys", service: string = "attic", jobs: int = countProcessors()) = + ## build and push store paths + nixBuildWithCache(name, rest, service, jobs) proc osCmd() = ## nixos-rebuild @@ -97,7 +97,8 @@ when isMainModule: "ref" : "git ref/branch/tag to trigger workflow on" } cacheHelp = //{ - "name" : "name of cachix binary cache" + "name" : "name of cachix binary cache", + "jobs" : "jobs when pushing paths" } // sharedHelp let osUsage = $bb("$command [[subcmd] $args\n$doc[bold]Options[/]:\n$options") diff --git a/pkgs/oizys/src/oizys/exec.nim b/pkgs/oizys/src/oizys/exec.nim index ad1da3c..2809582 100644 --- a/pkgs/oizys/src/oizys/exec.nim +++ b/pkgs/oizys/src/oizys/exec.nim @@ -9,7 +9,7 @@ import hwylterm func addArgs*(cmd: var string, args: openArray[string]) = cmd &= " " & args.join(" ") -func addArg*(cmd: var string, arg: string) = +func addArg*(cmd: var string, arg: string ) = cmd &= " " & arg proc runCmd*(cmd: string): int = diff --git a/pkgs/oizys/src/oizys/nix.nim b/pkgs/oizys/src/oizys/nix.nim index 91c174e..5bf7dbe 100644 --- a/pkgs/oizys/src/oizys/nix.nim +++ b/pkgs/oizys/src/oizys/nix.nim @@ -193,6 +193,7 @@ proc writeDervationsToStepSummary(drvs: seq[string]) = let output = open(summaryFilePath,fmAppend) output.writeLine("| derivation | hash |\n|---|---|") output.writeLine(rows.join("\n")) + close output proc nixBuild*(minimal: bool, rest: seq[string]) = var cmd = nixCommand("build") @@ -233,23 +234,42 @@ proc nixBuildHostDry*(minimal: bool, rest: seq[string]) = let output = parseDryRunOutput err display output -proc nixBuildWithCache*(minimal: bool, name: string, rest:seq[string]) = - if findExe("cachix") == "": fatalQuit "is cachix installed?" - info bbfmt"building and pushing to cache: [b]{name}" - var cmd = "cachix" - cmd.addArgs ["watch-exec","--"] - cmd.addArg "nix build" - if minimal: - debug "populating args with derivations not built/cached" - let drvs = systemPathDrvsToBuild() - if drvs.len == 0: - info "nothing to build" - quit "exiting...", QuitSuccess - cmd.addArgs drvs - cmd.addArg "--no-link" - else: - cmd.addArgs nixosConfigAttrs() - cmd.addArgs rest - let err = runCmd(cmd) - quit err + +proc nixBuildWithCache*(name: string, rest:seq[string], service: string, jobs: int) = + ## 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}" + debug "determining missing cache hits" + let drvs = systemPathDrvsToBuild() + if drvs.len == 0: + info "nothing to build" + quit "exiting...", QuitSuccess + + for drv in drvs: + var cmd = "nix build" + cmd.addArg drv + cmd.addArgs rest + let buildErr = runCmd(cmd) + if buildErr != 0: + error "failed to build: " & drv + continue + + let results = collect( + for k, p in walkDir(".", relative = true): + if k in { pcLinkToDir, pcLinkToFile} and p.startsWith("result"): + p + ) + + cmd = service + cmd.addArg "push" + cmd.addArg name + cmd.addArg "--jobs" + cmd.addArg $jobs + cmd.addArgs results + let pushErr = runCmd(cmd) + if pushErr != 0: + errorQuit "failed to push build to cache" + + for p in results: + removeFile p