reduce evaluation time

This commit is contained in:
Daylin Morgan 2024-11-04 12:24:47 -06:00
parent 2a492684c2
commit 5fd09508f4
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 25 additions and 23 deletions

View file

@ -134,8 +134,14 @@ proc evaluateDerivations(drvs: seq[string]): Table[string, NixDerivation] =
cmd.addArgs drvs cmd.addArgs drvs
let (output, _) = let (output, _) =
runCmdCaptWithSpinner(cmd, "evaluating derivations") 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 # TODO: replace asserts in this proc, would be easier with results type
proc findSystemPaths(drvs: Table[string, NixDerivation]): seq[string] = proc findSystemPaths(drvs: Table[string, NixDerivation]): seq[string] =
@ -172,33 +178,37 @@ func isIgnored(drv: string): bool =
if name.startswith(pkg): if name.startswith(pkg):
return true return true
# proc systemPathDrvsToBuild(): seq[string] =
type type
OizysDerivation = object OizysDerivation = object
drv: NixDerivation # do i need this ? drv: NixDerivation # do i need this ?
output: string output: string
name: string name: string
iterator getSystemPathDrvs(drvs: Table[string, NixDerivation]): string = proc getSystemPathDrvs(): seq[string] =
let systemPaths = findSystemPaths(drvs) let systemDrvs = nixDerivationShow(nixosConfigAttrs())
for p in systemPaths: let systemPathDrvs = findSystemPaths(systemDrvs)
for d in drvs[p].inputDrvs.keys(): result =
yield d collect:
for k, drv in nixDerivationShow(systemPathDrvs):
for inputDrv, _ in drv.inputDrvs:
inputDrv
proc getOizysDerivations(): seq[OizysDerivation] = proc getOizysDerivations(): seq[OizysDerivation] =
let toBuild = toBuildNixosConfiguration() let
let drvs = evaluateDerivations(nixosConfigAttrs()) toBuildDrvs = toBuildNixosConfiguration()
systemPathDrvs = getSystemPathDrvs()
toActullyBuildDrvs = systemPathDrvs.filterIt(it in toBuildDrvs)
for name in getSystemPathDrvs(drvs): for name, drv in nixDerivationShow(toActullyBuildDrvs):
if name in toBuild and not isIgnored(name): if not isIgnored(name):
let nixDrv = drvs[name]
result.add OizysDerivation( result.add OizysDerivation(
name: name, name: name,
output: nixDrv.outputs.`out`.path, output: drv.outputs.`out`.path,
drv: nixDrv, drv: drv,
) )
# TODO: remove this proc
proc systemPathDrvsToBuild(): seq[string] = proc systemPathDrvsToBuild(): seq[string] =
var inputDrvs, dropped: seq[string] var inputDrvs, dropped: seq[string]
let toBuild = toBuildNixosConfiguration() let toBuild = toBuildNixosConfiguration()
@ -210,12 +220,6 @@ proc systemPathDrvsToBuild(): seq[string] =
(result, _) = filterSeq(inputDrvs, (s) => s in toBuild) (result, _) = filterSeq(inputDrvs, (s) => s in toBuild)
(dropped, result) = filterSeq(result, isIgnored) (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" debug fmt"ignored {dropped.len} derivations"
result = result.mapIt(it & "^*") result = result.mapIt(it & "^*")
@ -294,8 +298,6 @@ proc nixBuildWithCache*(name: string, rest:seq[string], service: string, jobs: i
var cmd = "nix build" var cmd = "nix build"
cmd.addArg drv.name & "^*" cmd.addArg drv.name & "^*"
cmd.addArg "--no-link" cmd.addArg "--no-link"
# cmd.addArg "--print-out-paths"
# cmd.addArg "-L"
cmd.addArgs rest cmd.addArgs rest
let buildCode = runCmd(cmd) let buildCode = runCmd(cmd)
if buildCode != 0: if buildCode != 0: