Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

seed-ci: drop

+2 -286
+2 -11
.forgejo/workflows/build-x86_64.yaml
··· 8 8 SOWER_ENDPOINT: ${{ vars.SOWER_ENDPOINT }} 9 9 10 10 jobs: 11 - build-and-seed-x86_64: 12 - runs-on: local/x86_64-linux 13 - 14 - steps: 15 - - uses: actions/checkout@v4 16 - 17 - - run: | 18 - export HOME=$PWD 19 - nix develop .# --command seed-ci --attic-upload=true --nom=false --sower-seed=true --system x86_64-linux --cache-build-deps=true 20 - 21 11 sower: 22 12 runs-on: local/x86_64-linux 23 13 24 14 steps: 25 15 - uses: actions/checkout@v4 26 16 27 - - run: | 17 + - name: go cli 18 + run: | 28 19 export HOME=$PWD 29 20 30 21 nix develop .#ci --command attic login main $ATTIC_URL --set-default $ATTIC_KEY
-245
bin/seed-ci
··· 1 - #!/usr/bin/env nu 2 - 3 - def attic-setup [url: string, cache: string, token: string] { 4 - print $"⭐ Ensuring attic cache ($url)/($cache)" 5 - let check = attic cache info $"main:($cache)" | complete 6 - 7 - if $check.exit_code != 0 { 8 - attic login main $url --set-default $token 9 - } 10 - 11 - attic cache info $"main:($cache)" 12 - } 13 - 14 - def attic-use [cache: string] { 15 - attic use $"main:($cache)" 16 - } 17 - 18 - export def attic-upload [cache: string] { 19 - let paths = $in 20 - 21 - if ($paths | length) == 0 { 22 - print "‼️ No targets to push to attic. Skipping push" 23 - } else { 24 - print $"📤 Pushing to attic cache ($cache)" 25 - $paths | str join "\n" | attic push --stdin --ignore-upstream-cache-filter --jobs 30 $"main:($cache)" out+err> push.log 26 - cat push.log 27 - } 28 - } 29 - 30 - export def load-seeds [] { 31 - nix eval .#sower --json | from json | transpose seed_type targets | each {|seed_type| $seed_type | update targets ($seed_type.targets | transpose name config) } 32 - } 33 - 34 - export def filter-configs [--system: string] { 35 - let configs = $in 36 - 37 - if $system == null { 38 - $configs 39 - } else { 40 - $configs | each { |c| 41 - $c | update targets ( 42 - $c.targets | where { |i| 43 - $system in $i.config.systems 44 - } | each { |i| 45 - $i | update config.systems [$system] 46 - } 47 - ) 48 - } 49 - } 50 - } 51 - 52 - export def build-configs [--threads: int] { 53 - let configs = $in 54 - 55 - print $"Building configs with ($threads) threads" 56 - 57 - $configs | each { |c| 58 - $c | update targets ($c.targets | par-each --threads $threads { |i| 59 - let buildTarget: list<string> = if $c.seed_type == "nix-darwin" { 60 - [$".#darwinConfigurations.($i.name).system"] 61 - } else if $c.seed_type == "dev-shell" { 62 - $i.config.systems | each {|t| $".#devShells.($t).($i.name)" } 63 - } else if $c.seed_type == "home-manager" { 64 - [$".#homeConfigurations.($i.name).activationPackage"] 65 - } else if $c.seed_type == "nixos" { 66 - [$".#nixosConfigurations.($i.name).config.system.build.toplevel"] 67 - } else if $c.seed_type == "package" { 68 - $i.config.systems | each {|t| $".#packages.($t).($i.name)" } 69 - } else { 70 - print $"!! Unsupported type ($c.seed_type)" 71 - exit 1 72 - } 73 - 74 - let result = try { 75 - nix build --no-link --fallback --keep-going --json ...$buildTarget | from json 76 - } catch { 77 - null 78 - } 79 - 80 - $i | insert build $result 81 - }) 82 - } 83 - } 84 - 85 - export def upload-configs [--attic-cache: string, --cache-build-deps = false, --cache-inputs = false] { 86 - let configs = $in 87 - 88 - $configs | reduce --fold [] { |c, acc| 89 - let built_targets = $c.targets | where { |t| $t.build != null } | get build | flatten 90 - let build_dependencies = if $cache_build_deps { 91 - $built_targets | get drvPath | each { |drv| 92 - nix-store --query --requisites --include-outputs $drv | lines 93 - } | flatten 94 - } else { [] } 95 - let inputs = if $cache_inputs { get-flake-inputs | get outPath } else { [] } 96 - $acc ++ ( $built_targets | get outputs.out ) ++ $build_dependencies ++ $inputs 97 - } | attic-upload $attic_cache 98 - 99 - $configs 100 - } 101 - 102 - export def get-config-failures [] { 103 - let configs = $in 104 - 105 - $configs | where { |c| 106 - # filter top-levels down to failed ones 107 - $c.targets | any { |t| 108 - $t.build == null 109 - } 110 - } | each { |c| 111 - # filter targets down to failed ones 112 - $c | update targets ($c.targets | where { |t| 113 - $t.build == null 114 - }) 115 - } | each { |c| 116 - # simplify for output 117 - $c.targets | each { |t| 118 - { seed_type: $c.seed_type, name: $t.name } 119 - } 120 - } | flatten 121 - } 122 - 123 - export def get-config-outputs [] { 124 - let configs = $in 125 - 126 - $configs | each { |c| 127 - # simplify for output 128 - $c.targets | where { |t| $t.build != null } | each { |t| 129 - { seed_type: $c.seed_type, name: $t.name, artifact: $t.build.outputs.out.0 } 130 - } 131 - } | flatten 132 - } 133 - 134 - export def get-flake-inputs [] { 135 - nix flake archive --json | from json | get inputs | transpose | select column0 column1.path | each { |c| 136 - { 137 - name: $c.column0, 138 - outPath: $c."column1.path", 139 - drvPath: nul 140 - } 141 - } 142 - } 143 - 144 - export def post-sower-seeds [] { 145 - let configs = $in 146 - print $"🫱 Giving seeds to sower" 147 - 148 - let git_branch = get-git-branch 149 - let repo_url = get-repo-url 150 - 151 - # sower only understands certain build outputs 152 - $configs | where { |c| $c.seed_type == "home-manager" or $c.seed_type == "nix-darwin" or $c.seed_type == "nixos" } | each { |c| 153 - $c.targets | where { |t| $t.build != null } | each { |t| 154 - sower seed submit --name $t.name --type $c.seed_type --path $t.build.outputs.out.0 155 - } 156 - } 157 - } 158 - 159 - export def get-git-branch [] { 160 - if $env.CI_COMMIT_SOURCE_BRANCH? != null { 161 - $env.CI_COMMIT_SOURCE_BRANCH 162 - } else if $env.CI_COMMIT_BRANCH? != null { 163 - $env.CI_COMMIT_BRANCH 164 - } else if $env.GITHUB_HEAD_REF? != null { 165 - $env.GITHUB_HEAD_REF 166 - } else if $env.GITHUB_REF_NAME? != null { 167 - $env.GITHUB_REF_NAME 168 - } else if (".git" | path exists) { 169 - let dirty = if ((git diff-index --quiet HEAD -- | complete | get exit_code) == 0) { "" } else { "-" + (git rev-parse --short HEAD) + "-dirty" } 170 - $"(git rev-parse --abbrev-ref HEAD)($dirty)" 171 - } else { 172 - null 173 - } 174 - } 175 - 176 - export def get-repo-url [] { 177 - if $env.CI_REPO_URL? != null { 178 - $env.CI_REPO_URL 179 - } else if $env.GITHUB_REPOSITORY? != null { 180 - $env.GITHUB_REPOSITORY 181 - } else if (".git" | path exists) { 182 - git remote get-url origin 183 - } else { 184 - null 185 - } 186 - } 187 - 188 - def main [ 189 - --attic-upload = true, 190 - --attic-use = false, 191 - --cache-build-deps = false, 192 - --cache-inputs = true, 193 - --eval-only, 194 - --nom = true, 195 - --sower-seed = false, 196 - --system: string, 197 - --threads: int = 8 198 - ] { 199 - let attic_url = $env.ATTIC_URL? 200 - let attic_cache = $env.ATTIC_CACHE? 201 - let attic_token = $env.ATTIC_KEY? 202 - 203 - if $attic_use or $attic_upload { 204 - if ($attic_url == null) or ($attic_cache == null) or ($attic_token == null) { 205 - print "‼️ attic information missing, but attic-use or attic-upload are set to true" 206 - exit 1 207 - } 208 - 209 - attic-setup $attic_url $attic_cache $attic_token 210 - 211 - if $attic_use { 212 - attic-use $attic_cache 213 - } 214 - } 215 - 216 - if $sower_seed { 217 - let sower_endpoint = $env.SOWER_ENDPOINT? 218 - if $sower_endpoint == null { 219 - print "‼️ sower endpoint missing, but sower seed set to true" 220 - exit 1 221 - } 222 - } 223 - 224 - let seeds = load-seeds | filter-configs --system $system 225 - let built_seeds = $seeds | build-configs --threads $threads 226 - 227 - if $attic_upload { 228 - $built_seeds | upload-configs --attic-cache $attic_cache --cache-build-deps $cache_build_deps --cache-inputs $cache_inputs 229 - } 230 - 231 - if $sower_seed { 232 - $built_seeds | post-sower-seeds 233 - } 234 - 235 - print "🎯 Built seeds" 236 - print ($built_seeds | get-config-outputs | table --width 132 --expand) 237 - 238 - if ($built_seeds | any { |c| $c.targets | any { |t| $t.build == null } }) { 239 - print "💀 Failed targets" 240 - print ($built_seeds | get-config-failures | table --width 132 --expand) 241 - exit 1 242 - } else { 243 - print "🥳 Success!" 244 - } 245 - }
-3
flake.nix
··· 80 80 pkgs.oapi-codegen 81 81 82 82 pkgs.attic-client 83 - self'.packages.seed-ci 84 83 pkgs.nushell 85 84 86 85 pkgs.just ··· 122 121 }; 123 122 124 123 packages = rec { 125 - seed-ci = pkgs.callPackage ./nix/packages/seed-ci.nix { }; 126 - 127 124 cli = pkgs.callPackage ./nix/packages/cli.nix { 128 125 inherit version; 129 126 };
-26
nix/packages/seed-ci.nix
··· 1 - { 2 - lib, 3 - makeWrapper, 4 - runCommand, 5 - 6 - attic-client, 7 - coreutils, 8 - nushell, 9 - }: 10 - runCommand "seed-ci" 11 - { 12 - nativeBuildInputs = [ makeWrapper ]; 13 - buildInputs = [ nushell ]; 14 - } 15 - '' 16 - mkdir -p $out/bin 17 - cp ${../../bin/seed-ci} $out/bin/seed-ci 18 - patchShebangs $out/bin 19 - 20 - wrapProgram $out/bin/seed-ci --prefix PATH : ${ 21 - lib.makeBinPath [ 22 - attic-client 23 - coreutils 24 - ] 25 - } 26 - ''
-1
nix/tests/e2e.nix
··· 37 37 ]; 38 38 39 39 environment.systemPackages = [ 40 - flake.packages.${pkgs.stdenv.hostPlatform.system}.seed-ci 41 40 flake.packages.${pkgs.stdenv.hostPlatform.system}.cli 42 41 ]; 43 42