/ modules / home / services / radicle-web.nix
radicle-web.nix
 1  {
 2    config,
 3    lib,
 4    pkgs,
 5    ...
 6  }:
 7  
 8  let
 9    cfg = config.services.radicle-web;
10  in
11  {
12    options.services.radicle-web = {
13      enable = lib.mkEnableOption "Radicle web UI (httpd + explorer)";
14  
15      httpd.port = lib.mkOption {
16        type = lib.types.port;
17        default = 8080;
18        description = "Port for radicle-httpd API server.";
19      };
20  
21      explorer.port = lib.mkOption {
22        type = lib.types.port;
23        default = 3000;
24        description = "Port for radicle-explorer web frontend.";
25      };
26    };
27  
28    config = lib.mkIf cfg.enable {
29      home.packages = [
30        (pkgs.writeShellScriptBin "rad-web" ''
31          ${pkgs.radicle-httpd}/bin/radicle-httpd --listen 127.0.0.1:${toString cfg.httpd.port} &
32          HTTPD_PID=$!
33          trap "kill $HTTPD_PID 2>/dev/null" EXIT
34          echo "radicle-httpd started on :${toString cfg.httpd.port} (PID $HTTPD_PID)"
35          echo "Serving explorer on :${toString cfg.explorer.port}..."
36          echo "Open http://localhost:${toString cfg.explorer.port}/nodes/127.0.0.1:${toString cfg.httpd.port}"
37          cd ${pkgs.radicle-explorer}
38          ${pkgs.python3}/bin/python3 -m http.server ${toString cfg.explorer.port}
39        '')
40      ];
41    };
42  }