modules/betanin: init

This commit is contained in:
xeals 2023-09-27 14:12:26 +10:00
parent 8da5c3d901
commit 56bb9289f6
Signed by: xeals
SSH Key Fingerprint: SHA256:pRv+8swQDA+/LuZ7NHj9m006BbKexlNK62OUA01ZZBc
2 changed files with 115 additions and 0 deletions

View File

@ -2,6 +2,7 @@
amdgpu-common = ./services/hardware/amdgpu-common.nix;
amdgpu-fan = ./services/hardware/amdgpu-fan.nix;
amdgpu-pwm = ./services/hardware/amdgpu-pwm.nix;
betanin = ./services/web-apps/betanin.nix;
dunst = ./services/x11/dunst.nix;
radeon-profile-daemon = ./services/hardware/radeon-profile-daemon.nix;
}

View File

@ -0,0 +1,114 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkIf mkOption optionalAttrs types;
cfg = config.services.betanin;
yaml = pkgs.formats.yaml { };
configFile =
if (cfg.beetsConfigFile != null)
then cfg.beetsConfigFile
else yaml.generate "beets-config.yaml" cfg.beetsConfig;
defaultUser = "betanin";
defaultGroup = "betanin";
in
{
options = {
services.betanin = {
enable = lib.mkEnableOption "betanin";
package = mkOption {
description = "Package containing betanin program.";
type = types.package;
default = pkgs.betanin or (import ../../.. { inherit pkgs; }).betanin;
};
openFirewall = mkOption {
description = "Open ports in the firewall for the server.";
type = types.bool;
default = false;
};
port = mkOption {
description = "Port to access betanin on.";
type = types.port;
default = 9393;
};
user = mkOption {
description = "User that the betanin program should run under.";
type = types.str;
default = defaultUser;
};
group = mkOption {
description = "Group that the betanin program should run under.";
type = types.str;
default = defaultGroup;
};
dataDir = mkOption {
description = "Directory to store application data.";
type = types.str;
default = "/var/lib/betanin";
};
beetsConfig = mkOption {
description = "beets configuration.";
type = yaml.type;
default = { };
};
beetsConfigFile = mkOption {
description = "beets configuration file.";
type = nullOr (either str path);
default = null;
};
};
};
config = mkIf cfg.enable {
assertions = [{
assertion = (cfg.beetsConfig == { }) != (cfg.beetsConfigFile == null);
message = "either services.betanin.beetsConfig or services.betanin.beetsConfigFile is required";
}];
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
systemd.services.betanin = {
description = "Betanin service";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" ];
environment = {
HOME = cfg.dataDir;
};
serviceConfig = lib.mkMerge [
{
User = cfg.user;
Group = cfg.group;
ExecStart = "${cfg.package}/bin/betanin --port ${cfg.port}";
PrivateTmp = true;
Restart = "always";
WorkingDirectory = cfg.dataDir;
}
(mkIf (cfg.dataDir == "/var/lib/betanin") {
StateDirectory = "betanin";
})
];
};
users.users = optionalAttrs (cfg.user == defaultUser) {
${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
};
users.groups = optionalAttrs (cfg.group == defaultGroup) {
${cfg.group} = { };
};
};
}