pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / build-support / setup-hooks / wrap-gapps-hook / default.nix
blobb2ce7b4b2654b9b05b91450b8955cee9a9891b08
1 { stdenv
2 , lib
3 , makeSetupHook
4 , makeWrapper
5 , gobject-introspection
6 , isGraphical ? false
7 , gtk3
8 , librsvg
9 , dconf
10 , callPackage
11 , wrapGAppsHook3
12 , targetPackages
15 makeSetupHook {
16   name = "wrap-gapps-hook";
17   propagatedBuildInputs = [
18     # We use the wrapProgram function.
19     makeWrapper
20   ] ++ lib.optionals isGraphical [
21     # TODO: remove this, packages should depend on GTK explicitly.
22     gtk3
24     librsvg
25   ];
27   # depsTargetTargetPropagated will essentially be buildInputs when wrapGAppsHook3 is placed into nativeBuildInputs
28   # the librsvg and gtk3 above should be removed but kept to not break anything that implicitly depended on its binaries
29   depsTargetTargetPropagated = assert (lib.assertMsg (!targetPackages ? raw) "wrapGAppsHook3 must be in nativeBuildInputs"); lib.optionals isGraphical [
30     # librsvg provides a module for gdk-pixbuf to allow rendering
31     # SVG icons. Most icon themes are SVG-based and so are some
32     # graphics in GTK (e.g. cross for closing window in window title bar)
33     # so it is pretty much required for applications using GTK.
34     librsvg
36     # TODO: remove this, packages should depend on GTK explicitly.
37     gtk3
38   ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
39     # It is highly probable that a program will use GSettings,
40     # at minimum through GTK file chooser dialogue.
41     # Let’s add a GIO module for “dconf” GSettings backend
42     # to avoid falling back to “memory” backend. This is
43     # required for GSettings-based settings to be persisted.
44     # Unfortunately, it also requires the user to have dconf
45     # D-Bus service enabled globally (e.g. through a NixOS module).
46     dconf.lib
47   ];
48   passthru = {
49     tests = let
50       sample-project = ./tests/sample-project;
52       testLib = callPackage ./tests/lib.nix { };
53       inherit (testLib) expectSomeLineContainingYInFileXToMentionZ;
54     in rec {
55       # Simple derivation containing a program and a daemon.
56       basic = stdenv.mkDerivation {
57         name = "basic";
59         src = sample-project;
61         strictDeps = true;
62         nativeBuildInputs = [ wrapGAppsHook3 ];
64         installFlags = [ "bin-foo" "libexec-bar" ];
65       };
67       # The wrapper for executable files should add path to dconf GIO module.
68       basic-contains-dconf = let
69         tested = basic;
70       in testLib.runTest "basic-contains-dconf" (
71         testLib.skip stdenv.hostPlatform.isDarwin ''
72           ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GIO_EXTRA_MODULES" "${dconf.lib}/lib/gio/modules"}
73           ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GIO_EXTRA_MODULES" "${dconf.lib}/lib/gio/modules"}
74         ''
75       );
77       basic-contains-gdk-pixbuf = let
78         tested = basic;
79       in testLib.runTest "basic-contains-gdk-pixbuf" (
80         testLib.skip stdenv.hostPlatform.isDarwin ''
81           ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GDK_PIXBUF_MODULE_FILE" "${lib.getLib librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"}
82           ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GDK_PIXBUF_MODULE_FILE" "${lib.getLib librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"}
83         ''
84       );
86       # Simple derivation containing a gobject-introspection typelib.
87       typelib-Mahjong = stdenv.mkDerivation {
88         name = "typelib-Mahjong";
90         src = sample-project;
92         strictDeps = true;
94         installFlags = [ "typelib-Mahjong" ];
95       };
97       # Simple derivation using a typelib.
98       typelib-user = stdenv.mkDerivation {
99         name = "typelib-user";
101         src = sample-project;
103         strictDeps = true;
104         nativeBuildInputs = [
105           gobject-introspection
106           wrapGAppsHook3
107         ];
109         buildInputs = [
110           typelib-Mahjong
111         ];
113         installFlags = [ "bin-foo" "libexec-bar" ];
114       };
116       # Testing cooperation with gobject-introspection setup hook,
117       # which should populate GI_TYPELIB_PATH variable with paths
118       # to typelibs among the derivation’s dependencies.
119       # The resulting GI_TYPELIB_PATH should be picked up by the wrapper.
120       typelib-user-has-gi-typelib-path = let
121         tested = typelib-user;
122       in testLib.runTest "typelib-user-has-gi-typelib-path" ''
123         ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH" "${typelib-Mahjong}/lib/girepository-1.0"}
124         ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH" "${typelib-Mahjong}/lib/girepository-1.0"}
125       '';
127       # Simple derivation containing a gobject-introspection typelib in lib output.
128       typelib-Bechamel = stdenv.mkDerivation {
129         name = "typelib-Bechamel";
131         outputs = [ "out" "lib" ];
133         src = sample-project;
135         strictDeps = true;
137         makeFlags = [
138           "LIBDIR=${placeholder "lib"}/lib"
139         ];
141         installFlags = [ "typelib-Bechamel" ];
142       };
144       # Simple derivation using a typelib from non-default output.
145       typelib-multiout-user = stdenv.mkDerivation {
146         name = "typelib-multiout-user";
148         src = sample-project;
150         strictDeps = true;
151         nativeBuildInputs = [
152           gobject-introspection
153           wrapGAppsHook3
154         ];
156         buildInputs = [
157           typelib-Bechamel
158         ];
160         installFlags = [ "bin-foo" "libexec-bar" ];
161       };
163       # Testing cooperation with gobject-introspection setup hook,
164       # which should populate GI_TYPELIB_PATH variable with paths
165       # to typelibs among the derivation’s dependencies,
166       # even when they are not in default output.
167       # The resulting GI_TYPELIB_PATH should be picked up by the wrapper.
168       typelib-multiout-user-has-gi-typelib-path = let
169         tested = typelib-multiout-user;
170       in testLib.runTest "typelib-multiout-user-has-gi-typelib-path" ''
171         ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH" "${typelib-Bechamel.lib}/lib/girepository-1.0"}
172         ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH" "${typelib-Bechamel.lib}/lib/girepository-1.0"}
173       '';
175       # Simple derivation that contains a typelib as well as a program using it.
176       typelib-self-user = stdenv.mkDerivation {
177         name = "typelib-self-user";
179         src = sample-project;
181         strictDeps = true;
182         nativeBuildInputs = [
183           gobject-introspection
184           wrapGAppsHook3
185         ];
187         installFlags = [ "typelib-Cow" "bin-foo" "libexec-bar" ];
188       };
190       # Testing cooperation with gobject-introspection setup hook,
191       # which should add the path to derivation’s own typelibs
192       # to GI_TYPELIB_PATH variable.
193       # The resulting GI_TYPELIB_PATH should be picked up by the wrapper.
194       # https://github.com/NixOS/nixpkgs/issues/85515
195       typelib-self-user-has-gi-typelib-path = let
196         tested = typelib-self-user;
197       in testLib.runTest "typelib-self-user-has-gi-typelib-path" ''
198         ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH" "${typelib-self-user}/lib/girepository-1.0"}
199         ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH" "${typelib-self-user}/lib/girepository-1.0"}
200       '';
201     };
202   };
203 } ./wrap-gapps-hook.sh