From 3170c45be47d1f1488b997cb1755c965e3c232eb Mon Sep 17 00:00:00 2001 From: zimbatm Date: Fri, 5 Apr 2024 16:24:40 +0200 Subject: [PATCH] fix bashism [[ ]] is not available in POSIX sh, and test -o is not well defined either. Move the facts-gathering script out so it can be tested with shellcheck. --- src/default.nix | 4 ++-- src/get-facts.sh | 20 ++++++++++++++++++++ src/nixos-anywhere.sh | 29 ++++------------------------- 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100755 src/get-facts.sh diff --git a/src/default.nix b/src/default.nix index e465669..cd50360 100644 --- a/src/default.nix +++ b/src/default.nix @@ -37,13 +37,13 @@ stdenv.mkDerivation { src = ./..; nativeBuildInputs = [ makeWrapper ]; installPhase = '' - install -D -m 0755 src/nixos-anywhere.sh $out/bin/nixos-anywhere + install -D --target-directory=$out/libexec/nixos-anywhere/ -m 0755 src/*.sh # We prefer the system's openssh over our own, since it might come with features not present in ours: # https://github.com/nix-community/nixos-anywhere/issues/62 # # We also prefer system rsync to prevent crashes between rsync and ssh. - wrapProgram $out/bin/nixos-anywhere \ + makeShellWrapper $out/libexec/nixos-anywhere/nixos-anywhere.sh $out/bin/nixos-anywhere \ --prefix PATH : ${lib.makeBinPath runtimeDeps} --suffix PATH : ${lib.makeBinPath [ openssh ]} ''; diff --git a/src/get-facts.sh b/src/get-facts.sh new file mode 100755 index 0000000..789e78b --- /dev/null +++ b/src/get-facts.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -efu "${enable_debug:-}" +has() { + command -v "$1" >/dev/null && echo "y" || echo "n" +} +is_nixos=$(if test -f /etc/os-release && grep -q ID=nixos /etc/os-release; then echo "y"; else echo "n"; fi) +cat </dev/null && echo "y" || echo "n" -} -is_nixos=\$(if test -f /etc/os-release && grep -q ID=nixos /etc/os-release; then echo "y"; else echo "n"; fi) -cat <