From 90554a03c72b33d7636ebabe21e7f9d31f9566ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cillian=20de=20R=C3=B3iste?= Date: Thu, 1 Aug 2013 00:36:15 +0200 Subject: [PATCH 1/3] Supybot/limnoria: add service module --- modules/misc/ids.nix | 1 + modules/module-list.nix | 1 + modules/services/networking/supybot.nix | 97 +++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 modules/services/networking/supybot.nix diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix index 7272c3e7d5d..54c9b331ade 100644 --- a/modules/misc/ids.nix +++ b/modules/misc/ids.nix @@ -76,6 +76,7 @@ in nslcd = 58; nginx = 60; chrony = 61; + supybot = 62; # When adding a uid, make sure it doesn't match an existing gid. diff --git a/modules/module-list.nix b/modules/module-list.nix index ebe66d1fa6e..4f014c9d348 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -169,6 +169,7 @@ ./services/networking/rdnssd.nix ./services/networking/rpcbind.nix ./services/networking/sabnzbd.nix + ./services/networking/supybot.nix ./services/networking/ssh/lshd.nix ./services/networking/ssh/sshd.nix ./services/networking/tftpd.nix diff --git a/modules/services/networking/supybot.nix b/modules/services/networking/supybot.nix new file mode 100644 index 00000000000..f65665e41e4 --- /dev/null +++ b/modules/services/networking/supybot.nix @@ -0,0 +1,97 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + cfg = config.services.supybot; + configFile = pkgs.writeText "supybot.cfg" cfg.config; + +in + +{ + + ###### interface + + options = { + + services.supybot = { + + enable = mkOption { + default = false; + description = "Enable the supybot IRC bot"; + }; + + homeDir = mkOption { + default = "/home/supybot"; + description = " + Directory holding all state for nginx to run. + "; + }; + + config = mkOption { + type = types.lines; + default = ""; + description = '' + Verbatim contents of the supybot config, this can be + generated by supybot-wizard + ''; + }; + + user = mkOption { + default = "supybot"; + description = "User account under which supybot runs."; + }; + + group = mkOption { + default = "supybot"; + description = "Group account under which supybot runs."; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + environment.systemPackages = [ pkgs.pythonPackages.limnoria ]; + + users.extraUsers = singleton + { name = cfg.user; + uid = config.ids.uids.supybot; + group = "supybot"; + description = "Supybot IRC bot user"; + home = cfg.homeDir; + createHome = true; + }; + + users.extraGroups.supybot = {}; + + systemd.services.supybot = + { description = "Supybot IRC bot"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + path = [ pkgs.pythonPackages.limnoria ]; + preStart = '' + cd ${cfg.homeDir} + mkdir -p logs/plugins backup conf data plugins tmp + ''; + serviceConfig = + { ExecStart = + "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.homeDir}/supybot.cfg"; + PIDFile = "/run/supybot.pid"; + User = "${cfg.user}"; + Group = "${cfg.group}"; + UMask = "0007"; + Restart = "on-abort"; + StartLimitInterval = "5m"; + StartLimitBurst = "1"; + }; + }; + + }; + +} From 6e093113fe50a55fb055d0819d2bca797c140d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cillian=20de=20R=C3=B3iste?= Date: Sun, 4 Aug 2013 00:18:44 +0200 Subject: [PATCH 2/3] Supybot service: failing to create stateDir in /var/lib --- modules/services/networking/supybot.nix | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/modules/services/networking/supybot.nix b/modules/services/networking/supybot.nix index f65665e41e4..944e5828fe0 100644 --- a/modules/services/networking/supybot.nix +++ b/modules/services/networking/supybot.nix @@ -5,7 +5,6 @@ with pkgs.lib; let cfg = config.services.supybot; - configFile = pkgs.writeText "supybot.cfg" cfg.config; in @@ -19,19 +18,19 @@ in enable = mkOption { default = false; - description = "Enable the supybot IRC bot"; + description = "Enable Supybot, an IRC bot"; }; - homeDir = mkOption { - default = "/home/supybot"; + stateDir = mkOption { + default = "/var/lib/supybot"; description = " - Directory holding all state for nginx to run. + "; }; - config = mkOption { - type = types.lines; - default = ""; + configFile = mkOption { + type = types.path; + default = /dev/null; description = '' Verbatim contents of the supybot config, this can be generated by supybot-wizard @@ -56,7 +55,7 @@ in ###### implementation config = mkIf cfg.enable { - + environment.systemPackages = [ pkgs.pythonPackages.limnoria ]; users.extraUsers = singleton @@ -64,9 +63,9 @@ in uid = config.ids.uids.supybot; group = "supybot"; description = "Supybot IRC bot user"; - home = cfg.homeDir; + home = cfg.stateDir; createHome = true; - }; + }; users.extraGroups.supybot = {}; @@ -76,14 +75,18 @@ in wantedBy = [ "multi-user.target" ]; path = [ pkgs.pythonPackages.limnoria ]; preStart = '' - cd ${cfg.homeDir} + mkdir -m 0755 -p ${cfg.stateDir} + chown ${cfg.user}:${cfg.group} ${cfg.stateDir} + cd ${cfg.stateDir} mkdir -p logs/plugins backup conf data plugins tmp + ln -sf ${cfg.configFile} supybot.cfg + rm -f supybot.cfg.bak ''; serviceConfig = { ExecStart = - "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.homeDir}/supybot.cfg"; + "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg"; PIDFile = "/run/supybot.pid"; - User = "${cfg.user}"; + User = "${cfg.user}"; Group = "${cfg.group}"; UMask = "0007"; Restart = "on-abort"; From 5b25c5a18145e47fe27602b4cb721228edd6a1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cillian=20de=20R=C3=B3iste?= Date: Sun, 4 Aug 2013 03:56:01 +0200 Subject: [PATCH 3/3] supybot.service: tidy up --- modules/misc/ids.nix | 1 + modules/services/networking/supybot.nix | 98 +++++++++++-------------- 2 files changed, 44 insertions(+), 55 deletions(-) diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix index 54c9b331ade..f22a06e0c83 100644 --- a/modules/misc/ids.nix +++ b/modules/misc/ids.nix @@ -136,6 +136,7 @@ in scanner = 59; nginx = 60; systemd-journal = 62; + supybot = 63; # When adding a gid, make sure it doesn't match an existing uid. diff --git a/modules/services/networking/supybot.nix b/modules/services/networking/supybot.nix index 944e5828fe0..fa8b7556de5 100644 --- a/modules/services/networking/supybot.nix +++ b/modules/services/networking/supybot.nix @@ -10,8 +10,6 @@ in { - ###### interface - options = { services.supybot = { @@ -22,79 +20,69 @@ in }; stateDir = mkOption { - default = "/var/lib/supybot"; - description = " - - "; + # Setting this to /var/lib/supybot caused useradd to fail + default = "/home/supybot"; + description = "The root directory, logs and plugins are stored here"; }; configFile = mkOption { type = types.path; - default = /dev/null; description = '' - Verbatim contents of the supybot config, this can be - generated by supybot-wizard + Path to a supybot config file. This can be generated by + running supybot-wizard. + + Note: all paths should include the full path to the stateDir + directory (backup conf data logs logs/plugins plugins tmp web). ''; }; - user = mkOption { - default = "supybot"; - description = "User account under which supybot runs."; - }; - - group = mkOption { - default = "supybot"; - description = "Group account under which supybot runs."; - }; - }; }; - ###### implementation - config = mkIf cfg.enable { environment.systemPackages = [ pkgs.pythonPackages.limnoria ]; - users.extraUsers = singleton - { name = cfg.user; - uid = config.ids.uids.supybot; - group = "supybot"; - description = "Supybot IRC bot user"; - home = cfg.stateDir; - createHome = true; - }; + users.extraUsers = singleton { + name = "supybot"; + uid = config.ids.uids.supybot; + group = "supybot"; + description = "Supybot IRC bot user"; + home = cfg.stateDir; + createHome = true; + }; - users.extraGroups.supybot = {}; + users.extraGroups.supybot = { + name = "supybot"; + gid = config.ids.gids.supybot; + }; - systemd.services.supybot = - { description = "Supybot IRC bot"; - after = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - path = [ pkgs.pythonPackages.limnoria ]; - preStart = '' - mkdir -m 0755 -p ${cfg.stateDir} - chown ${cfg.user}:${cfg.group} ${cfg.stateDir} - cd ${cfg.stateDir} - mkdir -p logs/plugins backup conf data plugins tmp - ln -sf ${cfg.configFile} supybot.cfg - rm -f supybot.cfg.bak - ''; - serviceConfig = - { ExecStart = - "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg"; - PIDFile = "/run/supybot.pid"; - User = "${cfg.user}"; - Group = "${cfg.group}"; - UMask = "0007"; - Restart = "on-abort"; - StartLimitInterval = "5m"; - StartLimitBurst = "1"; - }; + systemd.services.supybot = { + description = "Supybot, an IRC bot"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + path = [ pkgs.pythonPackages.limnoria ]; + preStart = '' + cd ${cfg.stateDir} + mkdir -p backup conf data plugins logs/plugins tmp web + ln -sf ${cfg.configFile} supybot.cfg + # This needs to be created afresh every time + rm -f supybot.cfg.bak + ''; + + serviceConfig = { + ExecStart = "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg"; + PIDFile = "/run/supybot.pid"; + User = "supybot"; + Group = "supybot"; + UMask = "0007"; + Restart = "on-abort"; + StartLimitInterval = "5m"; + StartLimitBurst = "1"; }; + }; }; - }