-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolcon-home.nix
65 lines (54 loc) · 2.02 KB
/
colcon-home.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
{
# This is a list of mixins that are enabled when a `colcon build` is ran without any mixin options.
defaultBuildMixins ? [],
# Same as defaultBuildMixins but for `colcon test`.
defaultTestMixins ? [],
lib,
name ? "colcon-home",
# This is the list of mixins that is provided, in addition to the ones provided through defaultBuildMixins. These mixins
# are available but not used by default when `colcon build` is ran without mixin options.
providedBuildMixins ? [],
# Same as providedBuildMixins but for `colcon test`.
providedTestMixins ? [],
stdenv,
writeText,
writeTextFile,
}: let
have_test_mixins = lib.length providedTestMixins > 0;
# Mixin body is the combination of both the default enabled mixins and the provided mixins.
mixin_body = {
build = builtins.listToAttrs (lib.unique (defaultBuildMixins ++ providedBuildMixins));
} // (if have_test_mixins then
{
test = builtins.listToAttrs (lib.unique (defaultTestMixins ++ providedTestMixins));
}
else
{});
# Then, just the defaults are enabled by default through colcon's defaults.
enabled_build_mixins = lib.attrNames (lib.listToAttrs (lib.unique defaultBuildMixins));
enabled_test_mixins = lib.attrNames (lib.listToAttrs (lib.unique defaultTestMixins));
in stdenv.mkDerivation rec {
pname = "colcon-home";
version = "0.0.1";
phases = [ "buildPhase" ];
buildPhase = let
# Write the text file that provides all mixins
provided = writeTextFile {
name = "compile-commands-mixin";
text = builtins.toJSON mixin_body ;
};
# Write the text file that specifies which mixins are enabled for each command.
defaults = writeTextFile {
name = "colcon-home-defaults";
text = builtins.toJSON ({
build = {
mixin = enabled_build_mixins;
};
} // (if have_test_mixins then {test = {mixin = enabled_test_mixins; };} else {}));
};
in ''
mkdir -p $out/mixin
ln -s ${defaults} $out/defaults.yaml
ln -s ${provided} $out/mixin/all.mixin
'';
}