diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b74cf0b..c923197 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -190,6 +190,26 @@ jobs: ./configure ./install-sh + nix: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Allow unprivileged user namespaces (for Ubuntu 24.04) + run: | + sudo sysctl kernel.apparmor_restrict_unprivileged_userns=0 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + + - name: Run tests + run: | + nix-shell --run "sh scripts/run_tests.sh" + + prerelease: needs: - test-checkout diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..ecf1838 --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +{ pkgs ? import {}}: + +pkgs.mkShell { + buildInputs = with pkgs; [ + expect + mergerfs + attr + util-linux + time + shellcheck + ]; +} diff --git a/test/explore.sh b/test/explore.sh index 4a50f82..3f5d8a9 100755 --- a/test/explore.sh +++ b/test/explore.sh @@ -17,7 +17,7 @@ trap 'cleanup' EXIT try_workspace="$(mktemp -d)" cd "$try_workspace" || exit 9 -SHELL="/bin/bash --norc" +SHELL="/usr/bin/env bash --norc" export SHELL PS1="# " export PS1 @@ -25,7 +25,7 @@ export PS1 echo hi >expected.out cat >explore.exp </dev/null + rm -f "$new_bin_dir/usr/bin/unionfs" 2>/dev/null + + echo hi >expected + PATH="$new_bin_dir/usr/bin" "$TRY" -y "echo hi" >target 2>/dev/null || exit 1 + diff -q expected target || exit 2 +} + +run_nix() { + cat > shell.nix <<'EOF' + { pkgs ? import {} }: + pkgs.mkShell { + buildInputs = with pkgs; [ + attr + util-linux + ]; + } +EOF + + echo hi >expected + # Run the command in a nix-shell with only the specified packages + nix-shell --pure shell.nix --run "\"$TRY\" -y \"echo hi\"" >target 2>/dev/null || exit 3 + diff -q expected target || exit 4 +} + # particularly important that we run in mktemp: in some test machines, # the cwd is mounted, hence inaccessable. try_workspace="$(mktemp -d)" cd "$try_workspace" || exit 9 -new_bin_dir="$(mktemp -d)" -mkdir "$new_bin_dir/usr" -# -s makes symlinks -cp -rs /usr/bin "$new_bin_dir/usr/bin" - -# Delete mergerfs and unionfs and set the new PATH to the temporary directory -rm -f "$new_bin_dir/usr/bin/mergerfs" 2>/dev/null -rm -f "$new_bin_dir/usr/bin/unionfs" 2>/dev/null - -echo hi >expected -PATH="$new_bin_dir/usr/bin" "$TRY" -y "echo hi" >target 2>/dev/null || exit 1 -diff -q expected target || exit 2 +if [ -e /etc/NIXOS ] +then + run_nix +else + run_regular +fi