2024-10-03 08:34:20 +02:00
{
lib ,
pkgs ,
config ,
. . .
} :
let
cfg = config . services . barman ;
iniFormat = pkgs . formats . ini { } ;
defaultUser = " b a r m a n " ;
defaultHome = " / v a r / l i b / b a r m a n " ;
2024-10-10 08:41:09 +02:00
runtimeInputs = with pkgs ; [
cfg . package
bash
bzip2
gzip
lz4
pigz
postgresql
zstd
] ;
barmanWrapper = pkgs . writeShellApplication {
name = " b m " ;
inherit runtimeInputs ;
text = ''
sudo - - set-home - - user $ { cfg . settings . barman . barman_user } - - $ { cfg . package } /bin/barman " $ @ "
'' ;
} ;
2024-10-03 08:34:20 +02:00
in
{
options . services . barman = {
enable = lib . mkEnableOption " b a r m a n " ;
package = lib . mkPackageOption pkgs " b a r m a n " { } ;
settings = lib . mkOption {
description = " G l o b a l b a r m a n c o n f i g u r a t i o n t h a t g o e s i n t h e ` [ b a r m a n ] ` s e c t i o n o f ` b a r m a n . c o n f ` " ;
type = lib . types . submodule { freeformType = iniFormat . type ; } ;
example = {
barman_user = defaultUser ;
barman_home = defaultHome ;
log_file = " / v a r / l o g / b a r m a n / b a r m a n . l o g " ;
} ;
} ;
servers = lib . mkOption {
description = " S e r v e r c o n f i g u r a t i o n s " ;
type = lib . types . submodule { freeformType = iniFormat . type ; } ;
default = { } ;
} ;
# passwordsFile = lib.mkOption {
# description = "Path to the PostgreSQL password file. See [the documentation](https://www.postgresql.org/docs/current/libpq-pgpass.html) for the format.";
# type = lib.types.path;
# default = null;
# };
} ;
config = lib . mkIf cfg . enable {
services . barman . settings = {
barman = {
barman_user = lib . mkDefault defaultUser ;
barman_home = lib . mkDefault defaultHome ;
compression = lib . mkDefault " p i g z " ;
backup_compression = lib . mkDefault " z s t d " ;
} ;
} ;
users . users . " ${ cfg . settings . barman . barman_user } " = {
isSystemUser = true ;
home = cfg . settings . barman . barman_home ;
createHome = true ;
group = cfg . settings . barman . barman_user ;
} ;
users . groups . " ${ cfg . settings . barman . barman_user } " = { } ;
environment = {
etc =
{
" b a r m a n . c o n f " = {
user = cfg . settings . barman . barman_user ;
source = iniFormat . generate " b a r m a n . c o n f " cfg . settings ;
} ;
}
// ( lib . mapAttrs' ( name : serverConfig : {
name = " b a r m a n . d / ${ name } . c o n f " ;
value = {
user = cfg . settings . barman . barman_user ;
source = iniFormat . generate " ${ name } . c o n f " { " ${ name } " = serverConfig ; } ;
} ;
} ) cfg . servers ) ;
2024-10-10 08:41:09 +02:00
systemPackages = [
cfg . package
barmanWrapper
] ;
2024-10-03 08:34:20 +02:00
} ;
systemd = {
timers . barman = {
description = " U p d a t e t i m e r f o r b a r m a n " ;
partOf = [ " b a r m a n . s e r v i c e " ] ;
wantedBy = [ " t i m e r s . t a r g e t " ] ;
timerConfig = {
OnCalendar = " * : * : 0 " ;
} ;
} ;
services . barman = {
description = " R u n b a r m a n m a i n t e n a n c e t a s k s " ;
2024-10-10 08:41:09 +02:00
path = runtimeInputs ;
2024-10-15 16:38:32 +02:00
environment = {
HOME = cfg . settings . barman . barman_home ;
} ;
2024-10-03 08:34:20 +02:00
serviceConfig = {
Type = " o n e s h o t " ;
User = cfg . settings . barman . barman_user ;
ExecStart = " ${ cfg . package } / b i n / b a r m a n c r o n " ;
WorkingDirectory = cfg . settings . barman . barman_home ;
} ;
} ;
} ;
} ;
}