ci/nix: Allow IFD for runtime dependency replacements
Update docs / update (push) Successful in 1m5s
CI / Check, build and cache nixfiles (push) Failing after 1h2m10s

Share a single replacement list between NixOS and standalone Home
Manager. CI checks that list against its targets' nixpkgs channels.

When a replacement applies, warn and defer the flake check until
after the target builds. Runtime replacement needs to generate and
import store reference graphs during evaluation, which fails under
`nix flake check --no-build` on a fresh runner.

Keep the early eval-only check and disable IFD when the list is empty.
This commit is contained in:
jackos1998 committed 2026-11-23 23:45:23 +00:00
1 parent d5e2b93fd0
commit fabbb43fbf
8 files changed
+68 -22

No files matched your search

+27 -6
View File
@@ -30,27 +30,48 @@ jobs:
extra-trusted-public-keys = nix-cache.nul.ie-1:BzH5yMfF4HbzY1C977XzOxoPhEc9Zbu39ftPkUbH+m4= extra-trusted-public-keys = nix-cache.nul.ie-1:BzH5yMfF4HbzY1C977XzOxoPhEc9Zbu39ftPkUbH+m4=
- name: Check flake - 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 - name: Build (and cache) the world
id: build id: build
env: env:
HARMONIA_SSH_KEY: ${{ secrets.HARMONIA_SSH_KEY }} HARMONIA_SSH_KEY: ${{ secrets.HARMONIA_SSH_KEY }}
CI_IFD_REQUIRED: ${{ steps.ifd.outputs.required }}
run: | run: |
set -o pipefail
nix_options=(--option allow-import-from-derivation "$CI_IFD_REQUIRED")
echo "::group::Collect cache garbage" echo "::group::Collect cache garbage"
ci/push-to-cache.sh --gc ci/push-to-cache.sh --gc
echo "::endgroup::" 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" 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 "::endgroup::"
echo "::group::Cache $job" 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::" echo "::endgroup::"
done 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" echo "Building and caching CI derivation"
nix build --no-link .#ciDrv.x86_64-linux nix build "${nix_options[@]}" --no-link .#ciDrv.x86_64-linux
UPDATE_PROFILE=1 ci/push-to-cache.sh "$(nix eval --raw .#ciDrv.x86_64-linux)" UPDATE_PROFILE=1 ci/push-to-cache.sh "$(nix eval "${nix_options[@]}" --raw .#ciDrv.x86_64-linux)"
+6 -4
View File
@@ -80,10 +80,12 @@ Common ones:
Use the narrowest relevant evaluation while iterating: `check-system <host>` for a box config, Use the narrowest relevant evaluation while iterating: `check-system <host>` for a box config,
`nix eval .#nixfiles.config.nixos.allAssignments --json` for assignment generation, or `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 build --no-link .#nixfiles.config.nixos.optionsDoc` for the option reference. Runtime
`nix flake check --no-build` for final broad validation or reproducing CI. dependency replacement can build store reference graphs during evaluation, so use
CI builds each attr of `.#ci.x86_64-linux` (systems, homes, packages, shell) and pushes to the `nix flake check` for broad validation when replacements are enabled.
Harmonia binary cache; see `.gitea/workflows/ci.yaml` and `ci/push-to-cache.sh`. A separate 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 workflow (`.gitea/workflows/update-docs.yaml`) regenerates the network assignments, NixOS option
reference and live DNS reference under `docs/`. reference and live DNS reference under `docs/`.
+10 -3
View File
@@ -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 On pushes to `master`, this installs Determinate Nix on the runner (via
`DeterminateSystems/determinate-nix-action`, configured with the same performance settings and `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 Harmonia substituter as the boxes). CI normally runs `nix flake check --no-build` first and
of `.#ci.x86_64-linux`: systems as `system-<name>`, homes as `home-<name>` (with `@` changed to keeps import from derivation disabled. It builds every attribute of `.#ci.x86_64-linux`:
`-at-`), packages as `package-<name>`, and the development `shell`. Each result is pushed to the systems as `system-<name>`, homes as `home-<name>` (with `@` changed to `-at-`), packages as
`package-<name>`, 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 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 workflow deletes cache-profile generations older than its retention period, then collects
unreachable paths so a full cache cannot prevent collection from being reached. 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 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 `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 `/var/lib/harmonia`, `HARMONIA_SSH_KEY`, and pinned `ci/known_hosts`; clients use
+3 -2
View File
@@ -43,7 +43,7 @@ against the candidate revisions and leave a concrete next step for any outstandi
- `home-manager-stable.url = "home-manager/release-<STABLE>"` - `home-manager-stable.url = "home-manager/release-<STABLE>"`
- **Devshell commands:** `update-nixpkgs` = `nix flake update nixpkgs-{unstable,stable,mine,mine-stable}`; - **Devshell commands:** `update-nixpkgs` = `nix flake update nixpkgs-{unstable,stable,mine,mine-stable}`;
`update-home-manager` = `nix flake update home-manager-{unstable,stable}`. `update-home-manager` = `nix flake update home-manager-{unstable,stable}`.
- **Validation:** prefer `check-system <host>` and `nix flake check --no-build` over full builds. - **Validation:** prefer `check-system <host>` while iterating and reserve the flake check for final validation.
## Phase 1 — Determine the current NixOS stable ## Phase 1 — Determine the current NixOS stable
@@ -188,7 +188,8 @@ Don't blanket-update. Walk the other inputs deliberately:
## Phase 7 — Validate ## 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 <host>` on a representative box, and one exercising the stable channel if the 2. `check-system <host>` 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. boxes mix channels. This must exercise the refreshed kernel constants on both channels.
3. Build the actual devshell with 3. Build the actual devshell with
+15
View File
@@ -296,5 +296,20 @@
inherit shell; inherit shell;
}; };
ciDrv = pkgs.linkFarm "ci" ci; 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";
})); }));
} }
+3 -3
View File
@@ -7,7 +7,7 @@ let
inherit (lib.hm) dag; inherit (lib.hm) dag;
inherit (lib.my) mkOpt' dummyOption; 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 in
{ {
# Disabled: breaks `nix flake check` in CI (see flake.nix pi-agent note). # Disabled: breaks `nix flake check` in CI (see flake.nix pi-agent note).
@@ -34,14 +34,14 @@ in
home.activationPackage = mkOption { home.activationPackage = mkOption {
apply = drv: apply = drv:
if config.my.isStandalone && jsonCRuntimeReplacements != [ ] then if config.my.isStandalone && runtimeDependencyReplacements != [ ] then
(pkgs.replaceDependencies.override { (pkgs.replaceDependencies.override {
replaceDirectDependencies = pkgs.replaceDirectDependencies.override { replaceDirectDependencies = pkgs.replaceDirectDependencies.override {
nix = config.nix.package; nix = config.nix.package;
}; };
}) { }) {
inherit drv; inherit drv;
replacements = jsonCRuntimeReplacements; replacements = runtimeDependencyReplacements;
} }
else drv; else drv;
}; };
@@ -1,6 +1,6 @@
{ lib, pkgs, pkgsFlake }: { 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. # Patch the runtime library separately so existing consumers can be reused.
lib.optional ((pkgsFlake.rev or null) == "320600d55ff67365e933b98b339acdeac238eb26") { lib.optional ((pkgsFlake.rev or null) == "320600d55ff67365e933b98b339acdeac238eb26") {
oldDependency = pkgs.json_c; oldDependency = pkgs.json_c;
+3 -3
View File
@@ -3,7 +3,7 @@ let
inherit (lib) mkIf mkDefault mkMerge optionalAttrs versionOlder; inherit (lib) mkIf mkDefault mkMerge optionalAttrs versionOlder;
inherit (lib.my) mkDefault'; 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 in
{ {
options = with lib.types; { options = with lib.types; {
@@ -20,8 +20,8 @@ in
]; ];
config = mkMerge [ config = mkMerge [
(optionalAttrs (jsonCRuntimeReplacements != [ ]) { (optionalAttrs (runtimeDependencyReplacements != [ ]) {
system.replaceDependencies.replacements = jsonCRuntimeReplacements; system.replaceDependencies.replacements = runtimeDependencyReplacements;
}) })
{ {