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

with lib;

let cfg = config.hacc;

in {

  options.hacc.bindMounts = mkOption {
    type = types.attrsOf types.str;
    default = { };
    example = { "/etc/asdf" = "/persist/asdf"; };
  };
  options.hacc.bindToPersist = mkOption {
    type = types.listOf types.str;
    default = [];
    example = [ "postgres" ];
  };

  config.fileSystems = mapAttrs (_: device: {
    inherit device;
    options = [ "bind" ];
  }) cfg.bindMounts;

  config.hacc.bindMounts = listToAttrs
    (map (name: { inherit name; value = "/persist${name}"; })
      cfg.bindToPersist);
}