-
Notifications
You must be signed in to change notification settings - Fork 12
/
default.nix
101 lines (79 loc) · 2.9 KB
/
default.nix
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
let
fetchNixpkgs = {rev, sha256}: builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs-channels/archive/${rev}.tar.gz";
inherit sha256;
};
nixpkgs = fetchNixpkgs {
# nixos-20.03 of 08.08.2020
rev = "4364ff933ebec0ef856912b182f4f9272aa7f98f";
sha256 = "19ig1ywd2jq7qqzwpw6f1li90dq4kk3v0pbqgn6lzdabzf95bz6z";
};
pkgs = import nixpkgs {};
version =
let mkVersion = pkgs.stdenv.mkDerivation {
src = ./.;
name = "mkVersion";
phases = "buildPhase";
buildPhase = ''
mkdir -p $out
${pkgs.git}/bin/git -C $src describe --always --tags > $out/version
'';
};
in pkgs.lib.removeSuffix "\n" (builtins.readFile "${mkVersion}/version");
manpage = pkgs.stdenv.mkDerivation rec {
inherit version;
name = "manpage";
src = ./docs;
phases = "buildPhase";
buildPhase = ''
mkdir -p $out
# replace all @VARIABLES@ with their values from the environment
substituteAll $src/lsleases.org $out/lsleases.org
substituteAll $src/lsleasesd.org $out/lsleasesd.org
# create man pages
${pkgs.pandoc}/bin/pandoc -s -o $out/lsleases.1 $out/lsleases.org
${pkgs.pandoc}/bin/pandoc -s -o $out/lsleasesd.1 $out/lsleasesd.org
'';
};
lsleases = {arch ? "amd64", goos ? "linux" }:
let goModule = if arch == "i386" then pkgs.pkgsi686Linux.buildGoModule else pkgs.buildGoModule; in
goModule rec {
inherit version goos;
pname = "lsleases";
rev = "v${version}";
src = pkgs.lib.cleanSource ./.;
CGO_ENABLED = 0;
buildFlagsArray = ''
-ldflags=
-X main.version=${version}
-X github.com/j-keck/lsleases/pkg/daemon.version=${version}
'';
modSha256 = "sha256:1yjrdl73yilyg9vp7khqwjc5li88frc602ir3vb0xl3apbv9z0km";
preBuild = ''
export GOOS=${goos}
'';
installPhase = ''
BIN_PATH=${if goos == pkgs.stdenv.buildPlatform.parsed.kernel.name
then "$GOPATH/bin"
else "$GOPATH/bin/${goos}_$GOARCH"}
mkdir -p $out/bin
cp $BIN_PATH/lsleases $out/bin
cp $BIN_PATH/lsleasesd $out/bin
mkdir -p $out/man/man1
cp ${manpage}/lsleases.1 $out/man/man1
cp ${manpage}/lsleasesd.1 $out/man/man1
'';
meta = with pkgs.stdenv.lib; {
description = "DHCP leases sniffer";
homepage = "https://github.com/j-keck/lsleases";
license = licenses.mit;
maintainers = maintainers.j-keck;
};
};
in rec {
inherit lsleases;
package-deb = {arch ? "amd64"}: import ./build/package-deb.nix {inherit pkgs lsleases arch; };
package-deb-test = import ./build/package-deb-test.nix { inherit pkgs package-deb; };
package-rpm = {arch ? "amd64"}: import ./build/package-rpm.nix { inherit pkgs lsleases arch; };
package-osx = { arch ? "amd64"}: import ./build/package-osx.nix { inherit pkgs lsleases arch; };
}