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