move the nixosModule to nixosModules.heliwatch

This commit is contained in:
Astro 2021-11-09 01:02:26 +01:00
parent 873f0b639f
commit dda6953535
3 changed files with 60 additions and 59 deletions

View File

@ -54,64 +54,6 @@
nativeBuildInputs ++ buildInputs;
};
}) // {
nixosModule = { config, lib, pkgs, ... }: {
options.services.heliwatch = with lib; {
enable = mkEnableOption "Enable Heliwatch MUC bot";
jid = mkOption {
type = types.str;
};
password = mkOption {
type = types.str;
};
muc = mkOption {
type = types.str;
description = "Full Jabber-Id in the form of room@service/nickname";
};
user = mkOption {
type = types.str;
default = "heliwatch";
};
group = mkOption {
type = types.str;
default = "heliwatch";
};
};
config =
let
cfg = config.services.heliwatch;
in
lib.mkIf cfg.enable {
users = {
users.${cfg.user} = {
isSystemUser = true;
home = "/home/heliwatch";
createHome = true;
group = cfg.group;
};
groups.${cfg.group} = {};
};
systemd.services.heliwatch = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
path = with pkgs; [ bash curl ];
script = ''
${./fetch_data.sh}
exec ${self.packages.${pkgs.system}.heliwatch}/bin/heliwatch ${lib.escapeShellArgs (with cfg; [ jid password muc ])}
'';
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
WorkingDirectory = config.users.users.${cfg.user}.home;
ReadWritePaths = config.users.users.${cfg.user}.home;
ProtectSystem = "full";
Restart = "always";
RestartSec = "60s";
};
};
};
};
nixosModules.heliwatch = import ./heliwatch/module.nix;
};
}

59
heliwatch/module.nix Normal file
View File

@ -0,0 +1,59 @@
{ config, lib, pkgs, ... }: {
options.services.heliwatch = with lib; {
enable = mkEnableOption "Enable Heliwatch MUC bot";
jid = mkOption {
type = types.str;
};
password = mkOption {
type = types.str;
};
muc = mkOption {
type = types.str;
description = "Full Jabber-Id in the form of room@service/nickname";
};
user = mkOption {
type = types.str;
default = "heliwatch";
};
group = mkOption {
type = types.str;
default = "heliwatch";
};
};
config =
let
cfg = config.services.heliwatch;
in
lib.mkIf cfg.enable {
users = {
users.${cfg.user} = {
isSystemUser = true;
home = "/home/heliwatch";
createHome = true;
group = cfg.group;
};
groups.${cfg.group} = {};
};
systemd.services.heliwatch = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
path = with pkgs; [ bash curl ];
script = ''
${./fetch_data.sh}
exec ${self.packages.${pkgs.system}.heliwatch}/bin/heliwatch ${lib.escapeShellArgs (with cfg; [ jid password muc ])}
'';
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
WorkingDirectory = config.users.users.${cfg.user}.home;
ReadWritePaths = config.users.users.${cfg.user}.home;
ProtectSystem = "full";
Restart = "always";
RestartSec = "60s";
};
};
};
}