at v192 1.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.lambdabot; 8 9 rc = builtins.toFile "script.rc" cfg.script; 10 11in 12 13{ 14 15 ### configuration 16 17 options = { 18 19 services.lambdabot = { 20 21 enable = mkOption { 22 type = types.bool; 23 default = false; 24 description = "Enable the Lambdabot IRC bot"; 25 }; 26 27 package = mkOption { 28 type = types.package; 29 default = pkgs.lambdabot; 30 description = "Used lambdabot package"; 31 }; 32 33 script = mkOption { 34 type = types.str; 35 default = ""; 36 description = "Lambdabot script"; 37 }; 38 39 }; 40 41 }; 42 43 ### implementation 44 45 config = mkIf cfg.enable { 46 47 systemd.services.lambdabot = { 48 description = "Lambdabot daemon"; 49 after = [ "network.target" ]; 50 wantedBy = [ "multi-user.target" ]; 51 # Workaround for https://github.com/lambdabot/lambdabot/issues/117 52 script = '' 53 mkdir -p ~/.lambdabot 54 cd ~/.lambdabot 55 mkfifo /run/lambdabot/offline 56 ( 57 echo 'rc ${rc}' 58 while true; do 59 cat /run/lambdabot/offline 60 done 61 ) | ${cfg.package}/bin/lambdabot 62 ''; 63 serviceConfig = { 64 User = "lambdabot"; 65 RuntimeDirectory = [ "lambdabot" ]; 66 }; 67 }; 68 69 users.extraUsers.lambdabot = { 70 group = "lambdabot"; 71 description = "Lambdabot daemon user"; 72 home = "/var/lib/lambdabot"; 73 createHome = true; 74 uid = config.ids.uids.lambdabot; 75 }; 76 77 users.extraGroups.lambdabot.gid = config.ids.gids.lambdabot; 78 79 }; 80 81}