Skip to content
Snippets Groups Projects
client.nix 3.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • # Client section of our Monitoring VPN config
    
    
    Florian Sesser's avatar
    Florian Sesser committed
    { lib, config, ... }: let
      cfg = config.services.private-storage.monitoring.vpn;
    
    Florian Sesser's avatar
    Florian Sesser committed
    in {
    
    Florian Sesser's avatar
    Florian Sesser committed
      options.services.private-storage.monitoring.vpn.client = {
        enable = lib.mkEnableOption "PrivateStorageio Monitoring VPN client service";
        privateKeyFile = lib.mkOption {
    
    Florian Sesser's avatar
    Florian Sesser committed
          type = lib.types.path;
          example = lib.literalExample /var/secrets/monitoringvpn/host.key;
          default = /var/secrets/monitoringvpn/client.key;
    
    Florian Sesser's avatar
    Florian Sesser committed
          description = ''
    
    Florian Sesser's avatar
    Florian Sesser committed
            File with base64 private key generated by <command>wg genkey</command>.
    
            Shorthand for public and private key:
            <command>wg genkey | tee peer_A.key | wg pubkey > peer_A.pub</command>
    
    Florian Sesser's avatar
    Florian Sesser committed
          '';
        };
        publicKeyFile = lib.mkOption {
    
    Florian Sesser's avatar
    Florian Sesser committed
          type = lib.types.path;
          example = lib.literalExample /var/secrets/monitoringvpn/host.pub;
    
    Florian Sesser's avatar
    Florian Sesser committed
          description = ''
    
    Florian Sesser's avatar
    Florian Sesser committed
            File with base64 public key generated by <command>cat private.key | wg pubkey > pubkey.pub</command>.
    
            Shorthand for public and private key:
            <command>wg genkey | tee peer_A.key | wg pubkey > peer_A.pub</command>
    
    Florian Sesser's avatar
    Florian Sesser committed
          '';
        };
    
        presharedKeyFile = lib.mkOption {
          type = lib.types.path;
          example = lib.literalExample /var/secrets/monitoringvpn/preshared.key;
          default = /var/secrets/monitoringvpn/preshared.key;
          description = ''
            File with base64 preshared key generated by <command>wg genpsk</command>.
          '';
        };
    
    Florian Sesser's avatar
    Florian Sesser committed
        allowedIPs = lib.mkOption {
          type = lib.types.listOf lib.types.str;
          example = lib.literalExample [ "172.23.23.1/32" ];
    
    Florian Sesser's avatar
    Florian Sesser committed
          default = [ "172.23.23.1/32" ];
    
    Florian Sesser's avatar
    Florian Sesser committed
          description = ''
            Limits which IPs this client receives data from.
          '';
        };
    
    Florian Sesser's avatar
    Florian Sesser committed
        ip = lib.mkOption {
          type = lib.types.str;
          example = lib.literalExample "172.23.23.11";
    
    Florian Sesser's avatar
    Florian Sesser committed
          description = ''
            The IP addresses of the interface.
          '';
        };
    
    Florian Sesser's avatar
    Florian Sesser committed
        endpoint = lib.mkOption {
          type = lib.types.str;
          example = lib.literalExample "vpn.monitoring.private.storage:54321";
    
    Florian Sesser's avatar
    Florian Sesser committed
          default = "192.168.67.24:54321";
    
    Florian Sesser's avatar
    Florian Sesser committed
          description = ''
            The address and port number of the server to establish the VPN with.
          '';
        };
        endpointPublicKeyFile = lib.mkOption {
    
    Florian Sesser's avatar
    Florian Sesser committed
          type = lib.types.path;
          example = lib.literalExample /var/secrets/monitoringvpn/server.pub;
    
          default = ../../../../morph/PrivateStorageSecrets/monitoringvpn/server.pub;
    
    Florian Sesser's avatar
    Florian Sesser committed
          description = ''
            File with base64 public key generated by <command>cat private.key | wg pubkey > pubkey.pub</command>.
          '';
        };
    
    Florian Sesser's avatar
    Florian Sesser committed
      };
    
      config = lib.mkIf cfg.client.enable {
        networking.wireguard.interfaces.monitoringvpn = {
    
    Florian Sesser's avatar
    Florian Sesser committed
          ips = [ "${cfg.client.ip}/24" ];
    
    Florian Sesser's avatar
    Florian Sesser committed
          privateKeyFile = toString cfg.client.privateKeyFile;
    
    Florian Sesser's avatar
    Florian Sesser committed
          peers = [
            {
              allowedIPs = cfg.client.allowedIPs;
    
    Florian Sesser's avatar
    Florian Sesser committed
              endpoint = cfg.client.endpoint;  # meaning: the server.
              publicKey = builtins.readFile(cfg.client.endpointPublicKeyFile);
    
              presharedKeyFile = toString cfg.client.presharedKeyFile;
    
    Florian Sesser's avatar
    Florian Sesser committed
            }
          ];
        };