1{ lib
2, stdenv
3, fetchurl
4, substituteAll
5, gettext
6, pkg-config
7, dbus
8, gnome
9, systemd
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, libsoup
32, ethtool
33, gnused
34, iputils
35, kmod
36, jansson
37, elfutils
38, gtk-doc
39, libxslt
40, docbook_xsl
41, docbook_xml_dtd_412
42, docbook_xml_dtd_42
43, docbook_xml_dtd_43
44, openconnect
45, curl
46, meson
47, mesonEmulatorHook
48, ninja
49, libpsl
50, mobile-broadband-provider-info
51, runtimeShell
52, buildPackages
53}:
54
55let
56 pythonForDocs = python3.pythonForBuild.withPackages (pkgs: with pkgs; [ pygobject3 ]);
57in
58stdenv.mkDerivation rec {
59 pname = "networkmanager";
60 version = "1.42.8";
61
62 src = fetchurl {
63 url = "mirror://gnome/sources/NetworkManager/${lib.versions.majorMinor version}/NetworkManager-${version}.tar.xz";
64 sha256 = "sha256-AzfnWD0uxa3iui6MYl0vCe7M2h0ig27imqcpJdOZw1M=";
65 };
66
67 outputs = [ "out" "dev" "devdoc" "man" "doc" ];
68
69 # Right now we hardcode quite a few paths at build time. Probably we should
70 # patch networkmanager to allow passing these path in config file. This will
71 # remove unneeded build-time dependencies.
72 mesonFlags = [
73 # System paths
74 "--sysconfdir=/etc"
75 "--localstatedir=/var"
76 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system"
77 # to enable link-local connections
78 "-Dudev_dir=${placeholder "out"}/lib/udev"
79 "-Ddbus_conf_dir=${placeholder "out"}/share/dbus-1/system.d"
80 "-Dkernel_firmware_dir=/run/current-system/firmware"
81
82 # Platform
83 "-Dsession_tracking=systemd"
84 "-Dlibaudit=yes-disabled-by-default"
85 "-Dpolkit_agent_helper_1=/run/wrappers/bin/polkit-agent-helper-1"
86
87 # Features
88 # Allow using iwd when configured to do so
89 "-Diwd=true"
90 "-Dpppd=${ppp}/bin/pppd"
91 "-Diptables=${iptables}/bin/iptables"
92 "-Dnft=${nftables}/bin/nft"
93 "-Dmodem_manager=true"
94 "-Dnmtui=true"
95 "-Ddnsmasq=${dnsmasq}/bin/dnsmasq"
96 "-Dqt=false"
97
98 # Handlers
99 "-Dresolvconf=${openresolv}/bin/resolvconf"
100
101 # DHCP clients
102 # ISC DHCP client has reached it's end of life, so stop using it
103 "-Ddhclient=no"
104 "-Ddhcpcd=${dhcpcd}/bin/dhcpcd"
105 "-Ddhcpcanon=no"
106
107 # Miscellaneous
108 # almost cross-compiles, however fails with
109 # ** (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
110 "-Ddocs=${lib.boolToString (stdenv.buildPlatform == stdenv.hostPlatform)}"
111 # We don't use firewalld in NixOS
112 "-Dfirewalld_zone=false"
113 "-Dtests=no"
114 "-Dcrypto=gnutls"
115 "-Dmobile_broadband_provider_info_database=${mobile-broadband-provider-info}/share/mobile-broadband-provider-info/serviceproviders.xml"
116 ];
117
118 patches = [
119 (substituteAll {
120 src = ./fix-paths.patch;
121 inherit iputils kmod openconnect ethtool gnused systemd;
122 inherit runtimeShell;
123 })
124
125 # Meson does not support using different directories during build and
126 # for installation like Autotools did with flags passed to make install.
127 ./fix-install-paths.patch
128 ];
129
130 buildInputs = [
131 systemd
132 libselinux
133 audit
134 libpsl
135 libuuid
136 polkit
137 ppp
138 libndp
139 curl
140 mobile-broadband-provider-info
141 bluez5
142 dnsmasq
143 modemmanager
144 readline
145 newt
146 libsoup
147 jansson
148 dbus # used to get directory paths with pkg-config during configuration
149 ];
150
151 propagatedBuildInputs = [ gnutls libgcrypt ];
152
153 nativeBuildInputs = [
154 meson
155 ninja
156 gettext
157 pkg-config
158 vala
159 gobject-introspection
160 perl
161 elfutils # used to find jansson soname
162 # Docs
163 gtk-doc
164 libxslt
165 docbook_xsl
166 docbook_xml_dtd_412
167 docbook_xml_dtd_42
168 docbook_xml_dtd_43
169 pythonForDocs
170 ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
171 mesonEmulatorHook
172 ];
173
174 doCheck = false; # requires /sys, the net
175
176 postPatch = ''
177 patchShebangs ./tools
178 patchShebangs libnm/generate-setting-docs.py
179
180 # TODO: submit upstream
181 substituteInPlace meson.build \
182 --replace "'vala', req" "'vala', native: false, req"
183 '';
184
185 preBuild = ''
186 # Our gobject-introspection patches make the shared library paths absolute
187 # in the GIR files. When building docs, the library is not yet installed,
188 # though, so we need to replace the absolute path with a local one during build.
189 # We are using a symlink that will be overridden during installation.
190 mkdir -p ${placeholder "out"}/lib
191 ln -s $PWD/src/libnm-client-impl/libnm.so.0 ${placeholder "out"}/lib/libnm.so.0
192 '';
193
194 postFixup = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
195 cp -r ${buildPackages.networkmanager.devdoc} $devdoc
196 cp -r ${buildPackages.networkmanager.man} $man
197 '';
198
199 passthru = {
200 updateScript = gnome.updateScript {
201 packageName = "NetworkManager";
202 attrPath = "networkmanager";
203 versionPolicy = "odd-unstable";
204 };
205 };
206
207 meta = with lib; {
208 homepage = "https://wiki.gnome.org/Projects/NetworkManager";
209 description = "Network configuration and management tool";
210 license = licenses.gpl2Plus;
211 changelog = "https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/raw/${version}/NEWS";
212 maintainers = teams.freedesktop.members ++ (with maintainers; [ domenkozar obadz amaxine ]);
213 platforms = platforms.linux;
214 };
215}