about summary refs log tree commit diff
path: root/activate
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-05 17:24:38 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-27 15:08:16 +0000
commitfa3351f0099096419ef72d4fbc71b32c178396bc (patch)
treeb2200d2a29ebe7806f6a2fe218caf52010ca519d /activate
parentf0a202366786b44ffd486c588d9150d1fb5ecea3 (diff)
downloadnixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.gz
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.bz2
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.lz
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.xz
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.tar.zst
nixlib-fa3351f0099096419ef72d4fbc71b32c178396bc.zip
Add config
Diffstat (limited to 'activate')
-rwxr-xr-xactivate26
1 files changed, 26 insertions, 0 deletions
diff --git a/activate b/activate
new file mode 100755
index 000000000000..72550ebb2876
--- /dev/null
+++ b/activate
@@ -0,0 +1,26 @@
+#! /usr/bin/env bash
+
+# IMPORTANT: Don't use nix-shell shebang!
+# If a config has generated an invalid NIX_PATH, it still needs to be
+# possible to rescue the system by activating a different configuration.
+
+set -ueo pipefail
+
+d="$(dirname $0)"
+
+if [ "$#" -eq 0 ]; then
+    echo -e "\e[31;1merror:\e[0m must specify a system definition" >&2
+    echo "Available system definitions are:" >&2
+    find $d/sys -name *.nix | awk -F / '{print "- " $NF}' | sed 's/\.nix$//' >&2
+    exit 1
+fi
+
+sys="$1"
+shift
+
+export NIX_PATH=nixos-config=$d/sys/$sys.nix:$d
+link="$(mktemp -d)/result"
+nix build -f '<nixpkgs/nixos>' --out-link "$link" "$@" system
+path="$(readlink "$link")"
+nix-env -p /nix/var/nix/profiles/system --set "$path"
+exec "$path/bin/switch-to-configuration" switch