From bf06d2573b495063747f22d814dedc437e25bc11 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 14 Nov 2024 22:18:40 +0100 Subject: [PATCH] feat(nix): Use passthru for shells and return to importing the scripts --- .forgejo/workflows/check-meta.yaml | 2 +- .forgejo/workflows/check-workflows.yaml | 3 +- .forgejo/workflows/eval-nodes.yaml | 20 +++++----- .forgejo/workflows/pre-commit.yaml | 4 +- default.nix | 51 +++++++++++++------------ scripts/default.nix | 22 +++++------ shell.nix | 2 +- workflows/check-meta.nix | 2 +- workflows/check-workflows.nix | 2 +- workflows/eval-nodes.nix | 2 +- workflows/pre-commit.nix | 2 +- 11 files changed, 56 insertions(+), 56 deletions(-) diff --git a/.forgejo/workflows/check-meta.yaml b/.forgejo/workflows/check-meta.yaml index 7053542..df3a34a 100644 --- a/.forgejo/workflows/check-meta.yaml +++ b/.forgejo/workflows/check-meta.yaml @@ -4,7 +4,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Check the validity of the DNS configuration - run: nix-build meta/verify.nix -A dns --no-out-link + run: nix-build meta/verify.nix -A dns check_meta: runs-on: nix steps: diff --git a/.forgejo/workflows/check-workflows.yaml b/.forgejo/workflows/check-workflows.yaml index 336a4b7..3aa1994 100644 --- a/.forgejo/workflows/check-workflows.yaml +++ b/.forgejo/workflows/check-workflows.yaml @@ -4,7 +4,8 @@ jobs: steps: - uses: actions/checkout@v3 - name: Check that the workflows are up to date - run: nix-shell --run '[ $(git status --porcelain | wc -l) -eq 0 ]' + run: nix-shell -A check-workflows --run '[ $(git status --porcelain | wc -l) + -eq 0 ]' name: Check workflows 'on': pull_request: diff --git a/.forgejo/workflows/eval-nodes.yaml b/.forgejo/workflows/eval-nodes.yaml index 41538d0..fb6df7f 100644 --- a/.forgejo/workflows/eval-nodes.yaml +++ b/.forgejo/workflows/eval-nodes.yaml @@ -9,7 +9,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache bridge01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node compute01: runs-on: nix steps: @@ -20,7 +20,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache compute01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node geo01: runs-on: nix steps: @@ -31,7 +31,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache geo01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node geo02: runs-on: nix steps: @@ -42,7 +42,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache geo02 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node rescue01: runs-on: nix steps: @@ -53,7 +53,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache rescue01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node storage01: runs-on: nix steps: @@ -64,7 +64,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache storage01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node vault01: runs-on: nix steps: @@ -75,7 +75,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache vault01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node web01: runs-on: nix steps: @@ -86,7 +86,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache web01 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node web02: runs-on: nix steps: @@ -97,7 +97,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache web02 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node web03: runs-on: nix steps: @@ -108,7 +108,7 @@ jobs: STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} STORE_USER: admin name: Build and cache web03 - run: nix-shell --run cache-node + run: nix-shell -A eval-nodes --run cache-node name: Build all the nodes 'on': pull_request: diff --git a/.forgejo/workflows/pre-commit.yaml b/.forgejo/workflows/pre-commit.yaml index f99163b..d0573d6 100644 --- a/.forgejo/workflows/pre-commit.yaml +++ b/.forgejo/workflows/pre-commit.yaml @@ -4,8 +4,8 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run pre-commit on all files - run: nix-shell --run 'pre-commit run --all-files --hook-stage pre-push --show-diff-on-failure' - -A shells.pre-commit ./. + run: nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage + pre-push --show-diff-on-failure' name: Run pre-commit on all files 'on': - push diff --git a/default.nix b/default.nix index 4660861..fb1fa57 100644 --- a/default.nix +++ b/default.nix @@ -43,6 +43,7 @@ let inherit (pkgs.lib) isFunction + mapAttrs mapAttrs' nameValuePair removeSuffix @@ -88,6 +89,8 @@ let ) ) (builtins.readDir ./workflows); }; + + scripts = import ./scripts { inherit pkgs; }; in { @@ -99,37 +102,35 @@ in mkCacheSettings = import ./machines/storage01/tvix-cache/cache-settings.nix; - shells = { - default = pkgs.mkShell { - name = "dgnum-infra"; + devShell = pkgs.mkShell { + name = "dgnum-infra"; - packages = [ - (pkgs.nixos-generators.overrideAttrs (_: { - version = "1.8.0-unstable"; - src = builtins.storePath sources.nixos-generators; - })) - pkgs.npins + packages = [ + (pkgs.nixos-generators.overrideAttrs (_: { + version = "1.8.0-unstable"; + src = sources.nixos-generators; + })) + pkgs.npins - (pkgs.callPackage ./lib/colmena { inherit (nix-pkgs) colmena; }) - (pkgs.callPackage "${sources.agenix}/pkgs/agenix.nix" { }) - (pkgs.callPackage "${sources.lon}/nix/packages/lon.nix" { }) + (pkgs.callPackage ./lib/colmena { inherit (nix-pkgs) colmena; }) + (pkgs.callPackage "${sources.agenix}/pkgs/agenix.nix" { }) + (pkgs.callPackage "${sources.lon}/nix/packages/lon.nix" { }) + ] ++ (builtins.attrValues scripts); - ] ++ (pkgs.callPackage ./scripts { }); + shellHook = '' + ${git-checks.shellHook} + ${workflows.shellHook} + ''; - shellHook = '' - ${git-checks.shellHook} - ${workflows.shellHook} - ''; + preferLocalBuild = true; - preferLocalBuild = true; - }; + ### + # Alternative shells - pre-commit = pkgs.mkShell { - name = "pre-commit-shell"; - - shellHook = '' - ${git-checks.shellHook} - ''; + passthru = mapAttrs (name: value: pkgs.mkShell (value // { inherit name; })) { + pre-commit.shellHook = git-checks.shellHook; + check-workflows.shellHook = workflows.shellHook; + eval-nodes.packages = [ scripts.cache-node ]; }; }; } diff --git a/scripts/default.nix b/scripts/default.nix index ae3a1b8..d7844ab 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -1,16 +1,14 @@ -{ - lib, - writeShellApplication, - - # Dependencies - colmena, - jq, - nvd, - ... -}: +{ pkgs }: let - inherit (lib) mapAttrsToList; + inherit (pkgs.lib) mapAttrs; + + inherit (pkgs) + writeShellApplication + colmena + jq + nvd + ; scripts = { cache-node = [ colmena ]; @@ -24,7 +22,7 @@ let }; in -mapAttrsToList ( +mapAttrs ( name: runtimeInputs: writeShellApplication { inherit name runtimeInputs; diff --git a/shell.nix b/shell.nix index 0076170..d6d21cf 100644 --- a/shell.nix +++ b/shell.nix @@ -1 +1 @@ -(import ./. { }).shells.default +(import ./. { }).devShell diff --git a/workflows/check-meta.nix b/workflows/check-meta.nix index 13a9777..77fd75f 100644 --- a/workflows/check-meta.nix +++ b/workflows/check-meta.nix @@ -23,7 +23,7 @@ { uses = "actions/checkout@v3"; } { name = "Check the validity of the DNS configuration"; - run = "nix-build meta/verify.nix -A dns --no-out-link"; + run = "nix-build meta/verify.nix -A dns"; } ]; }; diff --git a/workflows/check-workflows.nix b/workflows/check-workflows.nix index 39cacc3..eb9afc9 100644 --- a/workflows/check-workflows.nix +++ b/workflows/check-workflows.nix @@ -12,7 +12,7 @@ { uses = "actions/checkout@v3"; } { name = "Check that the workflows are up to date"; - run = "nix-shell --run '[ $(git status --porcelain | wc -l) -eq 0 ]'"; + run = "nix-shell -A check-workflows --run '[ $(git status --porcelain | wc -l) -eq 0 ]'"; } ]; }; diff --git a/workflows/eval-nodes.nix b/workflows/eval-nodes.nix index 540ec47..a67bd45 100644 --- a/workflows/eval-nodes.nix +++ b/workflows/eval-nodes.nix @@ -19,7 +19,7 @@ in { uses = "actions/checkout@v3"; } { name = "Build and cache ${node}"; - run = "nix-shell --run cache-node"; + run = "nix-shell -A eval-nodes --run cache-node"; env = { STORE_ENDPOINT = "https://tvix-store.dgnum.eu/infra-signing/"; STORE_USER = "admin"; diff --git a/workflows/pre-commit.nix b/workflows/pre-commit.nix index 19cf3c8..c284745 100644 --- a/workflows/pre-commit.nix +++ b/workflows/pre-commit.nix @@ -11,7 +11,7 @@ { uses = "actions/checkout@v3"; } { name = "Run pre-commit on all files"; - run = "nix-shell --run 'pre-commit run --all-files --hook-stage pre-push --show-diff-on-failure' -A shells.pre-commit ./."; + run = "nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage pre-push --show-diff-on-failure'"; } ]; };