···
cfg = config.services.longview;
8
-
pidFile = "/run/longview.pid";
10
-
apacheConf = optionalString (cfg.apacheStatusUrl != "") ''
11
-
location ${cfg.apacheStatusUrl}?auto
13
-
mysqlConf = optionalString (cfg.mysqlUser != "") ''
14
-
username ${cfg.mysqlUser}
15
-
password ${cfg.mysqlPassword}
17
-
nginxConf = optionalString (cfg.nginxStatusUrl != "") ''
18
-
location ${cfg.nginxStatusUrl}
8
+
runDir = "/run/longview";
9
+
configsDir = "${runDir}/longview.d";
···
example = "01234567-89AB-CDEF-0123456789ABCDEF";
Longview API key. To get this, look in Longview settings which
are found at https://manager.linode.com/longview/.
32
+
Warning: this secret is stored in the world-readable Nix store!
33
+
Use <option>apiKeyFile</option> instead.
37
+
apiKeyFile = mkOption {
38
+
type = types.nullOr types.path;
40
+
example = "/run/keys/longview-api-key";
42
+
A file containing the Longview API key.
43
+
To get this, look in Longview settings which
44
+
are found at https://manager.linode.com/longview/.
46
+
<option>apiKeyFile</option> takes precedence over <option>apiKey</option>.
···
mysqlPassword = mkOption {
81
-
The password corresponding to mysqlUser. Warning: this is
82
-
stored in cleartext in the Nix store!
87
+
The password corresponding to <option>mysqlUser</option>.
88
+
Warning: this is stored in cleartext in the Nix store!
89
+
Use <option>mysqlPasswordFile</option> instead.
93
+
mysqlPasswordFile = mkOption {
94
+
type = types.nullOr types.path;
96
+
example = "/run/keys/dbpassword";
98
+
A file containing the password corresponding to <option>mysqlUser</option>.
···
serviceConfig.Type = "forking";
serviceConfig.ExecStop = "-${pkgs.coreutils}/bin/kill -TERM $MAINPID";
serviceConfig.ExecReload = "-${pkgs.coreutils}/bin/kill -HUP $MAINPID";
97
-
serviceConfig.PIDFile = pidFile;
114
+
serviceConfig.PIDFile = "${runDir}/longview.pid";
serviceConfig.ExecStart = "${pkgs.longview}/bin/longview";
118
+
mkdir -p ${configsDir}
119
+
'' + (optionalString (cfg.apiKeyFile != null) ''
120
+
cp --no-preserve=all "${cfg.apiKeyFile}" ${runDir}/longview.key
121
+
'') + (optionalString (cfg.apacheStatusUrl != "") ''
122
+
cat > ${configsDir}/Apache.conf <<EOF
123
+
location ${cfg.apacheStatusUrl}?auto
125
+
'') + (optionalString (cfg.mysqlUser != "" && cfg.mysqlPasswordFile != null) ''
126
+
cat > ${configsDir}/MySQL.conf <<EOF
127
+
username ${cfg.mysqlUser}
128
+
password `head -n1 "${cfg.mysqlPasswordFile}"`
130
+
'') + (optionalString (cfg.nginxStatusUrl != "") ''
131
+
cat > ${configsDir}/Nginx.conf <<EOF
132
+
location ${cfg.nginxStatusUrl}
101
-
environment.etc."linode/longview.key" = {
105
-
environment.etc."linode/longview.d/Apache.conf" = {
109
-
environment.etc."linode/longview.d/MySQL.conf" = {
113
-
environment.etc."linode/longview.d/Nginx.conf" = {
137
+
warnings = let warn = k: optional (cfg.${k} != "")
138
+
"config.services.longview.${k} is insecure. Use ${k}File instead.";
139
+
in concatMap warn [ "apiKey" "mysqlPassword" ];
142
+
{ assertion = cfg.apiKeyFile != null;
143
+
message = "Longview needs an API key configured";
147
+
# Create API key file if not configured.
148
+
services.longview.apiKeyFile = mkIf (cfg.apiKey != "")
149
+
(mkDefault (toString (pkgs.writeTextFile {
150
+
name = "longview.key";
154
+
# Create MySQL password file if not configured.
155
+
services.longview.mysqlPasswordFile = mkDefault (toString (pkgs.writeTextFile {
156
+
name = "mysql-password-file";
157
+
text = cfg.mysqlPassword;