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

+74 -12
+34 -12
nixos/modules/services/web-servers/apache-httpd/owncloud.nix
··· 188 188 /* date format to be used while writing to the owncloud logfile */ 189 189 'logdateformat' => 'F d, Y H:i:s', 190 190 191 - /* timezone used while writing to the owncloud logfile (default: UTC) */ 192 - 'logtimezone' => '${serverInfo.fullConfig.time.timeZone}', 191 + ${tzSetting} 193 192 194 193 /* Append all database queries and parameters to the log file. 195 194 (watch out, this option can increase the size of your log file)*/ ··· 339 338 340 339 ''; 341 340 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 + 342 366 in 343 367 344 368 rec { ··· 373 397 defaultText = "pkgs.owncloud70"; 374 398 example = literalExample "pkgs.owncloud70"; 375 399 description = '' 376 - PostgreSQL package to use. 400 + ownCloud package to use. 377 401 ''; 378 402 }; 379 403 ··· 574 598 chmod -R o-rwx ${config.dataDir} 575 599 chown -R wwwrun:wwwrun ${config.dataDir} 576 600 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} 584 602 fi 585 603 586 604 if [ -e ${config.package}/config/ca-bundle.crt ]; then ··· 591 609 592 610 chown wwwrun:wwwrun ${config.dataDir}/owncloud.log || true 593 611 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 596 618 ''; 597 619 }
+1
nixos/release.nix
··· 302 302 tests.leaps = callTest tests/leaps.nix { }; 303 303 tests.nsd = callTest tests/nsd.nix {}; 304 304 tests.openssh = callTest tests/openssh.nix {}; 305 + tests.owncloud = callTest tests/owncloud.nix {}; 305 306 tests.pam-oath-login = callTest tests/pam-oath-login.nix {}; 306 307 #tests.panamax = hydraJob (import tests/panamax.nix { system = "x86_64-linux"; }); 307 308 tests.peerflix = callTest tests/peerflix.nix {};
+39
nixos/tests/owncloud.nix
··· 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 + })