git.iko.soy/typeable/nixpkgs
on master help sign in
owncloud: fix some but not all errors

* Don't set timezone when it's null * Don't create the postgres role because the postgresqsl service already does that. * Fix documentation * Add a test suite

commitcb4b9b1cc196fec213c98541752f9df0cc6ee320 authorBas van Dijk <v.dijk.bas@gmail.com> dateTue 31 Oct 2017, 17:53 (9 years ago) parent4b49e21
3 files changed+74−12
nixos/modules/services/web-servers/apache-httpd/owncloud.nix+34−12 nixos/release.nix+1 nixos/tests/owncloud.nix+39
nixos/modules/services/web-servers/apache-httpd/owncloud.nix+34−12
@@ -188,8 +188,7 @@ let
188188 /* date format to be used while writing to the owncloud logfile */
189189 'logdateformat' => 'F d, Y H:i:s',
190190
191− /* timezone used while writing to the owncloud logfile (default: UTC) */
192− 'logtimezone' => '${serverInfo.fullConfig.time.timeZone}',
191+ ${tzSetting}
193192
194193 /* Append all database queries and parameters to the log file.
195194 (watch out, this option can increase the size of your log file)*/
@@ -339,6 +338,31 @@ let
339338
340339 '';
341340
341+ tzSetting = let tz = serverInfo.fullConfig.time.timeZone; in optionalString (!isNull tz) ''
342+ /* timezone used while writing to the owncloud logfile (default: UTC) */
343+ 'logtimezone' => '${tz}',
344+ '';
345+
346+ postgresql = serverInfo.fullConfig.services.postgresql.package;
347+
348+ setupDb = pkgs.writeScript "setup-owncloud-db" ''
349+ #!${pkgs.stdenv.shell}
350+ PATH="${postgresql}/bin"
351+ createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
352+ createdb "${config.dbName}" -O "${config.dbUser}" || true
353+ psql -U postgres -d postgres -c "alter user ${config.dbUser} with password '${config.dbPassword}';" || true
354+
355+ QUERY="CREATE TABLE appconfig
356+ ( appid VARCHAR( 255 ) NOT NULL
357+ , configkey VARCHAR( 255 ) NOT NULL
358+ , configvalue VARCHAR( 255 ) NOT NULL
359+ );
360+ GRANT ALL ON appconfig TO ${config.dbUser};
361+ ALTER TABLE appconfig OWNER TO ${config.dbUser};"
362+
363+ psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
364+ '';
365+
342366in
343367
344368rec {
@@ -373,7 +397,7 @@ rec {
373397 defaultText = "pkgs.owncloud70";
374398 example = literalExample "pkgs.owncloud70";
375399 description = ''
376− PostgreSQL package to use.
400+ ownCloud package to use.
377401 '';
378402 };
379403
@@ -574,13 +598,7 @@ rec {
574598 chmod -R o-rwx ${config.dataDir}
575599 chown -R wwwrun:wwwrun ${config.dataDir}
576600
577− ${pkgs.postgresql}/bin/createuser -s -r postgres
578− ${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
579− ${pkgs.postgresql}/bin/createdb "${config.dbName}" -O "${config.dbUser}" || true
580− ${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -U postgres -d postgres -c "alter user ${config.dbUser} with password '${config.dbPassword}';" || true
581−
582− QUERY="CREATE TABLE appconfig (appid VARCHAR( 255 ) NOT NULL ,configkey VARCHAR( 255 ) NOT NULL ,configvalue VARCHAR( 255 ) NOT NULL); GRANT ALL ON appconfig TO ${config.dbUser}; ALTER TABLE appconfig OWNER TO ${config.dbUser};"
583− ${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
601+ ${pkgs.sudo}/bin/sudo -u postgres ${setupDb}
584602 fi
585603
586604 if [ -e ${config.package}/config/ca-bundle.crt ]; then
@@ -591,7 +609,11 @@ rec {
591609
592610 chown wwwrun:wwwrun ${config.dataDir}/owncloud.log || true
593611
594− QUERY="INSERT INTO groups (gid) values('admin'); INSERT INTO users (uid,password) values('${config.adminUser}','${builtins.hashString "sha1" config.adminPassword}'); INSERT INTO group_user (gid,uid) values('admin','${config.adminUser}');"
595− ${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
612+ QUERY="INSERT INTO groups (gid) values('admin');
613+ INSERT INTO users (uid,password)
614+ values('${config.adminUser}','${builtins.hashString "sha1" config.adminPassword}');
615+ INSERT INTO group_user (gid,uid)
616+ values('admin','${config.adminUser}');"
617+ ${pkgs.sudo}/bin/sudo -u postgres ${postgresql}/bin/psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
596618 '';
597619}
nixos/release.nix+1
@@ -302,6 +302,7 @@ in rec {
302302 tests.leaps = callTest tests/leaps.nix { };
303303 tests.nsd = callTest tests/nsd.nix {};
304304 tests.openssh = callTest tests/openssh.nix {};
305+ tests.owncloud = callTest tests/owncloud.nix {};
305306 tests.pam-oath-login = callTest tests/pam-oath-login.nix {};
306307 #tests.panamax = hydraJob (import tests/panamax.nix { system = "x86_64-linux"; });
307308 tests.peerflix = callTest tests/peerflix.nix {};
nixos/tests/owncloud.nixnew file+39
@@ -0,0 +1,39 @@
1+import ./make-test.nix ({ pkgs, ... }:
2+
3+{
4+ name = "owncloud";
5+ nodes =
6+ { web =
7+ { config, pkgs, ... }:
8+ {
9+ services.postgresql.enable = true;
10+ services.httpd = {
11+ enable = true;
12+ logPerVirtualHost = true;
13+ adminAddr = "example@example.com";
14+ virtualHosts = [
15+ {
16+ hostName = "owncloud";
17+ extraSubservices =
18+ [
19+ {
20+ serviceType = "owncloud";
21+ adminPassword = "secret";
22+ dbPassword = "secret";
23+ }
24+ ];
25+ }
26+ ];
27+ };
28+ };
29+ };
30+
31+ testScript = ''
32+ startAll;
33+
34+ $web->waitForUnit("postgresql");
35+ $web->waitForUnit("httpd");
36+
37+ $web->succeed("curl -L 127.0.0.1:80");
38+ '';
39+})