{ config, lib, pkgs, ... }:

let mutableSymlink = config.lib.file.mkOutOfStoreSymlink;
in lib.mkMerge [
  {
    # Link private SSH keys to ~/.ssh/id_ed25519 (where SSH will automatically
    # find them) and ~/private-keys (where humans will find them).  Remember
    # that private keys must always be linked with mutable symlinks as to not
    # copy them into the world-readable Nix store!!
    home.file.".ssh/id_ed25519".source =
      mutableSymlink "/persist/private-keys/ssh/crumb-at-nixos-testbed";
    home.file."private-keys/ssh/crumb-at-nixos-testbed".source =
      mutableSymlink "/persist/private-keys/ssh/crumb-at-nixos-testbed";


    # Similarly, public keys are linked where SSH will find them as well as a
    # human-friendly ~/public-keys.
    home.file.".ssh/id_ed25519.pub".source =
      ../../public-keys/ssh/crumb-at-nixos-testbed.pub;
    home.file."public-keys/ssh/crumb-at-nixos-testbed".source =
      ../../public-keys/ssh/crumb-at-nixos-testbed.pub;
  }

  {
    ### Some basic impermanence setup.

    sydnix.impermanence = {
      enable = true;
      directories = [
        "Music"
        "Pictures"
        "Documents"
        "Videos"
        "src" # My projects.
        "scratch" # My playgrounds.
        "git" # Other peoples' projects.
        # Should "org" be declared in emacs.nix?  I don't think so.  I
        # conjecture that my org files are extremely valuable with or without
        # Emacs.
        "org"
        # REVIEW: I think it may be preferable to persist a few individual files
        # under ~/.ssh, rather than the whole directory.
        ".ssh"
      ];
    };
  }

  {
    ### Syncthing

    sydnix.syncthing = {
      enable = true;
      includeDevices = [
        "guix-rebound"
        "deertopia"
      ];
      directories = {
        "org" = {
          path = "~/org";
          devices = [
            "guix-rebound"
            "deertopia"
          ];
          ignorePerms = true;
        };
        "Music" = {
          path = "~/Music";
          devices = [
            "deertopia"
          ];
          ignorePerms = true;
        };
      };
    };
  }
]
