From dad23f2092a4fd716654bc4cdb696a8edd3445a1 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 25 Aug 2020 18:07:38 +0200 Subject: [PATCH 1/5] add extra_nix_config options This also cleans the install-nix.sh script a bit --- README.md | 1 + action.yml | 2 ++ lib/install-nix.sh | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index da8b4de..3c15c7a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ with developers. - `nix_path`: set `NIX_PATH` environment variable (if set `skip_adding_nixpkgs_channel` will be implicitly enabled) - `skip_adding_nixpkgs_channel`: set to `true` to skip adding nixpkgs-unstable channel (and save ~5s for each job build) +- `extra_nix_config`: gets appended to `/etc/nix/nix.conf` if passed. --- diff --git a/action.yml b/action.yml index aac769c..c5124a7 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,8 @@ inputs: description: 'Set NIX_PATH environment variable. If set "skip_adding_nixpkgs_channel" will be implicitly enabled' skip_adding_nixpkgs_channel: description: 'Skip adding nixpkgs-unstable channel' + extra_nix_config: + description: 'gets appended to `/etc/nix/nix.conf` if passed.' branding: color: 'blue' icon: 'sun' diff --git a/lib/install-nix.sh b/lib/install-nix.sh index 01f65df..1cc2175 100755 --- a/lib/install-nix.sh +++ b/lib/install-nix.sh @@ -5,16 +5,25 @@ set -euo pipefail sudo sh -c 'echo max-jobs = auto >> /tmp/nix.conf' # Allow binary caches for runner user sudo sh -c 'echo trusted-users = root runner >> /tmp/nix.conf' +if [[ -n $INPUT_EXTRA_NIX_CONFIG ]]; then + echo "$INPUT_EXTRA_NIX_CONFIG" >> /tmp/nix.conf +fi -if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || $INPUT_NIX_PATH != "" ]]; then - extra_cmd=--no-channel-add +install_options=( + --daemon + --daemon-user-count 4 + --nix-extra-conf-file /tmp/nix.conf + --darwin-use-unencrypted-nix-store-volume +) + +if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || -n $INPUT_NIX_PATH ]]; then + install_options+=(--no-channel-add) else - extra_cmd= INPUT_NIX_PATH="/nix/var/nix/profiles/per-user/root/channels" fi -sh <(curl --retry 5 --retry-connrefused -L ${INPUT_INSTALL_URL:-https://nixos.org/nix/install}) \ - --daemon --daemon-user-count 4 --nix-extra-conf-file /tmp/nix.conf --darwin-use-unencrypted-nix-store-volume $extra_cmd +sh <(curl --retry 5 --retry-connrefused -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}") \ + "${install_options[@]}" if [[ $OSTYPE =~ darwin ]]; then # Disable spotlight indexing of /nix to speed up performance From d953a4ee09c221bbd956a1d0b96ec5602791bfb6 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 25 Aug 2020 18:13:35 +0200 Subject: [PATCH 2/5] add failing test --- .github/workflows/test.yml | 18 ++++++++++++++++++ lib/install-nix.sh | 3 ++- test.nix | 7 +++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d18154..bb0898f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,3 +52,21 @@ jobs: nix_path: nixpkgs=channel:nixos-20.03 - run: test $NIX_PATH == "nixpkgs=channel:nixos-20.03" - run: nix-build test.nix + + extra-nix-config: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - run: yarn install --frozen-lockfile + - run: yarn build + - name: Install Nix + uses: ./ + with: + extra_nix_config: | + hello = world + # sandbox = relaxed + - run: cat /etc/nix/nix.conf + - run: nix-build test.nix --arg noChroot true diff --git a/lib/install-nix.sh b/lib/install-nix.sh index 1cc2175..1f55958 100755 --- a/lib/install-nix.sh +++ b/lib/install-nix.sh @@ -5,8 +5,9 @@ set -euo pipefail sudo sh -c 'echo max-jobs = auto >> /tmp/nix.conf' # Allow binary caches for runner user sudo sh -c 'echo trusted-users = root runner >> /tmp/nix.conf' +# Append extra nix configuration if provided if [[ -n $INPUT_EXTRA_NIX_CONFIG ]]; then - echo "$INPUT_EXTRA_NIX_CONFIG" >> /tmp/nix.conf + echo "$INPUT_EXTRA_NIX_CONFIG" | sudo tee -a /tmp/nix.conf >/dev/null fi install_options=( diff --git a/test.nix b/test.nix index f95abdf..4f6ba38 100644 --- a/test.nix +++ b/test.nix @@ -2,14 +2,17 @@ { size ? 1 # MB , num ? 10 # count , currentTime ? builtins.currentTime +, noChroot ? false }: with import {}; let - drv = i: runCommand "${toString currentTime}-${toString i}" {} '' + drv = i: runCommand "${toString currentTime}-${toString i}" { + __noChroot = noChroot; + } '' dd if=/dev/zero of=$out bs=${toString size}MB count=1 ''; in writeText "empty-${toString num}-${toString size}MB" '' ${lib.concatMapStringsSep "" drv (lib.range 1 num)} -'' \ No newline at end of file +'' From 434ba1c7f056ec00cf5dd64281276c860956d3bc Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 25 Aug 2020 18:20:10 +0200 Subject: [PATCH 3/5] fix the test --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb0898f..3c4d041 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,6 @@ jobs: uses: ./ with: extra_nix_config: | - hello = world - # sandbox = relaxed + sandbox = relaxed - run: cat /etc/nix/nix.conf - run: nix-build test.nix --arg noChroot true From 07dda1e6087b16ba09ce5313e18a23d579cbaeba Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 25 Aug 2020 18:26:01 +0200 Subject: [PATCH 4/5] more cleanup --- lib/install-nix.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/install-nix.sh b/lib/install-nix.sh index 1f55958..3e97cc5 100755 --- a/lib/install-nix.sh +++ b/lib/install-nix.sh @@ -1,30 +1,35 @@ #!/usr/bin/env bash set -euo pipefail +# Configure Nix +add_config() { + echo "$1" | sudo tee -a /tmp/nix.conf >/dev/null +} # Set jobs to number of cores -sudo sh -c 'echo max-jobs = auto >> /tmp/nix.conf' +add_config "max-jobs = auto" # Allow binary caches for runner user -sudo sh -c 'echo trusted-users = root runner >> /tmp/nix.conf' +add_config "trusted-users = root runner" # Append extra nix configuration if provided if [[ -n $INPUT_EXTRA_NIX_CONFIG ]]; then - echo "$INPUT_EXTRA_NIX_CONFIG" | sudo tee -a /tmp/nix.conf >/dev/null + add_config "$INPUT_EXTRA_NIX_CONFIG" fi -install_options=( +# Nix installer flags +installer_options=( --daemon --daemon-user-count 4 - --nix-extra-conf-file /tmp/nix.conf --darwin-use-unencrypted-nix-store-volume + --nix-extra-conf-file /tmp/nix.conf ) if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || -n $INPUT_NIX_PATH ]]; then - install_options+=(--no-channel-add) + installer_options+=(--no-channel-add) else INPUT_NIX_PATH="/nix/var/nix/profiles/per-user/root/channels" fi sh <(curl --retry 5 --retry-connrefused -L "${INPUT_INSTALL_URL:-https://nixos.org/nix/install}") \ - "${install_options[@]}" + "${installer_options[@]}" if [[ $OSTYPE =~ darwin ]]; then # Disable spotlight indexing of /nix to speed up performance @@ -41,6 +46,6 @@ fi echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin" echo "::add-path::/nix/var/nix/profiles/default/bin" -if [[ $INPUT_NIX_PATH != "" ]]; then +if [[ -n $INPUT_NIX_PATH ]]; then echo "::set-env name=NIX_PATH::${INPUT_NIX_PATH}" fi From 967d234ad851dfc1fd32b9ad191778568cd88922 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 25 Aug 2020 18:56:36 +0200 Subject: [PATCH 5/5] -n => != "" --- lib/install-nix.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/install-nix.sh b/lib/install-nix.sh index 3e97cc5..01b5fe4 100755 --- a/lib/install-nix.sh +++ b/lib/install-nix.sh @@ -10,7 +10,7 @@ add_config "max-jobs = auto" # Allow binary caches for runner user add_config "trusted-users = root runner" # Append extra nix configuration if provided -if [[ -n $INPUT_EXTRA_NIX_CONFIG ]]; then +if [[ $INPUT_EXTRA_NIX_CONFIG != "" ]]; then add_config "$INPUT_EXTRA_NIX_CONFIG" fi @@ -22,7 +22,7 @@ installer_options=( --nix-extra-conf-file /tmp/nix.conf ) -if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || -n $INPUT_NIX_PATH ]]; then +if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || $INPUT_NIX_PATH != "" ]]; then installer_options+=(--no-channel-add) else INPUT_NIX_PATH="/nix/var/nix/profiles/per-user/root/channels" @@ -46,6 +46,6 @@ fi echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin" echo "::add-path::/nix/var/nix/profiles/default/bin" -if [[ -n $INPUT_NIX_PATH ]]; then +if [[ $INPUT_NIX_PATH != "" ]]; then echo "::set-env name=NIX_PATH::${INPUT_NIX_PATH}" fi