aboutsummaryrefslogtreecommitdiff
path: root/tests/common.sh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-12-09 15:16:18 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-02-23 11:31:44 -0500
commit87da941348e1b345d1be348b091d3ae65ac66bb7 (patch)
tree443b357d8d5e7cc97853a84b3b3cc03f533df9a7 /tests/common.sh
parent5dbbf233327bff1c89088ed0fc45882563240b1a (diff)
Clean up daemon handling
Split `common.sh` into the vars and functions definitions vs starting the daemon (and possibly other initialization logic). This way, `init.sh` can just `source` the former. Trying to start the daemon before `nix.conf` is written will fail because `nix daemon` requires `--experimental-features 'nix-command'`. `killDaemon` is idempotent, so it's safe to call when no daemon is running. `startDaemon` and `killDaemon` use the PID (which is now exported to subshells) to decide whether there is work to be done, rather than `NIX_REMOTE`, which might conceivably be set differently even if a daemon is running. `startDaemon` and `killDaemon` can save/restore the old `NIX_REMOTE` as `NIX_REMOTE_OLD`. `init.sh` kills daemon before deleting everything (including the daemon socket).
Diffstat (limited to 'tests/common.sh')
-rw-r--r--tests/common.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/common.sh b/tests/common.sh
new file mode 100644
index 000000000..68b90a85f
--- /dev/null
+++ b/tests/common.sh
@@ -0,0 +1,12 @@
+set -e
+
+if [[ -z "${COMMON_SH_SOURCED-}" ]]; then
+
+COMMON_SH_SOURCED=1
+
+source "$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/common/vars-and-functions.sh"
+if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
+ startDaemon
+fi
+
+fi # COMMON_SH_SOURCED