{ 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); }; }