at 18.03-beta 2.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.nexus; 8 9in 10 11{ 12 options = { 13 services.nexus = { 14 enable = mkEnableOption "Sonatype Nexus3 OSS service"; 15 16 user = mkOption { 17 type = types.str; 18 default = "nexus"; 19 description = "User which runs Nexus3."; 20 }; 21 22 group = mkOption { 23 type = types.str; 24 default = "nexus"; 25 description = "Group which runs Nexus3."; 26 }; 27 28 home = mkOption { 29 type = types.str; 30 default = "/var/lib/sonatype-work"; 31 description = "Home directory of the Nexus3 instance."; 32 }; 33 34 listenAddress = mkOption { 35 type = types.str; 36 default = "127.0.0.1"; 37 description = "Address to listen on."; 38 }; 39 40 listenPort = mkOption { 41 type = types.int; 42 default = 8081; 43 description = "Port to listen on."; 44 }; 45 }; 46 }; 47 48 config = mkIf cfg.enable { 49 users.extraUsers."${cfg.user}" = { 50 isSystemUser = true; 51 group = cfg.group; 52 }; 53 54 users.extraGroups."${cfg.group}" = {}; 55 56 systemd.services.nexus = { 57 description = "Sonatype Nexus3"; 58 59 wantedBy = [ "multi-user.target" ]; 60 61 path = [ cfg.home ]; 62 63 environment = { 64 NEXUS_USER = cfg.user; 65 NEXUS_HOME = cfg.home; 66 }; 67 68 preStart = '' 69 mkdir -p ${cfg.home}/nexus3/etc 70 71 ln -sf ${cfg.home} /run/sonatype-work 72 73 chown -R ${cfg.user}:${cfg.group} ${cfg.home} 74 75 if [ ! -f ${cfg.home}/nexus3/etc/nexus.properties ]; then 76 echo "# Jetty section" > ${cfg.home}/nexus3/etc/nexus.properties 77 echo "application-port=${toString cfg.listenPort}" >> ${cfg.home}/nexus3/etc/nexus.properties 78 echo "application-host=${toString cfg.listenAddress}" >> ${cfg.home}/nexus3/etc/nexus.properties 79 else 80 sed 's/^application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 81 sed 's/^# application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 82 sed 's/^application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 83 sed 's/^# application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 84 fi 85 ''; 86 87 script = "${pkgs.nexus}/bin/nexus run"; 88 89 serviceConfig = { 90 User = cfg.user; 91 Group = cfg.group; 92 PrivateTmp = true; 93 PermissionsStartOnly = true; 94 LimitNOFILE = 102642; 95 }; 96 }; 97 }; 98 99 meta.maintainers = with stdenv.lib.maintainers; [ ironpinguin ]; 100}