Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7993355175 | |||
| db2c9be88c | |||
| a2473ab552 | |||
| f51ebf9a6f | |||
| 676d200580 | |||
| c6857b9a9d | |||
| e5b417b85f | |||
| 8ef3f8c93e | |||
| ad8814ae5d | |||
| 9c4e8b237e | |||
| 23e5c435a9 | |||
| c3983e7949 | |||
| 3c042d09d2 | |||
| 7b0893fcd8 | |||
| e4f741cb67 | |||
| a56dda90ad | |||
| cd7602a5a8 | |||
| f6047128c4 | |||
| 61795779f3 | |||
| 0b690dedac | |||
| 75ffa7fc74 | |||
| 5c2710f363 | |||
| 8cc782962a | |||
| c1489fff7b | |||
| 4ed4c86fdc | |||
| ccf4610648 | |||
| f97a8a062c | |||
| 766b8830f1 | |||
| fd6c226bf9 | |||
| 350241e13f | |||
| 481524661c | |||
| 164c9d00dc | |||
| 74f4d10531 | |||
| 86a97d5eb6 | |||
| 86e8caa071 | |||
| 151fdae2fc | |||
| 7fcb842097 | |||
| 8d9c69de11 | |||
| 6b0b02c6a2 | |||
| 6265732741 | |||
| 0e85ec287f | |||
| 5385bea1cb | |||
| d49867b627 | |||
| e8f36a90cd | |||
| 397a5c26a7 | |||
| 8d4286b90e | |||
| ca7cf68c63 | |||
| 94a9e4375c | |||
| da29cfd994 | |||
| 1e58ce3980 | |||
| 83c8f7dfdd | |||
| 37d6eb5161 | |||
| 813cf108af | |||
| 4a8c7256d3 | |||
| e4a38c246a | |||
| 9243e9b760 | |||
| 74b8a1f4e8 | |||
| 51bc05e2ea | |||
| 9ffa76fa74 |
@@ -0,0 +1,10 @@
|
||||
# https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
@@ -29,6 +29,7 @@
|
||||
"accessibility": "no-public"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-base-to-string": "error",
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script verifies that the version of Nix installed on the runner
|
||||
# matches the version supplied in the first argument.
|
||||
|
||||
EXPECTED_VERSION="${1}"
|
||||
|
||||
INSTALLED_NIX_VERSION_OUTPUT=$(nix --version)
|
||||
INSTALLED_NIX_VERSION=$(echo "${INSTALLED_NIX_VERSION_OUTPUT}" | awk '{print $NF}')
|
||||
EXPECTED_OUTPUT="nix (Nix) ${EXPECTED_VERSION}"
|
||||
|
||||
if [ "${INSTALLED_NIX_VERSION_OUTPUT}" != "${EXPECTED_OUTPUT}" ]; then
|
||||
echo "Nix version ${INSTALLED_NIX_VERSION} didn't match expected version ${EXPECTED_VERSION}"
|
||||
exit 1
|
||||
else
|
||||
echo "Success! Nix version ${INSTALLED_NIX_VERSION} installed as expected"
|
||||
exit 0
|
||||
fi
|
||||
@@ -7,6 +7,21 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-22.04
|
||||
needs:
|
||||
- check-dist-up-to-date
|
||||
- install-nix-linux
|
||||
- install-nix-macos
|
||||
- install-with-non-default-source-inputs
|
||||
# NOTE(cole-h): GitHub treats "skipped" as "OK" for the purposes of required checks on branch
|
||||
# protection, so we take advantage of this fact and fail if any of the dependent actions failed,
|
||||
# or "skip" (which is a success for GHA's purposes) if none of them did.
|
||||
if: failure()
|
||||
steps:
|
||||
- name: Dependent checks failed
|
||||
run: exit 1
|
||||
|
||||
check-dist-up-to-date:
|
||||
name: Check the dist/ folder is up to date
|
||||
runs-on: ubuntu-22.04
|
||||
@@ -28,8 +43,9 @@ jobs:
|
||||
run: git status --porcelain=v1
|
||||
- name: Ensure no staged changes
|
||||
run: git diff --exit-code
|
||||
run-test-suite:
|
||||
name: Run test suite
|
||||
|
||||
install-nix-linux:
|
||||
name: Run test suite for Linux systems
|
||||
strategy:
|
||||
matrix:
|
||||
runner:
|
||||
@@ -48,6 +64,7 @@ jobs:
|
||||
logger: pretty
|
||||
log-directives: nix_installer=trace
|
||||
backtrace: full
|
||||
_internal-strict-mode: true
|
||||
- name: echo $PATH
|
||||
run: echo $PATH
|
||||
|
||||
@@ -79,6 +96,7 @@ jobs:
|
||||
logger: pretty
|
||||
log-directives: nix_installer=trace
|
||||
backtrace: full
|
||||
_internal-strict-mode: true
|
||||
- name: Test `nix` with `$GITHUB_PATH`
|
||||
if: success() || failure()
|
||||
run: |
|
||||
@@ -96,6 +114,7 @@ jobs:
|
||||
reinstall: true
|
||||
extra-conf: |
|
||||
use-sqlite-wal = true
|
||||
_internal-strict-mode: true
|
||||
- name: Test `nix` with `$GITHUB_PATH`
|
||||
if: success() || failure()
|
||||
run: |
|
||||
@@ -116,9 +135,16 @@ jobs:
|
||||
duration: 5m
|
||||
authorized-users: grahamc
|
||||
|
||||
run-x86_64-darwin:
|
||||
name: Run x86_64 Darwin
|
||||
runs-on: macos-12
|
||||
install-nix-macos:
|
||||
name: Run test suite for macOS systems
|
||||
strategy:
|
||||
matrix:
|
||||
runner:
|
||||
# x86_64-darwin
|
||||
- macos-12
|
||||
# aarch64-darwin
|
||||
- macos-latest-xlarge
|
||||
runs-on: ${{ matrix.runner }}
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
@@ -130,6 +156,7 @@ jobs:
|
||||
logger: pretty
|
||||
log-directives: nix_installer=trace
|
||||
backtrace: full
|
||||
_internal-strict-mode: true
|
||||
- name: echo $PATH
|
||||
run: echo $PATH
|
||||
- name: Test `nix` with `$GITHUB_PATH`
|
||||
@@ -158,6 +185,7 @@ jobs:
|
||||
logger: pretty
|
||||
log-directives: nix_installer=trace
|
||||
backtrace: full
|
||||
_internal-strict-mode: true
|
||||
- name: Test `nix` with `$GITHUB_PATH`
|
||||
if: success() || failure()
|
||||
run: |
|
||||
@@ -175,6 +203,7 @@ jobs:
|
||||
reinstall: true
|
||||
extra-conf: |
|
||||
use-sqlite-wal = true
|
||||
_internal-strict-mode: true
|
||||
- name: Test `nix` with `$GITHUB_PATH`
|
||||
if: success() || failure()
|
||||
run: |
|
||||
@@ -194,3 +223,28 @@ jobs:
|
||||
with:
|
||||
duration: 5m
|
||||
authorized-users: grahamc
|
||||
|
||||
install-with-non-default-source-inputs:
|
||||
name: Install Nix using non-default source-${{ matrix.inputs.key }}
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
matrix:
|
||||
inputs:
|
||||
# https://github.com/DeterminateSystems/nix-installer/blob/v0.18.0
|
||||
- key: url
|
||||
value: https://github.com/DeterminateSystems/nix-installer/releases/download/v0.18.0/nix-installer-x86_64-linux
|
||||
nix-version: "2.21.2"
|
||||
# https://github.com/DeterminateSystems/nix-installer/tree/7011c077ec491da410fbc39f68676b0908b9ce7e
|
||||
- key: revision
|
||||
value: 7011c077ec491da410fbc39f68676b0908b9ce7e
|
||||
nix-version: "2.19.2"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install with alternative source-${{ matrix.inputs.key }}
|
||||
uses: ./
|
||||
with:
|
||||
source-${{ matrix.inputs.key }}: ${{ matrix.inputs.value }}
|
||||
_internal-strict-mode: true
|
||||
- name: Ensure that the expected Nix version ${{ matrix.inputs.nix-version }} is installed via alternative source-${{ matrix.inputs.key }}
|
||||
run: .github/verify-version.sh ${{ matrix.inputs.nix-version }}
|
||||
|
||||
+12
-3
@@ -19,6 +19,7 @@ inputs:
|
||||
default: false
|
||||
force-docker-shim:
|
||||
description: Force the use of Docker as a process supervisor. This setting is automatically enabled when necessary.
|
||||
required: false
|
||||
default: false
|
||||
github-token:
|
||||
description: A GitHub token for making authenticated requests (which have a higher rate-limit quota than unauthenticated requests)
|
||||
@@ -79,6 +80,9 @@ inputs:
|
||||
nix-build-user-prefix:
|
||||
description: The Nix build user prefix (user numbers will be postfixed)
|
||||
required: false
|
||||
source-binary:
|
||||
description: Run a version of the nix-installer binary from somewhere already on disk. Conflicts with all other `source-*` options. Intended only for testing this Action.
|
||||
required: false
|
||||
source-branch:
|
||||
description: The branch of `nix-installer` to use (conflicts with `source-tag`, `source-revision`, `source-pr`)
|
||||
required: false
|
||||
@@ -92,7 +96,7 @@ inputs:
|
||||
description: The tag of `nix-installer` to use (conflicts with `source-revision`, `source-branch`, `source-pr`)
|
||||
required: false
|
||||
source-url:
|
||||
description: A URL pointing to a `nix-installer.sh` script
|
||||
description: A URL pointing to a `nix-installer` executable
|
||||
required: false
|
||||
nix-package-url:
|
||||
description: The Nix package URL
|
||||
@@ -110,10 +114,11 @@ inputs:
|
||||
default: true
|
||||
diagnostic-endpoint:
|
||||
description: "Diagnostic endpoint url where the installer sends data to. To disable set this to an empty string."
|
||||
default: "https://install.determinate.systems/nix-installer/diagnostic"
|
||||
required: false
|
||||
default: "-"
|
||||
trust-runner-user:
|
||||
description: Whether to make the runner user trusted by the Nix daemon
|
||||
default: "true"
|
||||
default: true
|
||||
nix-installer-branch:
|
||||
description: (deprecated) The branch of `nix-installer` to use (conflicts with `nix-installer-tag`, `nix-installer-revision`, `nix-installer-pr`)
|
||||
required: false
|
||||
@@ -129,6 +134,10 @@ inputs:
|
||||
nix-installer-url:
|
||||
description: (deprecated) A URL pointing to a `nix-installer.sh` script
|
||||
required: false
|
||||
_internal-strict-mode:
|
||||
description: Whether to fail when any errors are thrown. Used only to test the Action; do not set this in your own workflows.
|
||||
required: false
|
||||
default: false
|
||||
|
||||
runs:
|
||||
using: "node20"
|
||||
|
||||
+1298
-555
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -33,9 +33,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||
"@types/node": "^20.12.11",
|
||||
"@types/node": "^20.12.13",
|
||||
"@types/uuid": "^9.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
|
||||
Generated
+260
-249
File diff suppressed because it is too large
Load Diff
+100
-70
@@ -7,7 +7,7 @@ import fs from "node:fs";
|
||||
import { userInfo } from "node:os";
|
||||
import stringArgv from "string-argv";
|
||||
import * as path from "path";
|
||||
import { IdsToolbox, inputs, platform } from "detsys-ts";
|
||||
import { DetSysAction, inputs, platform } from "detsys-ts";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
// Nix installation events
|
||||
@@ -30,12 +30,18 @@ const EVENT_CONCLUDE_WORKFLOW = "conclude_workflow";
|
||||
// Facts
|
||||
const FACT_HAS_DOCKER = "has_docker";
|
||||
const FACT_HAS_SYSTEMD = "has_systemd";
|
||||
const FACT_IN_GITHUB_ACTIONS = "in_act";
|
||||
const FACT_IN_ACT = "in_act";
|
||||
const FACT_IN_NAMESPACE_SO = "in_namespace_so";
|
||||
const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner";
|
||||
|
||||
class NixInstallerAction {
|
||||
idslib: IdsToolbox;
|
||||
type WorkflowConclusion =
|
||||
| "success"
|
||||
| "failure"
|
||||
| "cancelled"
|
||||
| "unavailable"
|
||||
| "no-jobs";
|
||||
|
||||
class NixInstallerAction extends DetSysAction {
|
||||
platform: string;
|
||||
nixPackageUrl: string | null;
|
||||
backtrace: string | null;
|
||||
@@ -45,7 +51,7 @@ class NixInstallerAction {
|
||||
kvm: boolean;
|
||||
githubServerUrl: string | null;
|
||||
githubToken: string | null;
|
||||
forceDockerShim: boolean | null;
|
||||
forceDockerShim: boolean;
|
||||
init: string | null;
|
||||
localRoot: string | null;
|
||||
logDirectives: string | null;
|
||||
@@ -65,14 +71,16 @@ class NixInstallerAction {
|
||||
planner: string | null;
|
||||
reinstall: boolean;
|
||||
startDaemon: boolean;
|
||||
trustRunnerUser: boolean | null;
|
||||
trustRunnerUser: boolean;
|
||||
runnerOs: string | undefined;
|
||||
|
||||
constructor() {
|
||||
this.idslib = new IdsToolbox({
|
||||
super({
|
||||
name: "nix-installer",
|
||||
fetchStyle: "nix-style",
|
||||
legacySourcePrefix: "nix-installer",
|
||||
requireNix: "ignore",
|
||||
diagnosticsSuffix: "diagnostic",
|
||||
});
|
||||
|
||||
this.platform = platform.getNixPlatform(platform.getArchOs());
|
||||
@@ -105,15 +113,43 @@ class NixInstallerAction {
|
||||
this.reinstall = inputs.getBool("reinstall");
|
||||
this.startDaemon = inputs.getBool("start-daemon");
|
||||
this.trustRunnerUser = inputs.getBool("trust-runner-user");
|
||||
this.runnerOs = process.env["RUNNER_OS"];
|
||||
}
|
||||
|
||||
async detectAndForceDockerShim(): Promise<void> {
|
||||
const runnerOs = process.env["RUNNER_OS"];
|
||||
async main(): Promise<void> {
|
||||
await this.detectAndForceDockerShim();
|
||||
await this.install();
|
||||
}
|
||||
|
||||
// Detect if we're in a GHA runner which is Linux, doesn't have Systemd, and does have Docker.
|
||||
// This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/),
|
||||
// and especially GitHub Enterprise Server.
|
||||
if (runnerOs !== "Linux") {
|
||||
async post(): Promise<void> {
|
||||
await this.cleanupDockerShim();
|
||||
await this.reportOverall();
|
||||
}
|
||||
|
||||
private get isMacOS(): boolean {
|
||||
return this.runnerOs === "macOS";
|
||||
}
|
||||
|
||||
private get isLinux(): boolean {
|
||||
return this.runnerOs === "Linux";
|
||||
}
|
||||
|
||||
private get isRunningInAct(): boolean {
|
||||
return process.env["ACT"] !== undefined && !(process.env["NOT_ACT"] === "");
|
||||
}
|
||||
|
||||
private get isRunningInNamespaceRunner(): boolean {
|
||||
return (
|
||||
process.env["NSC_VM_ID"] !== undefined &&
|
||||
!(process.env["NOT_NAMESPACE"] === "true")
|
||||
);
|
||||
}
|
||||
|
||||
// Detect if we're in a GHA runner which is Linux, doesn't have Systemd, and does have Docker.
|
||||
// This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/),
|
||||
// and especially GitHub Enterprise Server.
|
||||
async detectAndForceDockerShim(): Promise<void> {
|
||||
if (!this.isLinux) {
|
||||
if (this.forceDockerShim) {
|
||||
actionsCore.warning(
|
||||
"Ignoring force-docker-shim which is set to true, as it is only supported on Linux.",
|
||||
@@ -123,26 +159,33 @@ class NixInstallerAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isRunningInAct) {
|
||||
actionsCore.debug(
|
||||
"Not bothering to detect if the docker shim should be used, as it is typically incompatible with act.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const systemdCheck = fs.statSync("/run/systemd/system", {
|
||||
throwIfNoEntry: false,
|
||||
});
|
||||
if (systemdCheck?.isDirectory()) {
|
||||
this.addFact(FACT_HAS_SYSTEMD, true);
|
||||
if (this.forceDockerShim) {
|
||||
actionsCore.warning(
|
||||
"Systemd is detected, but ignoring it since force-docker-shim is enabled.",
|
||||
);
|
||||
} else {
|
||||
this.idslib.addFact(FACT_HAS_SYSTEMD, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.idslib.addFact(FACT_HAS_SYSTEMD, false);
|
||||
this.addFact(FACT_HAS_SYSTEMD, false);
|
||||
|
||||
actionsCore.debug(
|
||||
"Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor.",
|
||||
);
|
||||
|
||||
this.idslib.addFact(FACT_HAS_DOCKER, false); // Set to false here, and only in the success case do we set it to true
|
||||
this.addFact(FACT_HAS_DOCKER, false); // Set to false here, and only in the success case do we set it to true
|
||||
let exitCode;
|
||||
try {
|
||||
exitCode = await actionsExec.exec("docker", ["info"], {
|
||||
@@ -176,7 +219,7 @@ class NixInstallerAction {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.idslib.addFact(FACT_HAS_DOCKER, true);
|
||||
this.addFact(FACT_HAS_DOCKER, true);
|
||||
|
||||
if (
|
||||
!this.forceDockerShim &&
|
||||
@@ -309,11 +352,10 @@ class NixInstallerAction {
|
||||
|
||||
private async executionEnvironment(): Promise<ExecuteEnvironment> {
|
||||
const executionEnv: ExecuteEnvironment = {};
|
||||
const runnerOs = process.env["RUNNER_OS"];
|
||||
|
||||
executionEnv.NIX_INSTALLER_NO_CONFIRM = "true";
|
||||
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = JSON.stringify(
|
||||
this.idslib.getCorrelationHashes(),
|
||||
this.getCorrelationHashes(),
|
||||
);
|
||||
|
||||
if (this.backtrace !== null) {
|
||||
@@ -361,18 +403,18 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT =
|
||||
this.idslib.getDiagnosticsUrl()?.toString() ?? "";
|
||||
(await this.getDiagnosticsUrl())?.toString() ?? "";
|
||||
|
||||
// TODO: Error if the user uses these on not-MacOS
|
||||
if (this.macEncrypt !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt;
|
||||
}
|
||||
|
||||
if (this.macCaseSensitive !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error(
|
||||
"`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`",
|
||||
);
|
||||
@@ -381,7 +423,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
if (this.macVolumeLabel !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error(
|
||||
"`mac-volume-label` while `$RUNNER_OS` was not `macOS`",
|
||||
);
|
||||
@@ -390,7 +432,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
if (this.macRootDisk !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk;
|
||||
@@ -406,7 +448,7 @@ class NixInstallerAction {
|
||||
|
||||
// TODO: Error if the user uses these on MacOS
|
||||
if (this.init !== null) {
|
||||
if (runnerOs === "macOS") {
|
||||
if (this.isMacOS) {
|
||||
throw new Error(
|
||||
"`init` is not a valid option when `$RUNNER_OS` is `macOS`",
|
||||
);
|
||||
@@ -428,7 +470,7 @@ class NixInstallerAction {
|
||||
extraConf += `access-tokens = ${serverUrl}=${this.githubToken}`;
|
||||
extraConf += "\n";
|
||||
}
|
||||
if (this.trustRunnerUser !== null) {
|
||||
if (this.trustRunnerUser) {
|
||||
const user = userInfo().username;
|
||||
if (user) {
|
||||
extraConf += `trusted-users = root ${user}`;
|
||||
@@ -452,16 +494,16 @@ class NixInstallerAction {
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf;
|
||||
|
||||
if (process.env["ACT"] && !process.env["NOT_ACT"]) {
|
||||
this.idslib.addFact(FACT_IN_GITHUB_ACTIONS, true);
|
||||
if (this.isRunningInAct) {
|
||||
this.addFact(FACT_IN_ACT, true);
|
||||
actionsCore.info(
|
||||
"Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`",
|
||||
);
|
||||
executionEnv.NIX_INSTALLER_INIT = "none";
|
||||
}
|
||||
|
||||
if (process.env["NSC_VM_ID"] && !process.env["NOT_NAMESPACE"]) {
|
||||
this.idslib.addFact(FACT_IN_NAMESPACE_SO, true);
|
||||
if (this.isRunningInNamespaceRunner) {
|
||||
this.addFact(FACT_IN_NAMESPACE_SO, true);
|
||||
actionsCore.info(
|
||||
"Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace",
|
||||
);
|
||||
@@ -479,11 +521,11 @@ class NixInstallerAction {
|
||||
|
||||
const args = ["install"];
|
||||
if (this.planner) {
|
||||
this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
|
||||
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
|
||||
args.push(this.planner);
|
||||
} else {
|
||||
this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner());
|
||||
args.push(getDefaultPlanner());
|
||||
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.defaultPlanner);
|
||||
args.push(this.defaultPlanner);
|
||||
}
|
||||
|
||||
if (this.extraArgs) {
|
||||
@@ -491,7 +533,7 @@ class NixInstallerAction {
|
||||
args.concat(extraArgs);
|
||||
}
|
||||
|
||||
this.idslib.recordEvent(EVENT_INSTALL_NIX_START);
|
||||
this.recordEvent(EVENT_INSTALL_NIX_START);
|
||||
const exitCode = await actionsExec.exec(binaryPath, args, {
|
||||
env: {
|
||||
...executionEnv,
|
||||
@@ -500,13 +542,13 @@ class NixInstallerAction {
|
||||
});
|
||||
|
||||
if (exitCode !== 0) {
|
||||
this.idslib.recordEvent(EVENT_INSTALL_NIX_FAILURE, {
|
||||
this.recordEvent(EVENT_INSTALL_NIX_FAILURE, {
|
||||
exitCode,
|
||||
});
|
||||
throw new Error(`Non-zero exit code of \`${exitCode}\` detected`);
|
||||
}
|
||||
|
||||
this.idslib.recordEvent(EVENT_INSTALL_NIX_SUCCESS);
|
||||
this.recordEvent(EVENT_INSTALL_NIX_SUCCESS);
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
@@ -606,7 +648,7 @@ class NixInstallerAction {
|
||||
|
||||
{
|
||||
actionsCore.debug("Starting the Nix daemon through Docker...");
|
||||
this.idslib.recordEvent(EVENT_START_DOCKER_SHIM);
|
||||
this.recordEvent(EVENT_START_DOCKER_SHIM);
|
||||
const exitCode = await actionsExec.exec(
|
||||
"docker",
|
||||
[
|
||||
@@ -633,7 +675,7 @@ class NixInstallerAction {
|
||||
"always",
|
||||
"--init",
|
||||
"--name",
|
||||
`determinate-nix-shim-${this.idslib.getUniqueId()}-${randomUUID()}`,
|
||||
`determinate-nix-shim-${this.getUniqueId()}-${randomUUID()}`,
|
||||
"determinate-nix-shim:latest",
|
||||
],
|
||||
{
|
||||
@@ -696,7 +738,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
if (cleaned) {
|
||||
this.idslib.recordEvent(EVENT_CLEAN_UP_DOCKER_SHIM);
|
||||
this.recordEvent(EVENT_CLEAN_UP_DOCKER_SHIM);
|
||||
} else {
|
||||
actionsCore.warning(
|
||||
"Giving up on cleaning up the nix daemon container",
|
||||
@@ -725,7 +767,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
async flakehubLogin(): Promise<string> {
|
||||
this.idslib.recordEvent(EVENT_LOGIN_TO_FLAKEHUB);
|
||||
this.recordEvent(EVENT_LOGIN_TO_FLAKEHUB);
|
||||
const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`;
|
||||
|
||||
const jwt = await actionsCore.getIDToken("api.flakehub.com");
|
||||
@@ -752,7 +794,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
async executeUninstall(): Promise<number> {
|
||||
this.idslib.recordEvent(EVENT_UNINSTALL_NIX);
|
||||
this.recordEvent(EVENT_UNINSTALL_NIX);
|
||||
const exitCode = await actionsExec.exec(
|
||||
`/nix/nix-installer`,
|
||||
["uninstall"],
|
||||
@@ -784,7 +826,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
private async setupKvm(): Promise<boolean> {
|
||||
this.idslib.recordEvent(EVENT_SETUP_KVM);
|
||||
this.recordEvent(EVENT_SETUP_KVM);
|
||||
const currentUser = userInfo();
|
||||
const isRoot = currentUser.uid === 0;
|
||||
const maybeSudo = isRoot ? "" : "sudo";
|
||||
@@ -880,7 +922,7 @@ class NixInstallerAction {
|
||||
|
||||
private async fetchBinary(): Promise<string> {
|
||||
if (!this.localRoot) {
|
||||
return await this.idslib.fetchExecutable();
|
||||
return await this.fetchExecutable();
|
||||
} else {
|
||||
const localPath = join(this.localRoot, `nix-installer-${this.platform}`);
|
||||
actionsCore.info(`Using binary ${localPath}`);
|
||||
@@ -890,7 +932,7 @@ class NixInstallerAction {
|
||||
|
||||
async reportOverall(): Promise<void> {
|
||||
try {
|
||||
this.idslib.recordEvent(EVENT_CONCLUDE_WORKFLOW, {
|
||||
this.recordEvent(EVENT_CONCLUDE_WORKFLOW, {
|
||||
conclusion: await this.getWorkflowConclusion(),
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -899,7 +941,7 @@ class NixInstallerAction {
|
||||
}
|
||||
|
||||
private async getWorkflowConclusion(): Promise<
|
||||
undefined | "success" | "failure" | "cancelled" | "unavailable" | "no-jobs"
|
||||
undefined | WorkflowConclusion
|
||||
> {
|
||||
if (this.githubToken == null) {
|
||||
return undefined;
|
||||
@@ -946,6 +988,18 @@ class NixInstallerAction {
|
||||
return "unavailable";
|
||||
}
|
||||
}
|
||||
|
||||
private get defaultPlanner(): string {
|
||||
if (this.isMacOS) {
|
||||
return "macos";
|
||||
} else if (this.isLinux) {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new Error(
|
||||
`Unsupported \`RUNNER_OS\` (currently \`${this.runnerOs}\`)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ExecuteEnvironment = {
|
||||
@@ -974,32 +1028,8 @@ type ExecuteEnvironment = {
|
||||
NIX_INSTALLER_LOGGER?: string;
|
||||
};
|
||||
|
||||
function getDefaultPlanner(): string {
|
||||
const envOs = process.env["RUNNER_OS"];
|
||||
|
||||
if (envOs === "macOS") {
|
||||
return "macos";
|
||||
} else if (envOs === "Linux") {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${envOs}\`)`);
|
||||
}
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
const installer = new NixInstallerAction();
|
||||
|
||||
installer.idslib.onMain(async () => {
|
||||
await installer.detectAndForceDockerShim();
|
||||
await installer.install();
|
||||
});
|
||||
|
||||
installer.idslib.onPost(async () => {
|
||||
await installer.cleanupDockerShim();
|
||||
await installer.reportOverall();
|
||||
});
|
||||
|
||||
installer.idslib.execute();
|
||||
new NixInstallerAction().execute();
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user