1{
2 lib,
3 stdenv,
4 fetchurl,
5 replaceVars,
6 gettext,
7 pkg-config,
8 dbus,
9 gitUpdater,
10 libuuid,
11 polkit,
12 gnutls,
13 ppp,
14 dhcpcd,
15 iptables,
16 nftables,
17 python3,
18 vala,
19 libgcrypt,
20 dnsmasq,
21 bluez5,
22 readline,
23 libselinux,
24 audit,
25 gobject-introspection,
26 perl,
27 modemmanager,
28 openresolv,
29 libndp,
30 newt,
31 ethtool,
32 gnused,
33 iputils,
34 kmod,
35 jansson,
36 elfutils,
37 gtk-doc,
38 libxslt,
39 docbook_xsl,
40 docbook_xml_dtd_412,
41 docbook_xml_dtd_42,
42 docbook_xml_dtd_43,
43 curl,
44 meson,
45 mesonEmulatorHook,
46 ninja,
47 libpsl,
48 mobile-broadband-provider-info,
49 runtimeShell,
50 buildPackages,
51 nixosTests,
52 systemd,
53 udev,
54 udevCheckHook,
55 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
56}:
57
58let
59 pythonForDocs = python3.pythonOnBuildForHost.withPackages (pkgs: with pkgs; [ pygobject3 ]);
60in
61stdenv.mkDerivation (finalAttrs: {
62 pname = "networkmanager";
63 version = "1.52.1";
64
65 src = fetchurl {
66 url = "https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/releases/${finalAttrs.version}/downloads/NetworkManager-${finalAttrs.version}.tar.xz";
67 hash = "sha256-ixIsc0k6cvK65SfBJc69h3EWcbkDUtvisXiKupV1rG8=";
68 };
69
70 outputs = [
71 "out"
72 "dev"
73 "devdoc"
74 "man"
75 "doc"
76 ];
77
78 # Right now we hardcode quite a few paths at build time. Probably we should
79 # patch networkmanager to allow passing these path in config file. This will
80 # remove unneeded build-time dependencies.
81 mesonFlags = [
82 # System paths
83 "--sysconfdir=/etc"
84 "--localstatedir=/var"
85 (lib.mesonOption "systemdsystemunitdir" (
86 if withSystemd then "${placeholder "out"}/etc/systemd/system" else "no"
87 ))
88 # to enable link-local connections
89 "-Dudev_dir=${placeholder "out"}/lib/udev"
90 "-Ddbus_conf_dir=${placeholder "out"}/share/dbus-1/system.d"
91 "-Dkernel_firmware_dir=/run/current-system/firmware"
92
93 # Platform
94 "-Dmodprobe=${kmod}/bin/modprobe"
95 (lib.mesonOption "session_tracking" (if withSystemd then "systemd" else "no"))
96 (lib.mesonBool "systemd_journal" withSystemd)
97 "-Dlibaudit=yes-disabled-by-default"
98 "-Dpolkit_agent_helper_1=/run/wrappers/bin/polkit-agent-helper-1"
99
100 # Features
101 # Allow using iwd when configured to do so
102 "-Diwd=true"
103 "-Dpppd=${ppp}/bin/pppd"
104 "-Diptables=${iptables}/bin/iptables"
105 "-Dnft=${nftables}/bin/nft"
106 "-Dmodem_manager=true"
107 "-Dnmtui=true"
108 "-Ddnsmasq=${dnsmasq}/bin/dnsmasq"
109 "-Dqt=false"
110
111 # Handlers
112 "-Dresolvconf=${openresolv}/bin/resolvconf"
113
114 # DHCP clients
115 "-Ddhcpcd=${dhcpcd}/bin/dhcpcd"
116
117 # Miscellaneous
118 # almost cross-compiles, however fails with
119 # ** (process:9234): WARNING **: Failed to load shared library '/nix/store/...-networkmanager-aarch64-unknown-linux-gnu-1.38.2/lib/libnm.so.0' referenced by the typelib: /nix/store/...-networkmanager-aarch64-unknown-linux-gnu-1.38.2/lib/libnm.so.0: cannot open shared object file: No such file or directory
120 "-Ddocs=${lib.boolToString (stdenv.buildPlatform == stdenv.hostPlatform)}"
121 # We don't use firewalld in NixOS
122 "-Dfirewalld_zone=false"
123 "-Dtests=no"
124 "-Dcrypto=gnutls"
125 "-Dmobile_broadband_provider_info_database=${mobile-broadband-provider-info}/share/mobile-broadband-provider-info/serviceproviders.xml"
126 ];
127
128 patches = [
129 (replaceVars ./fix-paths.patch {
130 inherit
131 iputils
132 ethtool
133 gnused
134 ;
135 inherit runtimeShell;
136 })
137
138 # Meson does not support using different directories during build and
139 # for installation like Autotools did with flags passed to make install.
140 ./fix-install-paths.patch
141 ];
142
143 buildInputs = [
144 (if withSystemd then systemd else udev)
145 libselinux
146 audit
147 libpsl
148 libuuid
149 polkit
150 ppp
151 libndp
152 curl
153 mobile-broadband-provider-info
154 bluez5
155 dnsmasq
156 modemmanager
157 readline
158 newt
159 jansson
160 dbus # used to get directory paths with pkg-config during configuration
161 ];
162
163 propagatedBuildInputs = [
164 gnutls
165 libgcrypt
166 ];
167
168 nativeBuildInputs = [
169 meson
170 ninja
171 gettext
172 pkg-config
173 vala
174 gobject-introspection
175 perl
176 elfutils # used to find jansson soname
177 # Docs
178 gtk-doc
179 libxslt
180 docbook_xsl
181 docbook_xml_dtd_412
182 docbook_xml_dtd_42
183 docbook_xml_dtd_43
184 pythonForDocs
185 udevCheckHook
186 ]
187 ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
188 mesonEmulatorHook
189 ];
190
191 doCheck = false; # requires /sys, the net
192
193 postPatch = ''
194 patchShebangs ./tools
195 patchShebangs libnm/generate-setting-docs.py
196
197 # TODO: submit upstream
198 substituteInPlace meson.build \
199 --replace "'vala', req" "'vala', native: false, req"
200 ''
201 + lib.optionalString withSystemd ''
202 substituteInPlace data/NetworkManager.service.in \
203 --replace-fail /usr/bin/busctl ${systemd}/bin/busctl
204 '';
205
206 preBuild = ''
207 # Our gobject-introspection patches make the shared library paths absolute
208 # in the GIR files. When building docs, the library is not yet installed,
209 # though, so we need to replace the absolute path with a local one during build.
210 # We are using a symlink that will be overridden during installation.
211 mkdir -p ${placeholder "out"}/lib
212 ln -s $PWD/src/libnm-client-impl/libnm.so.0 ${placeholder "out"}/lib/libnm.so.0
213 '';
214
215 postFixup = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
216 cp -r ${buildPackages.networkmanager.devdoc} $devdoc
217 cp -r ${buildPackages.networkmanager.man} $man
218 '';
219
220 doInstallCheck = true;
221
222 passthru = {
223 updateScript = gitUpdater {
224 odd-unstable = true;
225 url = "https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git";
226 };
227 tests = {
228 inherit (nixosTests.networking) networkmanager;
229 };
230 };
231
232 meta = with lib; {
233 homepage = "https://networkmanager.dev";
234 description = "Network configuration and management tool";
235 license = licenses.gpl2Plus;
236 changelog = "https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/raw/${version}/NEWS";
237 maintainers = with maintainers; [
238 obadz
239 ];
240 teams = [ teams.freedesktop ];
241 platforms = platforms.linux;
242 badPlatforms = [
243 # Mandatory shared libraries.
244 lib.systems.inspect.platformPatterns.isStatic
245 ];
246 };
247})