From 30153a2d4e7e8d758c9869b240046756dc791663 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 6 May 2023 22:47:03 +0100 Subject: [PATCH] add min-copy-closure, a minimal nix-copy-closure substitute --- pkgs/default.nix | 1 + pkgs/min-copy-closure/default.nix | 13 +++++++ pkgs/min-copy-closure/min-copy-closure.fnl | 2 ++ pkgs/min-copy-closure/min-copy-closure.sh | 40 ++++++++++++++++++++++ pkgs/min-copy-closure/receive.sh | 9 +++++ 5 files changed, 65 insertions(+) create mode 100644 pkgs/min-copy-closure/default.nix create mode 100644 pkgs/min-copy-closure/min-copy-closure.fnl create mode 100755 pkgs/min-copy-closure/min-copy-closure.sh create mode 100644 pkgs/min-copy-closure/receive.sh diff --git a/pkgs/default.nix b/pkgs/default.nix index 8a569c6..ad3855e 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -45,5 +45,6 @@ openwrt = callPackage ./openwrt {}; + min-copy-closure = callPackage ./min-copy-closure {}; hi = callPackage ./hi {}; } diff --git a/pkgs/min-copy-closure/default.nix b/pkgs/min-copy-closure/default.nix new file mode 100644 index 0000000..298ce67 --- /dev/null +++ b/pkgs/min-copy-closure/default.nix @@ -0,0 +1,13 @@ +{ + stdenv +, nix +, cpio +}: stdenv.mkDerivation { + name = "min-copy-closure"; + buildInputs = [ nix cpio ]; + src = ./.; + installPhase = '' + mkdir -p $out/bin + cp min-copy-closure.sh $out/bin/nix-copy-closure + ''; +} diff --git a/pkgs/min-copy-closure/min-copy-closure.fnl b/pkgs/min-copy-closure/min-copy-closure.fnl new file mode 100644 index 0000000..6799923 --- /dev/null +++ b/pkgs/min-copy-closure/min-copy-closure.fnl @@ -0,0 +1,2 @@ + +(local ssh (io.popen " diff --git a/pkgs/min-copy-closure/min-copy-closure.sh b/pkgs/min-copy-closure/min-copy-closure.sh new file mode 100755 index 0000000..09b52aa --- /dev/null +++ b/pkgs/min-copy-closure/min-copy-closure.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +target_host=$1 +shift + +paths=$(nix-store -q --requisites "$@") +needed="" + +coproc remote { + ssh -C ${target_host} +} + +exec 10>&${remote[1]} + +for p in $paths; do + echo "test -e $p && echo skip || echo $p" >&10 + read n <&${remote[0]} + case $n in + skip) + : + ;; + *) + needed="${needed} $n" + echo Will copy $n + ;; + esac +done + +if test -z "$needed" ; then + echo Nothing to copy + exit 1 +fi + +echo "cd / && cpio -v -i >/dev/console" >&10 + +find $needed | cpio -H newc -o >&10 + +echo "date" >&10 +read n <&${remote[0]} +echo $n diff --git a/pkgs/min-copy-closure/receive.sh b/pkgs/min-copy-closure/receive.sh new file mode 100644 index 0000000..2ca715c --- /dev/null +++ b/pkgs/min-copy-closure/receive.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +cd /nix/store +while read f ; do + test "$f" = "end" && break + test -e $f || echo -n $f " " +done +mkdir -p /tmp/store +cd /tmp/store +cpio -i