about summary refs log tree commit diff
path: root/pkgs/applications/radio/gnuradio/wrapper.nix
blob: ac08d17397fa7596c34d104c78bf7e91591fec02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{ lib
, stdenv
# The unwrapped gnuradio derivation
, unwrapped
# If it's a minimal build, we don't want to wrap it with lndir and
# wrapProgram..
, doWrap ? true
# For the wrapper
, makeWrapper
# For lndir
, xorg
# To define a the gnuradio.pkgs scope
, newScope
# For Emulating wrapGAppsHook
, gsettings-desktop-schemas
, glib
, hicolor-icon-theme
, pango
, json-glib
, dconf
, gobject-introspection
, librsvg
, gdk-pixbuf
, harfbuzz
, at-spi2-core
, atk
# For Adding additional GRC blocks
, extraPackages ? []
# For Adding additional python packaages
, extraPythonPackages ? []
, soapysdr # For it's passthru.searchPath
# soapysdr plugins we add by default. Ideally, we should have a
# soapysdrPackages = soapysdr.pkgs attribute set, but until now this wasn't
# crucial.
, soapyairspy
, soapyaudio
, soapybladerf
, soapyhackrf
, soapyremote
, soapyrtlsdr
, soapyuhd
# For adding / changing soapysdr packages, like soapsdr-with-plugins does
, extraSoapySdrPackages ? [
  soapyairspy
  soapyaudio
  soapybladerf
  soapyhackrf
  soapyremote
  soapyrtlsdr
  soapyuhd
]
# Allow to add whatever you want to the wrapper
, extraMakeWrapperArgs ? []
}:

let
  # We don't check if `python-support` feature is on, as it's unlikely someone
  # may wish to wrap GR without python support.
  pythonPkgs = extraPythonPackages
    ++ [ (unwrapped.python.pkgs.toPythonModule unwrapped) ]
    # Add the extraPackages as python modules as well
    ++ (builtins.map unwrapped.python.pkgs.toPythonModule extraPackages)
    ++ lib.flatten (lib.mapAttrsToList (
      feat: info: (
        lib.optionals ((unwrapped.hasFeature feat) && (builtins.hasAttr "pythonRuntime" info)) info.pythonRuntime
      )
    ) unwrapped.featuresInfo)
  ;
  pythonEnv = unwrapped.python.withPackages(ps: pythonPkgs);

  pname = unwrapped.pname + "-wrapped";
  inherit (unwrapped) version;
  makeWrapperArgs = builtins.concatStringsSep " " ([
  ]
    # Emulating wrapGAppsHook & wrapQtAppsHook working together
    ++ lib.optionals (
      (unwrapped.hasFeature "gnuradio-companion")
      || (unwrapped.hasFeature "gr-qtgui")
      ) [
      "--prefix" "XDG_DATA_DIRS" ":" "$out/share"
      "--prefix" "XDG_DATA_DIRS" ":" "$out/share/gsettings-schemas/${pname}"
      "--prefix" "XDG_DATA_DIRS" ":" "${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
      "--prefix" "XDG_DATA_DIRS" ":" "${hicolor-icon-theme}/share"
      # Needs to run `gsettings` on startup, see:
      # https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1764890.html
      "--prefix" "PATH" ":" "${lib.getBin glib}/bin"
    ]
    ++ lib.optionals (unwrapped.hasFeature "gnuradio-companion") [
      "--set" "GDK_PIXBUF_MODULE_FILE" "${librsvg}/${gdk-pixbuf.moduleDir}.cache"
      "--prefix" "GIO_EXTRA_MODULES" ":" "${lib.getLib dconf}/lib/gio/modules"
      "--prefix" "XDG_DATA_DIRS" ":" "${unwrapped.gtk}/share"
      "--prefix" "XDG_DATA_DIRS" ":" "${unwrapped.gtk}/share/gsettings-schemas/${unwrapped.gtk.name}"
      "--prefix" "GI_TYPELIB_PATH" ":" "${lib.makeSearchPath "lib/girepository-1.0" [
        unwrapped.gtk
        gsettings-desktop-schemas
        atk
        # From some reason, if .out is not used, .bin is used, and we want
        # what's in `.out`.
        pango.out
        gdk-pixbuf
        json-glib
        harfbuzz
        librsvg
        gobject-introspection
        at-spi2-core
      ]}"
    ]
    ++ lib.optionals (extraPackages != []) [
      "--prefix" "GRC_BLOCKS_PATH" ":" "${lib.makeSearchPath "share/gnuradio/grc/blocks" extraPackages}"
    ]
    ++ lib.optionals (extraSoapySdrPackages != []) [
      "--prefix" "SOAPY_SDR_PLUGIN_PATH" ":" "${lib.makeSearchPath
      soapysdr.passthru.searchPath extraSoapySdrPackages}"
    ]
    ++ lib.optionals (unwrapped.hasFeature "gr-qtgui")
      # 3.7 builds with qt4
      (if lib.versionAtLeast unwrapped.versionAttr.major "3.8" then
        [
          "--prefix" "QT_PLUGIN_PATH" ":"
          "${
            lib.makeSearchPath
            unwrapped.qt.qtbase.qtPluginPrefix
            (builtins.map lib.getBin ([
              unwrapped.qt.qtbase
            ] ++ lib.optionals stdenv.isLinux [
              unwrapped.qt.qtwayland
            ]))
          }"
          "--prefix" "QML2_IMPORT_PATH" ":"
          "${
            lib.makeSearchPath
            unwrapped.qt.qtbase.qtQmlPrefix
            (builtins.map lib.getBin ([
              unwrapped.qt.qtbase
            ] ++ lib.optionals stdenv.isLinux [
              unwrapped.qt.qtwayland
            ]))
          }"
        ]
      else
        # Add here qt4 related environment for 3.7?
        [

        ]
      )
    ++ extraMakeWrapperArgs
  );

  packages = import ../../../top-level/gnuradio-packages.nix {
    inherit lib stdenv newScope;
    gnuradio = unwrapped;
  };
  passthru = unwrapped.passthru // {
    inherit
      pythonEnv
      pythonPkgs
      unwrapped
    ;
    pkgs = packages;
  };
  self = if doWrap then
    stdenv.mkDerivation {
      inherit pname version passthru;
      nativeBuildInputs = [ makeWrapper ];
      buildInputs = [
        xorg.lndir
      ];
      buildCommand = ''
        mkdir $out
        cd $out
        lndir -silent ${unwrapped}
        ${lib.optionalString
          (extraPackages != [])
          (builtins.concatStringsSep "\n"
            (builtins.map (pkg: ''
              if [[ -d ${lib.getBin pkg}/bin/ ]]; then
                lndir -silent ${pkg}/bin ./bin
              fi
            '') extraPackages)
          )
        }
        for i in $out/bin/*; do
          if [[ ! -x "$i" ]]; then
            continue
          fi
          cp -L "$i" "$i".tmp
          mv -f "$i".tmp "$i"
          if head -1 "$i" | grep -q ${unwrapped.python}; then
            substituteInPlace "$i" \
              --replace ${unwrapped.python} ${pythonEnv}
          fi
          wrapProgram "$i" ${makeWrapperArgs}
        done
      '';
      inherit (unwrapped) meta;
    }
  else
    unwrapped.overrideAttrs(_: {
      inherit passthru;
    })
  ;
in self