summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichele Catalano <michele.catalano@mayflower.de>2017-09-01 18:24:20 +0200
committerRobin Gloster <mail@glob.in>2017-09-04 22:32:02 +0200
commit4ea1d49643679761aaa2e809ade34a5812ace8e3 (patch)
treee642ec7b0594327ddc4475b220b426c1bda822ee
parente783c2b39cfcfa5d3994e774357404f87097aa82 (diff)
downloadnixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.tar
nixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.tar.gz
nixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.tar.bz2
nixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.tar.lz
nixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.tar.xz
nixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.tar.zst
nixpkgs-4ea1d49643679761aaa2e809ade34a5812ace8e3.zip
nexus: Add module for nexus.
Add also myself as maintainer
Add simple test of the nexus service
-rw-r--r--lib/maintainers.nix1
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/web-apps/nexus.nix100
-rw-r--r--nixos/tests/nexus.nix34
4 files changed, 136 insertions, 0 deletions
diff --git a/lib/maintainers.nix b/lib/maintainers.nix
index 0859fba7b1d..7251f45bc5d 100644
--- a/lib/maintainers.nix
+++ b/lib/maintainers.nix
@@ -252,6 +252,7 @@
   igsha = "Igor Sharonov <igor.sharonov@gmail.com>";
   ikervagyok = "Balázs Lengyel <ikervagyok@gmail.com>";
   infinisil = "Silvan Mosberger <infinisil@icloud.com>";
+  ironpinguin = "Michele Catalano <michele@catalano.de>";
   ivan-tkatchev = "Ivan Tkatchev <tkatchev@gmail.com>";
   j-keck = "Jürgen Keck <jhyphenkeck@gmail.com>";
   jagajaga = "Arseniy Seroka <ars.seroka@gmail.com>";
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 918bd18e6af..8a7a5bf4bc4 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -588,6 +588,7 @@
   ./services/web-apps/frab.nix
   ./services/web-apps/mattermost.nix
   ./services/web-apps/nixbot.nix
+  ./services/web-apps/nexus.nix
   ./services/web-apps/pgpkeyserver-lite.nix
   ./services/web-apps/piwik.nix
   ./services/web-apps/pump.io.nix
diff --git a/nixos/modules/services/web-apps/nexus.nix b/nixos/modules/services/web-apps/nexus.nix
new file mode 100644
index 00000000000..a750aa66b27
--- /dev/null
+++ b/nixos/modules/services/web-apps/nexus.nix
@@ -0,0 +1,100 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.nexus;
+
+in
+
+{
+  options = {
+    services.nexus = {
+      enable = mkEnableOption "SonarType Nexus3 OSS service";
+
+      user = mkOption {
+        type = types.str;
+        default = "nexus";
+        description = "User which runs Nexus3.";
+      };
+
+      group = mkOption {
+        type = types.str;
+        default = "nexus";
+        description = "Group which runs Nexus3.";
+      };
+
+      home = mkOption {
+        type = types.str;
+        default = "/var/lib/sonatype-work";
+        description = "Home directory of the Nexus3 instance.";
+      };
+
+      listenAddress = mkOption {
+        type = types.str;
+        default = "127.0.0.1";
+        description = "Address to listen on.";
+      };
+
+      listenPort = mkOption {
+        type = types.int;
+        default = 8081;
+        description = "Port to listen on.";
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    users.extraUsers."${cfg.user}" = {
+      isSystemUser = true;
+      group = cfg.group;
+    };
+
+    users.extraGroups."${cfg.group}" = {};
+
+    systemd.services.nexus = {
+      description = "SonarType Nexus3";
+
+      wantedBy = [ "multi-user.target" ];
+
+      path = [ cfg.home ];
+
+      environment = {
+        NEXUS_USER = cfg.user;
+        NEXUS_HOME = cfg.home;
+      };
+
+      preStart = ''
+        mkdir -p ${cfg.home}/nexus3/etc
+
+        ln -sf ${cfg.home} /run/sonatype-work
+
+        chown -R ${cfg.user}:${cfg.group} ${cfg.home}
+
+        if [ ! -f ${cfg.home}/nexus3/etc/nexus.properties ]; then
+          echo "# Jetty section" > ${cfg.home}/nexus3/etc/nexus.properties
+          echo "application-port=${toString cfg.listenPort}" >> ${cfg.home}/nexus3/etc/nexus.properties
+          echo "application-host=${toString cfg.listenAddress}" >> ${cfg.home}/nexus3/etc/nexus.properties
+        else
+          sed 's/^application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 
+          sed 's/^# application-port=.*/application-port=${toString cfg.listenPort}/' -i ${cfg.home}/nexus3/etc/nexus.properties 
+          sed 's/^application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 
+          sed 's/^# application-host=.*/application-host=${toString cfg.listenAddress}/' -i ${cfg.home}/nexus3/etc/nexus.properties 
+        fi
+      '';
+
+      script = "${pkgs.nexus}/bin/nexus run";
+
+      serviceConfig = {
+        User = cfg.user;
+        Group = cfg.group;
+        PrivateTmp = true;
+        PermissionsStartOnly = true;
+        LimitNOFILE = 102642;
+      };
+    };
+  };
+
+  meta.maintainers = with stdenv.lib.maintainers; [ ironpinguin ];
+}
diff --git a/nixos/tests/nexus.nix b/nixos/tests/nexus.nix
new file mode 100644
index 00000000000..1f19fc0867a
--- /dev/null
+++ b/nixos/tests/nexus.nix
@@ -0,0 +1,34 @@
+# verifies:
+#   1. nexus service starts on server
+#   2. nexus user can be extended on server
+#   3. nexus service not can startup on server (creating database and all other initial stuff)
+
+import ./make-test.nix ({ pkgs, ...} : {
+  name = "nexus";
+  meta = with pkgs.stdenv.lib.maintainers; {
+    maintainers = [ ironpinguin ];
+  };
+
+  nodes = {
+
+    server =
+      { config, pkgs, ... }:
+      { virtualisation.memorySize = 2048;
+
+        services.nexus.enable = true;
+
+        users.extraUsers.nexus.extraGroups = [ "users" ];
+      };
+  };
+
+  testScript = ''
+    startAll;
+
+    $server->waitForUnit("nexus");
+
+    print $server->execute("sudo -u nexus groups");
+    $server->mustSucceed("sudo -u nexus groups | grep nexus | grep users");
+
+    $server->waitForOpenPort(8081);
+  '';
+})