diff --git a/modules/dgn-console.nix b/modules/dgn-console.nix index 27c07f8..a8a3408 100644 --- a/modules/dgn-console.nix +++ b/modules/dgn-console.nix @@ -1,13 +1,18 @@ { config, lib, pkgs, ... }: let - inherit (lib) mkEnableOption mkIf; + inherit (lib) mkEnableOption mkOption mkIf; cfg = config.dgn-console; in { options.dgn-console = { enable = mkEnableOption "DGNum console setup." // { default = true; }; + + pg-upgrade-to = mkOption { + type = lib.types.package; + default = pkgs.postgresql_15; + }; }; config = mkIf cfg.enable { @@ -15,8 +20,6 @@ in { console = { keyMap = "fr"; }; - environment.systemPackages = with pkgs; [ neovim wget kitty.terminfo ]; - environment.variables.EDITOR = "nvim"; programs.neovim.vimAlias = true; @@ -58,5 +61,30 @@ in { ''; hardware.enableRedistributableFirmware = true; + + environment.systemPackages = (with pkgs; [ neovim wget kitty.terminfo ]) + ++ lib.optional (config.services.postgresql.package != cfg.pg-upgrade-to) + (pkgs.writeScriptBin "upgrade-pg-cluster" '' + set -eux + # XXX it's perhaps advisable to stop all services that depend on postgresql + systemctl stop postgresql + + export NEWDATA="/var/lib/postgresql/${cfg.pg-upgrade-to.psqlSchema}" + + export NEWBIN="${cfg.pg-upgrade-to}/bin" + + export OLDDATA="${config.services.postgresql.dataDir}" + export OLDBIN="${config.services.postgresql.package}/bin" + + install -d -m 0700 -o postgres -g postgres "$NEWDATA" + cd "$NEWDATA" + sudo -u postgres $NEWBIN/initdb -D "$NEWDATA" + + sudo -u postgres $NEWBIN/pg_upgrade \ + --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \ + --old-bindir $OLDBIN --new-bindir $NEWBIN \ + "$@" + ''); + }; }