nexus: Add module for nexus.

Add also myself as maintainer
Add simple test of the nexus service

authored by

Michele Catalano and committed by
Robin Gloster
4ea1d496 e783c2b3

+136
+1
lib/maintainers.nix
··· 252 252 igsha = "Igor Sharonov <igor.sharonov@gmail.com>"; 253 253 ikervagyok = "Balázs Lengyel <ikervagyok@gmail.com>"; 254 254 infinisil = "Silvan Mosberger <infinisil@icloud.com>"; 255 + ironpinguin = "Michele Catalano <michele@catalano.de>"; 255 256 ivan-tkatchev = "Ivan Tkatchev <tkatchev@gmail.com>"; 256 257 j-keck = "Jürgen Keck <jhyphenkeck@gmail.com>"; 257 258 jagajaga = "Arseniy Seroka <ars.seroka@gmail.com>";
+1
nixos/modules/module-list.nix
··· 588 588 ./services/web-apps/frab.nix 589 589 ./services/web-apps/mattermost.nix 590 590 ./services/web-apps/nixbot.nix 591 + ./services/web-apps/nexus.nix 591 592 ./services/web-apps/pgpkeyserver-lite.nix 592 593 ./services/web-apps/piwik.nix 593 594 ./services/web-apps/pump.io.nix
+100
nixos/modules/services/web-apps/nexus.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + 7 + cfg = config.services.nexus; 8 + 9 + in 10 + 11 + { 12 + options = { 13 + services.nexus = { 14 + enable = mkEnableOption "SonarType 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 = "SonarType 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 + }
+34
nixos/tests/nexus.nix
··· 1 + # verifies: 2 + # 1. nexus service starts on server 3 + # 2. nexus user can be extended on server 4 + # 3. nexus service not can startup on server (creating database and all other initial stuff) 5 + 6 + import ./make-test.nix ({ pkgs, ...} : { 7 + name = "nexus"; 8 + meta = with pkgs.stdenv.lib.maintainers; { 9 + maintainers = [ ironpinguin ]; 10 + }; 11 + 12 + nodes = { 13 + 14 + server = 15 + { config, pkgs, ... }: 16 + { virtualisation.memorySize = 2048; 17 + 18 + services.nexus.enable = true; 19 + 20 + users.extraUsers.nexus.extraGroups = [ "users" ]; 21 + }; 22 + }; 23 + 24 + testScript = '' 25 + startAll; 26 + 27 + $server->waitForUnit("nexus"); 28 + 29 + print $server->execute("sudo -u nexus groups"); 30 + $server->mustSucceed("sudo -u nexus groups | grep nexus | grep users"); 31 + 32 + $server->waitForOpenPort(8081); 33 + ''; 34 + })