From 218ac55d86ee49d151c0ba2dfbca6da104c66703 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 25 Aug 2025 14:19:52 +0200 Subject: ... --- modules/impermanence-timezone.nix | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 modules/impermanence-timezone.nix (limited to 'modules/impermanence-timezone.nix') diff --git a/modules/impermanence-timezone.nix b/modules/impermanence-timezone.nix new file mode 100644 index 00000000..a1edbfa5 --- /dev/null +++ b/modules/impermanence-timezone.nix @@ -0,0 +1,41 @@ +{ config, lib, utils, pkgs, ... }: + +{ + options = { + environment.persistence = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule { + options = { + timezone = lib.mkEnableOption "storing system timezone"; + }; + }); + }; + }; + + config = { + systemd = lib.mkMerge (lib.mapAttrsToList (name: cfg: lib.mkIf cfg.timezone { + services = { + "timezone@${utils.escapeSystemdPath name}" = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = "${pkgs.coreutils}/bin/cp -vP ${utils.escapeSystemdExecArg "${name}/etc/localtime"} /etc/localtime"; + ExecStop = "${pkgs.coreutils}/bin/cp -vP /etc/localtime ${utils.escapeSystemdExecArg "${name}/etc/localtime"}"; + }; + }; + "etc-localtime@${utils.escapeSystemdPath name}" = { + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.coreutils}/bin/cp -vP /etc/localtime ${utils.escapeSystemdExecArg "${name}/etc/localtime"}"; + }; + }; + }; + paths."etc-localtime@${utils.escapeSystemdPath name}" = { + wantedBy = [ "timezone@${utils.escapeSystemdPath name}.service" ]; + after = [ "timezone@${utils.escapeSystemdPath name}.service" ]; + + pathConfig.PathChanged = "/etc/localtime"; + }; + }) config.environment.persistence); + }; +} -- cgit v1.2.3