Skip to content

Commit

Permalink
Source nix-daemon.sh instead of bespoke path modification (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ELD authored Mar 11, 2023
1 parent 3a21be5 commit e9187ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ jobs:
- nix/install-cachix
- nix/with-cachix:
cachix-user: eld
nix-command: nix build nixpkgs#cowsay
nix-command: nix profile install nixpkgs#cowsay.out
- run:
name: Cowsay command
command: cowsay "Hello, nix-orb!"
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- None

## [1.1.0] - 2023-03-05(?)
## [1.1.1] - 2022-03-11

### Changed
- Set `$BASH_ENV` to source the `nix-daemon.sh` file rather than the bespoke `$PATH` construction

## [1.1.0] - 2023-03-10

### Added
- New `install-cachix` command to install Cachix
Expand Down
45 changes: 26 additions & 19 deletions src/scripts/install.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const fs = require('fs');
const { spawn } = require('child_process');
const fs = require("fs");
const { spawn } = require("child_process");

const nixInstallerUrl = 'https://install.determinate.systems/nix';
const nixInstallerUrl = "https://install.determinate.systems/nix";

// Check for existing install
if (fs.existsSync('/nix/receipt.json') && fs.existsSync('/nix/nix-installer')) {
if (fs.existsSync("/nix/receipt.json") && fs.existsSync("/nix/nix-installer")) {
if (process.env.REINSTALL) {
spawn('/nix/nix-installer uninstall --no-confirm', { stdio: 'inherit', shell: true });
spawn("/nix/nix-installer uninstall --no-confirm", { stdio: "inherit", shell: true });
process.exit(1);
} else {
console.log('Nix was already installed, using existing install');
spawn(`echo 'export path=/nix/var/nix/profiles/default/bin:"$PATH"' >> "$BASH_ENV"`, { stdio: 'inherit', shell: true })
console.log("Nix was already installed, using existing install");
spawn(`echo 'export path=/nix/var/nix/profiles/default/bin:"$PATH"' >> "$BASH_ENV"`, { stdio: "inherit", shell: true });
process.exit(0);
}
}

// Set environment variables
if (process.env.CHANNELS && process.env.CHANNELS !== '') {
if (process.env.CHANNELS && process.env.CHANNELS !== "") {
process.env.NIX_INSTALLER_CHANNELS = process.env.CHANNELS;
console.log(`Set NIX_INSTALLER_CHANNELS=${process.env.NIX_INSTALLER_CHANNELS}`);
}
Expand All @@ -31,7 +31,7 @@ if (process.env.NIX_BUILD_USER_COUNT && Number(process.env.NIX_BUILD_USER_COUNT)
console.log(`Set NIX_INSTALLER_NIX_BUILD_USER_COUNT=${process.env.NIX_INSTALLER_NIX_BUILD_USER_COUNT}`);
}

if (process.env.NIX_BUILD_GROUP_NAME && process.env.NIX_BUILD_GROUP_NAME !== '') {
if (process.env.NIX_BUILD_GROUP_NAME && process.env.NIX_BUILD_GROUP_NAME !== "") {
process.env.NIX_INSTALLER_NIX_BUILD_GROUP_NAME = process.env.NIX_BUILD_GROUP_NAME;
console.log(`Set NIX_INSTALLER_NIX_BUILD_GROUP_NAME=${process.env.NIX_INSTALLER_NIX_BUILD_GROUP_NAME}`);
}
Expand All @@ -41,7 +41,7 @@ if (process.env.NIX_BUILD_GROUP_ID && Number(process.env.NIX_BUILD_GROUP_ID) !==
console.log(`Set NIX_INSTALLER_NIX_BUILD_GROUP_ID=${process.env.NIX_INSTALLER_NIX_BUILD_GROUP_ID}`);
}

if (process.env.NIX_BUILD_USER_PREFIX && process.env.NIX_BUILD_USER_PREFIX !== '') {
if (process.env.NIX_BUILD_USER_PREFIX && process.env.NIX_BUILD_USER_PREFIX !== "") {
process.env.NIX_INSTALLER_NIX_BUILD_USER_PREFIX = process.env.NIX_BUILD_USER_PREFIX;
console.log(`Set NIX_INSTALLER_NIX_BUILD_USER_PREFIX=${process.env.NIX_INSTALLER_NIX_BUILD_USER_PREFIX}`);
}
Expand All @@ -51,12 +51,12 @@ if (process.env.NIX_BUILD_USER_BASE && Number(process.env.NIX_BUILD_USER_BASE) !
console.log(`Set NIX_INSTALLER_NIX_BUILD_USER_BASE=${process.env.NIX_INSTALLER_NIX_BUILD_USER_BASE}`);
}

if (process.env.NIX_PACKAGE_URL && process.env.NIX_PACKAGE_URL !== '') {
if (process.env.NIX_PACKAGE_URL && process.env.NIX_PACKAGE_URL !== "") {
process.env.NIX_INSTALLER_NIX_PACKAGE_URL = process.env.NIX_PACKAGE_URL;
console.log(`Set NIX_INSTALLER_NIX_PACKAGE_URL=${process.env.NIX_INSTALLER_NIX_PACKAGE_URL}`);
}

if (process.env.NIX_EXTRA_CONF && process.env.NIX_EXTRA_CONF !== '') {
if (process.env.NIX_EXTRA_CONF && process.env.NIX_EXTRA_CONF !== "") {
process.env.NIX_INSTALLER_EXTRA_CONF = `${process.env.NIX_EXTRA_CONF}\ntrusted-users = root ${process.env.USER}`;
console.log(`Set NIX_INSTALLER_EXTRA_CONF=${process.env.NIX_EXTRA_CONF}`);
}
Expand All @@ -71,27 +71,27 @@ if (process.env.MAC_CASE_SENSITIVE && !!Number(process.env.MAC_CASE_SENSITIVE))
console.log(`Set NIX_INSTALLER_CASE_SENSITIVE=${process.env.NIX_INSTALLER_CASE_SENSITIVE}`);
}

if (process.env.MAC_VOLUME_LABEL && process.env.MAC_VOLUME_LABEL !== '') {
if (process.env.MAC_VOLUME_LABEL && process.env.MAC_VOLUME_LABEL !== "") {
process.env.NIX_INSTALLER_VOLUME_LABEL = process.env.MAC_VOLUME_LABEL;
console.log(`Set NIX_INSTALLER_VOLUME_LABEL=${process.env.NIX_INSTALLER_VOLUME_LABEL}`);
}

if (process.env.MAC_ROOT_DISK && process.env.MAC_ROOT_DISK !== '') {
if (process.env.MAC_ROOT_DISK && process.env.MAC_ROOT_DISK !== "") {
process.env.NIX_INSTALLER_ROOT_DISK = process.env.MAC_ROOT_DISK;
console.log(`Set NIX_INSTALLER_ROOT_DISK=${process.env.NIX_INSTALLER_ROOT_DISK}`);
}

if (process.env.LOGGER && process.env.LOGGER !== '') {
if (process.env.LOGGER && process.env.LOGGER !== "") {
process.env.NIX_INSTALLER_LOGGER = process.env.LOGGER;
console.log(`Set NIX_INSTALLER_LOGGER=${process.env.NIX_INSTALLER_LOGGER}`);
}

if (process.env.INIT && process.env.INIT !== '') {
if (process.env.INIT && process.env.INIT !== "") {
process.env.NIX_INSTALLER_INIT = process.env.INIT;
console.log(`Set NIX_INSTALLER_INIT=${process.env.NIX_INSTALLER_INIT}`);
}

if (process.env.START_DAEMON && process.env.START_DAEMON !== '') {
if (process.env.START_DAEMON && process.env.START_DAEMON !== "") {
process.env.NIX_INSTALLER_START_DAEMON = process.env.START_DAEMON;
console.log(`Set NIX_INSTALLER_START_DAEMON=${process.env.NIX_INSTALLER_START_DAEMON}`);
}
Expand All @@ -100,5 +100,12 @@ process.env.NIX_INSTALLER_NO_CONFIRM = true;
console.log(`Set NIX_INSTALLER_NO_CONFIRM=${process.env.NIX_INSTALLER_NO_CONFIRM}`);

// Install Nix
spawn(`curl --retry 20 -L ${nixInstallerUrl} | sh -s -- install ${process.env.PLANNER}`, { stdio: 'inherit', shell: true });
spawn(`echo 'export PATH=/nix/var/nix/profiles/per-user/${process.env.USER}/profile/bin:/nix/var/nix/profiles/default/bin:"$PATH"' >> "$BASH_ENV"`, { stdio: 'inherit', shell: true });
spawn(`curl --retry 20 -L ${nixInstallerUrl} | sh -s -- install ${process.env.PLANNER}`, { stdio: "inherit", shell: true });

const nixDaemonFile = "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh";
fs.appendFileSync(
`${process.env.BASH_ENV}`,
`if [[ -n ${nixDaemonFile} ]]; then
. ${nixDaemonFile}
fi`
);

0 comments on commit e9187ec

Please sign in to comment.