diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d18154..3c4d041 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,3 +52,20 @@ 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: | + sandbox = relaxed + - run: cat /etc/nix/nix.conf + - run: nix-build test.nix --arg noChroot true 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..01b5fe4 100755 --- a/lib/install-nix.sh +++ b/lib/install-nix.sh @@ -1,20 +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 [[ $INPUT_EXTRA_NIX_CONFIG != "" ]]; then + add_config "$INPUT_EXTRA_NIX_CONFIG" +fi + +# Nix installer flags +installer_options=( + --daemon + --daemon-user-count 4 + --darwin-use-unencrypted-nix-store-volume + --nix-extra-conf-file /tmp/nix.conf +) if [[ $INPUT_SKIP_ADDING_NIXPKGS_CHANNEL = "true" || $INPUT_NIX_PATH != "" ]]; then - extra_cmd=--no-channel-add + installer_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}") \ + "${installer_options[@]}" if [[ $OSTYPE =~ darwin ]]; then # Disable spotlight indexing of /nix to speed up performance 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 +''