# modules/home/git-site.nix — a private sync job, kept encrypted. # # git-site-sync [auto|now|status|log] # # The job itself is secrets/git-site-sync.sh, a sops whole-file secret (see # .sops.yaml): this module only gives it a command and a timer. sops-nix # decrypts it into ~/.config/sops-nix/secrets/ at login, and the command runs # that copy with the tools below on PATH. A systemd user timer runs # `git-site-sync auto` every 15 minutes while you are logged in. # # Edit the job with `TMPDIR=/dev/shm sops secrets/git-site-sync.sh`, then # `nh os switch` (or wait for the next login) to have the new copy decrypted. { ... }: { flake.homeModules.git-site = { config, pkgs, lib, ... }: let script = config.sops.secrets."git-site-sync".path; tool = pkgs.writeShellApplication { name = "git-site-sync"; runtimeInputs = with pkgs; [ bash git openssh jq nodejs python3 util-linux # flock coreutils diffutils gnused libnotify # notify-send systemd ]; # The same strict mode writeShellApplication gave the script when it # was inlined here. text = '' [ -r ${script} ] || { echo "git-site-sync: ${script} is not decrypted yet (sops-nix runs at login)" >&2; exit 1; } exec bash -o errexit -o nounset -o pipefail ${script} "$@" ''; }; in { sops.secrets."git-site-sync" = { sopsFile = ../../secrets/git-site-sync.sh; format = "binary"; }; home.packages = [ tool ]; systemd.user.services.git-site-sync = { Unit = { Description = "Private sync job (secrets/git-site-sync.sh)"; After = [ "network-online.target" "sops-nix.service" ]; Wants = [ "sops-nix.service" ]; }; Service = { Type = "oneshot"; ExecStart = "${lib.getExe tool} auto"; Nice = 10; IOSchedulingClass = "idle"; }; }; systemd.user.timers.git-site-sync = { Unit.Description = "Run the private sync job every 15 minutes"; Timer = { OnCalendar = "*:0/15"; Persistent = true; # catch up after the laptop was asleep RandomizedDelaySec = "90"; }; Install.WantedBy = [ "timers.target" ]; }; }; }