Skip to content

Commit a10f64d

Browse files
fix(nix): handle various DNS setups in nix package (#867)
* test a workaround for DNS issues on nixos * try out a workflow to automatically update pnpm hash in nix package * try to trigger the new job * try out a different nix setup action * checkout submodules * chore(nix): update pnpm deps hash * cleanup --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1dc946d commit a10f64d

4 files changed

Lines changed: 179 additions & 90 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Update pnpm deps Nix hash
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- pnpm-lock.yaml
7+
8+
concurrency:
9+
group: pnpm-hash-${{ github.event.pull_request.number }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
update-pnpm-hash:
17+
runs-on:
18+
- codebuild-defguard-client-runner-${{ github.run_id }}-${{ github.run_attempt }}
19+
20+
steps:
21+
- uses: actions/checkout@v6
22+
with:
23+
# Check out the exact PR head commit so the sha we pass to the API
24+
# matches what we read from disk - avoids a race if the branch is
25+
# updated while this job is in flight.
26+
ref: ${{ github.event.pull_request.head.sha }}
27+
submodules: recursive
28+
29+
- uses: cachix/install-nix-action@v31
30+
with:
31+
install_options: --no-daemon
32+
extra_nix_config: |
33+
experimental-features = nix-command flakes
34+
35+
- name: Compute correct pnpm deps hash
36+
id: hash
37+
run: |
38+
set -euo pipefail
39+
40+
echo "nix version: $(nix --version 2>/dev/null || echo 'unavailable')"
41+
42+
# A valid-format but always-wrong sha256 hash.
43+
# Identical to lib.fakeHash in nixpkgs.
44+
FAKE="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
45+
46+
# Extract the current pnpm hash.
47+
CURRENT=$(sed -n 's/^[[:space:]]*hash = "\(sha256-[^"]*\)".*/\1/p' nix/package.nix | head -1)
48+
if [ -z "$CURRENT" ]; then
49+
echo "::error::Could not extract current hash from nix/package.nix"
50+
exit 1
51+
fi
52+
echo "current hash: ${CURRENT}"
53+
echo "current=${CURRENT}" >> "$GITHUB_OUTPUT"
54+
55+
# Swap in the fake hash so Nix will fail and report the real one.
56+
sed -i "s|hash = \"${CURRENT}\"|hash = \"${FAKE}\"|" nix/package.nix
57+
58+
# Build only the pnpmDeps fixed-output derivation.
59+
SYSTEM=$(nix eval --impure --raw --expr 'builtins.currentSystem')
60+
echo "building pnpmDeps for ${SYSTEM}..."
61+
BUILD_LOG=$(nix build --no-link --no-write-lock-file \
62+
".#packages.${SYSTEM}.default.pnpmDeps" 2>&1 || true)
63+
64+
# Nix prints "got: sha256-..." in the hash mismatch error.
65+
NEW=$(printf '%s' "$BUILD_LOG" | sed -n 's/.*got:[[:space:]]*\(sha256-[^[:space:]]*\).*/\1/p' | head -1)
66+
if [ -z "$NEW" ]; then
67+
echo "::error::Could not extract the correct hash from nix output."
68+
echo "Full build log:"
69+
printf '%s\n' "$BUILD_LOG"
70+
exit 1
71+
fi
72+
73+
echo "new hash: ${NEW}"
74+
echo "new=${NEW}" >> "$GITHUB_OUTPUT"
75+
76+
# Write the correct hash back into the file.
77+
sed -i "s|hash = \"${FAKE}\"|hash = \"${NEW}\"|" nix/package.nix
78+
79+
# Only commit when the hash actually changed; skip if it was already correct.
80+
- name: Commit updated hash
81+
if: steps.hash.outputs.current != steps.hash.outputs.new
82+
uses: actions/github-script@v7
83+
env:
84+
OLD_HASH: ${{ steps.hash.outputs.current }}
85+
NEW_HASH: ${{ steps.hash.outputs.new }}
86+
with:
87+
script: |
88+
const fs = require('fs');
89+
const content = fs.readFileSync('nix/package.nix', 'utf8');
90+
// GraphQL createCommitOnBranch requires base64-encoded file contents.
91+
const encoded = Buffer.from(content).toString('base64');
92+
93+
// The GraphQL createCommitOnBranch mutation creates commits that
94+
// GitHub signs automatically - producing a Verified badge.
95+
await github.graphql(`
96+
mutation CreateCommit($input: CreateCommitOnBranchInput!) {
97+
createCommitOnBranch(input: $input) {
98+
commit { url }
99+
}
100+
}
101+
`, {
102+
input: {
103+
branch: {
104+
repositoryNameWithOwner: `${context.repo.owner}/${context.repo.repo}`,
105+
branchName: context.payload.pull_request.head.ref,
106+
},
107+
message: { headline: 'chore(nix): update pnpm deps hash' },
108+
fileChanges: {
109+
additions: [{ path: 'nix/package.nix', contents: encoded }],
110+
},
111+
// Safety check - fails if the branch moved under us.
112+
expectedHeadOid: context.payload.pull_request.head.sha,
113+
},
114+
});

nix/package.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ in
9090
;
9191

9292
fetcherVersion = 2;
93-
hash = "sha256-vDLgpFaO+48s+tj1/2m2fgNJpCfnNkFJpQkC4Xah59E=";
93+
hash = "sha256-XXsR+zc4HsHByzzd2oHyAOrrpH9t2juUcAIoimlukbc=";
9494
};
9595

9696
buildPhase = ''
@@ -138,13 +138,19 @@ in
138138
lib.makeBinPath [
139139
# `defguard-service` needs `ip` to manage WireGuard
140140
pkgs.iproute2
141-
# `defguard-service` needs `resolvconf` to manage DNS
142-
pkgs.openresolv
143141
# `defguard-client` needs `update-desktop-database` and `lsb_release`
144142
pkgs.desktop-file-utils
145143
pkgs.lsb-release
146144
]
147145
}
146+
# `defguard-service` needs `resolvconf` to manage DNS. openresolv is
147+
# added as a suffix so the system PATH is checked first - on systems
148+
# with services.resolved enabled, NixOS puts systemd's resolvconf compat
149+
# there, which correctly integrates with systemd-resolved. openresolv
150+
# serves as a fallback for systems that don't use systemd-resolved.
151+
# Same approach used to fix the identical wg-quick issue in nixpkgs:
152+
# https://github.com/NixOS/nixpkgs/issues/139526
153+
--suffix PATH : ${lib.makeBinPath [pkgs.openresolv]}
148154
--prefix LD_LIBRARY_PATH : ${
149155
lib.makeLibraryPath [
150156
pkgs.libayatana-appindicator

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@react-hook/resize-observer": "^2.0.2",
5757
"@stablelib/base64": "^2.0.1",
5858
"@stablelib/x25519": "^2.0.1",
59-
"@tanstack/query-core": "^5.100.9",
59+
"@tanstack/query-core": "^5.100.10",
6060
"@tanstack/react-virtual": "^3.13.24",
6161
"@tauri-apps/api": "^2.11.0",
6262
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
@@ -115,12 +115,12 @@
115115
"@biomejs/biome": "^2.4.15",
116116
"@hookform/devtools": "^4.4.0",
117117
"@svgr/cli": "^8.1.0",
118-
"@tanstack/react-query": "^5.100.9",
119-
"@tanstack/react-query-devtools": "^5.100.9",
118+
"@tanstack/react-query": "^5.100.10",
119+
"@tanstack/react-query-devtools": "^5.100.10",
120120
"@tauri-apps/cli": "^2.11.1",
121121
"@types/file-saver": "^2.0.7",
122122
"@types/lodash-es": "^4.17.12",
123-
"@types/node": "^24.12.3",
123+
"@types/node": "^24.12.4",
124124
"@types/react": "^19.2.14",
125125
"@types/react-dom": "^19.2.3",
126126
"@vitejs/plugin-react": "^5.2.0",

0 commit comments

Comments
 (0)