From b8b7a570f5a2be4b3d2dfe0f5cafed20e893f921 Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Sat, 7 Sep 2024 20:43:05 -0700 Subject: [PATCH] nix-update: add, use for updates, simply main.nu --- flake.lock | 81 ++++++++++++++++++++++++++++++- flake.nix | 4 ++ main.nu | 140 +++++++++-------------------------------------------- 3 files changed, 107 insertions(+), 118 deletions(-) diff --git a/flake.lock b/flake.lock index 247598137..3a1bdceb5 100644 --- a/flake.lock +++ b/flake.lock @@ -36,6 +36,27 @@ "type": "github" } }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": [ + "nix-update", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -115,6 +136,26 @@ "type": "github" } }, + "nix-update": { + "inputs": { + "flake-parts": "flake-parts_2", + "nixpkgs": "nixpkgs_2", + "treefmt-nix": "treefmt-nix_2" + }, + "locked": { + "lastModified": 1725641144, + "narHash": "sha256-haSfwdurfltqQ/7YEmDcmWLnWwvAgelIHnXsHG34P1k=", + "owner": "Mic92", + "repo": "nix-update", + "rev": "1b151b14df5db78bfcca0ee670a8c71daa441125", + "type": "github" + }, + "original": { + "owner": "Mic92", + "repo": "nix-update", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1723221148, @@ -147,6 +188,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1720181791, + "narHash": "sha256-i4vJL12/AdyuQuviMMd1Hk2tsGt02hDNhA0Zj1m16N8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4284c2b73c8bce4b46a6adf23e16d9e2ec8da4bb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1725634671, "narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=", @@ -167,7 +224,8 @@ "flake-compat": "flake-compat", "lib-aggregate": "lib-aggregate", "nix-eval-jobs": "nix-eval-jobs", - "nixpkgs": "nixpkgs_2" + "nix-update": "nix-update", + "nixpkgs": "nixpkgs_3" } }, "systems": { @@ -205,6 +263,27 @@ "repo": "treefmt-nix", "type": "github" } + }, + "treefmt-nix_2": { + "inputs": { + "nixpkgs": [ + "nix-update", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719887753, + "narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index dd7570f65..9685a516d 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,9 @@ flake-compat = { url = "github:nix-community/flake-compat"; }; + nix-update = { + url = "github:Mic92/nix-update"; + }; }; nixConfig = { @@ -367,6 +370,7 @@ ripgrep sd inputs.nix-eval-jobs.outputs.packages.${system}.default + inputs.nix-update.outputs.packages.${system}.default ]; }; diff --git a/main.nu b/main.nu index 5af743b59..70dd252a3 100755 --- a/main.nu +++ b/main.nu @@ -13,23 +13,6 @@ $env.CACHIX_SIGNING_KEY = ( else "null" ) -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 getBadHash [ attrName: string ] { - let val = ((do -i { ^nix build --no-link $attrName }| complete) - | get stderr - | split row "\n" - | where ($it | str contains "got:") - | str replace --regex '\s+got:(.*)(sha256-.*)' '$2' - | get 0 - ) - $val -} - def replaceHash [ packageName: string, position: string, hashName: string, oldHash: string ] { let fakeSha256 = "0000000000000000000000000000000000000000000000000000"; @@ -46,54 +29,13 @@ def updatePkg [packageName: string] { let skip = (("skip" in ($verinfo | transpose | get column0)) and $verinfo.skip) if $skip { - print -e $"(ansi light_yellow) update ($packageName) - (ansi light_cyan_underline)skipped(ansi reset)" - } else { - # Try update rev - let newrev = ( - if ("repo_git" in ($verinfo | transpose | get column0)) { - (do -c { - ^git ls-remote $verinfo.repo_git $"refs/heads/($verinfo.branch)" - } | complete | get stdout | str trim | str replace --regex '(\s+)(.*)$' "") - } else if ( "repo_hg" in ($verinfo | transpose | get column0) ) { - (do -c { - ^hg identify $verinfo.repo_hg -r $verinfo.branch - } | complete | get stdout | str trim) - } else { - error make { msg: "unknown repo type" } - } - ) - - let shouldUpdate = (if ($forceCheck) { - print -e $"(ansi light_yellow) update ($packageName) - (ansi light_yellow_underline)forced(ansi reset)" - true - } else if ($newrev != $verinfo.rev) { - print -e $"(ansi light_yellow) update ($packageName) - (ansi light_yellow_underline)update to ($newrev)(ansi reset)" - true - } else { - print -e $"(ansi dark_gray) update ($packageName) - noop(ansi reset)" - false - }) - - if ($shouldUpdate) { - do -c { ^sd -s $"($verinfo.rev)" $"($newrev)" $"($position)" } - print -e {packageName: $packageName, oldrev: $verinfo.rev, newrev: $newrev} - - replaceHash $packageName $position "sha256" $verinfo.sha256 - if "vendorSha256" in ($verinfo | transpose | get column0) { - replaceHash $packageName $position "vendorSha256" $verinfo.vendorSha256 - } - - do -c { - ^git commit $position -m $"auto-update: ($packageName): ($verinfo.rev) => ($newrev)" - } | complete - } + return + } - null - } # end !skip + nix-update --flake $"packages.x86_64-linux.($packageName)" --version branch --commit --override-filename ./pkgs/($packageName)/metadata.nix } def updatePkgs [] { - header "light_yellow_reverse" "update packages" let pkgs = (^nix eval --json $".#packages.($system)" --apply 'x: builtins.attrNames x' | str trim | from json) let pkgs = ($pkgs | where ($it != "default")) $pkgs | each { |packageName| @@ -101,46 +43,8 @@ def updatePkgs [] { } # end each-pkg loop } -def buildDrv [ drvRef: string ] { - header "white_reverse" $"build ($drvRef)" "░" - header "blue_reverse" $"eval ($drvRef)" - let evalJobs = ( - ^nix-eval-jobs - --flake $".#($drvRef)" - | from json --objects - ) - - header "green_reverse" $"build ($drvRef)" - print -e ($evalJobs - | select name) - - $evalJobs - | 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 ($env.CACHIX_SIGNING_KEY != "null") { - let cachePathsStr = ($pushPaths | each {|it| $"($it)(char nl)"} | str join) - - let cacheResults = (echo $cachePathsStr | ^cachix push $env.CACHIX_CACHE | complete) - header "purple_reverse" $"cache/push ($drvRef)" - print -e $cacheResults - } else { - print -e "'$CACHIX_SIGNING_KEY_NIXPKGS_WAYLAND' not set, not pushing to cachix." - } -} - def "main rereadme" [] { let color = "yellow" - header $"($color)_reverse" $"readme" let packageNames = (nix eval --json $".#packages.($system)" --apply 'x: builtins.attrNames x' | str trim | from json) let pkgList = ($packageNames | where ($it != "default")) let delimStart = "" @@ -171,40 +75,42 @@ def "main rereadme" [] { do -i { ^git commit -m "auto-update: updated readme" "./README.md" } } -def "main build" [] { - buildDrv $"packages.($system)" - print -e "" - buildDrv $"devShells.($system).default.inputDerivation" -} - def flakeAdvance [] { - header "purple_reverse" "advance flake inputs" ^nix flake lock --recreate-lock-file --commit-lock-file } def gitPush [] { - header "purple_reverse" "git push origin HEAD" + print -e ":: git push origin HEAD" ^git push origin HEAD } -def "main advance" [] { - flakeAdvance - main build - gitPush -} +def "main build" [] { + print -e ":: nix build bundle (cachix)" + ^nix build --keep-going --print-out-paths '.#bundle.x86_64-linux' | cachix push $env.CACHIX_CACHE -def "main update1" [packageName: string] { - updatePkg $packageName + print -e ":: nix build devshell-inputDrv (cachix)" + ^nix build --keep-going --print-out-paths $"devShells.($system).default.inputDerivation" | cachix push $env.CACHIX_CACHE } -def "main update" [] { +def "main advance" [] { flakeAdvance - updatePkgs main build - main rereadme gitPush } +def "main update" [packageName?: string] { + print -e ":: update" + if $packageName == null { + flakeAdvance + updatePkgs + main build + main rereadme + gitPush + } else { + updatePkg $packageName + } +} + def main [] { print -e "commands: [advance, update, build]" }