Skip to content

Commit 714dbac

Browse files
authored
ci: upgrade nix install action, use it in nix-test-versions (#1316)
Changes extracted from #1311 so they can be merged sooner. - Upgrade the Nix installer action to v4 and configure the experimental features Devbox needs. - Print out the Nix version, `/etc/nix/nix.conf`, and the resolved Nix config to make debugging easier. - Do the same for `test-nix-versions` and add the last 3 Nix releases to the matrix. Nix 2.15.1 is the current stable version and 2.17.0 is the latest. - Update `TestContentAddressedPath` to accept hashes from Nix <2.17 and 2.17+.
1 parent c2f31cc commit 714dbac

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

.github/workflows/cli-tests.yaml

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ permissions:
3131
contents: read
3232
pull-requests: read
3333

34+
defaults:
35+
run:
36+
# Explicitly setting the shell to bash runs commands with
37+
# `bash --noprofile --norc -eo pipefail` instead of `bash -e`.
38+
shell: bash
39+
3440
env:
3541
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}"
3642
HOMEBREW_NO_ANALYTICS: 1
@@ -102,10 +108,10 @@ jobs:
102108
brew install dash zsh
103109
fi
104110
- name: Install Nix
105-
uses: DeterminateSystems/nix-installer-action@v1
111+
uses: DeterminateSystems/nix-installer-action@v4
106112
with:
107113
logger: pretty
108-
nix-build-user-count: 4
114+
extra-conf: experimental-features = ca-derivations fetch-closure
109115
- name: Run tests
110116
env:
111117
# For devbox.json tests, we default to non-debug mode since the debug output is less useful than for unit testscripts.
@@ -115,6 +121,15 @@ jobs:
115121
# Used in `go test -timeout` flag. Needs a value that time.ParseDuration can parse.
116122
DEVBOX_GOLANG_TEST_TIMEOUT: "${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && '35m' || '20m' }}"
117123
run: |
124+
echo "::group::Nix version"
125+
nix --version
126+
echo "::endgroup::"
127+
echo "::group::Contents of /etc/nix/nix.conf"
128+
cat /etc/nix/nix.conf || true
129+
echo "::endgroup::"
130+
echo "::group::Resolved Nix config"
131+
nix show-config
132+
echo "::endgroup::"
118133
go test -v -timeout $DEVBOX_GOLANG_TEST_TIMEOUT ./...
119134
120135
auto-nix-install: # ensure Devbox installs nix and works properly after installation.
@@ -141,12 +156,14 @@ jobs:
141156
devbox run echo "Installing packages..."
142157
- name: Test removing package
143158
run: devbox rm go
144-
145-
test-with-old-nix-version:
159+
160+
# Run a sanity test to make sure Devbox can install and remove packages with
161+
# the last 3 Nix releases.
162+
test-nix-versions:
146163
strategy:
147164
matrix:
148165
os: [ubuntu-latest, macos-latest]
149-
version: [2.15.1]
166+
version: [2.15.1, 2.16.1, 2.17.0]
150167
runs-on: ${{ matrix.os }}
151168
steps:
152169
- uses: actions/checkout@v3
@@ -155,15 +172,23 @@ jobs:
155172
go-version-file: ./go.mod
156173
- name: Build devbox
157174
run: go install ./cmd/devbox
158-
- name: Install nix
159-
run: sh <(curl -L https://releases.nixos.org/nix/nix-${{ matrix.version }}/install) --daemon
160-
- name: Install devbox packages
175+
- name: Install Nix
176+
uses: DeterminateSystems/nix-installer-action@v4
177+
with:
178+
logger: pretty
179+
extra-conf: experimental-features = ca-derivations fetch-closure
180+
nix-package-url: https://releases.nixos.org/nix/nix-${{ matrix.version }}/nix-${{ matrix.version }}-${{ runner.arch == 'X64' && 'x86_64' || 'aarch64' }}-${{ runner.os == 'macOS' && 'darwin' || 'linux' }}.tar.xz
181+
- name: Run devbox install, devbox run, devbox rm
161182
run: |
162-
# Setup github authentication to ensure Github's rate limits are not hit.
163-
# If this works, we can consider refactoring this into a reusable github action helper.
164-
mkdir -p ~/.config/nix
165-
echo "access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}" > ~/.config/nix/nix.conf
166-
167-
devbox run echo "Installing packages..."
168-
- name: Test removing package
169-
run: devbox rm go
183+
echo "::group::Nix version"
184+
nix --version
185+
echo "::endgroup::"
186+
echo "::group::Contents of /etc/nix/nix.conf"
187+
cat /etc/nix/nix.conf || true
188+
echo "::endgroup::"
189+
echo "::group::Resolved Nix config"
190+
nix show-config
191+
echo "::endgroup::"
192+
devbox install
193+
devbox run -- echo "Hello from devbox!"
194+
devbox rm go

internal/nix/store_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ package nix
22

33
import (
44
"fmt"
5+
"strings"
56
"testing"
7+
8+
"golang.org/x/exp/slices"
69
)
710

811
func TestContentAddressedPath(t *testing.T) {
9-
1012
testCases := []struct {
1113
storePath string
12-
expected string
14+
expected []string
1315
}{
1416
{
1517
"/nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1",
16-
"/nix/store/ldbhlwhh39wha58rm61bkiiwm6j7211j-git-2.33.1",
18+
[]string{
19+
// Hash from before Nix 2.17.0.
20+
"/nix/store/ldbhlwhh39wha58rm61bkiiwm6j7211j-git-2.33.1",
21+
22+
// Hash after Nix 2.17.0.
23+
"/nix/store/d49wyvsz5nkqa23qp4p0ikr04mw9n4h9-git-2.33.1",
24+
},
1725
},
1826
}
1927

@@ -23,10 +31,9 @@ func TestContentAddressedPath(t *testing.T) {
2331
if err != nil {
2432
t.Errorf("got error: %v", err)
2533
}
26-
if out != testCase.expected {
27-
t.Errorf("got %s, want %s", out, testCase.expected)
34+
if !slices.Contains(testCase.expected, out) {
35+
t.Errorf("got %q, want any of:\n%s", out, strings.Join(testCase.expected, "\n"))
2836
}
2937
})
30-
3138
}
3239
}

0 commit comments

Comments
 (0)