commit 55c7410a55901cb46e1f06fdfd2810914fe78093
parent 0f50648157387bde00e07d8ddfb239e9d75901b9
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 9 Oct 2024 13:35:02 +0100
add result/install.sh to systemConfiguration output
this makes it possible to install a systemconfig instead of
having to use nix-shell (which is very slow)
Diffstat:
2 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/pkgs/systemconfig/build-system-install.sh b/pkgs/systemconfig/build-system-install.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+
+# this shell script can be run on the build system to
+# min-copy-closure the system configuration onto the device
+# and reboot/restart services as requested
+
+die() {
+ echo "$@"
+ exit 1
+}
+
+PATH=@min-copy-closure@/bin:$PATH
+
+ssh_command=${SSH_COMMAND-ssh}
+
+reboot="reboot"
+
+case "$1" in
+ "--no-reboot")
+ unset reboot
+ shift
+ ;;
+ "--fast")
+ reboot="soft"
+ shift
+ ;;
+esac
+
+target_host=$1
+shift
+
+test -n "$target_host" || \
+ die "Usage: $0 [--no-reboot] [--fast] target-host"
+
+toplevel=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+test -e $toplevel/etc/nix-store-paths || die "missing etc/nix-store-paths, is this really a system configuration?"
+echo installing from systemConfiguration $toplevel to host $target_host
+
+min-copy-closure $target_host $toplevel
+$ssh_command $target_host $toplevel/bin/install
+case "$reboot" in
+ reboot)
+ $ssh_command $target_host "sync; source /etc/profile; reboot"
+ ;;
+ soft)
+ $ssh_command $target_host $toplevel/bin/restart-services
+ ;;
+ *)
+ ;;
+esac
diff --git a/pkgs/systemconfig/default.nix b/pkgs/systemconfig/default.nix
@@ -7,6 +7,7 @@
{
writeText,
writeFennel,
+ buildPackages,
lib,
s6-init-bin,
closureInfo,
@@ -82,6 +83,8 @@ in attrset:
$STRIP --remove-section=.note --remove-section=.comment --strip-all makedevs -o $out/bin/activate
ln -s ${s6-init-bin}/bin/init $out/bin/init
cp -p ${writeFennel "restart-services" {} ./restart-services.fnl} $out/bin/restart-services
+ substitute ${./build-system-install.sh} $out/install.sh --subst-var-by min-copy-closure ${buildPackages.min-copy-closure}
+ chmod +x $out/install.sh
cat > $out/bin/install <<EOF
#!/bin/sh -e
prefix=\''${1-/}