2019-05-01 04:38:58 +08:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
homu = pkgs.callPackage ./pkg.nix {};
|
|
|
|
cfg = config.services.homu;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.homu = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable the bot";
|
|
|
|
};
|
2019-05-02 13:53:34 +08:00
|
|
|
dbDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/db/homu";
|
|
|
|
description = "Path to the database file (use the same path in config.toml)";
|
|
|
|
};
|
2019-05-01 04:38:58 +08:00
|
|
|
config = mkOption {
|
2019-05-02 13:53:34 +08:00
|
|
|
description = "Location of config.toml";
|
|
|
|
type = types.str;
|
2019-05-01 04:38:58 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-05-01 04:50:26 +08:00
|
|
|
users.users.homu = {
|
|
|
|
group = "homu";
|
2019-05-02 13:53:34 +08:00
|
|
|
home = cfg.dbDir;
|
2019-05-01 04:50:26 +08:00
|
|
|
createHome = true;
|
2019-05-01 04:38:58 +08:00
|
|
|
};
|
2019-05-01 04:50:26 +08:00
|
|
|
users.groups.homu = {};
|
|
|
|
|
2019-05-01 04:38:58 +08:00
|
|
|
systemd.services.homu = {
|
|
|
|
description = "Homu bot";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2019-05-02 13:53:34 +08:00
|
|
|
ExecStart = "${homu}/bin/homu -c ${cfg.config}";
|
2019-05-01 04:38:58 +08:00
|
|
|
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5sec";
|
|
|
|
|
2019-05-01 04:50:26 +08:00
|
|
|
User = "homu";
|
|
|
|
Group = "homu";
|
2019-05-01 04:38:58 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|