From 4f471484b3a1e16230979a8406503a220b9101f4 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 10 Sep 2024 14:51:28 -0500 Subject: I think this is almost working! --- pkgs/misc/create-koboroot.nix | 5 ++++ pkgs/misc/deploy.nix | 65 +++++++++++++++++++++++++++++++++++++++++++ pkgs/misc/merge.nix | 10 +++---- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 pkgs/misc/create-koboroot.nix create mode 100644 pkgs/misc/deploy.nix (limited to 'pkgs/misc') diff --git a/pkgs/misc/create-koboroot.nix b/pkgs/misc/create-koboroot.nix new file mode 100644 index 0000000..7cf1bff --- /dev/null +++ b/pkgs/misc/create-koboroot.nix @@ -0,0 +1,5 @@ +{ runCommandLocal, ... }: p: +runCommand "mk-koboroot" {} '' + mkdir -p $out + tar czvf --mode=u+w $out/KoboRoot.tgz "${p}" +'' diff --git a/pkgs/misc/deploy.nix b/pkgs/misc/deploy.nix new file mode 100644 index 0000000..23973e9 --- /dev/null +++ b/pkgs/misc/deploy.nix @@ -0,0 +1,65 @@ +{ stdenvNoCC, writeShellApplication, makeWrapper, rsync, kobo-utils, lib, ... }: +src: +let + deployScript = writeShellApplication { + name = "deploy"; + runtimeInputs = [ + rsync + kobo-utils + ]; + text = '' + PAYLOAD="./payload" + + if [[ ! -d "$PAYLOAD" ]]; then + >&2 echo "./payload is not a directory I can copy..." + exit 1 + fi + + KOBOMNT="$(kobo-find -f -w)" + KOBODIR="$KOBOMNT/.kobo" + + if [[ -z "$KOBOMNT" ]]; then + >&2 echo "Cannot find mounted kobo" + exit 1 + elif [[ ! -d "$KOBODIR" ]]; then + >&2 echo "$KOBODIR does not appear to exist. Is this really a kobo?" + exit 1 + fi + + echo "Deploying payload" + + rsync -rv --executability --chmod=u+w "$PAYLOAD/" "$KOBODIR" + ''; + }; +in stdenvNoCC.mkDerivation (finalAttrs: { + name = "deploy-kobo"; + + inherit src; + + nativeBuildInputs = [ + makeWrapper + ]; + + buildInputs = [ + kobo-utils + rsync + ]; + + phases = "installPhase"; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -r $src $out/payload + + mkdir -p $out/bin + makeWrapper "${lib.getExe deployScript}" $out/bin/deploy --chdir "$out" + + runHook postInstall + ''; + + meta = { + mainProgram = "deploy"; + }; +}) diff --git a/pkgs/misc/merge.nix b/pkgs/misc/merge.nix index 9d6eabb..b4b4892 100644 --- a/pkgs/misc/merge.nix +++ b/pkgs/misc/merge.nix @@ -1,7 +1,7 @@ { runCommand, writeShellApplication, rsync, lib, ... }: args@{ name, paths, preferLocalBuild ? true, allowSubstitutes ? false, postBuild ? "" }: let - env = builtins.removeAttrs args [ "name" "postBuild" ]] // { + env = builtins.removeAttrs args [ "name" "postBuild" ] // { inherit preferLocalBuild allowSubstitutes; nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ rsync @@ -28,8 +28,7 @@ let case "$REALPATH" in "/nix/store/"* ) - echo "Replacing $FILE by $REALPATH" - cp -v --remove-destination "$REALPATH" "$FILE" + cp -vf --remove-destination "$REALPATH" "$FILE" ;; esac ''; @@ -39,10 +38,11 @@ in runCommand name env '' mkdir -p $out for i in $(cat $pathsPath); do - rsync -rv --copy-dirlinks --links --executability "$i/" "$out" + rsync -rv --copy-dirlinks --links --executability --chmod=u+w "$i/" "$out" done - find $out -type l -exec "replaceBadSymlink {}" \; + find $out/ -type l -exec replaceBadSymlink {} \; + ${postBuild} '' -- cgit v1.2.3