From 8eae39e8e670f228e9675fb3bc432ce512560396 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Tue, 10 Sep 2024 11:21:08 -0500 Subject: Created a merge function which will probably be better than symlinkJoin. Also started writing the cli manager in haskell --- pkgs/misc/firmware-check.nix | 8 ++++++-- pkgs/misc/merge.nix | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 pkgs/misc/merge.nix (limited to 'pkgs/misc') diff --git a/pkgs/misc/firmware-check.nix b/pkgs/misc/firmware-check.nix index 53cd2c2..373ea36 100644 --- a/pkgs/misc/firmware-check.nix +++ b/pkgs/misc/firmware-check.nix @@ -1,5 +1,9 @@ { writeShellApplication, jq, curl, ... }: -{ deviceID, affiliate ? "kobo" }: +{ deviceID +, affiliate ? "kobo" +, currentVersion ? "0.0" +, serialNumber ? "N0" +}: writeShellApplication { name = "kobo-check-firmware"; runtimeInputs = [ @@ -7,6 +11,6 @@ writeShellApplication { jq ]; text = '' - curl --silent "https://api.kobobooks.com/1.0/UpgradeCheck/Device/${deviceID}/${affiliate}/0.0/N0" | jq '.UpgradeURL' + curl --silent "https://api.kobobooks.com/1.0/UpgradeCheck/Device/${deviceID}/${affiliate}/${currentVersion}/${serialNumber}" | jq '.UpgradeURL' ''; } diff --git a/pkgs/misc/merge.nix b/pkgs/misc/merge.nix new file mode 100644 index 0000000..9d6eabb --- /dev/null +++ b/pkgs/misc/merge.nix @@ -0,0 +1,48 @@ +{ runCommand, writeShellApplication, rsync, lib, ... }: +args@{ name, paths, preferLocalBuild ? true, allowSubstitutes ? false, postBuild ? "" }: +let + env = builtins.removeAttrs args [ "name" "postBuild" ]] // { + inherit preferLocalBuild allowSubstitutes; + nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ + rsync + replaceBadSymlink + ]; + passAsFile = [ "paths" ]; + }; + + # copyDirs = p: '' + # ${lib.getExe rsync} -rv --copy-dirlinks --links --executability "${p}/" "$out" + # ''; + + replaceBadSymlink = writeShellApplication { + name = "replaceBadSymlink"; + # runtimeInputs = [ coreutils ]; + text = '' + FILE="''${1-}" + + if [[ -z "$FILE" ]]; then + >&2 echo "Need a file input" + fi + + REALPATH="$(readlink -f "$FILE")" + + case "$REALPATH" in + "/nix/store/"* ) + echo "Replacing $FILE by $REALPATH" + cp -v --remove-destination "$REALPATH" "$FILE" + ;; + esac + ''; + }; + +in runCommand name env '' + mkdir -p $out + + for i in $(cat $pathsPath); do + rsync -rv --copy-dirlinks --links --executability "$i/" "$out" + done + + find $out -type l -exec "replaceBadSymlink {}" \; + + ${postBuild} +'' -- cgit v1.2.3