summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2019-09-17 08:36:19 +0200
committertalyz <kim.lindberger@gmail.com>2019-09-24 15:04:20 +0200
commit58a75024211a18870bffd33466b0d5aefa846d74 (patch)
treeec4ce0dbd0c2f478211e677c2085cfcaa8c1f43a /nixos
parentec958d46acf6ec6e544a0045fcc4c7e3ccd51d96 (diff)
downloadnixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.tar
nixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.tar.gz
nixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.tar.bz2
nixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.tar.lz
nixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.tar.xz
nixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.tar.zst
nixpkgs-58a75024211a18870bffd33466b0d5aefa846d74.zip
nixos/gitlab: Only create the database when databaseHost is unset
Make sure that we don't create a database if we're not going to
connect to it. Also, fix the assertion that usernames be equal to only
trig when peer authentication is used (databaseHost == "").
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/gitlab.nix15
1 files changed, 9 insertions, 6 deletions
diff --git a/nixos/modules/services/misc/gitlab.nix b/nixos/modules/services/misc/gitlab.nix
index 1b6002498c6..26a01f6c61e 100644
--- a/nixos/modules/services/misc/gitlab.nix
+++ b/nixos/modules/services/misc/gitlab.nix
@@ -27,6 +27,9 @@ let
     } // cfg.extraDatabaseConfig;
   };
 
+  # We only want to create a database if we're actually going to connect to it.
+  databaseActuallyCreateLocally = cfg.databaseCreateLocally && cfg.databaseHost == "";
+
   gitalyToml = pkgs.writeText "gitaly.toml" ''
     socket_path = "${lib.escape ["\""] gitalySocket}"
     bin_dir = "${cfg.packages.gitaly}/bin"
@@ -263,8 +266,8 @@ in {
         description = ''
           Whether a database should be automatically created on the
           local host. Set this to <literal>false</literal> if you plan
-          on provisioning a local database yourself or use an external
-          one.
+          on provisioning a local database yourself. This has no effect
+          if <option>services.gitlab.databaseHost</option> is customized.
         '';
       };
 
@@ -554,8 +557,8 @@ in {
 
     assertions = [
       {
-        assertion = cfg.databaseCreateLocally -> (cfg.user == cfg.databaseUsername);
-        message = "For local automatic database provisioning services.gitlab.user and services.gitlab.databaseUsername should be identical.";
+        assertion = databaseActuallyCreateLocally -> (cfg.user == cfg.databaseUsername);
+        message = ''For local automatic database provisioning (services.gitlab.databaseCreateLocally == true) with peer authentication (services.gitlab.databaseHost == "") to work services.gitlab.user and services.gitlab.databaseUsername must be identical.'';
       }
       {
         assertion = (cfg.databaseHost != "") -> (cfg.databasePasswordFile != null);
@@ -589,14 +592,14 @@ in {
     services.redis.enable = mkDefault true;
 
     # We use postgres as the main data store.
-    services.postgresql = optionalAttrs cfg.databaseCreateLocally {
+    services.postgresql = optionalAttrs databaseActuallyCreateLocally {
       enable = true;
       ensureUsers = singleton { name = cfg.databaseUsername; };
     };
     # The postgresql module doesn't currently support concepts like
     # objects owners and extensions; for now we tack on what's needed
     # here.
-    systemd.services.postgresql.postStart = mkAfter (optionalString cfg.databaseCreateLocally ''
+    systemd.services.postgresql.postStart = mkAfter (optionalString databaseActuallyCreateLocally ''
       $PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${cfg.databaseName}'" | grep -q 1 || $PSQL -tAc 'CREATE DATABASE "${cfg.databaseName}" OWNER "${cfg.databaseUsername}"'
       current_owner=$($PSQL -tAc "SELECT pg_catalog.pg_get_userbyid(datdba) FROM pg_catalog.pg_database WHERE datname = '${cfg.databaseName}'")
       if [[ "$current_owner" != "${cfg.databaseUsername}" ]]; then