1 { pkgs, lib, config, ... }:
4 cfg = config.services.lanraragi;
7 meta.maintainers = with lib.maintainers; [ tomasajt ];
11 enable = lib.mkEnableOption "LANraragi";
12 package = lib.mkPackageOption pkgs "lanraragi" { };
15 type = lib.types.port;
17 description = "Port for LANraragi's web interface.";
20 passwordFile = lib.mkOption {
21 type = lib.types.nullOr lib.types.path;
23 example = "/run/keys/lanraragi-password";
25 A file containing the password for LANraragi's admin interface.
31 type = lib.types.port;
33 description = "Port for LANraragi's Redis server.";
35 passwordFile = lib.mkOption {
36 type = lib.types.nullOr lib.types.path;
38 example = "/run/keys/redis-lanraragi-password";
40 A file containing the password for LANraragi's Redis server.
47 config = lib.mkIf cfg.enable {
48 services.redis.servers.lanraragi = {
50 port = cfg.redis.port;
51 requirePassFile = cfg.redis.passwordFile;
54 systemd.services.lanraragi = {
55 description = "LANraragi main service";
56 after = [ "network.target" "redis-lanraragi.service" ];
57 requires = [ "redis-lanraragi.service" ];
58 wantedBy = [ "multi-user.target" ];
60 ExecStart = lib.getExe cfg.package;
62 StateDirectory = "lanraragi";
63 RuntimeDirectory = "lanraragi";
64 LogsDirectory = "lanraragi";
65 Restart = "on-failure";
66 WorkingDirectory = "/var/lib/lanraragi";
69 "LRR_TEMP_DIRECTORY" = "/run/lanraragi";
70 "LRR_LOG_DIRECTORY" = "/var/log/lanraragi";
71 "LRR_NETWORK" = "http://*:${toString cfg.port}";
72 "HOME" = "/var/lib/lanraragi";
77 redis_address => "127.0.0.1:${toString cfg.redis.port}",
78 redis_password => "${lib.optionalString (cfg.redis.passwordFile != null) ''$(head -n1 ${cfg.redis.passwordFile})''}",
79 redis_database => "0",
80 redis_database_minion => "1",
81 redis_database_config => "2",
82 redis_database_search => "3",
85 '' + lib.optionalString (cfg.passwordFile != null) ''
86 ${lib.getExe pkgs.redis} -h 127.0.0.1 -p ${toString cfg.redis.port} ${lib.optionalString (cfg.redis.passwordFile != null) ''-a "$(head -n1 ${cfg.redis.passwordFile})"''}<<EOF
88 HSET LRR_CONFIG password $(${cfg.package}/bin/helpers/lrr-make-password-hash $(head -n1 ${cfg.passwordFile}))