at 21.11-pre 3.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.quassel; 7 quassel = cfg.package; 8 user = if cfg.user != null then cfg.user else "quassel"; 9in 10 11{ 12 13 ###### interface 14 15 options = { 16 17 services.quassel = { 18 19 enable = mkEnableOption "the Quassel IRC client daemon"; 20 21 certificateFile = mkOption { 22 type = types.nullOr types.str; 23 default = null; 24 description = '' 25 Path to the certificate used for SSL connections with clients. 26 ''; 27 }; 28 29 requireSSL = mkOption { 30 type = types.bool; 31 default = false; 32 description = '' 33 Require SSL for connections from clients. 34 ''; 35 }; 36 37 package = mkOption { 38 type = types.package; 39 default = pkgs.quasselDaemon; 40 defaultText = "pkgs.quasselDaemon"; 41 description = '' 42 The package of the quassel daemon. 43 ''; 44 example = literalExample "pkgs.quasselDaemon"; 45 }; 46 47 interfaces = mkOption { 48 type = types.listOf types.str; 49 default = [ "127.0.0.1" ]; 50 description = '' 51 The interfaces the Quassel daemon will be listening to. If `[ 127.0.0.1 ]', 52 only clients on the local host can connect to it; if `[ 0.0.0.0 ]', clients 53 can access it from any network interface. 54 ''; 55 }; 56 57 portNumber = mkOption { 58 type = types.port; 59 default = 4242; 60 description = '' 61 The port number the Quassel daemon will be listening to. 62 ''; 63 }; 64 65 dataDir = mkOption { 66 default = "/home/${user}/.config/quassel-irc.org"; 67 type = types.str; 68 description = '' 69 The directory holding configuration files, the SQlite database and the SSL Cert. 70 ''; 71 }; 72 73 user = mkOption { 74 default = null; 75 type = types.nullOr types.str; 76 description = '' 77 The existing user the Quassel daemon should run as. If left empty, a default "quassel" user will be created. 78 ''; 79 }; 80 81 }; 82 83 }; 84 85 86 ###### implementation 87 88 config = mkIf cfg.enable { 89 assertions = [ 90 { assertion = cfg.requireSSL -> cfg.certificateFile != null; 91 message = "Quassel needs a certificate file in order to require SSL"; 92 }]; 93 94 users.users = optionalAttrs (cfg.user == null) { 95 quassel = { 96 name = "quassel"; 97 description = "Quassel IRC client daemon"; 98 group = "quassel"; 99 uid = config.ids.uids.quassel; 100 }; 101 }; 102 103 users.groups = optionalAttrs (cfg.user == null) { 104 quassel = { 105 name = "quassel"; 106 gid = config.ids.gids.quassel; 107 }; 108 }; 109 110 systemd.tmpfiles.rules = [ 111 "d '${cfg.dataDir}' - ${user} - - -" 112 ]; 113 114 systemd.services.quassel = 115 { description = "Quassel IRC client daemon"; 116 117 wantedBy = [ "multi-user.target" ]; 118 after = [ "network.target" ] ++ optional config.services.postgresql.enable "postgresql.service" 119 ++ optional config.services.mysql.enable "mysql.service"; 120 121 serviceConfig = 122 { 123 ExecStart = concatStringsSep " " ([ 124 "${quassel}/bin/quasselcore" 125 "--listen=${concatStringsSep "," cfg.interfaces}" 126 "--port=${toString cfg.portNumber}" 127 "--configdir=${cfg.dataDir}" 128 ] ++ optional cfg.requireSSL "--require-ssl" 129 ++ optional (cfg.certificateFile != null) "--ssl-cert=${cfg.certificateFile}"); 130 User = user; 131 }; 132 }; 133 134 }; 135 136}