From 541dda92627a96982e9f1473919ad66f65544f4d Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 30 Jun 2023 07:47:13 -0600 Subject: [PATCH] bins/gen-patches: initial script to help generate patches for nixpkgs --- bins/default.nix | 2 ++ bins/gen-patches.nix | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 bins/gen-patches.nix diff --git a/bins/default.nix b/bins/default.nix index 9bd146c..ae2e412 100644 --- a/bins/default.nix +++ b/bins/default.nix @@ -13,10 +13,12 @@ let inherit gosignify; inherit (pkgs) curl; }); + genPatches = import ./gen-patches.nix { inherit pkgs; }; in { environment.systemPackages = with pkgs; [ checkRestart + genPatches ix sfetch tstart diff --git a/bins/gen-patches.nix b/bins/gen-patches.nix new file mode 100644 index 0000000..e7157db --- /dev/null +++ b/bins/gen-patches.nix @@ -0,0 +1,50 @@ +{ writeShellApplication, diffutils, findutils, coreutils, ... }: + +let + genPatches = writeShellApplication { + name = "gen-patches"; + runtimeInputs = [ diffutils findutils coreutils ]; + text = '' + suffix=".orig" + srcdir=$PWD + output="$PWD/patches" + + usage() { + echo "Usage: $0 [-s suffix (default .orig)] [-d source directory (default PWD)] [-o output directory (default PWD/patches)]" 1>&2; + exit 1; + } + + while getopts "d:ho:s:" arg; do + case $arg in + d) + srcdir=$OPTARG + ;; + h) + usage + ;; + s) + suffix=$OPTARG + ;; + o) + output=$OPTARG + ;; + *) + usage + esac + done + + mkdir -p "$output" + + # hold my be er! + # shellcheck disable=SC2044 + for patch in $(find "$srcdir" -name "*$suffix"); do + fname=$(basename "$patch" "$suffix") + dname=$(dirname "$patch") + file="$dname/$fname" + outfile=$(echo "$dname/$fname" | sed 's;/;_;g') + diff -u "$file" "$patch" > "$output/$outfile"; + echo "==> Created patch: $output/$outfile" + done + ''; + }; +in genPatches