diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index aecd396..07b523e 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -30,27 +30,48 @@ jobs: extra-trusted-public-keys = nix-cache.nul.ie-1:BzH5yMfF4HbzY1C977XzOxoPhEc9Zbu39ftPkUbH+m4= - name: Check flake - run: nix flake check --no-build + id: ifd + run: | + reasons="$(nix eval --option allow-import-from-derivation false --json .#ciIfdReasons.x86_64-linux)" + required="$(jq -r 'length > 0' <<< "$reasons")" + echo "required=$required" >> "$GITHUB_OUTPUT" + + if [[ "$required" == true ]]; then + jq -r '.[] | "::warning::\(.). The flake check will run after the target builds."' <<< "$reasons" + else + nix flake check --no-build --option allow-import-from-derivation false + fi - name: Build (and cache) the world id: build env: HARMONIA_SSH_KEY: ${{ secrets.HARMONIA_SSH_KEY }} + CI_IFD_REQUIRED: ${{ steps.ifd.outputs.required }} run: | + set -o pipefail + nix_options=(--option allow-import-from-derivation "$CI_IFD_REQUIRED") + echo "::group::Collect cache garbage" ci/push-to-cache.sh --gc echo "::endgroup::" - nix eval --json --apply "builtins.attrNames" .#ci.x86_64-linux | jq -cr '.[]' | while read job; do + nix eval "${nix_options[@]}" --json --apply "builtins.attrNames" .#ci.x86_64-linux | jq -cr '.[]' | while read job; do echo "::group::Build $job" - nix build --no-link .#ci.x86_64-linux."$job" + nix build "${nix_options[@]}" --no-link .#ci.x86_64-linux."$job" echo "::endgroup::" echo "::group::Cache $job" - ci/push-to-cache.sh "$(nix eval --raw .#ci.x86_64-linux."$job")" + ci/push-to-cache.sh "$(nix eval "${nix_options[@]}" --raw .#ci.x86_64-linux."$job")" echo "::endgroup::" done + if [[ "$CI_IFD_REQUIRED" == true ]]; then + echo "::group::Check flake" + # The target closures are available for the evaluation-time reference graphs. + nix flake check "${nix_options[@]}" + echo "::endgroup::" + fi + echo "Building and caching CI derivation" - nix build --no-link .#ciDrv.x86_64-linux - UPDATE_PROFILE=1 ci/push-to-cache.sh "$(nix eval --raw .#ciDrv.x86_64-linux)" + nix build "${nix_options[@]}" --no-link .#ciDrv.x86_64-linux + UPDATE_PROFILE=1 ci/push-to-cache.sh "$(nix eval "${nix_options[@]}" --raw .#ciDrv.x86_64-linux)" diff --git a/AGENTS.md b/AGENTS.md index b8a1016..dab8bdf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -80,10 +80,12 @@ Common ones: Use the narrowest relevant evaluation while iterating: `check-system ` for a box config, `nix eval .#nixfiles.config.nixos.allAssignments --json` for assignment generation, or -`nix build --no-link .#nixfiles.config.nixos.optionsDoc` for the option reference. Reserve -`nix flake check --no-build` for final broad validation or reproducing CI. -CI builds each attr of `.#ci.x86_64-linux` (systems, homes, packages, shell) and pushes to the -Harmonia binary cache; see `.gitea/workflows/ci.yaml` and `ci/push-to-cache.sh`. A separate +`nix build --no-link .#nixfiles.config.nixos.optionsDoc` for the option reference. Runtime +dependency replacement can build store reference graphs during evaluation, so use +`nix flake check` for broad validation when replacements are enabled. +CI runs an eval-only flake check before building and caching `.#ci.x86_64-linux`. An active +`ciIfdReasons` entry allows import from derivation and moves the flake check after the builds. +See [CI in `docs/deployment.md`](docs/deployment.md#ci). A separate workflow (`.gitea/workflows/update-docs.yaml`) regenerates the network assignments, NixOS option reference and live DNS reference under `docs/`. diff --git a/docs/deployment.md b/docs/deployment.md index ea308a2..ffee42e 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -296,13 +296,20 @@ GitHub/Gitea Actions workflows live in [`.gitea/workflows/`](../.gitea/workflows On pushes to `master`, this installs Determinate Nix on the runner (via `DeterminateSystems/determinate-nix-action`, configured with the same performance settings and -Harmonia substituter as the boxes), runs `nix flake check --no-build`, then builds every attribute -of `.#ci.x86_64-linux`: systems as `system-`, homes as `home-` (with `@` changed to -`-at-`), packages as `package-`, and the development `shell`. Each result is pushed to the +Harmonia substituter as the boxes). CI normally runs `nix flake check --no-build` first and +keeps import from derivation disabled. It builds every attribute of `.#ci.x86_64-linux`: +systems as `system-`, homes as `home-` (with `@` changed to `-at-`), packages as +`package-`, and the development `shell`. Each result is pushed to the Harmonia cache with [`ci/push-to-cache.sh`](../ci/push-to-cache.sh). Before the first push, the workflow deletes cache-profile generations older than its retention period, then collects unreachable paths so a full cache cannot prevent collection from being reached. +When `.#ciIfdReasons.x86_64-linux` lists an active exception, CI logs a warning with the reason +and allows import from derivation for the target builds. It runs a build-capable flake +check afterward. CI checks [the shared runtime replacement list](../lib/runtime-dependency-replacements.nix) +against the nixpkgs channels used by its systems and standalone homes. A matching entry +requires reading generated store reference graphs during evaluation. + It then builds `.#ciDrv.x86_64-linux`, a `linkFarm` of all CI attributes, and pushes it with `UPDATE_PROFILE=1`. That updates the `nixfiles` profile on the cache box. The SSH store uses `/var/lib/harmonia`, `HARMONIA_SSH_KEY`, and pinned `ci/known_hosts`; clients use diff --git a/docs/nixpkgs-upgrade.md b/docs/nixpkgs-upgrade.md index c64dbac..8ca7d1a 100644 --- a/docs/nixpkgs-upgrade.md +++ b/docs/nixpkgs-upgrade.md @@ -43,7 +43,7 @@ against the candidate revisions and leave a concrete next step for any outstandi - `home-manager-stable.url = "home-manager/release-"` - **Devshell commands:** `update-nixpkgs` = `nix flake update nixpkgs-{unstable,stable,mine,mine-stable}`; `update-home-manager` = `nix flake update home-manager-{unstable,stable}`. -- **Validation:** prefer `check-system ` and `nix flake check --no-build` over full builds. +- **Validation:** prefer `check-system ` while iterating and reserve the flake check for final validation. ## Phase 1 — Determine the current NixOS stable @@ -188,7 +188,8 @@ Don't blanket-update. Walk the other inputs deliberately: ## Phase 7 — Validate -1. `nix flake check --no-build` (broad eval; reproduces CI's cheap checks). +1. `nix flake check --no-build` for broad validation. If `.#ciIfdReasons.x86_64-linux` lists + an active exception, use `nix flake check` so evaluation can build the required inputs. 2. `check-system ` on a representative box, and one exercising the stable channel if the boxes mix channels. This must exercise the refreshed kernel constants on both channels. 3. Build the actual devshell with diff --git a/flake.nix b/flake.nix index b318386..90f46f3 100644 --- a/flake.nix +++ b/flake.nix @@ -296,5 +296,20 @@ inherit shell; }; ciDrv = pkgs.linkFarm "ci" ci; + + ciIfdReasons = + let + inherit (nixfiles.config) nixos home-manager; + targets = builtins.attrValues nixos.systems ++ builtins.attrValues home-manager.homes; + channels = lib.unique (map (target: target.nixpkgs) (builtins.filter (target: target.system == system) targets)); + hasReplacements = channel: + (import ./lib/runtime-dependency-replacements.nix { + inherit lib; + pkgs = pkgs'.${channel}.${system}; + pkgsFlake = pkgsFlakes.${channel}; + }) != [ ]; + in + lib.optional (lib.any hasReplacements channels) + "Runtime dependency replacement reads generated store reference graphs"; })); } diff --git a/home-manager/modules/common.nix b/home-manager/modules/common.nix index e2d1298..dcd8129 100644 --- a/home-manager/modules/common.nix +++ b/home-manager/modules/common.nix @@ -7,7 +7,7 @@ let inherit (lib.hm) dag; inherit (lib.my) mkOpt' dummyOption; - jsonCRuntimeReplacements = import ../../lib/json-c-runtime.nix { inherit lib pkgs pkgsFlake; }; + runtimeDependencyReplacements = import ../../lib/runtime-dependency-replacements.nix { inherit lib pkgs pkgsFlake; }; in { # Disabled: breaks `nix flake check` in CI (see flake.nix pi-agent note). @@ -34,14 +34,14 @@ in home.activationPackage = mkOption { apply = drv: - if config.my.isStandalone && jsonCRuntimeReplacements != [ ] then + if config.my.isStandalone && runtimeDependencyReplacements != [ ] then (pkgs.replaceDependencies.override { replaceDirectDependencies = pkgs.replaceDirectDependencies.override { nix = config.nix.package; }; }) { inherit drv; - replacements = jsonCRuntimeReplacements; + replacements = runtimeDependencyReplacements; } else drv; }; diff --git a/lib/json-c-runtime.nix b/lib/runtime-dependency-replacements.nix similarity index 84% rename from lib/json-c-runtime.nix rename to lib/runtime-dependency-replacements.nix index 492e340..d0242ff 100644 --- a/lib/json-c-runtime.nix +++ b/lib/runtime-dependency-replacements.nix @@ -1,6 +1,6 @@ { lib, pkgs, pkgsFlake }: -# TODO: Drop this when updating the fork pin to a revision with the json-c fix. +# TODO: Drop the json-c replacement when updating the fork pin to a revision with the json-c fix. # Patch the runtime library separately so existing consumers can be reused. lib.optional ((pkgsFlake.rev or null) == "320600d55ff67365e933b98b339acdeac238eb26") { oldDependency = pkgs.json_c; diff --git a/nixos/modules/common.nix b/nixos/modules/common.nix index d397bb4..838124b 100644 --- a/nixos/modules/common.nix +++ b/nixos/modules/common.nix @@ -3,7 +3,7 @@ let inherit (lib) mkIf mkDefault mkMerge optionalAttrs versionOlder; inherit (lib.my) mkDefault'; - jsonCRuntimeReplacements = import ../../lib/json-c-runtime.nix { inherit lib pkgs pkgsFlake; }; + runtimeDependencyReplacements = import ../../lib/runtime-dependency-replacements.nix { inherit lib pkgs pkgsFlake; }; in { options = with lib.types; { @@ -20,8 +20,8 @@ in ]; config = mkMerge [ - (optionalAttrs (jsonCRuntimeReplacements != [ ]) { - system.replaceDependencies.replacements = jsonCRuntimeReplacements; + (optionalAttrs (runtimeDependencyReplacements != [ ]) { + system.replaceDependencies.replacements = runtimeDependencyReplacements; }) {