Skip to content

Commit

Permalink
Prefer RUNNER_TEMP for temporary directory (#50)
Browse files Browse the repository at this point in the history
The directory which the `RUNNER_TEMP` env var points to is cleaned after
each job run and it's also the place where the runner/other actions put
their temporary files. Additionally, for sandboxed runners, the
temporary directoy (as returned by `tmpdir`) is likely not accessible by
the host's Nix, so the garbage collector thinks the profiles in this
directory are no longer alive and garbage-collects them.
  • Loading branch information
Trundle authored Nov 8, 2024
1 parent fefec82 commit 7f943de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function createOrGetStateDir() {
let tmpDir = process.env.STATE_NIX_PROFILE_TMPDIR;
// Allow to execute this action multiple times with different packages
if (!tmpDir) {
tmpDir = yield fs_1.promises.mkdtemp(path.join((0, os_1.tmpdir)(), "nix-profile-"));
tmpDir = yield fs_1.promises.mkdtemp(path.join(process.env.RUNNER_TEMP || (0, os_1.tmpdir)(), "nix-profile-"));
}
return tmpDir;
});
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ async function createOrGetStateDir(): Promise<string> {
let tmpDir = process.env.STATE_NIX_PROFILE_TMPDIR;
// Allow to execute this action multiple times with different packages
if (!tmpDir) {
tmpDir = await promises.mkdtemp(path.join(tmpdir(), "nix-profile-"));
tmpDir = await promises.mkdtemp(
path.join(process.env.RUNNER_TEMP || tmpdir(), "nix-profile-"),
);
}

return tmpDir;
Expand Down

0 comments on commit 7f943de

Please sign in to comment.