Skip to content

Commit 572189b

Browse files
authored
Fix macos caching issue (#19)
### Description macOS caching is broken. This PR fixes it. This is related to `gtar` not having `sudo` permission, but `/nix/store` requires sudo. There are many many related issues out there. eg. actions/cache#749 I also switched to using DeterminateSystems nix installer. However, I noticed that even though cache is successfully restored in the latest round of CICD, we are still fetching the binaries from remote? (at least based on the log lines) Why is that? I suspect that I'm missing some sqlite data in the cached files. cc @savil @gcurtis if any of you have insights into this. EDIT: SOLVED. Added xdg paths in the cache and it reduces the time by half. 🎉 🎉 🎉 closes #13
1 parent a0bd99f commit 572189b

File tree

4 files changed

+53
-31
lines changed

4 files changed

+53
-31
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install devbox
3939
uses: ./
4040
with:
41-
devbox-version: 0.5.5
41+
devbox-version: 0.5.13
4242
project-path: 'testdata'
4343
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"
4444

@@ -60,10 +60,10 @@ jobs:
6060
- name: Install devbox
6161
uses: ./
6262
with:
63-
devbox-version: 0.5.5
63+
devbox-version: 0.5.13
6464
refresh-cli: true
6565
project-path: 'testdata'
66-
sha256-checksum: 'd5e623c032d38250346301040d51bcdca8e6db051c3688cc452e0dda5d95a070'
66+
sha256-checksum: '481cc5d270a22843d7f7c34eac6cea4bbe9f2cdfbc72f0217ea3823ebabecc43'
6767
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"
6868

6969
test-action-with-sha256-checksum-failure:
@@ -75,7 +75,7 @@ jobs:
7575
uses: ./
7676
continue-on-error: true
7777
with:
78-
devbox-version: 0.5.5
78+
devbox-version: 0.5.13
7979
refresh-cli: true
8080
sha256-checksum: 'bad-sha'
8181
project-path: 'testdata'
@@ -91,9 +91,9 @@ jobs:
9191
- name: Install devbox
9292
uses: ./
9393
with:
94-
devbox-version: 0.5.5
94+
devbox-version: 0.5.13
9595
enable-cache: true
9696
refresh-cli: true
97-
sha256-checksum: '3c2ce11638e3ffcd55881ec20143c38feeb24069ccdb5edf82b343c168aaca32'
97+
sha256-checksum: 'f5907e5782f6e1f5a7ca32c8ae2a0a81618549314bab237174a46fb216f43809'
9898
project-path: 'testdata'
9999
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
### Action Inputs
3333

3434
| Input argument | description | default |
35-
| ---------------- | ------------------------------------------------------------------------------------- | --------------------- |
35+
| ------------------------ | ------------------------------------------------------------------------------------- | --------------------- |
3636
| project-path | Path to the folder that contains a valid `devbox.json` | repo's root directory |
3737
| enable-cache | Cache the entire Nix store in github based on your `devbox.json` | false |
3838
| refresh-cli | Specify whether the CLI should be redownloaded | false |
@@ -51,7 +51,7 @@ Here's an example job with all inputs:
5151
project-path: 'path-to-folder'
5252
enable-cache: 'true'
5353
refresh-cli: 'false'
54-
devbox-version: 0.5.11
54+
devbox-version: 0.5.13
5555
disable-nix-access-token: 'false'
56-
sha256-sum: b6f7e24839de004ef2cad312f05865f77a73b1e0b1757e0f4d39a5911adabd50
56+
sha256-sum: f5907e5782f6e1f5a7ca32c8ae2a0a81618549314bab237174a46fb216f43809
5757
```

action.yml

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,6 @@ inputs:
2626
runs:
2727
using: "composite"
2828
steps:
29-
- name: Workaround for permission issue
30-
if: inputs.enable-cache == 'true' && runner.os != 'macOS'
31-
shell: bash
32-
run: sudo chmod u+s "$(command -v tar)"
33-
34-
- name: Mount nix store cache
35-
if: inputs.enable-cache == 'true'
36-
uses: actions/cache@v3
37-
with:
38-
path: |
39-
~/.nix-defexpr
40-
~/.nix-profile
41-
/nix/store
42-
/nix/var/nix
43-
~/.local/state/nix
44-
key: ${{ runner.os }}-devbox-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
45-
4629
- name: Get devbox version
4730
shell: bash
4831
env:
@@ -81,8 +64,6 @@ runs:
8164
export DEVBOX_USE_VERSION="${{ env.latest_version }}"
8265
curl -fsSL https://get.jetpack.io/devbox | FORCE=1 bash
8366
84-
devbox setup nix # temporary until 0.5.13 is released
85-
8667
version=$(devbox version)
8768
if [[ ! "$version" = "$DEVBOX_USE_VERSION" ]]; then
8869
echo "ERROR: mismatch devbox version downloaded. Expected $DEVBOX_USE_VERSION, got $version."
@@ -110,16 +91,46 @@ runs:
11091
fi
11192
sudo mv "$DEVBOX_BINARY" /usr/local/bin/devbox
11293
94+
- name: Workaround nix store cache permission issue
95+
if: inputs.enable-cache == 'true'
96+
shell: bash
97+
run: |
98+
if [ "$RUNNER_OS" == "macOS" ]; then
99+
sudo mv /usr/local/bin/gtar /usr/local/bin/gtar.orig
100+
echo "#!/bin/sh" >> /usr/local/bin/gtar
101+
echo 'exec sudo /usr/local/bin/gtar.orig "$@"' >> /usr/local/bin/gtar
102+
sudo chmod +x /usr/local/bin/gtar
103+
else
104+
sudo chmod u+s "$(command -v tar)"
105+
fi
106+
113107
- name: Configure nix access-tokens
114108
if: inputs.disable-nix-access-token == 'false'
115109
shell: bash
116110
run: |
117111
mkdir -p ~/.config/nix
118112
echo "access-tokens = github.com=${{ github.token }}" >> ~/.config/nix/nix.conf
119113
120-
- name: Install nix and devbox packages
114+
- name: Install nix
115+
uses: DeterminateSystems/nix-installer-action@v4
116+
with:
117+
logger: pretty
118+
extra-conf: experimental-features = ca-derivations fetch-closure
119+
120+
- name: Mount nix store cache
121+
if: inputs.enable-cache == 'true'
122+
uses: actions/cache@v3
123+
with:
124+
path: |
125+
~/.cache
126+
~/.local/state/nix
127+
~/.nix-defexpr
128+
~/.nix-profile
129+
/nix/store
130+
/nix/var/nix
131+
key: ${{ runner.os }}-devbox-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
132+
133+
- name: Install devbox packages
121134
shell: bash
122135
run: |
123-
NIX_INSTALLER_NO_CHANNEL_ADD=1
124-
NIX_BUILD_SHELL=/bin/bash
125136
devbox run --config=${{ inputs.project-path }} -- echo "Packages installed!"

testdata/devbox.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
"go@latest": {
5+
"last_modified": "2023-09-17T10:54:49Z",
6+
"resolved": "github:NixOS/nixpkgs/5148520bfab61f99fd25fb9ff7bfbb50dad3c9db#go_1_21",
7+
"source": "devbox-search",
8+
"version": "1.21.1"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)