-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.nu
executable file
·61 lines (49 loc) · 1.54 KB
/
main.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env nu
# original from https://github.com/nix-community/nixpkgs-wayland/blob/master/main.nu
let system = "x86_64-linux";
def header [ color: string text: string spacer="▒": string ] {
let text = $"($text) "
let header = $"("" | fill -c $spacer -w 2) ($text | fill -c $spacer -w 100)"
print -e $"(ansi $color)($header)(ansi reset)"
}
def main [] {
print -e "commands: [build]"
}
def "main build" [] {
buildDrv $"packages.($system)"
print -e ""
}
def buildDrv [ drvRef: string ] {
header "white_reverse" $"build ($drvRef)" "░"
header "blue_reverse" $"eval ($drvRef)"
let evalJobs = (
^nix-eval-jobs
--flake $".#($drvRef)"
--check-cache-status
| from json --objects
)
header "green_reverse" $"build ($drvRef)"
print -e ($evalJobs
| where isCached == false
| select name isCached)
$evalJobs
| where isCached == false
| each { |drv| do -c { ^nix build $'($drv.drvPath)^*' } }
header "purple_reverse" $"cache: calculate paths: ($drvRef)"
let pushPaths = ($evalJobs | each { |drv|
$drv.outputs | each { |outPath|
if ($outPath.out | path exists) {
$outPath.out
}
}
})
print -e $pushPaths
if ('CACHIX_AUTH_TOKEN' in $env) {
let cachePathsStr = ($pushPaths | each {|it| $"($it)(char nl)"} | str join)
let cacheResults = (echo $cachePathsStr | ^cachix push daeuniverse | complete)
header "purple_reverse" $"cache/push ($drvRef)"
print -e $cacheResults
} else {
print -e "'$CACHIX_AUTH_TOKEN' not set, not pushing to cachix."
}
}