From 69b89979ba52709d5df17a6b728d796bd366aa2e Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Apr 2020 15:02:25 +0200 Subject: [PATCH 1/3] wrapGAppsHook: move to a separate file --- .../setup-hooks/wrap-gapps-hook/default.nix | 16 ++++++++++++++++ .../{ => wrap-gapps-hook}/wrap-gapps-hook.sh | 0 pkgs/top-level/all-packages.nix | 4 +--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix rename pkgs/build-support/setup-hooks/{ => wrap-gapps-hook}/wrap-gapps-hook.sh (100%) diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix new file mode 100644 index 000000000000..83e4cd93c197 --- /dev/null +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix @@ -0,0 +1,16 @@ +{ stdenv +, lib +, makeSetupHook +, makeWrapper +, gtk3 +, librsvg +, dconf +}: + +makeSetupHook { + deps = lib.optional (!stdenv.isDarwin) dconf.lib ++ [ + gtk3 + librsvg + makeWrapper + ]; +} ./wrap-gapps-hook.sh diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook.sh b/pkgs/build-support/setup-hooks/wrap-gapps-hook/wrap-gapps-hook.sh similarity index 100% rename from pkgs/build-support/setup-hooks/wrap-gapps-hook.sh rename to pkgs/build-support/setup-hooks/wrap-gapps-hook/wrap-gapps-hook.sh diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5e397bf15562..7204ec17c553 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -502,9 +502,7 @@ in findXMLCatalogs = makeSetupHook { } ../build-support/setup-hooks/find-xml-catalogs.sh; - wrapGAppsHook = makeSetupHook { - deps = lib.optional (!stdenv.isDarwin) dconf.lib ++ [ gtk3 librsvg makeWrapper ]; - } ../build-support/setup-hooks/wrap-gapps-hook.sh; + wrapGAppsHook = callPackage ../build-support/setup-hooks/wrap-gapps-hook { }; separateDebugInfo = makeSetupHook { } ../build-support/setup-hooks/separate-debug-info.sh; From 49b89afcc22ba91265beddcbfd4b1fd5393c3512 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Apr 2020 21:17:45 +0200 Subject: [PATCH 2/3] wrapGAppsHook: add tests --- .../setup-hooks/wrap-gapps-hook/default.nix | 142 ++++++++++++++++++ .../setup-hooks/wrap-gapps-hook/tests/lib.nix | 30 ++++ .../tests/sample-project/Makefile | 30 ++++ 3 files changed, 202 insertions(+) create mode 100644 pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/lib.nix create mode 100644 pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/sample-project/Makefile diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix index 83e4cd93c197..50ef9b0f70d0 100644 --- a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix @@ -2,9 +2,13 @@ , lib , makeSetupHook , makeWrapper +, gobject-introspection , gtk3 , librsvg , dconf +, callPackage +, wrapGAppsHook +, writeTextFile }: makeSetupHook { @@ -13,4 +17,142 @@ makeSetupHook { librsvg makeWrapper ]; + substitutions = { + passthru.tests = let + sample-project = ./tests/sample-project; + + testLib = callPackage ./tests/lib.nix { }; + inherit (testLib) expectSomeLineContainingYInFileXToMentionZ; + in rec { + # Simple derivation containing a program and a daemon. + basic = stdenv.mkDerivation { + name = "basic"; + + src = sample-project; + + nativeBuildInputs = [ wrapGAppsHook ]; + + installFlags = [ "bin-foo" "libexec-bar" ]; + }; + + # The wrapper for executable files should add path to dconf GIO module. + basic-contains-dconf = let + tested = basic; + in testLib.runTest "basic-contains-dconf" ( + testLib.skip stdenv.isDarwin '' + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GIO_EXTRA_MODULES=" "${dconf.lib}/lib/gio/modules"} + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GIO_EXTRA_MODULES=" "${dconf.lib}/lib/gio/modules"} + '' + ); + + # Simple derivation containing a gobject-introspection typelib. + typelib-Mahjong = stdenv.mkDerivation { + name = "typelib-Mahjong"; + + src = sample-project; + + installFlags = [ "typelib-Mahjong" ]; + }; + + # Simple derivation using a typelib. + typelib-user = stdenv.mkDerivation { + name = "typelib-user"; + + src = sample-project; + + nativeBuildInputs = [ + gobject-introspection + wrapGAppsHook + ]; + + buildInputs = [ + typelib-Mahjong + ]; + + installFlags = [ "bin-foo" "libexec-bar" ]; + }; + + # Testing cooperation with gobject-introspection setup hook, + # which should populate GI_TYPELIB_PATH variable with paths + # to typelibs among the derivation’s dependencies. + # The resulting GI_TYPELIB_PATH should be picked up by the wrapper. + typelib-user-has-gi-typelib-path = let + tested = typelib-user; + in testLib.runTest "typelib-user-has-gi-typelib-path" '' + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH=" "${typelib-Mahjong}/lib/girepository-1.0"} + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH=" "${typelib-Mahjong}/lib/girepository-1.0"} + ''; + + # Simple derivation containing a gobject-introspection typelib in lib output. + typelib-Bechamel = stdenv.mkDerivation { + name = "typelib-Bechamel"; + + outputs = [ "out" "lib" ]; + + src = sample-project; + + makeFlags = [ + "LIBDIR=${placeholder "lib"}/lib" + ]; + + installFlags = [ "typelib-Bechamel" ]; + }; + + # Simple derivation using a typelib from non-default output. + typelib-multiout-user = stdenv.mkDerivation { + name = "typelib-multiout-user"; + + src = sample-project; + + nativeBuildInputs = [ + gobject-introspection + wrapGAppsHook + ]; + + buildInputs = [ + typelib-Bechamel + ]; + + installFlags = [ "bin-foo" "libexec-bar" ]; + }; + + # Testing cooperation with gobject-introspection setup hook, + # which should populate GI_TYPELIB_PATH variable with paths + # to typelibs among the derivation’s dependencies, + # even when they are not in default output. + # The resulting GI_TYPELIB_PATH should be picked up by the wrapper. + typelib-multiout-user-has-gi-typelib-path = let + tested = typelib-multiout-user; + in testLib.runTest "typelib-multiout-user-has-gi-typelib-path" '' + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH=" "${typelib-Bechamel.lib}/lib/girepository-1.0"} + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH=" "${typelib-Bechamel.lib}/lib/girepository-1.0"} + ''; + + # Simple derivation that contains a typelib as well as a program using it. + typelib-self-user = stdenv.mkDerivation { + name = "typelib-self-user"; + + src = sample-project; + + nativeBuildInputs = [ + gobject-introspection + wrapGAppsHook + ]; + + installFlags = [ "typelib-Cow" "bin-foo" "libexec-bar" ]; + }; + + # Testing cooperation with gobject-introspection setup hook, + # which should add the path to derivation’s own typelibs + # to GI_TYPELIB_PATH variable. + # The resulting GI_TYPELIB_PATH should be picked up by the wrapper. + # https://github.com/NixOS/nixpkgs/issues/85515 + typelib-self-user-has-gi-typelib-path = let + tested = typelib-self-user; + in testLib.runTest "typelib-self-user-has-gi-typelib-path" '' + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/bin/foo" "GI_TYPELIB_PATH=" "${typelib-self-user}/lib/girepository-1.0"} + ${expectSomeLineContainingYInFileXToMentionZ "${tested}/libexec/bar" "GI_TYPELIB_PATH=" "${typelib-self-user}/lib/girepository-1.0"} + ''; + }; + }; } ./wrap-gapps-hook.sh diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/lib.nix b/pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/lib.nix new file mode 100644 index 000000000000..1757bdbbe250 --- /dev/null +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/lib.nix @@ -0,0 +1,30 @@ +{ runCommand +}: + +rec { + runTest = name: body: runCommand name { } '' + set -o errexit + ${body} + touch $out + ''; + + skip = cond: text: + if cond then '' + echo "Skipping test $name" > /dev/stderr + '' else text; + + fail = text: '' + echo "FAIL: $name: ${text}" > /dev/stderr + exit 1 + ''; + + expectSomeLineContainingYInFileXToMentionZ = file: filter: expected: '' + if ! cat "${file}" | grep "${filter}"; then + ${fail "The file “${file}” should include a line containing “${filter}”."} + fi + + if ! cat "${file}" | grep "${filter}" | grep ${expected}; then + ${fail "The file “${file}” should include a line containing “${filter}” that also contains “${expected}”."} + fi + ''; +} diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/sample-project/Makefile b/pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/sample-project/Makefile new file mode 100644 index 000000000000..5d234db11a0b --- /dev/null +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook/tests/sample-project/Makefile @@ -0,0 +1,30 @@ +PREFIX = $(out) +BINDIR = $(PREFIX)/bin +LIBEXECDIR = $(PREFIX)/libexec +LIBDIR = $(PREFIX)/lib +TYPELIBDIR = $(LIBDIR)/girepository-1.0 + +all: + echo "Compiling…" +install: + echo "Installing…" + +bin: + mkdir -p $(BINDIR) +# Adds `bin-${foo}` targets, that install `${foo}` executable to `$(BINDIR)`. +bin-%: bin + touch $(BINDIR)/$(@:bin-%=%) + chmod +x $(BINDIR)/$(@:bin-%=%) + +libexec: + mkdir -p $(LIBEXECDIR) +# Adds `libexec-${foo}` targets, that install `${foo}` executable to `$(LIBEXECDIR)`. +libexec-%: libexec + touch $(LIBEXECDIR)/$(@:libexec-%=%) + chmod +x $(LIBEXECDIR)/$(@:libexec-%=%) + +typelib: + mkdir -p $(TYPELIBDIR) +# Adds `typelib-${foo}` targets, that install `${foo}-1.0.typelib` file to `$(TYPELIBDIR)`. +typelib-%: typelib + touch $(TYPELIBDIR)/$(@:typelib-%=%)-1.0.typelib From 0be3b18d3e172549b25acf504d31daea541acc84 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 24 Jul 2020 00:36:12 +0200 Subject: [PATCH 3/3] wrapGAppsHook: add comments --- .../setup-hooks/wrap-gapps-hook/default.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix index 50ef9b0f70d0..5a87893d9726 100644 --- a/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix +++ b/pkgs/build-support/setup-hooks/wrap-gapps-hook/default.nix @@ -12,9 +12,26 @@ }: makeSetupHook { - deps = lib.optional (!stdenv.isDarwin) dconf.lib ++ [ + deps = lib.optionals (!stdenv.isDarwin) [ + # It is highly probable that a program will use GSettings, + # at minimum through GTK file chooser dialogue. + # Let’s add a GIO module for “dconf” GSettings backend + # to avoid falling back to “memory” backend. This is + # required for GSettings-based settings to be persisted. + # Unfortunately, it also requires the user to have dconf + # D-Bus service enabled globally (e.g. through a NixOS module). + dconf.lib + ] ++ [ + # TODO: remove this, packages should depend on GTK explicitly. gtk3 + + # librsvg provides a module for gdk-pixbuf to allow rendering + # SVG icons. Most icon themes are SVG-based and so are some + # graphics in GTK (e.g. cross for closing window in window title bar) + # so it is pretty much required for applications using GTK. librsvg + + # We use the wrapProgram function. makeWrapper ]; substitutions = {