1# Disnix server
2{
3 config,
4 lib,
5 pkgs,
6 ...
7}:
8let
9
10 cfg = config.services.disnix;
11
12in
13
14{
15
16 ###### interface
17
18 options = {
19
20 services.disnix = {
21
22 enable = lib.mkEnableOption "Disnix";
23
24 enableMultiUser = lib.mkOption {
25 type = lib.types.bool;
26 default = true;
27 description = "Whether to support multi-user mode by enabling the Disnix D-Bus service";
28 };
29
30 useWebServiceInterface = lib.mkEnableOption "the DisnixWebService interface running on Apache Tomcat";
31
32 package = lib.mkPackageOption pkgs "disnix" { };
33
34 enableProfilePath = lib.mkEnableOption "exposing the Disnix profiles in the system's PATH";
35
36 profiles = lib.mkOption {
37 type = lib.types.listOf lib.types.str;
38 default = [ "default" ];
39 description = "Names of the Disnix profiles to expose in the system's PATH";
40 };
41 };
42
43 };
44
45 ###### implementation
46
47 config = lib.mkIf cfg.enable {
48 services.dysnomia.enable = true;
49
50 environment.systemPackages = [
51 pkgs.disnix
52 ] ++ lib.optional cfg.useWebServiceInterface pkgs.DisnixWebService;
53 environment.variables.PATH = lib.optionals cfg.enableProfilePath (
54 map (profileName: "/nix/var/nix/profiles/disnix/${profileName}/bin") cfg.profiles
55 );
56 environment.variables.DISNIX_REMOTE_CLIENT = lib.optionalString (cfg.enableMultiUser) "disnix-client";
57
58 services.dbus.enable = true;
59 services.dbus.packages = [ pkgs.disnix ];
60
61 services.tomcat.enable = cfg.useWebServiceInterface;
62 services.tomcat.extraGroups = [ "disnix" ];
63 services.tomcat.javaOpts = "${lib.optionalString cfg.useWebServiceInterface "-Djava.library.path=${pkgs.libmatthew_java}/lib/jni"} ";
64 services.tomcat.sharedLibs =
65 lib.optional cfg.useWebServiceInterface "${pkgs.DisnixWebService}/share/java/DisnixConnection.jar"
66 ++ lib.optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar";
67 services.tomcat.webapps = lib.optional cfg.useWebServiceInterface pkgs.DisnixWebService;
68
69 users.groups.disnix.gid = config.ids.gids.disnix;
70
71 systemd.services = {
72 disnix = lib.mkIf cfg.enableMultiUser {
73 description = "Disnix server";
74 wants = [ "dysnomia.target" ];
75 wantedBy = [ "multi-user.target" ];
76 after =
77 [ "dbus.service" ]
78 ++ lib.optional config.services.httpd.enable "httpd.service"
79 ++ lib.optional config.services.mysql.enable "mysql.service"
80 ++ lib.optional config.services.postgresql.enable "postgresql.service"
81 ++ lib.optional config.services.tomcat.enable "tomcat.service"
82 ++ lib.optional config.services.svnserve.enable "svnserve.service"
83 ++ lib.optional config.services.mongodb.enable "mongodb.service"
84 ++ lib.optional config.services.influxdb.enable "influxdb.service";
85
86 restartIfChanged = false;
87
88 path = [
89 config.nix.package
90 cfg.package
91 config.services.dysnomia.package
92 "/run/current-system/sw"
93 ];
94
95 environment =
96 {
97 HOME = "/root";
98 }
99 // (lib.optionalAttrs (config.environment.variables ? DYSNOMIA_CONTAINERS_PATH) {
100 inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH;
101 })
102 // (lib.optionalAttrs (config.environment.variables ? DYSNOMIA_MODULES_PATH) {
103 inherit (config.environment.variables) DYSNOMIA_MODULES_PATH;
104 });
105
106 serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service";
107 };
108
109 };
110 };
111}