From 5aaffa6e32f9cfaf5c5fda588ce01c04a58fa580 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 13 Nov 2024 17:33:50 -0500 Subject: [PATCH 1/4] Log in to flakehub if the machine is already installed --- dist/index.js | 21 ++++++++++++++------- src/index.ts | 26 ++++++++++++++++++-------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0613d9d..0846373 100644 --- a/dist/index.js +++ b/dist/index.js @@ -102679,6 +102679,9 @@ ${stderrBuffer}` ); await this.executeUninstall(); } else { + if (this.determinate) { + await this.flakehubLogin(); + } await this.setGithubPath(); core.info("Nix was already installed, using existing install"); return; @@ -102893,13 +102896,17 @@ ${stderrBuffer}` } async setGithubPath() { try { - const nixVarNixProfilePath = "/nix/var/nix/profiles/default/bin"; - const homeNixProfilePath = `${process.env["HOME"]}/.nix-profile/bin`; - core.addPath(nixVarNixProfilePath); - core.addPath(homeNixProfilePath); - core.info( - `Added \`${nixVarNixProfilePath}\` and \`${homeNixProfilePath}\` to \`$GITHUB_PATH\`` - ); + const paths = [ + "/nix/var/nix/profiles/default/bin", + `${process.env["HOME"]}/.nix-profile/bin` + ]; + if (this.determinate) { + paths.push("/usr/local/bin"); + } + for (const p of paths) { + core.addPath(p); + core.debug(`Added \`${p}\` to \`$GITHUB_PATH\``); + } } catch { core.info( "Skipping setting $GITHUB_PATH in action, the `nix-installer` crate seems to have done this already. From `nix-installer` version 0.11.0 and up, this step is done in the action. Prior to 0.11.0, this was only done in the `nix-installer` binary." diff --git a/src/index.ts b/src/index.ts index 78d21ce..5ed2240 100644 --- a/src/index.ts +++ b/src/index.ts @@ -614,7 +614,11 @@ class NixInstallerAction extends DetSysAction { ); await this.executeUninstall(); } else { - // We're already installed, and not reinstalling, just set GITHUB_PATH and finish early + // We're already installed, and not reinstalling, just log in to FlakeHub, set GITHUB_PATH and finish early + if (this.determinate) { + await this.flakehubLogin(); + } + await this.setGithubPath(); actionsCore.info("Nix was already installed, using existing install"); return; @@ -859,13 +863,19 @@ class NixInstallerAction extends DetSysAction { async setGithubPath(): Promise { // Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error. try { - const nixVarNixProfilePath = "/nix/var/nix/profiles/default/bin"; - const homeNixProfilePath = `${process.env["HOME"]}/.nix-profile/bin`; - actionsCore.addPath(nixVarNixProfilePath); - actionsCore.addPath(homeNixProfilePath); - actionsCore.info( - `Added \`${nixVarNixProfilePath}\` and \`${homeNixProfilePath}\` to \`$GITHUB_PATH\``, - ); + const paths = [ + "/nix/var/nix/profiles/default/bin", + `${process.env["HOME"]}/.nix-profile/bin`, + ]; + + if (this.determinate) { + paths.push("/usr/local/bin"); + } + + for (const p of paths) { + actionsCore.addPath(p); + actionsCore.debug(`Added \`${p}\` to \`$GITHUB_PATH\``); + } } catch { actionsCore.info( "Skipping setting $GITHUB_PATH in action, the `nix-installer` crate seems to have done this already. From `nix-installer` version 0.11.0 and up, this step is done in the action. Prior to 0.11.0, this was only done in the `nix-installer` binary.", From d32de47bcf3f37bb7698314a941b32626513762a Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 13 Nov 2024 19:04:13 -0500 Subject: [PATCH 2/4] Put the nix store paths first (in the PATH) --- dist/index.js | 7 +++---- src/index.ts | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0846373..16be54e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -102896,13 +102896,12 @@ ${stderrBuffer}` } async setGithubPath() { try { - const paths = [ - "/nix/var/nix/profiles/default/bin", - `${process.env["HOME"]}/.nix-profile/bin` - ]; + const paths = []; if (this.determinate) { paths.push("/usr/local/bin"); } + paths.push("/nix/var/nix/profiles/default/bin"); + paths.push(`${process.env["HOME"]}/.nix-profile/bin`); for (const p of paths) { core.addPath(p); core.debug(`Added \`${p}\` to \`$GITHUB_PATH\``); diff --git a/src/index.ts b/src/index.ts index 5ed2240..65ea296 100644 --- a/src/index.ts +++ b/src/index.ts @@ -863,15 +863,15 @@ class NixInstallerAction extends DetSysAction { async setGithubPath(): Promise { // Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error. try { - const paths = [ - "/nix/var/nix/profiles/default/bin", - `${process.env["HOME"]}/.nix-profile/bin`, - ]; + const paths = []; if (this.determinate) { paths.push("/usr/local/bin"); } + paths.push("/nix/var/nix/profiles/default/bin"); + paths.push(`${process.env["HOME"]}/.nix-profile/bin`); + for (const p of paths) { actionsCore.addPath(p); actionsCore.debug(`Added \`${p}\` to \`$GITHUB_PATH\``); From 849c0a32d0a533147fcc8b7f024f1668635ea66f Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 13 Nov 2024 19:07:04 -0500 Subject: [PATCH 3/4] set the path earlier --- dist/index.js | 4 ++-- src/index.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 16be54e..9460c2f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -102679,10 +102679,10 @@ ${stderrBuffer}` ); await this.executeUninstall(); } else { + await this.setGithubPath(); if (this.determinate) { await this.flakehubLogin(); } - await this.setGithubPath(); core.info("Nix was already installed, using existing install"); return; } @@ -102706,10 +102706,10 @@ ${stderrBuffer}` if (this.forceDockerShim) { await this.spawnDockerShim(); } + await this.setGithubPath(); if (this.determinate) { await this.flakehubLogin(); } - await this.setGithubPath(); } async spawnDockerShim() { core.startGroup( diff --git a/src/index.ts b/src/index.ts index 65ea296..7ab0a56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -615,11 +615,12 @@ class NixInstallerAction extends DetSysAction { await this.executeUninstall(); } else { // We're already installed, and not reinstalling, just log in to FlakeHub, set GITHUB_PATH and finish early + await this.setGithubPath(); + if (this.determinate) { await this.flakehubLogin(); } - await this.setGithubPath(); actionsCore.info("Nix was already installed, using existing install"); return; } @@ -647,11 +648,11 @@ class NixInstallerAction extends DetSysAction { await this.spawnDockerShim(); } + await this.setGithubPath(); + if (this.determinate) { await this.flakehubLogin(); } - - await this.setGithubPath(); } async spawnDockerShim(): Promise { From 9e61458926fb03ffd55847bc8b7ff301884186c9 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 13 Nov 2024 19:16:42 -0500 Subject: [PATCH 4/4] Warn on login failures --- dist/index.js | 1 + src/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index 9460c2f..b4fd743 100644 --- a/dist/index.js +++ b/dist/index.js @@ -102919,6 +102919,7 @@ ${stderrBuffer}` try { await exec.exec(`determinate-nixd`, ["login", "github-action"]); } catch (e) { + core.warning(`FlakeHub Login failure: ${stringifyError(e)}`); this.recordEvent("flakehub-login:failure", { exception: stringifyError(e) }); diff --git a/src/index.ts b/src/index.ts index 7ab0a56..a51fda3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -894,6 +894,7 @@ class NixInstallerAction extends DetSysAction { try { await actionsExec.exec(`determinate-nixd`, ["login", "github-action"]); } catch (e: unknown) { + actionsCore.warning(`FlakeHub Login failure: ${stringifyError(e)}`); this.recordEvent("flakehub-login:failure", { exception: stringifyError(e), });