-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun-tests-in-container.sh
executable file
·48 lines (39 loc) · 1.42 KB
/
run-tests-in-container.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
scriptDir="$(dirname "$(readlink -f "$0")")"
PATH=$scriptDir:$PATH
cleanup() {
# clean immutable files inside the container
for f in /var/lib/*containers/test-extra-container/var/lib/*containers/*/var/empty; do
chattr -i -a "$f"
rm -rf "$f"
done
extra-container destroy test-extra-container || true
}
trap "cleanup" EXIT
trap "echo \"Error at $(realpath ${BASH_SOURCE[0]}):\$LINENO\"" ERR
cleanup
#―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
nixpkgs=$(nix-instantiate --eval -E '(toString <nixpkgs>)' | tr -d '"')
extra-container create -s <<EOF
{ config, pkgs, lib, ... }:
{
containers.test-extra-container = {
bindMounts."/extra-container".hostPath = "$scriptDir";
bindMounts."/nixpkgs".hostPath = "$nixpkgs";
config = { options, ... }: {
environment = {
systemPackages = [ pkgs.nixos-container ];
variables.NIX_PATH = lib.mkForce "nixpkgs=/nixpkgs";
};
boot = lib.optionalAttrs (options.boot ? extraSystemdUnitPaths) {
extraSystemdUnitPaths = [ "/etc/systemd-mutable/system" ];
};
};
};
}
EOF
echo "Running tests"
echo
nixos-container run test-extra-container -- '/extra-container/test.sh'