-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
127 lines (104 loc) · 3.94 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
{
description = "prometheus exporter for restic backups";
inputs = { flake-utils.url = "github:numtide/flake-utils"; };
outputs = { self, nixpkgs, flake-utils, ... }:
{
nixosModules.default = self.nixosModules.restic-exporter;
nixosModules.restic-exporter = { lib, pkgs, config, ... }:
with lib;
let cfg = config.services.restic-exporter;
in
{
options.services.restic-exporter = {
enable = mkEnableOption "restic-exporter";
port = mkOption {
type = types.str;
default = "8080";
description = "Port under which restic-exporter is accessible.";
};
address = mkOption {
type = types.str;
default = "localhost";
example = "127.0.0.1";
description = "Address under which restic-exporter is accessible.";
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
Environment file (see <literal>systemd.exec(5)</literal>
"EnvironmentFile=" section for the syntax) to define extra variables
for the exporter
'';
};
user = mkOption {
type = types.str;
default = "restic-exporter";
description = "User account under which restic-exporter runs.";
};
group = mkOption {
type = types.str;
default = "restic-exporter";
description = "Group under which restic-exporter runs.";
};
};
config = mkIf cfg.enable {
systemd.services.restic-exporter = {
description = "A restic metrics exporter";
wantedBy = [ "multi-user.target" ];
serviceConfig = mkMerge [{
User = cfg.user;
Group = cfg.group;
CacheDirectory = "restic-exporter";
ExecStart = "${self.packages."${pkgs.system}".default}/bin/restic-exporter";
Restart = "on-failure";
EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
Environment = [
"RESTIC_EXPORTER_BIN=${pkgs.restic}/bin/restic"
"RESTIC_EXPORTER_PORT=${cfg.port}"
"RESTIC_EXPORTER_ADDRESS=${cfg.address}"
"RESTIC_EXPORTER_CACHEDIR=/var/cache/restic-exporter"
];
}];
};
users.users = mkIf (cfg.user == "restic-exporter") {
restic-exporter = {
isSystemUser = true;
group = cfg.group;
description = "restic-exporter system user";
};
};
users.groups =
mkIf (cfg.group == "restic-exporter") { restic-exporter = { }; };
};
meta.maintainers = with lib.maintainers; [ pinpox ];
};
}
//
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in
rec {
formatter = pkgs.nixpkgs-fmt;
packages = flake-utils.lib.flattenTree rec {
default = pkgs.buildGoModule rec {
pname = "restic-exporter";
version = "1.0.0";
src = self;
vendorHash = "sha256-HUruT0+yOP+v5lxd4jrxYhRBzE0FcoW4OpcWgRRedwA=";
installCheckPhase = ''
runHook preCheck
$out/bin/restic-exporter -h
runHook postCheck
'';
doCheck = true;
meta = with pkgs.lib; {
description = "restic prometheus exporter";
homepage = "https://github.com/pinpox/restic-exporter";
platforms = platforms.unix;
maintainers = with maintainers; [ pinpox ];
};
};
};
});
}