|
1 | 1 | { |
2 | | - pkgs, |
3 | 2 | self, |
| 3 | + pkgs, |
| 4 | + tlib, |
4 | 5 | ... |
5 | 6 | }: |
6 | 7 |
|
7 | 8 | let |
8 | | - # Create a dummy package with a desktop file that references itself |
9 | | - dummyPackage = |
10 | | - (pkgs.runCommand "dummy-app" { } '' |
11 | | - mkdir -p $out/bin |
12 | | - mkdir -p $out/share/applications |
| 9 | + inherit (tlib) isFile fileContains test; |
| 10 | +in |
| 11 | +test "filesToPatch-test" { |
| 12 | + regular = let |
| 13 | + wrappedPackage = self.lib.wrapPackage { |
| 14 | + inherit pkgs; |
| 15 | + # Create a dummy package with a desktop file that references itself |
| 16 | + package = (pkgs.runCommand "dummy-app" { } '' |
| 17 | + mkdir -p $out/bin |
| 18 | + mkdir -p $out/share/applications |
13 | 19 |
|
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 |
| 20 | + cat > $out/bin/dummy-app <<'EOF' |
| 21 | + #!/bin/sh |
| 22 | + echo "Hello from dummy app" |
| 23 | + EOF |
| 24 | + chmod +x $out/bin/dummy-app |
20 | 25 |
|
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 | | - '') |
30 | | - // { |
31 | | - meta.mainProgram = "dummy-app"; |
| 26 | + cat > $out/share/applications/dummy-app.desktop <<EOF |
| 27 | + [Desktop Entry] |
| 28 | + Name=Dummy App |
| 29 | + Exec=$out/bin/dummy-app |
| 30 | + Icon=$out/share/icons/dummy-app.png |
| 31 | + Type=Application |
| 32 | + EOF |
| 33 | + '') |
| 34 | + // { |
| 35 | + meta.mainProgram = "dummy-app"; |
| 36 | + }; |
32 | 37 | }; |
33 | | - |
34 | | - # Wrap the package |
35 | | - wrappedPackage = self.lib.wrapPackage { |
36 | | - inherit pkgs; |
37 | | - package = dummyPackage; |
38 | | - }; |
39 | | - |
40 | | -in |
41 | | -pkgs.runCommand "filesToPatch-test" |
42 | | - { |
43 | | - originalPath = "${dummyPackage}"; |
| 38 | + originalPath = "${wrappedPackage.configuration.package}"; |
44 | 39 | wrappedPath = "${wrappedPackage}"; |
45 | | - } |
46 | | - '' |
47 | | - echo "Testing filesToPatch functionality..." |
48 | | - echo "Original package path: $originalPath" |
49 | | - echo "Wrapped package path: $wrappedPath" |
50 | | -
|
51 | | - # Read the desktop file |
52 | | - desktopFile="${wrappedPackage}/share/applications/dummy-app.desktop" |
53 | | -
|
54 | | - if [ ! -f "$desktopFile" ]; then |
55 | | - echo "FAIL: Desktop file not found at $desktopFile" |
56 | | - exit 1 |
57 | | - fi |
58 | | -
|
59 | | - # The desktop file should NOT contain references to the original package |
60 | | - if grep -qF "$originalPath" "$desktopFile"; then |
61 | | - echo "FAIL: Desktop file still contains reference to original package" |
62 | | - echo "Original path: $originalPath" |
63 | | - exit 1 |
64 | | - fi |
65 | | -
|
66 | | - # The desktop file SHOULD contain references to the wrapped package |
67 | | - if ! grep -qF "$wrappedPath" "$desktopFile"; then |
68 | | - echo "FAIL: Desktop file does not contain reference to wrapped package" |
69 | | - echo "Wrapped path: $wrappedPath" |
70 | | - exit 1 |
71 | | - fi |
72 | | -
|
73 | | - echo "SUCCESS: Desktop file was properly patched" |
74 | | - touch $out |
75 | | - '' |
| 40 | + desktopFile = "${wrappedPackage}/share/applications/dummy-app.desktop"; |
| 41 | + in { |
| 42 | + desktopFileExists = isFile desktopFile; |
| 43 | + noOriginalReferences = { |
| 44 | + cond = ''! grep -qF '${originalPath}' '${desktopFile}' ''; |
| 45 | + msg = "Desktop file still contains reference to original package. Original path: ${originalPath}"; |
| 46 | + }; |
| 47 | + containsWrappedReferences = fileContains desktopFile wrappedPath; |
| 48 | + }; |
| 49 | + binary = let |
| 50 | + wrappedPackage = self.lib.wrapPackage [ { inherit pkgs; } |
| 51 | + ({ wlib, pkgs, ... }: { |
| 52 | + filesToPatch = [ "bin/fileToBePatched" ]; |
| 53 | + package = wlib.wrapPackage [ { inherit pkgs; } |
| 54 | + ({pkgs, ... }: { |
| 55 | + config.package = pkgs.hello; |
| 56 | + config.wrapperImplementation = "binary"; |
| 57 | + config.wrapperVariants.fileToBePatched.exePath = "bin/hello"; # <- not the main one, the outer wrapper module will thus not wrap it automatically. |
| 58 | + config.flags."--greeting" = "Hello, ${placeholder "out"}"; # <- maybe stick a \0 at the end here for good measure? Just in case it didnt already have null bytes? IDK? |
| 59 | + }) |
| 60 | + ]; |
| 61 | + }) |
| 62 | + ]; |
| 63 | + originalPath = "${wrappedPackage.configuration.package}"; |
| 64 | + wrappedPath = "${wrappedPackage}/bin/fileToBePatched"; |
| 65 | + in { |
| 66 | + noOriginalReferences = { |
| 67 | + cond = ''! grep -qF '${originalPath}' '${wrappedPath}' ''; |
| 68 | + msg = "Desktop file still contains reference to original package. Original path: ${originalPath}"; |
| 69 | + }; |
| 70 | + containsWrappedReferences = fileContains wrappedPath wrappedPackage; |
| 71 | + }; |
| 72 | +} |
0 commit comments