tests: run flake-info in sandbox

Don't use sandboxing in Cirrus CI where namespace support is missing.
This commit is contained in:
Erik Arvstedt 2022-09-23 09:03:58 +02:00 committed by Greg Shuflin
parent bdb4ee0e0b
commit 5e6b560fcf
2 changed files with 45 additions and 2 deletions

View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
# Run flake-info for the nix-bitcoin flake in a sandbox:
# - Adds a consistent, reproducible runtime environment
# - Removes the need to trust the flake-info binary
#
# Use bubblewrap instead of a sandboxed Nix build so that we don't have to copy
# the whole repo to the sandbox when running this test.
cd "${BASH_SOURCE[0]%/*}"
nbFlake=$(realpath ../..)
# shellcheck disable=SC2016
PATH=$(nix shell -L .#{flake-info,bubblewrap} -c sh -c 'echo $PATH')
tmpDir=$(mktemp -d /tmp/nix-bitcoin-flake-info.XXX)
trap 'rm -rf $tmpDir' EXIT
echo '
experimental-features = nix-command flakes
flake-registry = /dev/null
' > "$tmpDir/nix.conf"
echo "Running flake-info (nixos-search)"
bwrap \
--unshare-all \
--clearenv \
--setenv PATH "$PATH" \
--setenv NIX_PATH "$NIX_PATH" \
--bind "$tmpDir" / \
--proc /proc \
--dev /dev \
--tmpfs /tmp \
--ro-bind "$nbFlake" "$nbFlake" \
--ro-bind /nix /nix \
--ro-bind /etc /etc \
--tmpfs /etc/nix \
--ro-bind "$tmpDir/nix.conf" /etc/nix/nix.conf \
--ro-bind /usr /usr \
--ro-bind-try /run /run \
-- flake-info flake "$nbFlake"

View File

@ -286,8 +286,7 @@ nixosSearch() {
# Add gcroots for flake-info
nix build "$scriptDir/nixos-search#flake-info" -o "$outLinkPrefix-flake-info"
fi
echo "Running flake-info (nixos-search)"
nix run "$scriptDir/nixos-search#flake-info" -- flake "$scriptDir/.."
"$scriptDir/nixos-search/flake-info-sandboxed.sh"
}
# A basic subset of tests to keep the total runtime within