Compare commits

...

28 commits

Author SHA1 Message Date
Bruno BELANYI d2e9f300ce fixup! WIP: nixos: system: add persist
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-10-03 13:20:42 +00:00
Bruno BELANYI a9a1028164 WIP: add notes for missing persistence/backup
All checks were successful
ci/woodpecker/push/check Pipeline was successful
TODO:
* Look at for more inspiration https://github.com/nix-community/impermanence/pull/108
* Do home-manager
* Common files https://github.com/nix-community/impermanence/issues/10
2024-07-02 16:36:35 +00:00
Bruno BELANYI 3150f9bf22 nixos: services: quassel: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI c0c8e65c22 nixos: services: pirate: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI b51799218d nixos: services: monitoring: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI 238a31e98d nixos: services: nginx: persist SSL certificates 2024-07-02 16:36:35 +00:00
Bruno BELANYI e1d5f7ce8e nixos: services: transmission: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI 3a5781ba4b nixos: services: sabnzbd: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI cd8f0c3c7f nixos: services: rss-bridge: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI 357276bfb7 nixos: services: podgrab: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI e2bb819b74 nixos: services: nextcloud: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI db03432cea nixos: services: navidrome: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI 6290554b90 nixos: services: lohr: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI 4e50e84148 nixos: services: jellyfin: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI ef57bac9d6 nixos: services: indexers: persist data 2024-07-02 16:36:35 +00:00
Bruno BELANYI 7bd66dcafe nixos: services: postgresql: persist data 2024-07-02 16:32:19 +00:00
Bruno BELANYI 2299ef237c nixos: services: postgresql-backup: persist data 2024-07-02 16:32:19 +00:00
Bruno BELANYI c0dc0b2a54 nixos: services: paperless: persist data 2024-07-02 16:32:19 +00:00
Bruno BELANYI 61a6208087 nixos: services: matrix: persist data 2024-07-02 16:32:18 +00:00
Bruno BELANYI 464ce18c2f nixos: services: forgejo: persist repositories 2024-07-02 16:32:12 +00:00
Bruno BELANYI 2e0d3751e9 nixos: services: gitea: persist repositories 2024-07-02 16:32:12 +00:00
Bruno BELANYI 830a687554 nixos: services: calibre-web: persist library 2024-07-02 16:23:41 +00:00
Bruno BELANYI 1686f620a0 nixos: services: blog: persist website data 2024-07-02 16:23:41 +00:00
Bruno BELANYI dc9efaef58 nixos: hardware: bluetooth: persist connections 2024-07-02 16:23:41 +00:00
Bruno BELANYI 8b6621905c nixos: hardware: netowrking persist connections 2024-07-02 16:23:41 +00:00
Bruno BELANYI dd92c987b3 nixos: services: ssh-server: persist host keys 2024-07-02 16:23:41 +00:00
Bruno BELANYI 605934d230 WIP: nixos: system: add persist
This is the module that takes care of configuring impermanence at the
system level.

WIP:
    * address FIXMEs
    * activate home-manager persistence?
        * set `programs.fuse.userAllowOther = true;` ?
    * point `age` to persisted paths [1] ?
    * make sure all services and modules are persisted correctly...

[1]: b1d18d25b8
2024-07-02 16:23:41 +00:00
Bruno BELANYI 715cfdffee flake: add 'impermanence' 2024-07-02 16:23:41 +00:00
38 changed files with 243 additions and 0 deletions

View file

@ -150,6 +150,22 @@
"type": "github" "type": "github"
} }
}, },
"impermanence": {
"locked": {
"lastModified": 1697303681,
"narHash": "sha256-caJ0rXeagaih+xTgRduYtYKL1rZ9ylh06CIrt1w5B4g=",
"owner": "nix-community",
"repo": "impermanence",
"rev": "0f317c2e9e56550ce12323eb39302d251618f5b5",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "master",
"repo": "impermanence",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1719254875, "lastModified": 1719254875,
@ -214,6 +230,7 @@
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"futils": "futils", "futils": "futils",
"home-manager": "home-manager", "home-manager": "home-manager",
"impermanence": "impermanence",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nur": "nur", "nur": "nur",
"pre-commit-hooks": "pre-commit-hooks", "pre-commit-hooks": "pre-commit-hooks",

View file

@ -43,6 +43,13 @@
}; };
}; };
impermanence = {
type = "github";
owner = "nix-community";
repo = "impermanence";
ref = "master";
};
nixpkgs = { nixpkgs = {
type = "github"; type = "github";
owner = "NixOS"; owner = "NixOS";

View file

@ -18,6 +18,13 @@ in
services.blueman.enable = true; services.blueman.enable = true;
} }
# Persist bluetooth files
{
my.system.persist.directories = [
"/var/lib/bluetooth"
];
}
# Support for additional bluetooth codecs # Support for additional bluetooth codecs
(lib.mkIf cfg.loadExtraCodecs { (lib.mkIf cfg.loadExtraCodecs {
hardware.pulseaudio = { hardware.pulseaudio = {

View file

@ -22,6 +22,11 @@ in
config = lib.mkMerge [ config = lib.mkMerge [
(lib.mkIf cfg.wireless.enable { (lib.mkIf cfg.wireless.enable {
networking.networkmanager.enable = true; networking.networkmanager.enable = true;
# Persist NetworkManager files
my.system.persist.directories = [
"/etc/NetworkManager/system-connections"
];
}) })
]; ];
} }

View file

@ -72,5 +72,6 @@ in
}; };
# NOTE: unfortunately aria2 does not log connection failures for fail2ban # NOTE: unfortunately aria2 does not log connection failures for fail2ban
# FIXME: persistence?
}; };
} }

View file

@ -35,5 +35,7 @@ in
}; };
}; };
}; };
# FIXME: persistence?
}; };
} }

View file

@ -41,5 +41,12 @@ in
# Those are all subdomains, no problem # Those are all subdomains, no problem
my.services.nginx.virtualHosts = hostsInfo; my.services.nginx.virtualHosts = hostsInfo;
my.system.persist.directories = [
"/var/www/blog"
"/var/www/cv"
"/var/www/dev"
"/var/www/key"
];
}; };
} }

View file

@ -53,6 +53,11 @@ in
]; ];
}; };
my.system.persist.directories = [
"/var/lib/${config.services.calibre-web.dataDir}"
cfg.libraryPath
];
services.fail2ban.jails = { services.fail2ban.jails = {
calibre-web = '' calibre-web = ''
enabled = true enabled = true

View file

@ -27,5 +27,7 @@ in
inherit (cfg) port; inherit (cfg) port;
}; };
}; };
# FIXME: persistence?
}; };
} }

View file

@ -147,6 +147,11 @@ in
]; ];
}; };
my.system.persist.directories = [
config.services.gitea.lfs.contentDir
config.services.gitea.repositoryRoot
];
services.fail2ban.jails = { services.fail2ban.jails = {
forgejo = '' forgejo = ''
enabled = true enabled = true

View file

@ -131,6 +131,11 @@ in
]; ];
}; };
my.system.persist.directories = [
config.services.gitea.lfs.contentDir
config.services.gitea.repositoryRoot
];
services.fail2ban.jails = { services.fail2ban.jails = {
gitea = '' gitea = ''
enabled = true enabled = true

View file

@ -36,5 +36,8 @@ in
forceSSL = true; forceSSL = true;
useACMEHost = config.networking.domain; useACMEHost = config.networking.domain;
}; };
# FIXME: backup
# FIXME: persistence
}; };
} }

View file

@ -33,6 +33,10 @@ in
port = jackettPort; port = jackettPort;
}; };
}; };
my.system.persist.directories = [
config.services.jackett.dataDir
];
}) })
(lib.mkIf cfg.nzbhydra.enable { (lib.mkIf cfg.nzbhydra.enable {
@ -45,6 +49,10 @@ in
port = nzbhydraPort; port = nzbhydraPort;
}; };
}; };
my.system.persist.directories = [
config.services.nzbhydra2.dataDir
];
}) })
(lib.mkIf cfg.prowlarr.enable { (lib.mkIf cfg.prowlarr.enable {
@ -58,6 +66,10 @@ in
}; };
}; };
my.system.persist.directories = [
"/var/lib/${config.systemd.services.prowlarr.serviceConfig.StateDirectory}"
];
services.fail2ban.jails = { services.fail2ban.jails = {
prowlarr = '' prowlarr = ''
enabled = true enabled = true

View file

@ -41,5 +41,9 @@ in
}; };
}; };
}; };
my.system.persist.directories = [
"/var/lib/${config.systemd.services.jellyfin.serviceConfig.StateDirectory}"
];
}; };
} }

View file

@ -107,5 +107,9 @@ in
}; };
}; };
}; };
my.system.persist.directories = [
"/var/lib/${config.systemd.services.lohr.serviceConfig.StateDirectory}"
];
}; };
} }

View file

@ -253,5 +253,9 @@ in
config.services.matrix-synapse.dataDir config.services.matrix-synapse.dataDir
]; ];
}; };
my.system.persist.directories = [
config.services.matrix-synapse.dataDir
];
}; };
} }

View file

@ -71,5 +71,8 @@ in
}; };
}; };
}; };
# FIXME: backup
# FIXME: persistence
}; };
} }

View file

@ -48,5 +48,8 @@ in
inherit (cfg) port; inherit (cfg) port;
}; };
}; };
# FIXME: backup
# FIXME: persistence
}; };
} }

View file

@ -130,5 +130,10 @@ in
inherit (cfg.grafana) port; inherit (cfg.grafana) port;
}; };
}; };
my.system.persist.directories = [
config.services.grafana.dataDir
"/var/lib/${config.services.prometheus.stateDir}"
];
}; };
} }

View file

@ -52,5 +52,9 @@ in
inherit (cfg) port; inherit (cfg) port;
}; };
}; };
my.system.persist.directories = [
"/var/lib/${config.systemd.services.navidrome.serviceConfig.StateDirectory}"
];
}; };
} }

View file

@ -87,5 +87,10 @@ in
"${config.services.nextcloud.home}/data/appdata_*/preview" "${config.services.nextcloud.home}/data/appdata_*/preview"
]; ];
}; };
my.system.persist.directories = [
config.services.nextcloud.home
config.services.nextcloud.datadir
];
}; };
} }

View file

@ -465,5 +465,9 @@ in
} }
]; ];
}; };
my.system.persist.directories = [
config.users.user.acme.home
];
}; };
} }

View file

@ -166,5 +166,10 @@ in
config.services.paperless.mediaDir config.services.paperless.mediaDir
]; ];
}; };
my.system.persist.directories = [
config.services.paperless-ng.dataDir
config.services.paperless-ng.mediaDir
];
}; };
} }

View file

@ -18,6 +18,11 @@ let
enable = true; enable = true;
group = "media"; group = "media";
}; };
# Thankfully those old style services all define users with homes
my.system.persist.directories = [
config.users.user.${service}.home
];
}; };
mkRedirection = service: { mkRedirection = service: {

View file

@ -51,5 +51,10 @@ in
inherit (cfg) port; inherit (cfg) port;
}; };
}; };
my.system.persist.directories = [
config.systemd.services.podgrab.environment.CONFIG
config.systemd.services.podgrab.environment.DATA
];
}; };
} }

View file

@ -24,5 +24,9 @@ in
(config.services.postgresqlBackup.location + "/*.prev.sql.gz") (config.services.postgresqlBackup.location + "/*.prev.sql.gz")
]; ];
}; };
my.system.persist.directories = [
config.services.postgresqlBackup.location
];
}; };
} }

View file

@ -18,6 +18,13 @@ in
}; };
}) })
# Only persist directory if the actual service is enabled
(lib.mkIf config.services.postgresql.enable {
my.system.persist.directories = [
config.services.postgresql.dataDir
];
})
# Taken from the manual # Taken from the manual
(lib.mkIf cfg.upgradeScript { (lib.mkIf cfg.upgradeScript {
environment.systemPackages = environment.systemPackages =

View file

@ -54,5 +54,7 @@ in
}; };
# FIXME: fail2ban # FIXME: fail2ban
# FIXME: backup
# FIXME: persistence
}; };
} }

View file

@ -46,5 +46,9 @@ in
# Because Quassel does not use the socket, I simply trust its connection # Because Quassel does not use the socket, I simply trust its connection
authentication = "host quassel quassel localhost trust"; authentication = "host quassel quassel localhost trust";
}; };
my.system.persist.directories = [
config.services.quassel.dataDir
];
}; };
} }

View file

@ -22,5 +22,9 @@ in
forceSSL = true; forceSSL = true;
useACMEHost = config.networking.domain; useACMEHost = config.networking.domain;
}; };
my.system.persist.directories = [
config.services.rss-bridge.dataDir
];
}; };
} }

View file

@ -24,6 +24,10 @@ in
}; };
}; };
my.system.persist.files = [
config.services.sabnzbd.configFile
];
services.fail2ban.jails = { services.fail2ban.jails = {
sabnzbd = '' sabnzbd = ''
enabled = true enabled = true

View file

@ -20,6 +20,14 @@ in
}; };
}; };
# Persist SSH keys
my.system.persist.files = [
"/etc/ssh/ssh_host_ed25519_key"
"/etc/ssh/ssh_host_ed25519_key.pub"
"/etc/ssh/ssh_host_rsa_key"
"/etc/ssh/ssh_host_rsa_key.pub"
];
# Opens the relevant UDP ports. # Opens the relevant UDP ports.
programs.mosh.enable = true; programs.mosh.enable = true;
}; };

View file

@ -82,5 +82,8 @@ in
}; };
}; };
}; };
# FIXME: backup
# FIXME: persistence
}; };
} }

View file

@ -90,5 +90,9 @@ in
allowedTCPPorts = [ cfg.peerPort ]; allowedTCPPorts = [ cfg.peerPort ];
allowedUDPPorts = [ cfg.peerPort ]; allowedUDPPorts = [ cfg.peerPort ];
}; };
my.system.persist.directories = [
config.services.transmission.home
];
}; };
} }

View file

@ -99,5 +99,7 @@ in
config.services.vikunja.settings.files.basepath config.services.vikunja.settings.files.basepath
]; ];
}; };
# FIXME: persistence
}; };
} }

View file

@ -61,5 +61,7 @@ in
port = cfg.rpcPort; port = cfg.rpcPort;
}; };
}; };
# FIXME: persistence
}; };
} }

View file

@ -9,6 +9,7 @@
./language ./language
./nix ./nix
./packages ./packages
./persist
./podman ./podman
./polkit ./polkit
./printing ./printing

View file

@ -0,0 +1,69 @@
# Ephemeral root configuration
{ config, inputs, lib, ... }:
let
cfg = config.my.system.persist;
in
{
imports = [
inputs.impermanence.nixosModules.impermanence
];
options.my.system.persist = with lib; {
enable = mkEnableOption "stateless system configuration";
mountPoint = lib.mkOption {
type = types.str;
default = "/persistent";
example = "/etc/nix/persist";
description = ''
Which mount point should be used to persist this system's files and
directories.
'';
};
files = lib.mkOption {
type = with types; listOf str;
default = [ ];
example = [
"/etc/nix/id_rsa"
];
description = ''
Additional files in the root to link to persistent storage.
'';
};
directories = lib.mkOption {
type = with types; listOf str;
default = [ ];
example = [
"/var/lib/libvirt"
];
description = ''
Additional directories in the root to link to persistent storage.
'';
};
};
config = lib.mkIf cfg.enable {
environment.persistence."${cfg.mountPoint}" = {
files = [
"/etc/machine-id"
]
++ cfg.files
;
directories = [
"/etc/nixos"
"/var/log"
"/var/lib/nixos"
"/var/lib/systemd/coredump"
]
++ (lib.optionals config.virtualisation.docker.enable [
"/var/lib/docker"
])
# FIXME: podman
++ cfg.directories
;
};
};
}