diff options
author | Jonas Heinrich <onny@project-insanity.org> | 2023-05-01 20:04:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 20:04:20 +0200 |
commit | fcf6662fb579a0cfc0867296960a7c2eade3e3c4 (patch) | |
tree | e7ebd481f77ea1aa15ba9953727d18b20ce63548 /nixos/tests | |
parent | 1a0c498ee1f81fd06fdab35fd19639c860721b35 (diff) | |
parent | fddf531c6fa3c769f70a4a0dfc4d886216f0107e (diff) |
Merge pull request #229159 from Misterio77/refactor-nextcloud-createlocally
nixos/nextcloud: refactor database.createLocally
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix | 43 | ||||
-rw-r--r-- | nixos/tests/nextcloud/with-mysql-and-memcached.nix | 11 | ||||
-rw-r--r-- | nixos/tests/nextcloud/with-postgresql-and-redis.nix | 20 |
3 files changed, 24 insertions, 50 deletions
diff --git a/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix b/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix index 93e655c3056be..ce0019e9da4a7 100644 --- a/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix +++ b/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix @@ -1,6 +1,11 @@ import ../make-test-python.nix ({ pkgs, ...}: let - adminpass = "hunter2"; - adminuser = "custom-admin-username"; + username = "custom_admin_username"; + # This will be used both for redis and postgresql + pass = "hunter2"; + # Don't do this at home, use a file outside of the nix store instead + passFile = toString (pkgs.writeText "pass-file" '' + ${pass} + ''); in { name = "nextcloud-with-declarative-redis"; meta = with pkgs.lib.maintainers; { @@ -22,15 +27,15 @@ in { redis = true; memcached = false; }; + # This test also validates that we can use an "external" database + database.createLocally = false; config = { dbtype = "pgsql"; dbname = "nextcloud"; - dbuser = "nextcloud"; - dbhost = "/run/postgresql"; - inherit adminuser; - adminpassFile = toString (pkgs.writeText "admin-pass-file" '' - ${adminpass} - ''); + dbuser = username; + dbpassFile = passFile; + adminuser = username; + adminpassFile = passFile; }; secretFile = "/etc/nextcloud-secrets.json"; @@ -52,20 +57,20 @@ in { systemd.services.nextcloud-setup= { requires = ["postgresql.service"]; - after = [ - "postgresql.service" - ]; + after = [ "postgresql.service" ]; }; services.postgresql = { enable = true; - ensureDatabases = [ "nextcloud" ]; - ensureUsers = [ - { name = "nextcloud"; - ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES"; - } - ]; }; + systemd.services.postgresql.postStart = pkgs.lib.mkAfter '' + password=$(cat ${passFile}) + ${config.services.postgresql.package}/bin/psql <<EOF + CREATE ROLE ${username} WITH LOGIN PASSWORD '$password' CREATEDB; + CREATE DATABASE nextcloud; + GRANT ALL PRIVILEGES ON DATABASE nextcloud TO ${username}; + EOF + ''; # This file is meant to contain secret options which should # not go into the nix store. Here it is just used to set the @@ -86,8 +91,8 @@ in { export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/" export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud" - export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}" - export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})" + export RCLONE_CONFIG_NEXTCLOUD_USER="${username}" + export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${pass})" "''${@}" ''; copySharedFile = pkgs.writeScript "copy-shared-file" '' diff --git a/nixos/tests/nextcloud/with-mysql-and-memcached.nix b/nixos/tests/nextcloud/with-mysql-and-memcached.nix index 63e0e2c59639e..f673e5e75d3ba 100644 --- a/nixos/tests/nextcloud/with-mysql-and-memcached.nix +++ b/nixos/tests/nextcloud/with-mysql-and-memcached.nix @@ -26,24 +26,13 @@ in { redis = false; memcached = true; }; - database.createLocally = true; config = { dbtype = "mysql"; - dbname = "nextcloud"; - dbuser = "nextcloud"; - dbhost = "127.0.0.1"; - dbport = 3306; - dbpassFile = "${pkgs.writeText "dbpass" "hunter2" }"; # Don't inherit adminuser since "root" is supposed to be the default adminpassFile = "${pkgs.writeText "adminpass" adminpass}"; # Don't try this at home! }; }; - systemd.services.nextcloud-setup= { - requires = ["mysql.service"]; - after = ["mysql.service"]; - }; - services.memcached.enable = true; }; }; diff --git a/nixos/tests/nextcloud/with-postgresql-and-redis.nix b/nixos/tests/nextcloud/with-postgresql-and-redis.nix index d28c1bdfd6e1e..43892d39e9f0c 100644 --- a/nixos/tests/nextcloud/with-postgresql-and-redis.nix +++ b/nixos/tests/nextcloud/with-postgresql-and-redis.nix @@ -27,9 +27,6 @@ in { }; config = { dbtype = "pgsql"; - dbname = "nextcloud"; - dbuser = "nextcloud"; - dbhost = "/run/postgresql"; inherit adminuser; adminpassFile = toString (pkgs.writeText "admin-pass-file" '' ${adminpass} @@ -48,23 +45,6 @@ in { services.redis.servers."nextcloud".enable = true; services.redis.servers."nextcloud".port = 6379; - - systemd.services.nextcloud-setup= { - requires = ["postgresql.service"]; - after = [ - "postgresql.service" - ]; - }; - - services.postgresql = { - enable = true; - ensureDatabases = [ "nextcloud" ]; - ensureUsers = [ - { name = "nextcloud"; - ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES"; - } - ]; - }; }; }; |