at master 3.5 kB view raw
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 ] 53 ++ lib.optional cfg.useWebServiceInterface pkgs.DisnixWebService; 54 environment.variables.PATH = lib.optionals cfg.enableProfilePath ( 55 map (profileName: "/nix/var/nix/profiles/disnix/${profileName}/bin") cfg.profiles 56 ); 57 environment.variables.DISNIX_REMOTE_CLIENT = lib.optionalString (cfg.enableMultiUser) "disnix-client"; 58 59 services.dbus.enable = true; 60 services.dbus.packages = [ pkgs.disnix ]; 61 62 services.tomcat.enable = cfg.useWebServiceInterface; 63 services.tomcat.extraGroups = [ "disnix" ]; 64 services.tomcat.javaOpts = "${lib.optionalString cfg.useWebServiceInterface "-Djava.library.path=${pkgs.libmatthew_java}/lib/jni"} "; 65 services.tomcat.sharedLibs = 66 lib.optional cfg.useWebServiceInterface "${pkgs.DisnixWebService}/share/java/DisnixConnection.jar" 67 ++ lib.optional cfg.useWebServiceInterface "${pkgs.dbus_java}/share/java/dbus.jar"; 68 services.tomcat.webapps = lib.optional cfg.useWebServiceInterface pkgs.DisnixWebService; 69 70 users.groups.disnix.gid = config.ids.gids.disnix; 71 72 systemd.services = { 73 disnix = lib.mkIf cfg.enableMultiUser { 74 description = "Disnix server"; 75 wants = [ "dysnomia.target" ]; 76 wantedBy = [ "multi-user.target" ]; 77 after = [ 78 "dbus.service" 79 ] 80 ++ lib.optional config.services.httpd.enable "httpd.service" 81 ++ lib.optional config.services.mysql.enable "mysql.service" 82 ++ lib.optional config.services.postgresql.enable "postgresql.target" 83 ++ lib.optional config.services.tomcat.enable "tomcat.service" 84 ++ lib.optional config.services.svnserve.enable "svnserve.service" 85 ++ lib.optional config.services.mongodb.enable "mongodb.service" 86 ++ lib.optional config.services.influxdb.enable "influxdb.service"; 87 88 restartIfChanged = false; 89 90 path = [ 91 config.nix.package 92 cfg.package 93 config.services.dysnomia.package 94 "/run/current-system/sw" 95 ]; 96 97 environment = { 98 HOME = "/root"; 99 } 100 // (lib.optionalAttrs (config.environment.variables ? DYSNOMIA_CONTAINERS_PATH) { 101 inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; 102 }) 103 // (lib.optionalAttrs (config.environment.variables ? DYSNOMIA_MODULES_PATH) { 104 inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; 105 }); 106 107 serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service"; 108 }; 109 110 }; 111 }; 112}