forked from j-keck/zsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
96 lines (78 loc) · 2.24 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
{ goos ? "linux", with-dev-tools ? false }:
let
fetchNixpkgs = {rev, sha256}: builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs-channels/archive/${rev}.tar.gz";
inherit sha256;
};
pkgs = import (fetchNixpkgs {
rev = "8a9807f1941d046f120552b879cf54a94fca4b38";
sha256 = "0s8gj8b7y1w53ak138f3hw1fvmk40hkpzgww96qrsgf490msk236";
}) {};
version =
let lookup-version = pkgs.stdenv.mkDerivation {
src = builtins.path { name = "git"; path = ./.git; };
name = "zsd-lookup-version";
phases = "buildPhase";
buildPhase = ''
mkdir -p $out
${pkgs.git}/bin/git --git-dir=$src describe --always --tags > $out/version
'';
};
in pkgs.lib.removeSuffix "\n" (builtins.readFile "${lookup-version}/version");
zsd = pkgs.buildGo112Module rec {
pname = "zsd";
inherit version;
src = pkgs.nix-gitignore.gitignoreSource [ ".gitignore" ] ./.;
modSha256 = "1i8bd6cli45zcl40xc5cw0ywj8nz1xnz5jyxq5rd7adw89m0fd40";
preBuild = ''
export GOOS=${goos}
'';
CGO_ENABLED = 0;
buildFlagsArray = ''
-ldflags=
-X main.version=${version}
'';
installPhase = ''
mkdir -p $out
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/zsd $out/bin
mkdir -p $out/share
cp LICENSE $out/share
'';
};
site =
let theme = pkgs.fetchFromGitHub {
owner = "alex-shpak";
repo = "hugo-book";
rev = "dae803fa442973561821a44b08e3a964614d07df";
sha256 = "0dpb860kddclsqnr4ls356jn4d1l8ymw5rs9wfz2xq4kkrgls4dl";
};
in pkgs.stdenv.mkDerivation rec {
name = "zsd-site";
inherit version;
src = ./doc/site;
buildPhase = ''
cp -a ${theme}/. themes/book
${pkgs.hugo}/bin/hugo --minify
'';
installPhase = ''
cp -r public $out
'';
};
in
if pkgs.lib.inNixShell then pkgs.mkShell {
buildInputs = with pkgs;
[ go_1_12 ] ++
(if with-dev-tools
then [ hugo ]
else []);
shellHooks = ''
unset GOPATH
'';
}
else {
inherit zsd site;
}