Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / by-name / op / opensnitch / package.nix
blob41172f038cc85accaaeff0cded259a666ef6b751
1 { buildGoModule
2 , fetchFromGitHub
3 , protobuf
4 , go-protobuf
5 , pkg-config
6 , libnetfilter_queue
7 , libnfnetlink
8 , lib
9 , iptables
10 , makeWrapper
11 , protoc-gen-go-grpc
12 , testers
13 , opensnitch
14 , nixosTests
17 buildGoModule rec {
18   pname = "opensnitch";
19   version = "1.6.6";
21   src = fetchFromGitHub {
22     owner = "evilsocket";
23     repo = "opensnitch";
24     rev = "refs/tags/v${version}";
25     hash = "sha256-pJPpkXRp7cby6Mvc7IzxH9u6MY4PcrRPkimTw3je6iI=";
26   };
28   postPatch = ''
29     # Allow configuring Version at build time
30     substituteInPlace daemon/core/version.go --replace "const " "var "
31   '';
33   modRoot = "daemon";
35   buildInputs = [
36     libnetfilter_queue
37     libnfnetlink
38   ];
40   nativeBuildInputs = [
41     pkg-config
42     protobuf
43     go-protobuf
44     makeWrapper
45     protoc-gen-go-grpc
46   ];
48   vendorHash = "sha256-PX41xeUJb/WKv3+z5kbRmJNP1vFu8x35NZvN2Dgp4CQ=";
50   preBuild = ''
51     # Fix inconsistent vendoring build error
52     # https://github.com/evilsocket/opensnitch/issues/770
53     cp ${./go.mod} go.mod
54     cp ${./go.sum} go.sum
56     make -C ../proto ../daemon/ui/protocol/ui.pb.go
57   '';
59   postBuild = ''
60     mv $GOPATH/bin/daemon $GOPATH/bin/opensnitchd
61     mkdir -p $out/etc/opensnitchd $out/lib/systemd/system
62     cp system-fw.json $out/etc/opensnitchd/
63     substitute default-config.json $out/etc/opensnitchd/default-config.json \
64       --replace "/var/log/opensnitchd.log" "/dev/stdout"
65     # Do not mkdir rules path
66     sed -i '8d' opensnitchd.service
67     # Fixup hardcoded paths
68     substitute opensnitchd.service $out/lib/systemd/system/opensnitchd.service \
69       --replace "/usr/local/bin/opensnitchd" "$out/bin/opensnitchd"
70   '';
72   ldflags = [
73     "-s"
74     "-w"
75     "-X github.com/evilsocket/opensnitch/daemon/core.Version=${version}"
76   ];
78   postInstall = ''
79     wrapProgram $out/bin/opensnitchd \
80       --prefix PATH : ${lib.makeBinPath [ iptables ]}
81   '';
83   passthru.tests = {
84     inherit (nixosTests) opensnitch;
85     version = testers.testVersion {
86       package = opensnitch;
87       command = "opensnitchd -version";
88     };
89   };
91   meta = with lib; {
92     description = "Application firewall";
93     mainProgram = "opensnitchd";
94     homepage = "https://github.com/evilsocket/opensnitch/wiki";
95     license = licenses.gpl3Only;
96     maintainers = with maintainers; [ onny ];
97     platforms = platforms.linux;
98   };