Skip to content

Commit e50d5f7

Browse files
authored
Log in to flakehub on existing installs (#129)
* Log in to flakehub if the machine is already installed * Put the nix store paths first (in the PATH) * set the path earlier * Warn on login failures
1 parent 25431d2 commit e50d5f7

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

dist/index.js

+15-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+22-10
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,13 @@ class NixInstallerAction extends DetSysAction {
614614
);
615615
await this.executeUninstall();
616616
} else {
617-
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
617+
// We're already installed, and not reinstalling, just log in to FlakeHub, set GITHUB_PATH and finish early
618618
await this.setGithubPath();
619+
620+
if (this.determinate) {
621+
await this.flakehubLogin();
622+
}
623+
619624
actionsCore.info("Nix was already installed, using existing install");
620625
return;
621626
}
@@ -643,11 +648,11 @@ class NixInstallerAction extends DetSysAction {
643648
await this.spawnDockerShim();
644649
}
645650

651+
await this.setGithubPath();
652+
646653
if (this.determinate) {
647654
await this.flakehubLogin();
648655
}
649-
650-
await this.setGithubPath();
651656
}
652657

653658
async spawnDockerShim(): Promise<void> {
@@ -859,13 +864,19 @@ class NixInstallerAction extends DetSysAction {
859864
async setGithubPath(): Promise<void> {
860865
// Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error.
861866
try {
862-
const nixVarNixProfilePath = "/nix/var/nix/profiles/default/bin";
863-
const homeNixProfilePath = `${process.env["HOME"]}/.nix-profile/bin`;
864-
actionsCore.addPath(nixVarNixProfilePath);
865-
actionsCore.addPath(homeNixProfilePath);
866-
actionsCore.info(
867-
`Added \`${nixVarNixProfilePath}\` and \`${homeNixProfilePath}\` to \`$GITHUB_PATH\``,
868-
);
867+
const paths = [];
868+
869+
if (this.determinate) {
870+
paths.push("/usr/local/bin");
871+
}
872+
873+
paths.push("/nix/var/nix/profiles/default/bin");
874+
paths.push(`${process.env["HOME"]}/.nix-profile/bin`);
875+
876+
for (const p of paths) {
877+
actionsCore.addPath(p);
878+
actionsCore.debug(`Added \`${p}\` to \`$GITHUB_PATH\``);
879+
}
869880
} catch {
870881
actionsCore.info(
871882
"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.",
@@ -883,6 +894,7 @@ class NixInstallerAction extends DetSysAction {
883894
try {
884895
await actionsExec.exec(`determinate-nixd`, ["login", "github-action"]);
885896
} catch (e: unknown) {
897+
actionsCore.warning(`FlakeHub Login failure: ${stringifyError(e)}`);
886898
this.recordEvent("flakehub-login:failure", {
887899
exception: stringifyError(e),
888900
});

0 commit comments

Comments
 (0)