Skip to content

Commit

Permalink
add shell.nix (#175)
Browse files Browse the repository at this point in the history
Tests had to be lightly changed to support installation under Nix.

Added a Nix testing target to run all tests under Nix.
  • Loading branch information
ezrizhu authored Dec 13, 2024
1 parent b63d1e7 commit f938e2a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ pkgs ? import <nixpkgs> {}}:

pkgs.mkShell {
buildInputs = with pkgs; [
expect
mergerfs
attr
util-linux
time
shellcheck
];
}
4 changes: 2 additions & 2 deletions test/explore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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

echo hi >expected.out

cat >explore.exp <<EOF
#!/usr/bin/expect
#!/usr/bin/env expect
set timeout 3
Expand Down
50 changes: 38 additions & 12 deletions test/missing_unionfs_mergerfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,46 @@ cleanup() {

trap 'cleanup' EXIT

run_regular() {
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
}

run_nix() {
cat > shell.nix <<'EOF'
{ pkgs ? import <nixpkgs> {} }:
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

0 comments on commit f938e2a

Please sign in to comment.