at 25.11-pre 3.1 kB view raw
1{ 2 pkgs, 3 lib, 4 config, 5 ... 6}: 7 8let 9 cfg = config.services.lanraragi; 10in 11{ 12 meta.maintainers = with lib.maintainers; [ tomasajt ]; 13 14 options.services = { 15 lanraragi = { 16 enable = lib.mkEnableOption "LANraragi"; 17 package = lib.mkPackageOption pkgs "lanraragi" { }; 18 19 port = lib.mkOption { 20 type = lib.types.port; 21 default = 3000; 22 description = "Port for LANraragi's web interface."; 23 }; 24 25 passwordFile = lib.mkOption { 26 type = lib.types.nullOr lib.types.path; 27 default = null; 28 example = "/run/keys/lanraragi-password"; 29 description = '' 30 A file containing the password for LANraragi's admin interface. 31 ''; 32 }; 33 34 redis = { 35 port = lib.mkOption { 36 type = lib.types.port; 37 default = 6379; 38 description = "Port for LANraragi's Redis server."; 39 }; 40 passwordFile = lib.mkOption { 41 type = lib.types.nullOr lib.types.path; 42 default = null; 43 example = "/run/keys/redis-lanraragi-password"; 44 description = '' 45 A file containing the password for LANraragi's Redis server. 46 ''; 47 }; 48 }; 49 }; 50 }; 51 52 config = lib.mkIf cfg.enable { 53 services.redis.servers.lanraragi = { 54 enable = true; 55 port = cfg.redis.port; 56 requirePassFile = cfg.redis.passwordFile; 57 }; 58 59 systemd.services.lanraragi = { 60 description = "LANraragi main service"; 61 after = [ 62 "network.target" 63 "redis-lanraragi.service" 64 ]; 65 requires = [ "redis-lanraragi.service" ]; 66 wantedBy = [ "multi-user.target" ]; 67 serviceConfig = { 68 ExecStart = lib.getExe cfg.package; 69 DynamicUser = true; 70 StateDirectory = "lanraragi"; 71 RuntimeDirectory = "lanraragi"; 72 LogsDirectory = "lanraragi"; 73 Restart = "on-failure"; 74 WorkingDirectory = "/var/lib/lanraragi"; 75 }; 76 environment = { 77 "LRR_TEMP_DIRECTORY" = "/run/lanraragi"; 78 "LRR_LOG_DIRECTORY" = "/var/log/lanraragi"; 79 "LRR_NETWORK" = "http://*:${toString cfg.port}"; 80 "HOME" = "/var/lib/lanraragi"; 81 }; 82 preStart = 83 '' 84 cat > lrr.conf <<EOF 85 { 86 redis_address => "127.0.0.1:${toString cfg.redis.port}", 87 redis_password => "${ 88 lib.optionalString (cfg.redis.passwordFile != null) ''$(head -n1 ${cfg.redis.passwordFile})'' 89 }", 90 redis_database => "0", 91 redis_database_minion => "1", 92 redis_database_config => "2", 93 redis_database_search => "3", 94 } 95 EOF 96 '' 97 + lib.optionalString (cfg.passwordFile != null) '' 98 ${lib.getExe pkgs.redis} -h 127.0.0.1 -p ${toString cfg.redis.port} ${ 99 lib.optionalString (cfg.redis.passwordFile != null) ''-a "$(head -n1 ${cfg.redis.passwordFile})"'' 100 }<<EOF 101 SELECT 2 102 HSET LRR_CONFIG password $(${cfg.package}/bin/helpers/lrr-make-password-hash $(head -n1 ${cfg.passwordFile})) 103 EOF 104 ''; 105 }; 106 }; 107}