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