-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.nix
86 lines (80 loc) · 2.17 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
{ lib, pkgs, config, ... }:
with lib;
let
pkg-puff = import ./nix/default.nix {};
cfg = config.services.puff;
faucet-txt = pkgs.writeTextFile {
name = "faucet.json";
text = ''{"faucet_sk":"${cfg.faucet-sk}", "faucet_address":"${cfg.faucet-address}"}'';
};
jolt-deploy = pkgs.fetchFromGitHub {
owner = "carbonideltd";
repo = "jolt-deploy";
rev = "495de70720cc1f0b5b0ea854042ffc97768774e3";
sha256 = "00v119qysh3cin36hb4pr5kk9976wh37wvjjmbgwl0v4r85p4g05";
};
in {
options = {
services.puff = {
enable = mkEnableOption "puff service";
package = mkOption {
type = types.package;
default = pkg-puff;
description = ''
The package that contains puff's sources. Can be overriden.
'';
};
host = mkOption {
type = types.str;
default = "127.0.0.1:8080";
description = ''
The host and port to run on
'';
};
dataDir = mkOption {
type = types.path;
default = "/run/puff";
description = ''
path to files served
'';
};
faucet-sk = mkOption {
type = types.str;
default = null;
description = ''
faucet's secret key, yes, this temporary is a dirty hack
'';
};
faucet-address = mkOption {
type = types.str;
default = null;
description = ''
faucet's address
'';
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.puff = {
after = [ "network.target" ];
description = "Puff";
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -m 0755 -p ${cfg.dataDir}
ln -sf ${jolt-deploy}/deploy ${cfg.dataDir}/jolt
ln -sf ${cfg.package}/static/favicon.ico ${cfg.dataDir}/favicon.ico
ln -sf ${faucet-txt} ${cfg.dataDir}/faucet.json
'';
postStop = ''
rm -rf ${cfg.dataDir}
'';
serviceConfig = {
Type = "simple";
PermissionsStartOnly = true;
RuntimeDirectory = cfg.dataDir;
ExecStart = "${cfg.package}/bin/puff ${cfg.host} ${cfg.dataDir}";
DynamicUser = true;
};
};
};
}