summary refs log tree commit diff
path: root/pkgs/by-name/co/connman/package.nix
blob: a90fb1ffd727a41b95ccce327914eee8dfe53afe (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
{ lib
, stdenv
, fetchurl
, fetchpatch
, autoreconfHook
, dbus
, file
, glib
, gnutls
, iptables
, libmnl
, libnftnl # for nftables
, nixosTests
, openconnect
, openvpn
, pkg-config
, polkit
, ppp
, pptp
, readline
, vpnc
, dnsType ? "internal" # or "systemd-resolved"
, enableBluetooth ? true
, enableClient ? true
, enableDatafiles ? true
, enableDundee ? true
, enableEthernet ? true
, enableGadget ? true
, enableHh2serialGps ? false
, enableIospm ? false
, enableL2tp ? false
, enableLoopback ? true
, enableNeard ? true
, enableNetworkManager ? null
, enableNetworkManagerCompatibility ?
  if enableNetworkManager == null
  then false
  else lib.warn "enableNetworkManager option is deprecated; use enableNetworkManagerCompatibility instead" enableNetworkManager
, enableOfono ? true
, enableOpenconnect ? true
, enableOpenvpn ? true
, enablePacrunner ? true
, enablePolkit ? true
, enablePptp ? true
, enableStats ? true
, enableTist ? false
, enableTools ? true
, enableVpnc ? true
, enableWifi ? true
, enableWireguard ? true
, enableWispr ? true
, firewallType ? "iptables" # or "nftables"
}:

let
  inherit (lib)
    enableFeature
    enableFeatureAs
    optionals
    withFeatureAs;
in
assert lib.asserts.assertOneOf "firewallType" firewallType [ "iptables" "nftables" ];
assert lib.asserts.assertOneOf "dnsType" dnsType [ "internal" "systemd-resolved" ];
stdenv.mkDerivation (finalAttrs: {
  pname = "connman";
  version = "1.42";

  src = fetchurl {
    url = "mirror://kernel/linux/network/connman/connman-${finalAttrs.version}.tar.xz";
    hash = "sha256-o+a65G/Age8una48qk92Sd6JLD3mIsICg6wMqBQjwqo=";
  };

  patches = [
    # simply the middle section of upstream commit a48864a2e5d2a725dfc6eef567108bc13b43857f
    # dist tarball is broken, hence this patch as a workaround
    ./create-libppp-compat.h.patch
  ] ++ optionals stdenv.hostPlatform.isMusl [
    # Fix Musl build by avoiding a Glibc-only API.
    (fetchurl {
      url = "https://git.alpinelinux.org/aports/plain/community/connman/libresolv.patch?id=e393ea84386878cbde3cccadd36a30396e357d1e";
      hash = "sha256-7Q1bp8rD/gGVYUqnIXqjr9vypR8jlC926p3KYWl9kLw=";
    })
  ];

  nativeBuildInputs = [
    autoreconfHook
    file
    pkg-config
  ];

  buildInputs = [
    glib
    dbus
    libmnl
    gnutls
    readline
  ]
  ++ optionals (firewallType == "iptables") [ iptables ]
  ++ optionals (firewallType == "nftables") [ libnftnl ]
  ++ optionals (enableOpenconnect) [ openconnect ]
  ++ optionals (enablePolkit) [ polkit ]
  ++ optionals (enablePptp) [ pptp ppp ]
  ;

  postPatch = ''
    sed -i "s@/usr/bin/file@file@g" ./configure
  '';

  configureFlags = [
    # directories flags
    "--sysconfdir=/etc"
    "--localstatedir=/var"
  ] ++ [
    # production build flags
    (enableFeature false "maintainer-mode")
    (enableFeatureAs true "session-policy-local" "builtin")
    # for building and running tests
    # (enableFeature true "tests") # installs the tests, we don't want that
    (enableFeature true "tools")
    (enableFeature enableLoopback "loopback")
    (enableFeature enableEthernet "ethernet")
    (enableFeature enableWireguard "wireguard")
    (enableFeature enableGadget "gadget")
    (enableFeature enableWifi "wifi")
    # enable IWD support for wifi as it doesn't require any new dependencies and
    # it's easier for the NixOS module to use only one connman package when IWD
    # is requested
    (enableFeature enableWifi "iwd")
    (enableFeature enableBluetooth "bluetooth")
    (enableFeature enableOfono "ofono")
    (enableFeature enableDundee "dundee")
    (enableFeature enablePacrunner "pacrunner")
    (enableFeature enableNeard "neard")
    (enableFeature enableWispr "wispr")
    (enableFeature enableTools "tools")
    (enableFeature enableStats "stats")
    (enableFeature enableClient "client")
    (enableFeature enableDatafiles "datafiles")
    (enableFeature enablePolkit "polkit")
    (enableFeature enablePptp "pptp")
    (enableFeature enableWireguard "wireguard")
    (enableFeature enableNetworkManagerCompatibility "nmcompat")
    (enableFeature enableHh2serialGps "hh2serial-gps")
    (enableFeature enableL2tp "l2tp")
    (enableFeature enableIospm "iospm")
    (enableFeature enableTist "tist")
  ] ++ [
    (enableFeatureAs enableOpenconnect "openconnect" "builtin")
    (enableFeatureAs enableOpenvpn "openvpn" "builtin")
    (enableFeatureAs enableVpnc "vpnc" "builtin")
  ] ++ [
    (withFeatureAs true "dbusconfdir" "${placeholder "out"}/share")
    (withFeatureAs true "dbusdatadir" "${placeholder "out"}/share")
    (withFeatureAs true "tmpfilesdir" "${placeholder "out"}/tmpfiles.d")
    (withFeatureAs true "systemdunitdir" "${placeholder "out"}/systemd/system")
    (withFeatureAs true "dns-backend" "${dnsType}")
    (withFeatureAs true "firewall" "${firewallType}")
    (withFeatureAs enableOpenconnect "openconnect" "${openconnect}/sbin/openconnect")
    (withFeatureAs enableOpenvpn "openvpn" "${openvpn}/sbin/openvpn")
    (withFeatureAs enableVpnc "vpnc" "${vpnc}/sbin/vpnc")
    (withFeatureAs enablePptp "pptp" "${pptp}/sbin/pptp")
  ];

  doCheck = true;

  passthru.tests.connman = nixosTests.connman;

  meta = {
    description = "A daemon for managing internet connections";
    homepage = "https://git.kernel.org/pub/scm/network/connman/connman.git/about/";
    license = lib.licenses.gpl2Only;
    mainProgram = "connmanctl";
    maintainers = with lib.maintainers; [ eclairevoyant AndersonTorres ];
    platforms = lib.platforms.linux;
  };
})