Compare commits

..

5 commits

Author SHA1 Message Date
Bruno BELANYI e215f7aa1d modules: services: nextcloud: upgrade version
All checks were successful
continuous-integration/drone/push Build is passing
2021-07-29 13:42:28 +02:00
Bruno BELANYI afb683f1cf flake: bump inputs
And update package names for grafana dashboards to avoid breaking the
config.
2021-07-29 13:42:28 +02:00
Bruno BELANYI c320387746 modules: services: postgres: upgrade version 2021-07-29 13:03:10 +02:00
Bruno BELANYI bbb1231ad3 modules: services: postgres: add migration script
The process to upgrade is:

* Make sure the version number of the script is one major version over
  the service version.

* Activate the script, rebuild configuration.

* Run `upgrade-pg-cluster` as `root`. One can give arguments like
  `--link` or `--jobs 4` to speedup the process. See documentation for
  some details.

* Change package to new version once the upgrade is finished, rebuild
  configuration.

* Optionally, `ANALYZE` the new database.
2021-07-29 13:02:49 +02:00
Bruno BELANYI 9f00d8a38e modules: services: add postgresql
Enable the service itself in other modules when needed, but pin the
package in a single place.
2021-07-29 12:43:28 +02:00
8 changed files with 75 additions and 13 deletions

View file

@ -23,11 +23,11 @@
]
},
"locked": {
"lastModified": 1626073055,
"narHash": "sha256-vocByfpVu6m9zvtJugDvmd6/9iT2HJuG4tmDICKd0lI=",
"lastModified": 1627501942,
"narHash": "sha256-rG2PUTgzmXvf/fSDCWKhlRwZjZs1/0TySC5eYHVJrmg=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "775cb20bd4af7781fbf336fb201df02ee3d544bb",
"rev": "2272fc312d5dc477e70816d94e550d08729b307b",
"type": "github"
},
"original": {
@ -39,11 +39,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1626046891,
"narHash": "sha256-Zt8saH+hAehXskW0iFAzk+iMillYoFBxvLReYNqGT9E=",
"lastModified": 1627391865,
"narHash": "sha256-tPoWBO9Nzu3wuX37WcnctzL6LoDCErJLnfLGqqmXCm4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d8f8f31af9d77a48220e4e8a301d1e79774cb7d2",
"rev": "8ecc61c91a596df7d3293603a9c2384190c1b89a",
"type": "github"
},
"original": {
@ -55,11 +55,11 @@
},
"nur": {
"locked": {
"lastModified": 1626192709,
"narHash": "sha256-REQ9ByMk4crAX37e8YDZOBl9Kxn+nTfnnLwwxczcoP0=",
"lastModified": 1627534577,
"narHash": "sha256-cGVIlBkZZA9VvhXRRrWsTpkesJ/bSlGSPYPxafQVjSU=",
"owner": "nix-community",
"repo": "NUR",
"rev": "564ec91b61dab796f1af44502ff3a9c124f4d6da",
"rev": "0e1a91ef1d0460adfb5c669a9c0114f46e67956c",
"type": "github"
},
"original": {

View file

@ -20,6 +20,7 @@
./pirate.nix
./podgrab.nix
./postgresql-backup.nix
./postgresql.nix
./quassel.nix
./rss-bridge.nix
./sabnzbd.nix

View file

@ -81,6 +81,7 @@ in
users.groups.drone = { };
services.postgresql = {
enable = true;
ensureDatabases = [ "drone" ];
ensureUsers = [{
name = "drone";

View file

@ -63,7 +63,6 @@ in
config = lib.mkIf cfg.enable {
services.postgresql = {
enable = true;
package = pkgs.postgresql_12;
initialScript = pkgs.writeText "synapse-init.sql" ''
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"

View file

@ -78,7 +78,7 @@ in
dashboards = [
{
name = "Node Exporter";
options.path = pkgs.nur.repos.alarsyo.grafana-dashboards.node-exporter;
options.path = pkgs.nur.repos.alarsyo.grafanaDashboards.node-exporter;
disableDeletion = true;
}
];

View file

@ -30,7 +30,7 @@ in
config = lib.mkIf cfg.enable {
services.nextcloud = {
enable = true;
package = pkgs.nextcloud21;
package = pkgs.nextcloud22;
hostName = nextcloudDomain;
home = "/var/lib/nextcloud";
maxUploadSize = cfg.maxSize;

View file

@ -44,7 +44,7 @@
services.grafana.provision.dashboards = [
{
name = "NGINX";
options.path = pkgs.nur.repos.alarsyo.grafana-dashboards.nginx;
options.path = pkgs.nur.repos.alarsyo.grafanaDashboards.nginx;
disableDeletion = true;
}
];

View file

@ -0,0 +1,61 @@
{ config, lib, pkgs, ... }:
let
cfg = config.my.services.postgresql;
in
{
options.my.services.postgresql = with lib; {
enable = my.mkDisableOption "postgres configuration";
# Transient option to be enabled for migrations
upgradeScript = mkEnableOption "postgres upgrade script";
};
config = lib.mkMerge [
# Let other services enable postgres when they need it
(lib.mkIf cfg.enable {
services.postgresql = {
package = pkgs.postgresql_13;
};
})
# Taken from the manual
(lib.mkIf cfg.upgradeScript {
containers.temp-pg.config.services.postgresql = {
enable = true;
package = pkgs.postgresql_13;
};
environment.systemPackages =
let
newpg = config.containers.temp-pg.config.services.postgresql;
in
[
(pkgs.writeScriptBin "upgrade-pg-cluster" ''
#!/usr/bin/env bash
set -x
export OLDDATA="${config.services.postgresql.dataDir}"
export NEWDATA="${newpg.dataDir}"
export OLDBIN="${config.services.postgresql.package}/bin"
export NEWBIN="${newpg.package}/bin"
if [ "$OLDDATA" -ef "$NEWDATA" ]; then
echo "Cannot migrate to same data directory" >&2
exit 1
fi
install -d -m 0700 -o postgres -g postgres "$NEWDATA"
cd "$NEWDATA"
sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
systemctl stop postgresql # old one
sudo -u postgres $NEWBIN/pg_upgrade \
--old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
--old-bindir $OLDBIN --new-bindir $NEWBIN \
"$@"
'')
];
})
];
}