feat(modules/dgn-console): Add a pg upgrade script when necessary
This commit is contained in:
parent
a4d9497158
commit
7e5920fd16
1 changed files with 31 additions and 3 deletions
|
@ -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 \
|
||||
"$@"
|
||||
'');
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue