xin/modules/gotosocial.nix

84 lines
2.0 KiB
Nix
Raw Normal View History

2023-09-12 08:44:05 -06:00
{ config
, lib
, pkgs
, ...
2023-07-11 09:12:50 -06:00
}:
with pkgs; let
cfg = config.services.gotosocial;
2023-09-12 08:44:05 -06:00
gotosocial = callPackage ../pkgs/gotosocial.nix { };
settingsFormat = pkgs.formats.json { };
settingsType = settingsFormat.type;
prettyJSON = conf:
2023-09-12 08:44:05 -06:00
pkgs.runCommandLocal "gotosocial-config.json" { } ''
echo '${
builtins.toJSON conf
}' | ${pkgs.buildPackages.jq}/bin/jq 'del(._module)' > $out
'';
2023-09-12 08:44:05 -06:00
in
{
options = with lib; {
services.gotosocial = {
enable = mkEnableOption "Enable gotosocial";
user = mkOption {
2023-09-12 08:44:05 -06:00
type = with types; oneOf [ str int ];
default = "gotosocial";
description = ''
The user the service will use.
'';
};
group = mkOption {
2023-09-12 08:44:05 -06:00
type = with types; oneOf [ str int ];
default = "gotosocial";
description = ''
The user the service will use.
'';
};
configuration = mkOption {
type = settingsType;
description = ''
Specify the configuration for GoToSocial in Nix.
'';
};
package = mkOption {
type = types.package;
default = gotosocial;
defaultText = literalExpression "pkgs.gotosocial";
description = "The package to use for gotosocial";
};
};
};
config = lib.mkIf cfg.enable {
2023-09-12 08:44:05 -06:00
users.groups.gotosocial = { };
users.users.gotosocial = {
description = "Gotosocial service user";
isSystemUser = true;
home = "/var/lib/gotosocial";
createHome = true;
group = "gotosocial";
};
systemd.services.gotosocial = {
enable = true;
description = "GoToSocial server";
2023-09-12 08:44:05 -06:00
wantedBy = [ "multi-user.target" ];
after = [ "postgresql.service" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
RuntimeDirectory = "/var/lib/gotosocial";
ExecStart = "${cfg.package}/bin/gotosocial --config-path ${
2023-07-11 09:12:50 -06:00
prettyJSON cfg.configuration
} server start";
};
};
};
}