Use less esoteric formatting settings

This commit is contained in:
Ana Hobden 2023-07-13 10:11:00 -07:00
parent 195f007ef0
commit 5eda0a4d27
5 changed files with 349 additions and 359 deletions

View file

@ -64,11 +64,6 @@
"@typescript-eslint/promise-function-async": "error", "@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error", "@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error", "@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": [
"error",
"never"
],
"@typescript-eslint/type-annotation-spacing": "error", "@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error" "@typescript-eslint/unbound-method": "error"
}, },

View file

@ -1,10 +1 @@
{ {}
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}

158
dist/index.js vendored
View file

@ -55,46 +55,46 @@ const string_argv_1 = __importDefault(__nccwpck_require__(9663));
class NixInstallerAction { class NixInstallerAction {
constructor() { constructor() {
this.platform = get_nix_platform(); this.platform = get_nix_platform();
this.nix_package_url = action_input_string_or_null('nix-package-url'); this.nix_package_url = action_input_string_or_null("nix-package-url");
this.backtrace = action_input_string_or_null('backtrace'); this.backtrace = action_input_string_or_null("backtrace");
this.extra_args = action_input_string_or_null('extra-args'); this.extra_args = action_input_string_or_null("extra-args");
this.extra_conf = action_input_multiline_string_or_null('extra-conf'); this.extra_conf = action_input_multiline_string_or_null("extra-conf");
this.github_token = action_input_string_or_null('github-token'); this.github_token = action_input_string_or_null("github-token");
this.init = action_input_string_or_null('init'); this.init = action_input_string_or_null("init");
this.local_root = action_input_string_or_null('local-root'); this.local_root = action_input_string_or_null("local-root");
this.log_directives = action_input_string_or_null('log-directives'); this.log_directives = action_input_string_or_null("log-directives");
this.logger = action_input_string_or_null('logger'); this.logger = action_input_string_or_null("logger");
this.ssl_cert_file = action_input_string_or_null('ssl-cert-file'); this.ssl_cert_file = action_input_string_or_null("ssl-cert-file");
this.proxy = action_input_string_or_null('proxy'); this.proxy = action_input_string_or_null("proxy");
this.mac_case_sensitive = action_input_string_or_null('mac-case-sensitive'); this.mac_case_sensitive = action_input_string_or_null("mac-case-sensitive");
this.mac_encrypt = action_input_string_or_null('mac-encrypt'); this.mac_encrypt = action_input_string_or_null("mac-encrypt");
this.mac_root_disk = action_input_string_or_null('mac-root-disk'); this.mac_root_disk = action_input_string_or_null("mac-root-disk");
this.mac_volume_label = action_input_string_or_null('mac-volume-label'); this.mac_volume_label = action_input_string_or_null("mac-volume-label");
this.modify_profile = action_input_bool('modify-profile'); this.modify_profile = action_input_bool("modify-profile");
this.nix_build_group_id = action_input_number_or_null('nix-build-group-id'); this.nix_build_group_id = action_input_number_or_null("nix-build-group-id");
this.nix_build_group_name = action_input_string_or_null('nix-build-group-name'); this.nix_build_group_name = action_input_string_or_null("nix-build-group-name");
this.nix_build_user_base = action_input_number_or_null('nix_build-user-base'); this.nix_build_user_base = action_input_number_or_null("nix_build-user-base");
this.nix_build_user_count = action_input_number_or_null('nix-build-user-count'); this.nix_build_user_count = action_input_number_or_null("nix-build-user-count");
this.nix_build_user_prefix = action_input_string_or_null('nix-build-user-prefix'); this.nix_build_user_prefix = action_input_string_or_null("nix-build-user-prefix");
this.planner = action_input_string_or_null('planner'); this.planner = action_input_string_or_null("planner");
this.reinstall = action_input_bool('reinstall'); this.reinstall = action_input_bool("reinstall");
this.start_daemon = action_input_bool('start-daemon'); this.start_daemon = action_input_bool("start-daemon");
this.diagnostic_endpoint = action_input_string_or_null('diagnostic-endpoint'); this.diagnostic_endpoint = action_input_string_or_null("diagnostic-endpoint");
this.trust_runner_user = action_input_bool('trust-runner-user'); this.trust_runner_user = action_input_bool("trust-runner-user");
this.nix_installer_url = resolve_nix_installer_url(this.platform); this.nix_installer_url = resolve_nix_installer_url(this.platform);
} }
executionEnvironment() { executionEnvironment() {
const execution_env = {}; const execution_env = {};
execution_env.NIX_INSTALLER_NO_CONFIRM = 'true'; execution_env.NIX_INSTALLER_NO_CONFIRM = "true";
if (this.backtrace !== null) { if (this.backtrace !== null) {
execution_env.RUST_BACKTRACE = this.backtrace; execution_env.RUST_BACKTRACE = this.backtrace;
} }
if (this.modify_profile !== null) { if (this.modify_profile !== null) {
if (this.modify_profile) { if (this.modify_profile) {
execution_env.NIX_INSTALLER_MODIFY_PROFILE = 'true'; execution_env.NIX_INSTALLER_MODIFY_PROFILE = "true";
} }
else { else {
execution_env.NIX_INSTALLER_MODIFY_PROFILE = 'false'; execution_env.NIX_INSTALLER_MODIFY_PROFILE = "false";
} }
} }
if (this.nix_build_group_id !== null) { if (this.nix_build_group_id !== null) {
@ -124,7 +124,8 @@ class NixInstallerAction {
execution_env.NIX_INSTALLER_SSL_CERT_FILE = this.ssl_cert_file; execution_env.NIX_INSTALLER_SSL_CERT_FILE = this.ssl_cert_file;
} }
if (this.diagnostic_endpoint !== null) { if (this.diagnostic_endpoint !== null) {
execution_env.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT = this.diagnostic_endpoint; execution_env.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT =
this.diagnostic_endpoint;
} }
// TODO: Error if the user uses these on not-MacOS // TODO: Error if the user uses these on not-MacOS
if (this.mac_encrypt !== null) { if (this.mac_encrypt !== null) {
@ -151,30 +152,30 @@ class NixInstallerAction {
} }
if (this.start_daemon !== null) { if (this.start_daemon !== null) {
if (this.start_daemon) { if (this.start_daemon) {
execution_env.NIX_INSTALLER_START_DAEMON = 'true'; execution_env.NIX_INSTALLER_START_DAEMON = "true";
} }
else { else {
execution_env.NIX_INSTALLER_START_DAEMON = 'false'; execution_env.NIX_INSTALLER_START_DAEMON = "false";
} }
} }
let extra_conf = ''; let extra_conf = "";
if (this.github_token !== null) { if (this.github_token !== null) {
extra_conf += `access-tokens = github.com=${this.github_token}`; extra_conf += `access-tokens = github.com=${this.github_token}`;
extra_conf += '\n'; extra_conf += "\n";
} }
if (this.trust_runner_user !== null) { if (this.trust_runner_user !== null) {
// TODO: Consider how to improve this // TODO: Consider how to improve this
extra_conf += `trusted-users = root ${process.env.USER}`; extra_conf += `trusted-users = root ${process.env.USER}`;
extra_conf += '\n'; extra_conf += "\n";
} }
if (this.extra_conf !== null && this.extra_conf.length !== 0) { if (this.extra_conf !== null && this.extra_conf.length !== 0) {
extra_conf += this.extra_conf.join('\n'); extra_conf += this.extra_conf.join("\n");
extra_conf += '\n'; extra_conf += "\n";
} }
execution_env.NIX_INSTALLER_EXTRA_CONF = extra_conf; execution_env.NIX_INSTALLER_EXTRA_CONF = extra_conf;
if (process.env.ACT && !process.env.NOT_ACT) { if (process.env.ACT && !process.env.NOT_ACT) {
actions_core.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 settings of the `init` as well as `extra-conf` to be compatible with `act`'); actions_core.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 settings of the `init` as well as `extra-conf` to be compatible with `act`");
execution_env.NIX_INSTALLER_INIT = 'none'; execution_env.NIX_INSTALLER_INIT = "none";
} }
return execution_env; return execution_env;
} }
@ -182,7 +183,7 @@ class NixInstallerAction {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const execution_env = this.executionEnvironment(); const execution_env = this.executionEnvironment();
actions_core.info(`Execution environment: ${JSON.stringify(execution_env, null, 4)}`); actions_core.info(`Execution environment: ${JSON.stringify(execution_env, null, 4)}`);
const args = ['install']; const args = ["install"];
if (this.planner) { if (this.planner) {
args.push(this.planner); args.push(this.planner);
} }
@ -195,24 +196,24 @@ class NixInstallerAction {
} }
const merged_env = Object.assign(Object.assign({}, process.env), execution_env); const merged_env = Object.assign(Object.assign({}, process.env), execution_env);
const spawned = (0, node_child_process_1.spawn)(`${binary_path}`, args, { const spawned = (0, node_child_process_1.spawn)(`${binary_path}`, args, {
env: merged_env env: merged_env,
}); });
spawned.stdout.setEncoding('utf-8'); spawned.stdout.setEncoding("utf-8");
spawned.stdout.on('data', data => { spawned.stdout.on("data", (data) => {
const trimmed = data.trimEnd(); const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed); actions_core.info(trimmed);
} }
}); });
spawned.stderr.setEncoding('utf-8'); spawned.stderr.setEncoding("utf-8");
spawned.stderr.on('data', data => { spawned.stderr.on("data", (data) => {
const trimmed = data.trimEnd(); const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed); actions_core.info(trimmed);
} }
}); });
const exit_code = yield new Promise((resolve, _reject) => { const exit_code = yield new Promise((resolve, _reject) => {
spawned.on('close', resolve); spawned.on("close", resolve);
}); });
if (exit_code !== 0) { if (exit_code !== 0) {
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`); throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
@ -226,13 +227,13 @@ class NixInstallerAction {
if (existing_install) { if (existing_install) {
if (this.reinstall) { if (this.reinstall) {
// We need to uninstall, then reinstall // We need to uninstall, then reinstall
actions_core.info('Nix was already installed, `reinstall` is set, uninstalling for a reinstall'); actions_core.info("Nix was already installed, `reinstall` is set, uninstalling for a reinstall");
yield this.execute_uninstall(); yield this.execute_uninstall();
} }
else { else {
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early // We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
this.set_github_path(); this.set_github_path();
actions_core.info('Nix was already installed, using existing install'); actions_core.info("Nix was already installed, using existing install");
return; return;
} }
} }
@ -243,31 +244,30 @@ class NixInstallerAction {
}); });
} }
set_github_path() { set_github_path() {
actions_core.addPath('/nix/var/nix/profiles/default/bin'); actions_core.addPath("/nix/var/nix/profiles/default/bin");
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`); actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`);
} }
execute_uninstall() { execute_uninstall() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const spawned = (0, node_child_process_1.spawn)(`/nix/nix-installer`, ['uninstall'], { const spawned = (0, node_child_process_1.spawn)(`/nix/nix-installer`, ["uninstall"], {
env: Object.assign({ NIX_INSTALLER_NO_CONFIRM: 'true' }, process.env // To get $PATH, etc env: Object.assign({ NIX_INSTALLER_NO_CONFIRM: "true" }, process.env),
)
}); });
spawned.stdout.setEncoding('utf-8'); spawned.stdout.setEncoding("utf-8");
spawned.stdout.on('data', data => { spawned.stdout.on("data", (data) => {
const trimmed = data.trimEnd(); const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed); actions_core.info(trimmed);
} }
}); });
spawned.stderr.setEncoding('utf-8'); spawned.stderr.setEncoding("utf-8");
spawned.stderr.on('data', data => { spawned.stderr.on("data", (data) => {
const trimmed = data.trimEnd(); const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed); actions_core.info(trimmed);
} }
}); });
const exit_code = yield new Promise((resolve, _reject) => { const exit_code = yield new Promise((resolve, _reject) => {
spawned.on('close', resolve); spawned.on("close", resolve);
}); });
if (exit_code !== 0) { if (exit_code !== 0) {
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`); throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
@ -277,7 +277,7 @@ class NixInstallerAction {
} }
detect_existing() { detect_existing() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const receipt_path = '/nix/receipt.json'; const receipt_path = "/nix/receipt.json";
// TODO: Maybe this should be a bit smarter? // TODO: Maybe this should be a bit smarter?
try { try {
yield (0, promises_1.access)(receipt_path); yield (0, promises_1.access)(receipt_path);
@ -298,7 +298,7 @@ class NixInstallerAction {
if (!response.ok) { if (!response.ok) {
throw new Error(`Got a status of ${response.status} from \`${this.nix_installer_url}\`, expected a 200`); throw new Error(`Got a status of ${response.status} from \`${this.nix_installer_url}\`, expected a 200`);
} }
const tempdir = yield (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'nix-installer-')); const tempdir = yield (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "nix-installer-"));
const tempfile = (0, node_path_1.join)(tempdir, `nix-installer-${this.platform}`); const tempfile = (0, node_path_1.join)(tempdir, `nix-installer-${this.platform}`);
if (!response.ok) { if (!response.ok) {
throw new Error(`unexpected response ${response.statusText}`); throw new Error(`unexpected response ${response.statusText}`);
@ -309,7 +309,7 @@ class NixInstallerAction {
actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``); actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
} }
else { else {
throw new Error('No response body recieved'); throw new Error("No response body recieved");
} }
// Make executable // Make executable
yield (0, promises_1.chmod)(tempfile, node_fs_1.default.constants.S_IXUSR | node_fs_1.default.constants.S_IXGRP); yield (0, promises_1.chmod)(tempfile, node_fs_1.default.constants.S_IXUSR | node_fs_1.default.constants.S_IXGRP);
@ -326,17 +326,17 @@ class NixInstallerAction {
function get_nix_platform() { function get_nix_platform() {
const env_os = process.env.RUNNER_OS; const env_os = process.env.RUNNER_OS;
const env_arch = process.env.RUNNER_ARCH; const env_arch = process.env.RUNNER_ARCH;
if (env_os === 'macOS' && env_arch === 'X64') { if (env_os === "macOS" && env_arch === "X64") {
return 'x86_64-darwin'; return "x86_64-darwin";
} }
else if (env_os === 'macOS' && env_arch === 'ARM64') { else if (env_os === "macOS" && env_arch === "ARM64") {
return 'aarch64-darwin'; return "aarch64-darwin";
} }
else if (env_os === 'Linux' && env_arch === 'X64') { else if (env_os === "Linux" && env_arch === "X64") {
return 'x86_64-linux'; return "x86_64-linux";
} }
else if (env_os === 'Linux' && env_arch === 'ARM64') { else if (env_os === "Linux" && env_arch === "ARM64") {
return 'aarch64-linux'; return "aarch64-linux";
} }
else { else {
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`) and \`RUNNER_ARCH\` (currently \`${env_arch}\`) combination`); throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`) and \`RUNNER_ARCH\` (currently \`${env_arch}\`) combination`);
@ -344,11 +344,11 @@ function get_nix_platform() {
} }
function get_default_planner() { function get_default_planner() {
const env_os = process.env.RUNNER_OS; const env_os = process.env.RUNNER_OS;
if (env_os === 'macOS') { if (env_os === "macOS") {
return 'macos'; return "macos";
} }
else if (env_os === 'Linux') { else if (env_os === "Linux") {
return 'linux'; return "linux";
} }
else { else {
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`)`); throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`)`);
@ -356,11 +356,11 @@ function get_default_planner() {
} }
function resolve_nix_installer_url(platform) { function resolve_nix_installer_url(platform) {
// Only one of these are allowed. // Only one of these are allowed.
const nix_installer_branch = action_input_string_or_null('nix-installer-branch'); const nix_installer_branch = action_input_string_or_null("nix-installer-branch");
const nix_installer_pr = action_input_number_or_null('nix-installer-pr'); const nix_installer_pr = action_input_number_or_null("nix-installer-pr");
const nix_installer_revision = action_input_string_or_null('nix-installer-revision'); const nix_installer_revision = action_input_string_or_null("nix-installer-revision");
const nix_installer_tag = action_input_string_or_null('nix-installer-tag'); const nix_installer_tag = action_input_string_or_null("nix-installer-tag");
const nix_installer_url = action_input_string_or_null('nix-installer-url'); const nix_installer_url = action_input_string_or_null("nix-installer-url");
let num_set = 0; let num_set = 0;
if (nix_installer_branch !== null) { if (nix_installer_branch !== null) {
num_set += 1; num_set += 1;
@ -401,7 +401,7 @@ function resolve_nix_installer_url(platform) {
} }
function action_input_string_or_null(name) { function action_input_string_or_null(name) {
const value = actions_core.getInput(name); const value = actions_core.getInput(name);
if (value === '') { if (value === "") {
return null; return null;
} }
else { else {
@ -419,7 +419,7 @@ function action_input_multiline_string_or_null(name) {
} }
function action_input_number_or_null(name) { function action_input_number_or_null(name) {
const value = actions_core.getInput(name); const value = actions_core.getInput(name);
if (value === '') { if (value === "") {
return null; return null;
} }
else { else {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -1,524 +1,528 @@
import * as actions_core from '@actions/core' import * as actions_core from "@actions/core";
import {mkdtemp, chmod, access} from 'node:fs/promises' import { mkdtemp, chmod, access } from "node:fs/promises";
import {spawn} from 'node:child_process' import { spawn } from "node:child_process";
import {join} from 'node:path' import { join } from "node:path";
import {tmpdir} from 'node:os' import { tmpdir } from "node:os";
import {pipeline} from 'node:stream' import { pipeline } from "node:stream";
import fetch from 'node-fetch' import fetch from "node-fetch";
import {promisify} from 'node:util' import { promisify } from "node:util";
import fs from 'node:fs' import fs from "node:fs";
import stringArgv from 'string-argv' import stringArgv from "string-argv";
class NixInstallerAction { class NixInstallerAction {
platform: string platform: string;
nix_package_url: string | null nix_package_url: string | null;
backtrace: string | null backtrace: string | null;
extra_args: string | null extra_args: string | null;
extra_conf: string[] | null extra_conf: string[] | null;
github_token: string | null github_token: string | null;
// TODO: linux_init // TODO: linux_init
init: string | null init: string | null;
local_root: string | null local_root: string | null;
log_directives: string | null log_directives: string | null;
logger: string | null logger: string | null;
ssl_cert_file: string | null ssl_cert_file: string | null;
proxy: string | null proxy: string | null;
mac_case_sensitive: string | null mac_case_sensitive: string | null;
mac_encrypt: string | null mac_encrypt: string | null;
mac_root_disk: string | null mac_root_disk: string | null;
mac_volume_label: string | null mac_volume_label: string | null;
modify_profile: boolean modify_profile: boolean;
nix_build_group_id: number | null nix_build_group_id: number | null;
nix_build_group_name: string | null nix_build_group_name: string | null;
nix_build_user_base: number | null nix_build_user_base: number | null;
nix_build_user_count: number | null nix_build_user_count: number | null;
nix_build_user_prefix: string | null nix_build_user_prefix: string | null;
planner: string | null planner: string | null;
reinstall: boolean reinstall: boolean;
start_daemon: boolean start_daemon: boolean;
diagnostic_endpoint: string | null diagnostic_endpoint: string | null;
trust_runner_user: boolean | null trust_runner_user: boolean | null;
nix_installer_url: URL nix_installer_url: URL;
constructor() { constructor() {
this.platform = get_nix_platform() this.platform = get_nix_platform();
this.nix_package_url = action_input_string_or_null('nix-package-url') this.nix_package_url = action_input_string_or_null("nix-package-url");
this.backtrace = action_input_string_or_null('backtrace') this.backtrace = action_input_string_or_null("backtrace");
this.extra_args = action_input_string_or_null('extra-args') this.extra_args = action_input_string_or_null("extra-args");
this.extra_conf = action_input_multiline_string_or_null('extra-conf') this.extra_conf = action_input_multiline_string_or_null("extra-conf");
this.github_token = action_input_string_or_null('github-token') this.github_token = action_input_string_or_null("github-token");
this.init = action_input_string_or_null('init') this.init = action_input_string_or_null("init");
this.local_root = action_input_string_or_null('local-root') this.local_root = action_input_string_or_null("local-root");
this.log_directives = action_input_string_or_null('log-directives') this.log_directives = action_input_string_or_null("log-directives");
this.logger = action_input_string_or_null('logger') this.logger = action_input_string_or_null("logger");
this.ssl_cert_file = action_input_string_or_null('ssl-cert-file') this.ssl_cert_file = action_input_string_or_null("ssl-cert-file");
this.proxy = action_input_string_or_null('proxy') this.proxy = action_input_string_or_null("proxy");
this.mac_case_sensitive = action_input_string_or_null('mac-case-sensitive') this.mac_case_sensitive = action_input_string_or_null("mac-case-sensitive");
this.mac_encrypt = action_input_string_or_null('mac-encrypt') this.mac_encrypt = action_input_string_or_null("mac-encrypt");
this.mac_root_disk = action_input_string_or_null('mac-root-disk') this.mac_root_disk = action_input_string_or_null("mac-root-disk");
this.mac_volume_label = action_input_string_or_null('mac-volume-label') this.mac_volume_label = action_input_string_or_null("mac-volume-label");
this.modify_profile = action_input_bool('modify-profile') this.modify_profile = action_input_bool("modify-profile");
this.nix_build_group_id = action_input_number_or_null('nix-build-group-id') this.nix_build_group_id = action_input_number_or_null("nix-build-group-id");
this.nix_build_group_name = action_input_string_or_null( this.nix_build_group_name = action_input_string_or_null(
'nix-build-group-name' "nix-build-group-name",
) );
this.nix_build_user_base = action_input_number_or_null( this.nix_build_user_base = action_input_number_or_null(
'nix_build-user-base' "nix_build-user-base",
) );
this.nix_build_user_count = action_input_number_or_null( this.nix_build_user_count = action_input_number_or_null(
'nix-build-user-count' "nix-build-user-count",
) );
this.nix_build_user_prefix = action_input_string_or_null( this.nix_build_user_prefix = action_input_string_or_null(
'nix-build-user-prefix' "nix-build-user-prefix",
) );
this.planner = action_input_string_or_null('planner') this.planner = action_input_string_or_null("planner");
this.reinstall = action_input_bool('reinstall') this.reinstall = action_input_bool("reinstall");
this.start_daemon = action_input_bool('start-daemon') this.start_daemon = action_input_bool("start-daemon");
this.diagnostic_endpoint = action_input_string_or_null( this.diagnostic_endpoint = action_input_string_or_null(
'diagnostic-endpoint' "diagnostic-endpoint",
) );
this.trust_runner_user = action_input_bool('trust-runner-user') this.trust_runner_user = action_input_bool("trust-runner-user");
this.nix_installer_url = resolve_nix_installer_url(this.platform) this.nix_installer_url = resolve_nix_installer_url(this.platform);
} }
private executionEnvironment(): ExecuteEnvironment { private executionEnvironment(): ExecuteEnvironment {
const execution_env: ExecuteEnvironment = {} const execution_env: ExecuteEnvironment = {};
execution_env.NIX_INSTALLER_NO_CONFIRM = 'true' execution_env.NIX_INSTALLER_NO_CONFIRM = "true";
if (this.backtrace !== null) { if (this.backtrace !== null) {
execution_env.RUST_BACKTRACE = this.backtrace execution_env.RUST_BACKTRACE = this.backtrace;
} }
if (this.modify_profile !== null) { if (this.modify_profile !== null) {
if (this.modify_profile) { if (this.modify_profile) {
execution_env.NIX_INSTALLER_MODIFY_PROFILE = 'true' execution_env.NIX_INSTALLER_MODIFY_PROFILE = "true";
} else { } else {
execution_env.NIX_INSTALLER_MODIFY_PROFILE = 'false' execution_env.NIX_INSTALLER_MODIFY_PROFILE = "false";
} }
} }
if (this.nix_build_group_id !== null) { if (this.nix_build_group_id !== null) {
execution_env.NIX_INSTALLER_NIX_BUILD_GROUP_ID = `${this.nix_build_group_id}` execution_env.NIX_INSTALLER_NIX_BUILD_GROUP_ID = `${this.nix_build_group_id}`;
} }
if (this.nix_build_group_name !== null) { if (this.nix_build_group_name !== null) {
execution_env.NIX_INSTALLER_NIX_BUILD_GROUP_NAME = execution_env.NIX_INSTALLER_NIX_BUILD_GROUP_NAME =
this.nix_build_group_name this.nix_build_group_name;
} }
if (this.nix_build_user_prefix !== null) { if (this.nix_build_user_prefix !== null) {
execution_env.NIX_INSTALLER_NIX_BUILD_USER_PREFIX = execution_env.NIX_INSTALLER_NIX_BUILD_USER_PREFIX =
this.nix_build_user_prefix this.nix_build_user_prefix;
} }
if (this.nix_build_user_count !== null) { if (this.nix_build_user_count !== null) {
execution_env.NIX_INSTALLER_NIX_BUILD_USER_COUNT = `${this.nix_build_user_count}` execution_env.NIX_INSTALLER_NIX_BUILD_USER_COUNT = `${this.nix_build_user_count}`;
} }
if (this.nix_build_user_base !== null) { if (this.nix_build_user_base !== null) {
execution_env.NIX_INSTALLER_NIX_BUILD_USER_ID_BASE = `${this.nix_build_user_count}` execution_env.NIX_INSTALLER_NIX_BUILD_USER_ID_BASE = `${this.nix_build_user_count}`;
} }
if (this.nix_package_url !== null) { if (this.nix_package_url !== null) {
execution_env.NIX_INSTALLER_NIX_PACKAGE_URL = `${this.nix_package_url}` execution_env.NIX_INSTALLER_NIX_PACKAGE_URL = `${this.nix_package_url}`;
} }
if (this.proxy !== null) { if (this.proxy !== null) {
execution_env.NIX_INSTALLER_PROXY = this.proxy execution_env.NIX_INSTALLER_PROXY = this.proxy;
} }
if (this.ssl_cert_file !== null) { if (this.ssl_cert_file !== null) {
execution_env.NIX_INSTALLER_SSL_CERT_FILE = this.ssl_cert_file execution_env.NIX_INSTALLER_SSL_CERT_FILE = this.ssl_cert_file;
} }
if (this.diagnostic_endpoint !== null) { if (this.diagnostic_endpoint !== null) {
execution_env.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT = this.diagnostic_endpoint execution_env.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT =
this.diagnostic_endpoint;
} }
// TODO: Error if the user uses these on not-MacOS // TODO: Error if the user uses these on not-MacOS
if (this.mac_encrypt !== null) { if (this.mac_encrypt !== null) {
execution_env.NIX_INSTALLER_ENCRYPT = this.mac_encrypt execution_env.NIX_INSTALLER_ENCRYPT = this.mac_encrypt;
} }
if (this.mac_case_sensitive !== null) { if (this.mac_case_sensitive !== null) {
execution_env.NIX_INSTALLER_CASE_SENSITIVE = this.mac_case_sensitive execution_env.NIX_INSTALLER_CASE_SENSITIVE = this.mac_case_sensitive;
} }
if (this.mac_volume_label !== null) { if (this.mac_volume_label !== null) {
execution_env.NIX_INSTALLER_VOLUME_LABEL = this.mac_volume_label execution_env.NIX_INSTALLER_VOLUME_LABEL = this.mac_volume_label;
} }
if (this.mac_root_disk !== null) { if (this.mac_root_disk !== null) {
execution_env.NIX_INSTALLER_ROOT_DISK = this.mac_root_disk execution_env.NIX_INSTALLER_ROOT_DISK = this.mac_root_disk;
} }
if (this.logger !== null) { if (this.logger !== null) {
execution_env.NIX_INSTALLER_LOGGER = this.logger execution_env.NIX_INSTALLER_LOGGER = this.logger;
} }
if (this.log_directives !== null) { if (this.log_directives !== null) {
execution_env.NIX_INSTALLER_LOG_DIRECTIVES = this.log_directives execution_env.NIX_INSTALLER_LOG_DIRECTIVES = this.log_directives;
} }
// TODO: Error if the user uses these on MacOS // TODO: Error if the user uses these on MacOS
if (this.init !== null) { if (this.init !== null) {
execution_env.NIX_INSTALLER_INIT = this.init execution_env.NIX_INSTALLER_INIT = this.init;
} }
if (this.start_daemon !== null) { if (this.start_daemon !== null) {
if (this.start_daemon) { if (this.start_daemon) {
execution_env.NIX_INSTALLER_START_DAEMON = 'true' execution_env.NIX_INSTALLER_START_DAEMON = "true";
} else { } else {
execution_env.NIX_INSTALLER_START_DAEMON = 'false' execution_env.NIX_INSTALLER_START_DAEMON = "false";
} }
} }
let extra_conf = '' let extra_conf = "";
if (this.github_token !== null) { if (this.github_token !== null) {
extra_conf += `access-tokens = github.com=${this.github_token}` extra_conf += `access-tokens = github.com=${this.github_token}`;
extra_conf += '\n' extra_conf += "\n";
} }
if (this.trust_runner_user !== null) { if (this.trust_runner_user !== null) {
// TODO: Consider how to improve this // TODO: Consider how to improve this
extra_conf += `trusted-users = root ${process.env.USER}` extra_conf += `trusted-users = root ${process.env.USER}`;
extra_conf += '\n' extra_conf += "\n";
} }
if (this.extra_conf !== null && this.extra_conf.length !== 0) { if (this.extra_conf !== null && this.extra_conf.length !== 0) {
extra_conf += this.extra_conf.join('\n') extra_conf += this.extra_conf.join("\n");
extra_conf += '\n' extra_conf += "\n";
} }
execution_env.NIX_INSTALLER_EXTRA_CONF = extra_conf execution_env.NIX_INSTALLER_EXTRA_CONF = extra_conf;
if (process.env.ACT && !process.env.NOT_ACT) { if (process.env.ACT && !process.env.NOT_ACT) {
actions_core.info( actions_core.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 settings of the `init` as well as `extra-conf` to be compatible with `act`' "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 settings of the `init` as well as `extra-conf` to be compatible with `act`",
) );
execution_env.NIX_INSTALLER_INIT = 'none' execution_env.NIX_INSTALLER_INIT = "none";
} }
return execution_env return execution_env;
} }
private async execute_install(binary_path: string): Promise<number> { private async execute_install(binary_path: string): Promise<number> {
const execution_env = this.executionEnvironment() const execution_env = this.executionEnvironment();
actions_core.info( actions_core.info(
`Execution environment: ${JSON.stringify(execution_env, null, 4)}` `Execution environment: ${JSON.stringify(execution_env, null, 4)}`,
) );
const args = ['install'] const args = ["install"];
if (this.planner) { if (this.planner) {
args.push(this.planner) args.push(this.planner);
} else { } else {
args.push(get_default_planner()) args.push(get_default_planner());
} }
if (this.extra_args) { if (this.extra_args) {
const extra_args = stringArgv(this.extra_args) const extra_args = stringArgv(this.extra_args);
args.concat(extra_args) args.concat(extra_args);
} }
const merged_env = { const merged_env = {
...process.env, // To get $PATH, etc ...process.env, // To get $PATH, etc
...execution_env ...execution_env,
} };
const spawned = spawn(`${binary_path}`, args, { const spawned = spawn(`${binary_path}`, args, {
env: merged_env env: merged_env,
}) });
spawned.stdout.setEncoding('utf-8') spawned.stdout.setEncoding("utf-8");
spawned.stdout.on('data', data => { spawned.stdout.on("data", (data) => {
const trimmed = data.trimEnd() const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed) actions_core.info(trimmed);
} }
}) });
spawned.stderr.setEncoding('utf-8') spawned.stderr.setEncoding("utf-8");
spawned.stderr.on('data', data => { spawned.stderr.on("data", (data) => {
const trimmed = data.trimEnd() const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed) actions_core.info(trimmed);
} }
}) });
const exit_code: number = await new Promise((resolve, _reject) => { const exit_code: number = await new Promise((resolve, _reject) => {
spawned.on('close', resolve) spawned.on("close", resolve);
}) });
if (exit_code !== 0) { if (exit_code !== 0) {
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`) throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
} }
return exit_code return exit_code;
} }
async install(): Promise<void> { async install(): Promise<void> {
const existing_install = await this.detect_existing() const existing_install = await this.detect_existing();
if (existing_install) { if (existing_install) {
if (this.reinstall) { if (this.reinstall) {
// We need to uninstall, then reinstall // We need to uninstall, then reinstall
actions_core.info( actions_core.info(
'Nix was already installed, `reinstall` is set, uninstalling for a reinstall' "Nix was already installed, `reinstall` is set, uninstalling for a reinstall",
) );
await this.execute_uninstall() await this.execute_uninstall();
} else { } else {
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early // We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
this.set_github_path() this.set_github_path();
actions_core.info('Nix was already installed, using existing install') actions_core.info("Nix was already installed, using existing install");
return return;
} }
} }
// Normal just doing of the install // Normal just doing of the install
const binary_path = await this.fetch_binary() const binary_path = await this.fetch_binary();
await this.execute_install(binary_path) await this.execute_install(binary_path);
// TODO: Add `this.set_github_path()` and remove that from the installer crate // TODO: Add `this.set_github_path()` and remove that from the installer crate
} }
set_github_path(): void { set_github_path(): void {
actions_core.addPath('/nix/var/nix/profiles/default/bin') actions_core.addPath("/nix/var/nix/profiles/default/bin");
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`) actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`);
} }
async execute_uninstall(): Promise<number> { async execute_uninstall(): Promise<number> {
const spawned = spawn(`/nix/nix-installer`, ['uninstall'], { const spawned = spawn(`/nix/nix-installer`, ["uninstall"], {
env: { env: {
NIX_INSTALLER_NO_CONFIRM: 'true', NIX_INSTALLER_NO_CONFIRM: "true",
...process.env // To get $PATH, etc ...process.env, // To get $PATH, etc
} },
}) });
spawned.stdout.setEncoding('utf-8') spawned.stdout.setEncoding("utf-8");
spawned.stdout.on('data', data => { spawned.stdout.on("data", (data) => {
const trimmed = data.trimEnd() const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed) actions_core.info(trimmed);
} }
}) });
spawned.stderr.setEncoding('utf-8') spawned.stderr.setEncoding("utf-8");
spawned.stderr.on('data', data => { spawned.stderr.on("data", (data) => {
const trimmed = data.trimEnd() const trimmed = data.trimEnd();
if (trimmed.length >= 0) { if (trimmed.length >= 0) {
actions_core.info(trimmed) actions_core.info(trimmed);
} }
}) });
const exit_code: number = await new Promise((resolve, _reject) => { const exit_code: number = await new Promise((resolve, _reject) => {
spawned.on('close', resolve) spawned.on("close", resolve);
}) });
if (exit_code !== 0) { if (exit_code !== 0) {
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`) throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
} }
return exit_code return exit_code;
} }
async detect_existing(): Promise<boolean> { async detect_existing(): Promise<boolean> {
const receipt_path = '/nix/receipt.json' const receipt_path = "/nix/receipt.json";
// TODO: Maybe this should be a bit smarter? // TODO: Maybe this should be a bit smarter?
try { try {
await access(receipt_path) await access(receipt_path);
// There is a /nix/receipt.json // There is a /nix/receipt.json
return true return true;
} catch { } catch {
// No /nix/receipt.json // No /nix/receipt.json
return false return false;
} }
} }
private async fetch_binary(): Promise<string> { private async fetch_binary(): Promise<string> {
if (!this.local_root) { if (!this.local_root) {
actions_core.info(`Fetching binary from ${this.nix_installer_url}`) actions_core.info(`Fetching binary from ${this.nix_installer_url}`);
const response = await fetch(this.nix_installer_url) const response = await fetch(this.nix_installer_url);
if (!response.ok) { if (!response.ok) {
throw new Error( throw new Error(
`Got a status of ${response.status} from \`${this.nix_installer_url}\`, expected a 200` `Got a status of ${response.status} from \`${this.nix_installer_url}\`, expected a 200`,
) );
} }
const tempdir = await mkdtemp(join(tmpdir(), 'nix-installer-')) const tempdir = await mkdtemp(join(tmpdir(), "nix-installer-"));
const tempfile = join(tempdir, `nix-installer-${this.platform}`) const tempfile = join(tempdir, `nix-installer-${this.platform}`);
if (!response.ok) { if (!response.ok) {
throw new Error(`unexpected response ${response.statusText}`) throw new Error(`unexpected response ${response.statusText}`);
} }
if (response.body !== null) { if (response.body !== null) {
const streamPipeline = promisify(pipeline) const streamPipeline = promisify(pipeline);
await streamPipeline(response.body, fs.createWriteStream(tempfile)) await streamPipeline(response.body, fs.createWriteStream(tempfile));
actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``) actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
} else { } else {
throw new Error('No response body recieved') throw new Error("No response body recieved");
} }
// Make executable // Make executable
await chmod(tempfile, fs.constants.S_IXUSR | fs.constants.S_IXGRP) await chmod(tempfile, fs.constants.S_IXUSR | fs.constants.S_IXGRP);
return tempfile return tempfile;
} else { } else {
const local_path = join(this.local_root, `nix-installer-${this.platform}`) const local_path = join(
actions_core.info(`Using binary ${local_path}`) this.local_root,
return local_path `nix-installer-${this.platform}`,
);
actions_core.info(`Using binary ${local_path}`);
return local_path;
} }
} }
} }
type ExecuteEnvironment = { type ExecuteEnvironment = {
// All env vars are strings, no fanciness here. // All env vars are strings, no fanciness here.
RUST_BACKTRACE?: string RUST_BACKTRACE?: string;
NIX_INSTALLER_MODIFY_PROFILE?: string NIX_INSTALLER_MODIFY_PROFILE?: string;
NIX_INSTALLER_NIX_BUILD_GROUP_NAME?: string NIX_INSTALLER_NIX_BUILD_GROUP_NAME?: string;
NIX_INSTALLER_NIX_BUILD_GROUP_ID?: string NIX_INSTALLER_NIX_BUILD_GROUP_ID?: string;
NIX_INSTALLER_NIX_BUILD_USER_PREFIX?: string NIX_INSTALLER_NIX_BUILD_USER_PREFIX?: string;
NIX_INSTALLER_NIX_BUILD_USER_COUNT?: string NIX_INSTALLER_NIX_BUILD_USER_COUNT?: string;
NIX_INSTALLER_NIX_BUILD_USER_ID_BASE?: string NIX_INSTALLER_NIX_BUILD_USER_ID_BASE?: string;
NIX_INSTALLER_NIX_PACKAGE_URL?: string NIX_INSTALLER_NIX_PACKAGE_URL?: string;
NIX_INSTALLER_PROXY?: string NIX_INSTALLER_PROXY?: string;
NIX_INSTALLER_SSL_CERT_FILE?: string NIX_INSTALLER_SSL_CERT_FILE?: string;
NIX_INSTALLER_DIAGNOSTIC_ENDPOINT?: string NIX_INSTALLER_DIAGNOSTIC_ENDPOINT?: string;
NIX_INSTALLER_ENCRYPT?: string NIX_INSTALLER_ENCRYPT?: string;
NIX_INSTALLER_CASE_SENSITIVE?: string NIX_INSTALLER_CASE_SENSITIVE?: string;
NIX_INSTALLER_VOLUME_LABEL?: string NIX_INSTALLER_VOLUME_LABEL?: string;
NIX_INSTALLER_ROOT_DISK?: string NIX_INSTALLER_ROOT_DISK?: string;
NIX_INSTALLER_INIT?: string NIX_INSTALLER_INIT?: string;
NIX_INSTALLER_START_DAEMON?: string NIX_INSTALLER_START_DAEMON?: string;
NIX_INSTALLER_NO_CONFIRM?: string NIX_INSTALLER_NO_CONFIRM?: string;
NIX_INSTALLER_EXTRA_CONF?: string NIX_INSTALLER_EXTRA_CONF?: string;
NIX_INSTALLER_LOG_DIRECTIVES?: string NIX_INSTALLER_LOG_DIRECTIVES?: string;
NIX_INSTALLER_LOGGER?: string NIX_INSTALLER_LOGGER?: string;
} };
function get_nix_platform(): string { function get_nix_platform(): string {
const env_os = process.env.RUNNER_OS const env_os = process.env.RUNNER_OS;
const env_arch = process.env.RUNNER_ARCH const env_arch = process.env.RUNNER_ARCH;
if (env_os === 'macOS' && env_arch === 'X64') { if (env_os === "macOS" && env_arch === "X64") {
return 'x86_64-darwin' return "x86_64-darwin";
} else if (env_os === 'macOS' && env_arch === 'ARM64') { } else if (env_os === "macOS" && env_arch === "ARM64") {
return 'aarch64-darwin' return "aarch64-darwin";
} else if (env_os === 'Linux' && env_arch === 'X64') { } else if (env_os === "Linux" && env_arch === "X64") {
return 'x86_64-linux' return "x86_64-linux";
} else if (env_os === 'Linux' && env_arch === 'ARM64') { } else if (env_os === "Linux" && env_arch === "ARM64") {
return 'aarch64-linux' return "aarch64-linux";
} else { } else {
throw new Error( throw new Error(
`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`) and \`RUNNER_ARCH\` (currently \`${env_arch}\`) combination` `Unsupported \`RUNNER_OS\` (currently \`${env_os}\`) and \`RUNNER_ARCH\` (currently \`${env_arch}\`) combination`,
) );
} }
} }
function get_default_planner(): string { function get_default_planner(): string {
const env_os = process.env.RUNNER_OS const env_os = process.env.RUNNER_OS;
if (env_os === 'macOS') { if (env_os === "macOS") {
return 'macos' return "macos";
} else if (env_os === 'Linux') { } else if (env_os === "Linux") {
return 'linux' return "linux";
} else { } else {
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`)`) throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${env_os}\`)`);
} }
} }
function resolve_nix_installer_url(platform: string): URL { function resolve_nix_installer_url(platform: string): URL {
// Only one of these are allowed. // Only one of these are allowed.
const nix_installer_branch = action_input_string_or_null( const nix_installer_branch = action_input_string_or_null(
'nix-installer-branch' "nix-installer-branch",
) );
const nix_installer_pr = action_input_number_or_null('nix-installer-pr') const nix_installer_pr = action_input_number_or_null("nix-installer-pr");
const nix_installer_revision = action_input_string_or_null( const nix_installer_revision = action_input_string_or_null(
'nix-installer-revision' "nix-installer-revision",
) );
const nix_installer_tag = action_input_string_or_null('nix-installer-tag') const nix_installer_tag = action_input_string_or_null("nix-installer-tag");
const nix_installer_url = action_input_string_or_null('nix-installer-url') const nix_installer_url = action_input_string_or_null("nix-installer-url");
let num_set = 0 let num_set = 0;
if (nix_installer_branch !== null) { if (nix_installer_branch !== null) {
num_set += 1 num_set += 1;
} }
if (nix_installer_pr !== null) { if (nix_installer_pr !== null) {
num_set += 1 num_set += 1;
} }
if (nix_installer_revision !== null) { if (nix_installer_revision !== null) {
num_set += 1 num_set += 1;
} }
if (nix_installer_tag !== null) { if (nix_installer_tag !== null) {
num_set += 1 num_set += 1;
} }
if (nix_installer_url !== null) { if (nix_installer_url !== null) {
num_set += 1 num_set += 1;
} }
if (num_set > 1) { if (num_set > 1) {
throw new Error( throw new Error(
`The following options are mututally exclusive, but ${num_set} were set: \`nix_installer_branch\`, \`nix_installer_pr\`, \`nix_installer_revision\`, \`nix_installer_tag\`, and \`nix_installer_url\`` `The following options are mututally exclusive, but ${num_set} were set: \`nix_installer_branch\`, \`nix_installer_pr\`, \`nix_installer_revision\`, \`nix_installer_tag\`, and \`nix_installer_url\``,
) );
} }
if (nix_installer_branch !== null) { if (nix_installer_branch !== null) {
return new URL( return new URL(
`https://install.determinate.systems/nix/branch/${nix_installer_branch}/nix-installer-${platform}?ci=github` `https://install.determinate.systems/nix/branch/${nix_installer_branch}/nix-installer-${platform}?ci=github`,
) );
} else if (nix_installer_pr !== null) { } else if (nix_installer_pr !== null) {
return new URL( return new URL(
`https://install.determinate.systems/nix/pr/${nix_installer_pr}/nix-installer-${platform}?ci=github` `https://install.determinate.systems/nix/pr/${nix_installer_pr}/nix-installer-${platform}?ci=github`,
) );
} else if (nix_installer_revision !== null) { } else if (nix_installer_revision !== null) {
return new URL( return new URL(
`https://install.determinate.systems/nix/rev/${nix_installer_revision}/nix-installer-${platform}?ci=github` `https://install.determinate.systems/nix/rev/${nix_installer_revision}/nix-installer-${platform}?ci=github`,
) );
} else if (nix_installer_tag !== null) { } else if (nix_installer_tag !== null) {
return new URL( return new URL(
`https://install.determinate.systems/nix/tag/${nix_installer_tag}/nix-installer-${platform}?ci=github` `https://install.determinate.systems/nix/tag/${nix_installer_tag}/nix-installer-${platform}?ci=github`,
) );
} else if (nix_installer_url !== null) { } else if (nix_installer_url !== null) {
return new URL(nix_installer_url) return new URL(nix_installer_url);
} else { } else {
return new URL( return new URL(
`https://install.determinate.systems/nix/nix-installer-${platform}?ci=github` `https://install.determinate.systems/nix/nix-installer-${platform}?ci=github`,
) );
} }
} }
function action_input_string_or_null(name: string): string | null { function action_input_string_or_null(name: string): string | null {
const value = actions_core.getInput(name) const value = actions_core.getInput(name);
if (value === '') { if (value === "") {
return null return null;
} else { } else {
return value return value;
} }
} }
function action_input_multiline_string_or_null(name: string): string[] | null { function action_input_multiline_string_or_null(name: string): string[] | null {
const value = actions_core.getMultilineInput(name) const value = actions_core.getMultilineInput(name);
if (value.length === 0) { if (value.length === 0) {
return null return null;
} else { } else {
return value return value;
} }
} }
function action_input_number_or_null(name: string): number | null { function action_input_number_or_null(name: string): number | null {
const value = actions_core.getInput(name) const value = actions_core.getInput(name);
if (value === '') { if (value === "") {
return null return null;
} else { } else {
return Number(value) return Number(value);
} }
} }
function action_input_bool(name: string): boolean { function action_input_bool(name: string): boolean {
return actions_core.getBooleanInput(name) return actions_core.getBooleanInput(name);
} }
async function main(): Promise<void> { async function main(): Promise<void> {
try { try {
const installer = new NixInstallerAction() const installer = new NixInstallerAction();
await installer.install() await installer.install();
} catch (error) { } catch (error) {
if (error instanceof Error) actions_core.setFailed(error) if (error instanceof Error) actions_core.setFailed(error);
} }
} }
main() main();