From 5fd09508f4318c587c2396fe4e4534c003e86462 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 4 Nov 2024 12:24:47 -0600 Subject: [PATCH] reduce evaluation time --- pkgs/oizys/src/oizys/nix.nim | 48 ++++++++++--------- .../src/oizys/pkgs/oizys/src/oizys/nix.nim | 0 2 files changed, 25 insertions(+), 23 deletions(-) delete mode 100644 pkgs/oizys/src/oizys/pkgs/oizys/src/oizys/nix.nim diff --git a/pkgs/oizys/src/oizys/nix.nim b/pkgs/oizys/src/oizys/nix.nim index 205788b..e3234e1 100644 --- a/pkgs/oizys/src/oizys/nix.nim +++ b/pkgs/oizys/src/oizys/nix.nim @@ -134,8 +134,14 @@ proc evaluateDerivations(drvs: seq[string]): Table[string, NixDerivation] = cmd.addArgs drvs let (output, _) = runCmdCaptWithSpinner(cmd, "evaluating derivations") - fromJson(output, Table[string,NixDerivation]) + fromJson(output, Table[string, NixDerivation]) +proc nixDerivationShow(drvs: seq[string]): Table[string, NixDerivation] = + var cmd = "nix derivation show" + cmd.addArgs drvs + let (output, _ ) = + runCmdCaptWithSpinner(cmd, "evaluating " & drvs.join(" ")) + fromJson(output, Table[string, NixDerivation]) # TODO: replace asserts in this proc, would be easier with results type proc findSystemPaths(drvs: Table[string, NixDerivation]): seq[string] = @@ -172,33 +178,37 @@ func isIgnored(drv: string): bool = if name.startswith(pkg): return true -# proc systemPathDrvsToBuild(): seq[string] = - type OizysDerivation = object drv: NixDerivation # do i need this ? output: string name: string -iterator getSystemPathDrvs(drvs: Table[string, NixDerivation]): string = - let systemPaths = findSystemPaths(drvs) - for p in systemPaths: - for d in drvs[p].inputDrvs.keys(): - yield d +proc getSystemPathDrvs(): seq[string] = + let systemDrvs = nixDerivationShow(nixosConfigAttrs()) + let systemPathDrvs = findSystemPaths(systemDrvs) + result = + collect: + for k, drv in nixDerivationShow(systemPathDrvs): + for inputDrv, _ in drv.inputDrvs: + inputDrv + proc getOizysDerivations(): seq[OizysDerivation] = - let toBuild = toBuildNixosConfiguration() - let drvs = evaluateDerivations(nixosConfigAttrs()) + let + toBuildDrvs = toBuildNixosConfiguration() + systemPathDrvs = getSystemPathDrvs() + toActullyBuildDrvs = systemPathDrvs.filterIt(it in toBuildDrvs) - for name in getSystemPathDrvs(drvs): - if name in toBuild and not isIgnored(name): - let nixDrv = drvs[name] + for name, drv in nixDerivationShow(toActullyBuildDrvs): + if not isIgnored(name): result.add OizysDerivation( name: name, - output: nixDrv.outputs.`out`.path, - drv: nixDrv, + output: drv.outputs.`out`.path, + drv: drv, ) +# TODO: remove this proc proc systemPathDrvsToBuild(): seq[string] = var inputDrvs, dropped: seq[string] let toBuild = toBuildNixosConfiguration() @@ -210,12 +220,6 @@ proc systemPathDrvsToBuild(): seq[string] = (result, _) = filterSeq(inputDrvs, (s) => s in toBuild) (dropped, result) = filterSeq(result, isIgnored) - echo "SOMETHING SHOULD HAPPEN HERE!" - for drv in result: - echo drv - echo drvs[drv] - - debug fmt"ignored {dropped.len} derivations" result = result.mapIt(it & "^*") @@ -294,8 +298,6 @@ proc nixBuildWithCache*(name: string, rest:seq[string], service: string, jobs: i var cmd = "nix build" cmd.addArg drv.name & "^*" cmd.addArg "--no-link" - # cmd.addArg "--print-out-paths" - # cmd.addArg "-L" cmd.addArgs rest let buildCode = runCmd(cmd) if buildCode != 0: diff --git a/pkgs/oizys/src/oizys/pkgs/oizys/src/oizys/nix.nim b/pkgs/oizys/src/oizys/pkgs/oizys/src/oizys/nix.nim deleted file mode 100644 index e69de29..0000000