-
Notifications
You must be signed in to change notification settings - Fork 39
/
flake.nix
156 lines (148 loc) · 5.7 KB
/
flake.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
description =
"Filesystem watcher. Works anywhere. Simple, efficient and friendly.";
inputs =
{ nixpkgs = { url = "github:nixos/nixpkgs/nixos-unstable"; };
flake-utils = { url = "github:numtide/flake-utils"; };
snitch-repo = { url = "github:cschreib/snitch"; flake = false; };
};
outputs =
{ self
, nixpkgs
, flake-utils
, snitch-repo
, ...
}:
(
flake-utils.lib.eachDefaultSystem(system:
let
pkgs = import nixpkgs { inherit system; };
build_deps = [ pkgs.clang pkgs.cmake ];
# If on Darwin, we need this to use FSEvents, dispatch, etc.
maybe_sys_deps = pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.CoreServices ];
snitch = pkgs.stdenv.mkDerivation {
pname = "snitch";
version = "0.1.0";
src = snitch-repo;
nativeBuildInputs = build_deps;
buildPhase = ''cmake --build .'';
installPhase = ''cmake --install . --prefix "$out"'';
};
mkWatcherDerivation =
{ src
, pname
, buildcfg
, targets
# We should just make this a regular target
, installBashScriptName ? ""
, installBashScript ? ""
}: pkgs.stdenv.mkDerivation {
inherit src pname buildcfg targets;
version = "0.13.2"; # hook: tool/release
nativeBuildInputs = build_deps ++ maybe_sys_deps ++ [ snitch ];
env.WTR_WATCHER_USE_SYSTEM_SNITCH = 1;
buildPhase = ''
echo "Building in $PWD/$buildcfg"
cmake \
-S .. \
-B "$buildcfg" \
-DCMAKE_BUILD_TYPE="$buildcfg" \
-DCMAKE_INSTALL_PREFIX="$out"
for target in $targets
do
cmake \
--build "$buildcfg" \
--config "$buildcfg" \
--target "$target" \
--parallel "$(nproc)"
if echo "$target" | grep -q 'hdr_'
then cp ../include/wtr/watcher.hpp "$buildcfg"
fi
done
'';
installPhase = ''
echo "Installing targets (${toString targets}) from $PWD/$buildcfg to $out"
ls -al "$buildcfg"
for target in $targets
do
if echo "$target" | grep -q 'hdr_'
then to=$out/include/wtr/watcher.hpp
else to=$out/bin/$target
fi
fromfile=$(basename "$to")
todir=$(dirname "$to")
test -d "$todir" || mkdir -p "$todir"
mv "$buildcfg/$fromfile" "$to"
echo "$target -> $to"
stat "$to"
done
if [ -n "${installBashScript}" ]
then
echo "${installBashScript}" | tee -a "$out/bin/${installBashScriptName}"
chmod +x "$out/bin/${installBashScriptName}"
fi
'';
};
watcher = mkWatcherDerivation {
src = self;
pname = "wtr.watcher";
buildcfg = "Release";
targets = [ "wtr.watcher"
"wtr.hdr_watcher" ];
};
tw = mkWatcherDerivation {
src = self;
pname = "tw";
buildcfg = "Release";
targets = [ "tw" ];
};
watcher-cli = mkWatcherDerivation {
src = self;
pname = "wtr.watcher";
buildcfg = "Release";
targets = [ "wtr.watcher" ];
};
watcher-hdr = mkWatcherDerivation {
src = self;
pname = "exit";
buildcfg = "Release";
targets = [ "wtr.hdr_watcher" ];
};
watcher-test = mkWatcherDerivation {
src = self;
pname = "wtr.test_watcher.allsan";
buildcfg = "Debug";
targets = [ "wtr.test_watcher"
"wtr.test_watcher.asan"
"wtr.test_watcher.msan"
"wtr.test_watcher.tsan"
"wtr.test_watcher.ubsan" ];
installBashScriptName = "wtr.test_watcher.allsan";
installBashScript = ''
#!/usr/bin/env bash
PATH="$PATH:$out/bin"
mkdir -p /tmp/watcher-test
cd /tmp/watcher-test
if command -v wtr.test_watcher ; then wtr.test_watcher ; fi
if command -v wtr.test_watcher.asan ; then wtr.test_watcher.asan ; fi
if command -v wtr.test_watcher.msan ; then wtr.test_watcher.msan ; fi
if command -v wtr.test_watcher.tsan ; then wtr.test_watcher.tsan ; fi
if command -v wtr.test_watcher.ubsan; then wtr.test_watcher.ubsan; fi
rm -rf /tmp/watcher-test
'';
};
# Bring watcher's tree and all of its dependencies in via inputsFrom,
# and pre-build watcher via buildInputs so that we can use it right away.
watcher-devshell = pkgs.mkShell {
inputsFrom = [ tw watcher-cli watcher-hdr watcher-test ];
buildInputs = [ watcher ];
};
in {
packages = { inherit watcher tw watcher-cli watcher-hdr watcher-test; };
defaultApp = flake-utils.lib.mkApp { drv = watcher-cli; };
defaultPackage = watcher;
devShell = watcher-devshell;
}
)
);
}