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