Replace the shell scripts in flake.nix with Nushell scripts in ci/, exposed as flake apps in nix/ci-tasks.nix, so every workflow command is a plain nix call. Build the workspace dependencies in a step of their own, upload to Cachix only after the builds, and run the formatting check through the pre-commit hooks. Automated pushes, tags and pull requests now use the wvhulle-bot account. A weekly cron updates Cargo.lock and flake.lock and opens or updates one pull request from bot/dependency-updates. Claude-Session: https://claude.ai/code/session_01D8dLLgYd8cfR2aQfA5eZXa
80 lines
2.5 KiB
Nu
Executable File
80 lines
2.5 KiB
Nu
Executable File
#!/usr/bin/env nu
|
|
|
|
const EXPORT_DIRECTORY_NAME = ".nix-built-paths"
|
|
const PATH_LIST_FILE_NAME = "paths.txt"
|
|
const CACHIX_CACHE_NAME = "wvhulle"
|
|
const CACHIX_CACHE_URL = "https://wvhulle.cachix.org"
|
|
|
|
def export-directory []: nothing -> path {
|
|
$env.CI_WORKSPACE | path join $EXPORT_DIRECTORY_NAME
|
|
}
|
|
|
|
def store-paths-from-lines []: string -> list<string> {
|
|
lines | compact --empty
|
|
}
|
|
|
|
def exported-store-paths []: nothing -> list<string> {
|
|
let path_list_file = export-directory | path join $PATH_LIST_FILE_NAME
|
|
if ($path_list_file | path exists) {
|
|
open --raw $path_list_file | store-paths-from-lines
|
|
} else {
|
|
[]
|
|
}
|
|
}
|
|
|
|
def nix-config-with-hook [existing_config: string, hook_program: string]: nothing -> string {
|
|
$"($existing_config)\npost-build-hook = ($hook_program)"
|
|
}
|
|
|
|
def "main export-built-paths-hook" []: nothing -> nothing {
|
|
let built_paths = $env.OUT_PATHS | split row " " | compact --empty
|
|
let directory = export-directory
|
|
mkdir $directory
|
|
^nix copy --quiet --to $"file://($directory)?compression=zstd" ...$built_paths
|
|
$built_paths | each {|built_path| $"($built_path)\n" } | str join | save --append ($directory | path join $PATH_LIST_FILE_NAME)
|
|
}
|
|
|
|
def --wrapped "main build-and-export-paths" [
|
|
...build_arguments: string
|
|
]: nothing -> nothing {
|
|
let hook_config = nix-config-with-hook ($env.NIX_CONFIG? | default "") $env.EXPORT_HOOK_PROGRAM
|
|
with-env {NIX_CONFIG: $hook_config} {
|
|
^nix build --quiet --print-build-logs ...$build_arguments
|
|
}
|
|
}
|
|
|
|
def "main build-unless-cached" [
|
|
installable: string
|
|
]: nothing -> nothing {
|
|
let built_output = ^nix eval --quiet --raw $"($installable).outPath"
|
|
let cache_lookup = do { ^nix path-info --quiet --store $CACHIX_CACHE_URL $built_output } | complete
|
|
if $cache_lookup.exit_code == 0 {
|
|
print $"($built_output) is already in Cachix"
|
|
} else {
|
|
main build-and-export-paths $installable
|
|
}
|
|
}
|
|
|
|
def "main import-exported-paths" []: nothing -> nothing {
|
|
let exported_paths = exported-store-paths
|
|
if ($exported_paths | is-empty) {
|
|
print "No exported paths to import"
|
|
} else {
|
|
^nix copy --quiet --no-check-sigs --from $"file://(export-directory)" ...$exported_paths
|
|
}
|
|
}
|
|
|
|
def "main upload-exported-paths" []: nothing -> nothing {
|
|
let exported_paths = exported-store-paths
|
|
if ($exported_paths | is-empty) {
|
|
print "No newly built paths to upload"
|
|
} else {
|
|
main import-exported-paths
|
|
^cachix push $CACHIX_CACHE_NAME ...$exported_paths
|
|
}
|
|
}
|
|
|
|
def main []: nothing -> nothing {
|
|
print "Run a subcommand, for example: build-and-export-paths"
|
|
}
|