77let
88 # Create a dummy package with a desktop file that references itself
99 dummyPackage =
10- ( pkgs . runCommand "dummy-app" { } ''
11- mkdir -p $out/bin
12- mkdir -p $out/share/applications
10+ ( pkgs . runCommand "dummy-app"
11+ {
12+ nativeBuildInputs = [ pkgs . makeBinaryWrapper ] ;
13+ }
14+ ''
15+ mkdir -p $out/bin
16+ mkdir -p $out/share/applications
1317
14- # Create a simple executable
15- cat > $out/bin/dummy-app <<'EOF'
16- #!/bin/sh
17- echo "Hello from dummy app"
18- EOF
19- chmod +x $out/bin/dummy-app
18+ # Make a dummy program to have a valid package
19+ makeWrapper ${ pkgs . hello } /bin/hello $out/bin/dummy-app
2020
21- # Create a desktop file that references the package path
22- cat > $out/share/applications/dummy-app.desktop <<EOF
23- [Desktop Entry]
24- Name=Dummy App
25- Exec=$out/bin/dummy-app
26- Icon=$out/share/icons/dummy-app.png
27- Type=Application
28- EOF
29- '' )
21+ # Add a secondary binary file that references the package path
22+ makeWrapper ${ pkgs . hello } /bin/hello $out/bin/other-bin \
23+ --add-flag "--greeting" \
24+ --add-flag "Hello, $out"
25+
26+ # Create a desktop file that references the package path
27+ cat > $out/share/applications/dummy-app.desktop <<EOF
28+ [Desktop Entry]
29+ Name=Dummy App
30+ Exec=$out/bin/dummy-app
31+ Icon=$out/share/icons/dummy-app.png
32+ Type=Application
33+ EOF
34+ ''
35+ )
3036 // {
3137 meta . mainProgram = "dummy-app" ;
3238 } ;
3339
3440 # Wrap the package
35- wrappedPackage = self . lib . wrapPackage {
36- inherit pkgs ;
37- package = dummyPackage ;
38- } ;
41+ wrappedPackage = self . lib . wrapPackage (
42+ { options , ... } :
43+ {
44+ inherit pkgs ;
45+
46+ filesToPatch = options . filesToPatch . default ++ [ "bin/other-bin" ] ;
3947
48+ package = dummyPackage ;
49+ }
50+ ) ;
4051in
4152pkgs . runCommand "filesToPatch-test"
4253 {
@@ -48,8 +59,8 @@ pkgs.runCommand "filesToPatch-test"
4859 echo "Original package path: $originalPath"
4960 echo "Wrapped package path: $wrappedPath"
5061
51- # Read the desktop file
52- desktopFile="${ wrappedPackage } /share/applications/dummy-app.desktop"
62+ # Test 1: Check replace in text file (.desktop)
63+ desktopFile="$wrappedPath /share/applications/dummy-app.desktop"
5364
5465 if [ ! -f "$desktopFile" ]; then
5566 echo "FAIL: Desktop file not found at $desktopFile"
@@ -70,6 +81,24 @@ pkgs.runCommand "filesToPatch-test"
7081 exit 1
7182 fi
7283
73- echo "SUCCESS: Desktop file was properly patched"
84+ # Test 2: Check replace in binary file
85+ binaryFile="$wrappedPath/bin/other-bin"
86+
87+ # The binary file should NOT contain references to the original package
88+ if grep -qF "$originalPath" "$binaryFile"; then
89+ cat "$binaryFile"
90+ echo "FAIL: Binary file still contains reference to original package"
91+ echo "Original path: $originalPath"
92+ exit 1
93+ fi
94+
95+ # The binary file SHOULD contain references to the original package
96+ if ! grep -qF "$wrappedPath" "$binaryFile"; then
97+ echo "FAIL: Binary file does not contain reference to wrapped package"
98+ echo "Original path: $originalPath"
99+ exit 1
100+ fi
101+
102+ echo "SUCCESS: files properly patched"
74103 touch $out
75104 ''
0 commit comments