Skip to content

Commit 8cc78f6

Browse files
authored
Merge pull request #121 from zimward/push-zsprtpvprpuk
lib/wrapPackage: add patchHook
2 parents 7ba6fe0 + 17dcf99 commit 8cc78f6

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Arguments:
146146
- Example: `["bin/*", "lib/*.sh"]` to replace original package paths with wrapped package paths
147147
- Desktop files are patched by default to update Exec= and Icon= paths
148148
- `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (default: `[]`)
149+
- `patchHook`: Shell script that runs after patchPhase to modify the wrapper package files
149150
- `wrapper`: Custom wrapper function (optional, overrides default exec wrapper)
150151

151152
The function:

checks/patchHook.nix

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
pkgs,
3+
self,
4+
}:
5+
6+
let
7+
# Create a dummy package with a desktop file that references itself
8+
dummyPackage =
9+
(pkgs.runCommand "dummy-app" { } ''
10+
# empty dir as a package
11+
mkdir -p $out
12+
'')
13+
// {
14+
meta.mainProgram = "dummy-app";
15+
};
16+
17+
# Wrap the package
18+
wrappedPackage = self.lib.wrapPackage {
19+
inherit pkgs;
20+
package = dummyPackage;
21+
patchHook = ''
22+
touch $out/test
23+
'';
24+
};
25+
26+
in
27+
pkgs.runCommand "patchHook-test"
28+
{
29+
wrappedPath = "${wrappedPackage}";
30+
}
31+
''
32+
echo "Testing patchHook functionality..."
33+
echo "Wrapped package path: $wrappedPath"
34+
35+
if [ ! -f "$wrappedPath/test" ]; then
36+
echo "FAIL: file not created in patched package"
37+
exit 1
38+
fi
39+
40+
echo "SUCCESS: patchHook executed correctly"
41+
touch $out
42+
''

lib/default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ let
384384
- `aliases`: List of additional names to symlink to the wrapped executable (optional)
385385
- `filesToPatch`: List of file paths (glob patterns) to patch for self-references (optional, defaults to ["share/applications/*.desktop"])
386386
- `filesToExclude`: List of file paths (glob patterns) to exclude from the wrapped package (optional, defaults to [])
387+
- `patchHook`: Shell script that runs after patchPhase to modify the wrapper package files
387388
- `wrapper`: Custom wrapper function (optional, defaults to exec'ing the original binary with args)
388389
- Called with { env, flags, args, envString, flagsString, exePath, preHook }
389390
@@ -451,6 +452,7 @@ let
451452
filesToPatch ? [ "share/applications/*.desktop" ],
452453
# List of file paths (glob patterns) to exclude from the wrapped package (e.g., ["bin/unwanted-*", "share/doc/*"])
453454
filesToExclude ? [ ],
455+
patchHook ? "",
454456
wrapper ? (
455457
{
456458
exePath,
@@ -511,6 +513,7 @@ let
511513
binName ? null,
512514
filesToPatch ? [ ],
513515
filesToExclude ? [ ],
516+
patchHook ? "",
514517
...
515518
}@args:
516519
pkgs.stdenv.mkDerivation (
@@ -566,6 +569,7 @@ let
566569
done
567570
'') filesToPatch}
568571
''}
572+
${patchHook}
569573
570574
# Create symlinks for aliases
571575
${lib.optionalString (aliases != [ ] && binName != null) ''
@@ -604,6 +608,7 @@ let
604608
"binName"
605609
"filesToPatch"
606610
"filesToExclude"
611+
"patchHook"
607612
])
608613
);
609614

@@ -638,6 +643,7 @@ let
638643
binName
639644
filesToPatch
640645
filesToExclude
646+
patchHook
641647
;
642648
passthru =
643649
(package.passthru or { })

0 commit comments

Comments
 (0)