From dda695353570911bda0f05fa75bd92941cc8cf7c Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 9 Nov 2021 01:02:26 +0100 Subject: [PATCH] move the nixosModule to nixosModules.heliwatch --- flake.nix | 60 +----------------------- fetch_data.sh => heliwatch/fetch_data.sh | 0 heliwatch/module.nix | 59 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 59 deletions(-) rename fetch_data.sh => heliwatch/fetch_data.sh (100%) create mode 100644 heliwatch/module.nix diff --git a/flake.nix b/flake.nix index 386ea13..e5c6b12 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } diff --git a/fetch_data.sh b/heliwatch/fetch_data.sh similarity index 100% rename from fetch_data.sh rename to heliwatch/fetch_data.sh diff --git a/heliwatch/module.nix b/heliwatch/module.nix new file mode 100644 index 0000000..de1b178 --- /dev/null +++ b/heliwatch/module.nix @@ -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"; + }; + }; + }; +}