bins/gen-patches: initial script to help generate patches for nixpkgs

This commit is contained in:
Aaron Bieber 2023-06-30 07:47:13 -06:00
parent 4ab16c9beb
commit 541dda9262
No known key found for this signature in database
2 changed files with 52 additions and 0 deletions

View File

@ -13,10 +13,12 @@ let
inherit gosignify; inherit gosignify;
inherit (pkgs) curl; inherit (pkgs) curl;
}); });
genPatches = import ./gen-patches.nix { inherit pkgs; };
in { in {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
checkRestart checkRestart
genPatches
ix ix
sfetch sfetch
tstart tstart

50
bins/gen-patches.nix Normal file
View File

@ -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