Commit 88ab42c
build(nix): reduce the manually pinned hashes to one and automate it (#5593)
* build(nix): reduce the manually pinned hashes to one and automate it
Every mix or npm dependency bump invalidated one or more hashes in nix/flake-modules/package.nix, and each one had to be looked up from a failing build and pasted back by hand. Three changes shrink that to a single hash and take the pasting out of it.
Fetch the npm dependencies with pkgs.importNpmLock instead of
buildNpmPackage. The integrity hashes in assets/package-lock.json are already authoritative, so npmDepsHash is gone entirely and npm bumps no longer touch the Nix code at all. The phoenix, phoenix_html and phoenix_live_view entries are file: links into deps/, which only exists in a working tree after mix deps.get, so packageSourceOverrides points them at mixFodDeps. That also replaces the previous approach of letting npm install them and swapping them for symlinks afterwards, so the substitution is now declarative instead of a correction after the fact.
The resulting assets are byte-identical to the previous ones.
Derive the cldr revision from the ex_cldr version in mix.lock. It had to match, but that was only stated in a comment, and a stale revision is the one failure mode here that does not fail the build: Nix resolves the old output hash to the store path it already has and silently ships the locale data of the previous release. Reading it from the lockfile makes the two impossible to drift apart, and a lockfile without ex_cldr now aborts the evaluation instead of falling back to something plausible.
This carries the locale data from 2.47.4 to 2.47.5, matching mix.lock.
Add nix run .#update-nix-hashes for what is left. It builds, reads the
hash mismatch Nix reports, writes it back and repeats until the build
succeeds, so a green run also proves the package still builds. It keys on the reported hash string rather than on attribute names, so a further fixed-output derivation is covered without touching the script.
Document the command in the development guide and replace the warning about stale cldr hashes with the reason the revision must not be pinned by hand.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* ci: let Dependabot pull requests refresh the Nix hashes
A mix.lock bump invalidates the mixFodDeps hash, and an ex_cldrb ump moves the cldr revision and with it its hash, so every such pull request needed a manual nix run .#update-nix-hashes before it could be merged.
Refreshing the hashes builds the dependencies the pull request updates and therefore runs their code, so the work is split across two jobs. The first has no credentials and only publishes a patch. The second starts from a clean checkout that never ran repository code, and is the only one that sees a write token, in its final push step. In a single job the pushing step would share a workspace with the build, where a git hook or a core.fsmonitor entry left behind during the build would run while the token is in the environment.
That patch is untrusted input, so the second job validates what a commit would contain rather than the patch syntax: it applies the patch to the index without a token and then requires every staged entry to be a modification of an existing .nix file below nix/, with an unchanged file mode, whose content equals the one in HEAD once well formed sha256 literals are masked out. Checking the staged result instead of the diff text leaves no room for a binary hunk or for ---/+++ paths that disagree with the diff --git header.
Restricted to Dependabot's own pull requests from branches in this repository. The actor check also stops the updater from running on the commit it pushes itself, while the regular CI workflows, which are not actor-gated, still verify it.
closes: #4156
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* ci: verify Nix hashes on all dependency pull requests
The updater only ran for Dependabot, so a stale hash in a human pull request went unnoticed: a fixed-output derivation is addressed by its hash, and a stale one resolves to the path fetched for it earlier, which means the build stays green and no check reports anything.
The compute job now runs for every pull request touching mix.exs or mix.lock, and the new verify job fails whenever the hashes it produces differ from the ones in the tree. The patch is published as an artifact for the author to apply.
Pushing a repair into a pull request branch stays limited to Dependabot's own pull requests from branches in this repository. The commit job depends
on compute alone, not on verify, so the failing check does not block the repair; its push produces a new run in which nothing is left to change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* ci(nix): keep the hash check off workflow-touching pull requests
Pull requests that touch .github are not run automatically in this
repository for SecOp reasons. This workflow did not honour that.
Exclude the .github paths the way devops.yml does, and gate the compute job on the existing check_paths workflow, which is what covers a pull request
that carries both a dependency change and a workflow change. Add a manual
trigger so the hashes of such a pull request can still be verified
deliberately, by someone who is allowed to start a run; that path only
verifies, because the commit job's actor check does not hold for it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* ci: let maintainers run CI on pull requests touching .github
Pull requests touching .github are deliberately kept out of the automatic runs, because with pull_request the workflow definition that runs is the one from the pull request. There was no way to run those checks anyway:
devops.yml gated its jobs on github.event_name == 'schedule', but it has never had a schedule trigger, so that condition could never be true, and buildx.yml offered a workflow_dispatch trigger whose jobs the same gate skipped.
Gate on workflow_dispatch instead, so starting a run by hand, which takes write access, reaches the jobs. devops.yml replaces the unreachable condition, buildx.yml keeps its schedule condition and gains this one, and osv-scanner.yml gains the trigger it was missing; a manual run there does the full repository scan rather than the pull request diff.
Note that a manual buildx run publishes: from a branch it overwrites the edge tag. That was already the case for branches that do not touch .github, this only widens it.
* ci: extend retention period for nix-hashes patch to 7 days
* ci: update git push command to enhance security for token usage
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 926afa3 commit 88ab42c
11 files changed
Lines changed: 525 additions & 40 deletions
File tree
- .github/workflows
- nix/flake-modules
- website/docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
32 | | - | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
65 | | - | |
| 70 | + | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
| |||
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | | - | |
| 91 | + | |
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
42 | | - | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | | - | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
56 | | - | |
| 60 | + | |
57 | 61 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| |||
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
34 | | - | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
0 commit comments