nixpkgs/nixos/modules/services/web-apps/galene.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

215 lines
6.7 KiB
Nix
Raw Normal View History

{ config, lib, options, pkgs, ... }:
2020-12-30 20:22:51 +00:00
with lib;
let
cfg = config.services.galene;
opt = options.services.galene;
2020-12-30 20:22:51 +00:00
defaultstateDir = "/var/lib/galene";
defaultrecordingsDir = "${cfg.stateDir}/recordings";
defaultgroupsDir = "${cfg.stateDir}/groups";
defaultdataDir = "${cfg.stateDir}/data";
in
{
options = {
services.galene = {
enable = mkEnableOption (lib.mdDoc "Galene Service");
2020-12-30 20:22:51 +00:00
stateDir = mkOption {
default = defaultstateDir;
type = types.str;
description = lib.mdDoc ''
2020-12-30 20:22:51 +00:00
The directory where Galene stores its internal state. If left as the default
value this directory will automatically be created before the Galene server
starts, otherwise the sysadmin is responsible for ensuring the directory
exists with appropriate ownership and permissions.
'';
};
user = mkOption {
type = types.str;
default = "galene";
description = lib.mdDoc "User account under which galene runs.";
2020-12-30 20:22:51 +00:00
};
group = mkOption {
type = types.str;
default = "galene";
description = lib.mdDoc "Group under which galene runs.";
2020-12-30 20:22:51 +00:00
};
insecure = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
2020-12-30 20:22:51 +00:00
Whether Galene should listen in http or in https. If left as the default
value (false), Galene needs to be fed a private key and a certificate.
'';
};
certFile = mkOption {
type = types.nullOr types.str;
default = null;
example = "/path/to/your/cert.pem";
description = lib.mdDoc ''
2020-12-30 20:22:51 +00:00
Path to the server's certificate. The file is copied at runtime to
Galene's data directory where it needs to reside.
'';
};
keyFile = mkOption {
type = types.nullOr types.str;
default = null;
example = "/path/to/your/key.pem";
description = lib.mdDoc ''
2020-12-30 20:22:51 +00:00
Path to the server's private key. The file is copied at runtime to
Galene's data directory where it needs to reside.
'';
};
httpAddress = mkOption {
type = types.str;
default = "";
description = lib.mdDoc "HTTP listen address for galene.";
2020-12-30 20:22:51 +00:00
};
httpPort = mkOption {
type = types.port;
default = 8443;
description = lib.mdDoc "HTTP listen port.";
2020-12-30 20:22:51 +00:00
};
staticDir = mkOption {
type = types.str;
default = "${cfg.package.static}/static";
defaultText = literalExpression ''"''${package.static}/static"'';
2020-12-30 20:22:51 +00:00
example = "/var/lib/galene/static";
description = lib.mdDoc "Web server directory.";
2020-12-30 20:22:51 +00:00
};
recordingsDir = mkOption {
type = types.str;
default = defaultrecordingsDir;
defaultText = literalExpression ''"''${config.${opt.stateDir}}/recordings"'';
2020-12-30 20:22:51 +00:00
example = "/var/lib/galene/recordings";
description = lib.mdDoc "Recordings directory.";
2020-12-30 20:22:51 +00:00
};
dataDir = mkOption {
type = types.str;
default = defaultdataDir;
defaultText = literalExpression ''"''${config.${opt.stateDir}}/data"'';
2020-12-30 20:22:51 +00:00
example = "/var/lib/galene/data";
description = lib.mdDoc "Data directory.";
2020-12-30 20:22:51 +00:00
};
groupsDir = mkOption {
type = types.str;
default = defaultgroupsDir;
defaultText = literalExpression ''"''${config.${opt.stateDir}}/groups"'';
2020-12-30 20:22:51 +00:00
example = "/var/lib/galene/groups";
description = lib.mdDoc "Web server directory.";
2020-12-30 20:22:51 +00:00
};
package = mkOption {
default = pkgs.galene;
defaultText = literalExpression "pkgs.galene";
2020-12-30 20:22:51 +00:00
type = types.package;
description = lib.mdDoc ''
2020-12-30 20:22:51 +00:00
Package for running Galene.
'';
};
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = cfg.insecure || (cfg.certFile != null && cfg.keyFile != null);
message = ''
Galene needs both certFile and keyFile defined for encryption, or
the insecure flag.
'';
}
];
systemd.services.galene = {
description = "galene";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
${optionalString (cfg.insecure != true) ''
install -m 700 -o '${cfg.user}' -g '${cfg.group}' ${cfg.certFile} ${cfg.dataDir}/cert.pem
install -m 700 -o '${cfg.user}' -g '${cfg.group}' ${cfg.keyFile} ${cfg.dataDir}/key.pem
''}
2020-12-30 20:22:51 +00:00
'';
serviceConfig = mkMerge [
{
Type = "simple";
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.stateDir;
ExecStart = ''${cfg.package}/bin/galene \
${optionalString (cfg.insecure) "-insecure"} \
-data ${cfg.dataDir} \
-groups ${cfg.groupsDir} \
-recordings ${cfg.recordingsDir} \
-static ${cfg.staticDir}'';
Restart = "always";
# Upstream Requirements
LimitNOFILE = 65536;
StateDirectory = [ ] ++
optional (cfg.stateDir == defaultstateDir) "galene" ++
optional (cfg.dataDir == defaultdataDir) "galene/data" ++
optional (cfg.groupsDir == defaultgroupsDir) "galene/groups" ++
optional (cfg.recordingsDir == defaultrecordingsDir) "galene/recordings";
2022-01-22 11:58:23 +00:00
# Hardening
CapabilityBoundingSet = [ "" ];
DeviceAllow = [ "" ];
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
PrivateUsers = true;
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
ReadWritePaths = cfg.recordingsDir;
RemoveIPC = true;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [ "@system-service" "~@privileged" ];
2022-01-22 11:58:23 +00:00
UMask = "0077";
2020-12-30 20:22:51 +00:00
}
];
};
users.users = mkIf (cfg.user == "galene")
{
galene = {
description = "galene Service";
group = cfg.group;
isSystemUser = true;
};
};
users.groups = mkIf (cfg.group == "galene") {
galene = { };
};
};
meta.maintainers = with lib.maintainers; [ rgrunbla ];
}