lol
1{ buildGoModule
2, fetchFromGitHub
3, fetchpatch
4, protobuf
5, go-protobuf
6, pkg-config
7, libnetfilter_queue
8, libnfnetlink
9, lib
10, coreutils
11, iptables
12, makeWrapper
13, protoc-gen-go-grpc
14, testers
15, opensnitch
16, nixosTests
17}:
18
19buildGoModule rec {
20 pname = "opensnitch";
21 version = "1.6.3";
22
23 src = fetchFromGitHub {
24 owner = "evilsocket";
25 repo = "opensnitch";
26 rev = "v${version}";
27 hash = "sha256-C8Uuz2FC7Zu07ZmFpp+ejpNxkyC3/mM9J2dc5FUKx64=";
28 };
29
30 postPatch = ''
31 # Allow configuring Version at build time
32 substituteInPlace daemon/core/version.go --replace "const " "var "
33 '';
34
35 modRoot = "daemon";
36
37 buildInputs = [
38 libnetfilter_queue
39 libnfnetlink
40 ];
41
42 nativeBuildInputs = [
43 pkg-config
44 protobuf
45 go-protobuf
46 makeWrapper
47 protoc-gen-go-grpc
48 ];
49
50 vendorHash = "sha256-bUzGWpQxeXzvkzQ7G53ljQJq6wwqiXqbi6bgeFlNvvM=";
51
52 preBuild = ''
53 # Fix inconsistent vendoring build error
54 # https://github.com/evilsocket/opensnitch/issues/770
55 cp ${./go.mod} go.mod
56 cp ${./go.sum} go.sum
57
58 make -C ../proto ../daemon/ui/protocol/ui.pb.go
59 '';
60
61 postBuild = ''
62 mv $GOPATH/bin/daemon $GOPATH/bin/opensnitchd
63 mkdir -p $out/etc/opensnitchd $out/lib/systemd/system
64 cp system-fw.json $out/etc/opensnitchd/
65 substitute default-config.json $out/etc/opensnitchd/default-config.json \
66 --replace "/var/log/opensnitchd.log" "/dev/stdout"
67 substitute opensnitchd.service $out/lib/systemd/system/opensnitchd.service \
68 --replace "/usr/local/bin/opensnitchd" "$out/bin/opensnitchd" \
69 --replace "/etc/opensnitchd/rules" "/var/lib/opensnitch/rules" \
70 --replace "/bin/mkdir" "${coreutils}/bin/mkdir"
71 '';
72
73 ldflags = [ "-s" "-w" "-X github.com/evilsocket/opensnitch/daemon/core.Version=${version}" ];
74
75 postInstall = ''
76 wrapProgram $out/bin/opensnitchd \
77 --prefix PATH : ${lib.makeBinPath [ iptables ]}
78 '';
79
80 passthru.tests = {
81 inherit (nixosTests) opensnitch;
82 version = testers.testVersion {
83 package = opensnitch;
84 command = "opensnitchd -version";
85 };
86 };
87
88 meta = with lib; {
89 description = "An application firewall";
90 homepage = "https://github.com/evilsocket/opensnitch/wiki";
91 license = licenses.gpl3Only;
92 maintainers = with maintainers; [ onny ];
93 platforms = platforms.linux;
94 };
95}