Compare commits

...

59 Commits

Author SHA1 Message Date
Luc Perkins 7993355175 Merge pull request #98 from DeterminateSystems/update-detsys-ts-status-page
Update detsys-ts (status page changes)
2024-06-03 09:18:33 -07:00
Luc Perkins db2c9be88c Update detsys-ts (status page changes) 2024-06-03 09:11:14 -07:00
Graham Christensen a2473ab552 Srv update (#97)
* Update to srv

* Hi, footgun

* Make sure we don't toString promises, update deps

* Update

* Pass - as the default diagnostic endpoint

* Specify the diagnostic suffix

* Update deps

* SRV update
2024-05-31 12:30:37 -04:00
Cole Helbling f51ebf9a6f Merge pull request #96 from DeterminateSystems/fixup-required-tests
tests: make megajob block on failure
2024-05-30 05:53:28 -07:00
Cole Helbling 676d200580 tests: make megajob block on failure
GitHub Actions considers a "skipped" job successful for the purposes
of required jobs for branch protections. We take advantage of this
by failing if any dependent actions failed, or "skip" if they all
succeeded.
2024-05-29 12:39:53 -07:00
Luc Perkins c6857b9a9d Merge pull request #93 from DeterminateSystems/update-detsys-ts
Update detsys-ts
2024-05-29 16:32:28 -03:00
Luc Perkins e5b417b85f Move comment to better location 2024-05-29 16:26:46 -03:00
Luc Perkins 8ef3f8c93e Fix direction of Boolean check 2024-05-29 16:07:07 -03:00
Luc Perkins ad8814ae5d Fix check for ACT environment 2024-05-29 15:59:19 -03:00
Luc Perkins 9c4e8b237e Provide better if statement 2024-05-29 15:51:33 -03:00
Luc Perkins 23e5c435a9 Update detsys-ts 2024-05-29 15:16:45 -03:00
Luc Perkins c3983e7949 Make strict mode input not required 2024-05-23 12:14:07 -03:00
Luc Perkins 3c042d09d2 Add source-binary to action.yml 2024-05-22 18:35:27 -03:00
Luc Perkins 7b0893fcd8 Regenerate dist 2024-05-22 18:29:40 -03:00
Luc Perkins e4f741cb67 Apply internal strict mode to CI runs 2024-05-22 15:41:57 -03:00
Luc Perkins a56dda90ad Update detsys-ts again 2024-05-22 13:47:58 -03:00
Luc Perkins cd7602a5a8 Add workflow conclusion enum 2024-05-22 13:43:59 -03:00
Luc Perkins f6047128c4 Streamline runner OS logic 2024-05-22 13:40:01 -03:00
Luc Perkins 61795779f3 Add ci-mode to action.yml 2024-05-22 13:24:59 -03:00
Luc Perkins 0b690dedac Update detsys-ts 2024-05-22 13:19:09 -03:00
Graham Christensen 75ffa7fc74 Disable docker under act (#90)
* Rename IN_GITHUB_ACTIONS to IN_ACT

* If the trusted runner user is truthy, setup the runner as a trusted user.

The boolean option is always set.

* Set HAS_SYSTEMD in more cases

* Unquote trust-runner-user in the action.yml

* Don't bother with the docker shim under act

* fmt

* Regenerate

* fixup
2024-05-18 18:46:09 -04:00
Luc Perkins 5c2710f363 Merge pull request #91 from DeterminateSystems/fix-source-uri-description
Provide new test matrix for source-* inputs
2024-05-17 11:21:44 -04:00
Luc Perkins 8cc782962a Add to tests 2024-05-17 11:41:26 -03:00
Luc Perkins c1489fff7b Remove more tests 2024-05-17 11:37:53 -03:00
Luc Perkins 4ed4c86fdc Remove branch test 2024-05-17 11:35:28 -03:00
Luc Perkins ccf4610648 Fix branch version 2024-05-17 11:33:26 -03:00
Luc Perkins f97a8a062c Fix PR version 2024-05-17 11:32:15 -03:00
Luc Perkins 766b8830f1 Provide new test matrix for source-* inputs 2024-05-17 11:28:50 -03:00
Luc Perkins fd6c226bf9 Merge pull request #89 from DeterminateSystems/fix-source-uri-description
Update action.yml description for source-url
2024-05-17 10:22:17 -04:00
Luc Perkins 350241e13f Fix expected version 2024-05-17 11:12:58 -03:00
Luc Perkins 481524661c Fix comparison script 2024-05-17 11:10:24 -03:00
Luc Perkins 164c9d00dc Check expected Nix versions using script 2024-05-17 11:04:45 -03:00
Luc Perkins 74f4d10531 Fix name of workflow 2024-05-16 21:07:06 -03:00
Luc Perkins 86a97d5eb6 Add missing checkout action 2024-05-16 21:05:48 -03:00
Luc Perkins 86e8caa071 Fix path in uses declarations 2024-05-16 21:04:04 -03:00
Luc Perkins 151fdae2fc Add more test cases 2024-05-16 21:02:46 -03:00
Luc Perkins 7fcb842097 Undo matrix logic 2024-05-16 20:53:46 -03:00
Luc Perkins 8d9c69de11 Update expected versions 2024-05-16 20:52:41 -03:00
Luc Perkins 6b0b02c6a2 Fix string interpolation (again) 2024-05-16 20:51:04 -03:00
Luc Perkins 6265732741 Fix string interpolation 2024-05-16 20:50:21 -03:00
Luc Perkins 0e85ec287f Add expected Nix versions 2024-05-16 20:49:32 -03:00
Luc Perkins 5385bea1cb Try with somewhat older versions 2024-05-16 20:42:24 -03:00
Luc Perkins d49867b627 Apply matrix strategy 2024-05-16 20:41:04 -03:00
Luc Perkins e8f36a90cd Fix URL for executable 2024-05-16 20:38:07 -03:00
Luc Perkins 397a5c26a7 Update input description and add test workflow 2024-05-16 20:37:01 -03:00
Luc Perkins 8d4286b90e Merge pull request #87 from DeterminateSystems/fix-docker-invocation
Add CI run for aarch64-darwin
2024-05-15 17:25:33 -04:00
Luc Perkins ca7cf68c63 Add megajob called tests 2024-05-15 18:16:09 -03:00
Luc Perkins 94a9e4375c Rename jobs 2024-05-15 17:56:08 -03:00
Luc Perkins da29cfd994 Merge remote-tracking branch 'origin/main' into fix-docker-invocation 2024-05-15 17:51:53 -03:00
Graham Christensen 1e58ce3980 Revert "Fix ESM build" (#86) 2024-05-15 20:45:00 +00:00
Luc Perkins 83c8f7dfdd Fix formatting 2024-05-15 17:44:11 -03:00
Luc Perkins 37d6eb5161 Add CI run for aarch64-darwin 2024-05-15 17:39:35 -03:00
Luc Perkins 813cf108af Merge pull request #83 from DeterminateSystems/fix-esm-build
Fix ESM build
2024-05-15 16:24:28 -04:00
Luc Perkins 4a8c7256d3 Don't clean dist using tsup 2024-05-15 17:18:32 -03:00
Luc Perkins e4a38c246a Regenerate dist 2024-05-15 17:17:12 -03:00
Luc Perkins 9243e9b760 Fix merge conflicts with main 2024-05-15 17:16:08 -03:00
Luc Perkins 74b8a1f4e8 Update dependencies 2024-05-03 11:05:02 -03:00
Luc Perkins 51bc05e2ea Fix method of finding docker shims 2024-05-02 17:19:07 -03:00
Luc Perkins 9ffa76fa74 Fix ESM build 2024-05-02 17:07:51 -03:00
9 changed files with 1760 additions and 884 deletions
+10
View File
@@ -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
+1
View File
@@ -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",
+18
View File
@@ -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
+59 -5
View File
@@ -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
View File
@@ -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"
Generated Vendored
+1298 -555
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -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",
+260 -249
View File
File diff suppressed because it is too large Load Diff
+100 -70
View File
@@ -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();