nixos/windmill: add database.url option and defaults (#341675)

Yt 2ac0a669 ef29d8d6

Changed files
+26 -7
nixos
modules
services
web-apps
+26 -7
nixos/modules/services/web-apps/windmill.nix
···
description = "Database user.";
};
+
url = lib.mkOption {
+
type = lib.types.str;
+
default = "postgres://${config.services.windmill.database.name}?host=/var/run/postgresql";
+
defaultText = lib.literalExpression ''
+
"postgres://\$\{config.services.windmill.database.name}?host=/var/run/postgresql";
+
'';
+
description = "Database url. Note that any secret here would be world-readable. Use `services.windmill.database.urlPath` unstead to include secrets in the url.";
+
};
+
urlPath = lib.mkOption {
-
type = lib.types.path;
+
type = lib.types.nullOr lib.types.path;
description = ''
Path to the file containing the database url windmill should connect to. This is not deducted from database user and name as it might contain a secret
'';
+
default = null;
example = "config.age.secrets.DATABASE_URL_FILE.path";
};
+
createLocally = lib.mkOption {
type = lib.types.bool;
default = true;
···
baseUrl = lib.mkOption {
type = lib.types.str;
+
default = "https://localhost:${toString config.services.windmill.serverPort}";
+
defaultText = lib.literalExpression ''
+
"https://localhost:\$\{toString config.services.windmill.serverPort}";
+
'';
description = ''
The base url that windmill will be served on.
'';
···
systemd.services =
let
+
useUrlPath = (cfg.database.urlPath != null);
serviceConfig = {
DynamicUser = true;
# using the same user to simplify db connection
···
ExecStart = "${pkgs.windmill}/bin/windmill";
Restart = "always";
+
} // lib.optionalAttrs useUrlPath {
LoadCredential = [
"DATABASE_URL_FILE:${cfg.database.urlPath}"
];
+
};
+
db_url_envs = lib.optionalAttrs useUrlPath {
+
DATABASE_URL_FILE = "%d/DATABASE_URL_FILE";
+
} // lib.optionalAttrs (!useUrlPath) {
+
DATABASE_URL = cfg.database.url;
};
in
{
···
serviceConfig = serviceConfig // { StateDirectory = "windmill";};
environment = {
-
DATABASE_URL_FILE = "%d/DATABASE_URL_FILE";
PORT = builtins.toString cfg.serverPort;
WM_BASE_URL = cfg.baseUrl;
RUST_LOG = cfg.logLevel;
MODE = "server";
-
};
+
} // db_url_envs;
};
windmill-worker = {
···
serviceConfig = serviceConfig // { StateDirectory = "windmill-worker";};
environment = {
-
DATABASE_URL_FILE = "%d/DATABASE_URL_FILE";
WM_BASE_URL = cfg.baseUrl;
RUST_LOG = cfg.logLevel;
MODE = "worker";
WORKER_GROUP = "default";
KEEP_JOB_DIR = "false";
-
};
+
} // db_url_envs;
};
windmill-worker-native = {
···
serviceConfig = serviceConfig // { StateDirectory = "windmill-worker-native";};
environment = {
-
DATABASE_URL_FILE = "%d/DATABASE_URL_FILE";
WM_BASE_URL = cfg.baseUrl;
RUST_LOG = cfg.logLevel;
MODE = "worker";
WORKER_GROUP = "native";
-
};
+
} // db_url_envs;
};
};
};