about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/programs/mosh.nix
blob: 593246ab6dcd13bee32dbfb34135db217aa24ed1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{ config, lib, pkgs, ... }:

let

  cfg  = config.programs.mosh;

in
{
  options.programs.mosh = {
    enable = lib.mkEnableOption "mosh";
    openFirewall = lib.mkEnableOption "" // {
      description = "Whether to automatically open the necessary ports in the firewall.";
      default = true;
    };
    withUtempter = lib.mkEnableOption "" // {
      description = lib.mdDoc ''
        Whether to enable libutempter for mosh.

        This is required so that mosh can write to /var/run/utmp (which can be queried with `who` to display currently connected user sessions).
        Note, this will add a guid wrapper for the group utmp!
      '';
      default = true;
    };
  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ pkgs.mosh ];
    networking.firewall.allowedUDPPortRanges = lib.optional cfg.openFirewall { from = 60000; to = 61000; };
    security.wrappers = lib.mkIf cfg.withUtempter {
      utempter = {
        source = "${pkgs.libutempter}/lib/utempter/utempter";
        owner = "root";
        group = "utmp";
        setuid = false;
        setgid = true;
      };
    };
  };
}