@@ -0,0 +1,72 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+
7+ cfg = config.services.virtlyst;
8+ stateDir = "/var/lib/virtlyst";
9+
10+ ini = pkgs.writeText "virtlyst-config.ini" ''
11+ [wsgi]
12+ master = true
13+ threads = auto
14+ http-socket = ${cfg.httpSocket}
15+ application = ${pkgs.virtlyst}/lib/libVirtlyst.so
16+ chdir2 = ${stateDir}
17+ static-map = /static=${pkgs.virtlyst}/root/static
18+
19+ [Cutelyst]
20+ production = true
21+ DatabasePath = virtlyst.sqlite
22+ TemplatePath = ${pkgs.virtlyst}/root/src
23+
24+ [Rules]
25+ cutelyst.* = true
26+ virtlyst.* = true
27+ '';
28+
29+in
30+
31+{
32+
33+ options.services.virtlyst = {
34+ enable = mkEnableOption "Virtlyst libvirt web interface";
35+
36+ adminPassword = mkOption {
37+ type = types.str;
38+ description = ''
39+ Initial admin password with which the database will be seeded.
40+ '';
41+ };
42+
43+ httpSocket = mkOption {
44+ type = types.str;
45+ default = "localhost:3000";
46+ description = ''
47+ IP and/or port to which to bind the http socket.
48+ '';
49+ };
50+ };
51+
52+ config = mkIf cfg.enable {
53+ users.extraUsers.virtlyst = {
54+ home = stateDir;
55+ createHome = true;
56+ group = mkIf config.virtualisation.libvirtd.enable "libvirtd";
57+ };
58+
59+ systemd.services.virtlyst = {
60+ wantedBy = [ "multi-user.target" ];
61+ environment = {
62+ VIRTLYST_ADMIN_PASSWORD = cfg.adminPassword;
63+ };
64+ serviceConfig = {
65+ ExecStart = "${pkgs.cutelyst}/bin/cutelyst-wsgi2 --ini ${ini}";
66+ User = "virtlyst";
67+ WorkingDirectory = stateDir;
68+ };
69+ };
70+ };
71+
72+}