-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
111 lines (107 loc) · 2.39 KB
/
module.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
{
options,
config,
lib,
pkgs,
...
}: let
inherit
(lib)
mkEnableOption
mkPackageOption
mkOption
types
mkIf
;
json = pkgs.formats.json {};
cfg = config.renovate;
generateValidatedConfig = name: value:
pkgs.callPackage (
{
runCommand,
jq,
}:
runCommand name
{
nativeBuildInputs = [
jq
cfg.package
];
value = builtins.toJSON value;
passAsFile = ["value"];
preferLocalBuild = true;
}
''
jq . "$valuePath"> $out
renovate-config-validator $out
''
) {};
generateConfig =
if cfg.validateSettings
then generateValidatedConfig
else json.generate;
in {
options.renovate = {
enable = mkEnableOption "renovate";
package = mkPackageOption pkgs "renovate" {};
validateSettings = mkOption {
type = types.bool;
default = true;
description = "Wether to run renovate's config validator on the built configuration.";
};
settings = mkOption {
type = json.type;
default = {};
example = {
platform = "gitea";
endpoint = "https://git.example.com";
gitAuthor = "Renovate <[email protected]>";
};
description = ''Renovate's global configuration.'';
};
};
config = let
renovatePreview = pkgs.callPackage ./renovate-preview.nix {
renovate = cfg.package;
};
configFile = generateConfig "renovate-config.json" cfg.settings;
in
mkIf cfg.enable {
# add package to devenv.sh
${
if (options ? devenv && options ? packages)
then "packages"
else null
} = [cfg.package renovatePreview];
${
if (options ? devenv && options ? env)
then "env"
else null
} = {RENOVATE_CONFIG_FILE = configFile;};
# Add command in devenv.nix
${
if (options ? devshell && options ? commands)
then "commands"
else null
} = [
{
package = cfg.package;
help = "Renovate";
}
{
package = renovatePreview;
help = "Renovate Preview";
}
];
${
if (options ? devshell && options ? env)
then "env"
else null
} = [
{
name = "RENOVATE_CONFIG_FILE";
value = configFile;
}
];
};
}