about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/networking/miniupnpd/default.nix
blob: dabf5194f881ba9ade4d84bdad862f613be6bd1e (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
{ stdenv, lib, fetchurl, iptables-legacy, libuuid, openssl, pkg-config
, which, iproute2, gnused, coreutils, gnugrep, gawk, makeWrapper
, nixosTests
, firewall ? "iptables", nftables, libmnl, libnftnl
}:

let
  scriptBinEnv = lib.makeBinPath {
    iptables = [
      # needed for dirname in ip{,6}tables_*.sh
      coreutils
      # used in miniupnpd_functions.sh:
      which
      iproute2
      iptables-legacy
      gnused
      gnugrep
      gawk
    ];
    nftables = [
      # needed for dirname in nft_*.sh & cat in nft_init.sh
      coreutils
      # used in miniupnpd_functions.sh:
      which
      nftables
    ];
  }.${firewall};
in
stdenv.mkDerivation rec {
  pname = "miniupnpd";
  version = "2.3.4";

  src = fetchurl {
    url = "https://miniupnp.tuxfamily.org/files/miniupnpd-${version}.tar.gz";
    sha256 = "sha256-5zAzSPyKxCfefwTw7rdX1J3Mg2cxHuJYJVLDj11toIo=";
  };

  buildInputs = [ iptables-legacy libuuid openssl ]
    ++ lib.optionals (firewall == "nftables") [ libmnl libnftnl ];
  nativeBuildInputs= [ pkg-config makeWrapper ];

  # ./configure is not a standard configure file, errors with:
  # Option not recognized : --prefix=
  dontAddPrefix = true;
  configureFlags = [
    "--firewall=${firewall}"
    # allow using various config options
    "--ipv6"
    "--leasefile"
    "--regex"
    "--vendorcfg"
    # hardening
    "--portinuse"
  ];

  installFlags = [ "PREFIX=$(out)" "INSTALLPREFIX=$(out)" ];

  postFixup = {
    # Ideally we'd prefer using system's config.firewall.package here for iptables,
    # however for some reason switching --prefix to --suffix breaks the script
    iptables = ''
      for script in $out/etc/miniupnpd/ip{,6}tables_{init,removeall}.sh
      do
        wrapProgram $script --prefix PATH : '${scriptBinEnv}:$PATH'
      done
    '';
    nftables = ''
      for script in $out/etc/miniupnpd/nft_{delete_chain,flush,init,removeall}.sh
      do
        wrapProgram $script --suffix PATH : '${scriptBinEnv}:$PATH'
      done
    '';
  }.${firewall};

  passthru.tests = {
    bittorrent-integration = nixosTests.bittorrent;
    inherit (nixosTests) upnp;
  };

  meta = with lib; {
    homepage = "https://miniupnp.tuxfamily.org/";
    description = "A daemon that implements the UPnP Internet Gateway Device (IGD) specification";
    platforms = platforms.linux;
    license = licenses.bsd3;
    mainProgram = "miniupnpd";
  };
}