mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
add a nixos module
This commit is contained in:
parent
17eb354590
commit
33e7a46b53
2 changed files with 121 additions and 1 deletions
|
|
@ -94,5 +94,9 @@
|
|||
|
||||
devShells.default = (mkScope pkgs).shell;
|
||||
}
|
||||
);
|
||||
)
|
||||
//
|
||||
{
|
||||
nixosModules.default = import ./nix/modules/default inputs;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
116
nix/modules/default/default.nix
Normal file
116
nix/modules/default/default.nix
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
inputs:
|
||||
|
||||
{ config
|
||||
, lib
|
||||
, pkgs
|
||||
, ...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib) types;
|
||||
|
||||
cfg = config.services.grapevine;
|
||||
configFile = format.generate "config.toml" cfg.settings;
|
||||
format = pkgs.formats.toml {};
|
||||
in
|
||||
|
||||
{
|
||||
options.services.grapevine = {
|
||||
enable = lib.mkEnableOption "grapevine";
|
||||
package = lib.mkPackageOption
|
||||
inputs.self.packages.${pkgs.system}
|
||||
"grapevine"
|
||||
{
|
||||
default = "default";
|
||||
pkgsText = "inputs.grapevine.packages.\${pkgs.system}";
|
||||
};
|
||||
|
||||
extraEnvironment = lib.mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
description = ''
|
||||
Extra environment variables to set for the process.
|
||||
'';
|
||||
default = {};
|
||||
example = { RUST_BACKTRACE="yes"; };
|
||||
};
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = types.submodule {
|
||||
freeformType = format.type;
|
||||
options = {
|
||||
global.address = lib.mkOption {
|
||||
type = types.nonEmptyStr;
|
||||
description = ''
|
||||
The local IP address to bind to.
|
||||
'';
|
||||
default = "::1";
|
||||
};
|
||||
global.database_path = lib.mkOption {
|
||||
type = types.nonEmptyStr;
|
||||
readOnly = true;
|
||||
description = ''
|
||||
The path to store persistent data in.
|
||||
|
||||
Note that this is read-only because this module makes use of
|
||||
systemd's `StateDirectory` option.
|
||||
'';
|
||||
default = "/var/lib/grapevine";
|
||||
};
|
||||
global.port = lib.mkOption {
|
||||
type = types.port;
|
||||
description = ''
|
||||
The local port to bind to.
|
||||
'';
|
||||
default = 6167;
|
||||
};
|
||||
};
|
||||
};
|
||||
default = {};
|
||||
description = ''
|
||||
The TOML configuration file is generated from this attribute set.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.grapevine = {
|
||||
description = "Grapevine (Matrix homeserver)";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
environment = lib.mkMerge [
|
||||
{
|
||||
GRAPEVINE_CONFIG = configFile;
|
||||
}
|
||||
cfg.extraEnvironment
|
||||
];
|
||||
|
||||
# Keep sorted
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
ExecStart = "${lib.getExe cfg.package}";
|
||||
LockPersonality = true;
|
||||
MemoryDenyWriteExecute = true;
|
||||
PrivateDevices = true;
|
||||
PrivateMounts = true;
|
||||
PrivateUsers = true;
|
||||
ProtectClock = true;
|
||||
ProtectControlGroups = true;
|
||||
ProtectHostname = true;
|
||||
ProtectKernelLogs = true;
|
||||
ProtectKernelModules = true;
|
||||
ProtectKernelTunables = true;
|
||||
Restart = "on-failure";
|
||||
RestartSec = 10;
|
||||
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
||||
RestrictNamespaces = true;
|
||||
RestrictRealtime = true;
|
||||
StartLimitBurst = 5;
|
||||
StateDirectory = "grapevine";
|
||||
StateDirectoryMode = "0700";
|
||||
SystemCallArchitectures = "native";
|
||||
SystemCallFilter = [ "@system-service" "~@privileged" ];
|
||||
UMask = "077";
|
||||
User = "grapevine";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue