···11-{ config, pkgs, cfgLib, ... }:
11+{ config, lib, pkgs, cfgLib, ... }:
2233let
44 cfg = cfgLib.cfg;
···20202121 # Touch ID for sudo – driven from settings/config/darwin.nix
2222 security.pam.services.sudo_local.touchIdAuth = cfg.darwin.security.touchIdForSudo;
2323+2424+ # ── Time Machine destination ──────────────────────────────────────────────────
2525+ # No native nix-darwin option exists for tmutil setdestination, so we use an
2626+ # activation script. It is idempotent: skipped if the URL is already registered.
2727+ #
2828+ # First-time setup (one-off, interactive — stores password in macOS keychain):
2929+ # sudo tmutil setdestination -p smb://<user>@server/TimeMachine
3030+ # After that, nrs registers it automatically on every rebuild without prompting.
3131+ system.activationScripts.timeMachineDestination = lib.mkIf cfg.server.timemachine.enable {
3232+ text = let
3333+ shareUrl = "smb://${cfg.user.username}@server/${cfg.server.timemachine.shareName}";
3434+ in ''
3535+ shareUrl='${shareUrl}'
3636+ echo "Checking Time Machine destination ($shareUrl)..."
3737+ if /usr/bin/tmutil destinationinfo 2>/dev/null | /usr/bin/grep -qF "$shareUrl"; then
3838+ echo " already registered, skipping"
3939+ else
4040+ echo " registering..."
4141+ # -a adds alongside existing destinations rather than replacing them.
4242+ # Credentials come from the macOS keychain — never stored in the Nix store.
4343+ /usr/bin/tmutil setdestination -a "$shareUrl" 2>&1 || \
4444+ echo " WARNING: could not register (share may be unreachable right now)"
4545+ fi
4646+ '';
4747+ };
2348}