1{ config, lib, pkgs, ... }:
2
3let
4
5 cfg = config.programs.mosh;
6
7in
8{
9 options.programs.mosh = {
10 enable = lib.mkEnableOption "mosh";
11 openFirewall = lib.mkEnableOption "" // {
12 description = "Whether to automatically open the necessary ports in the firewall.";
13 default = true;
14 };
15 withUtempter = lib.mkEnableOption "" // {
16 description = ''
17 Whether to enable libutempter for mosh.
18
19 This is required so that mosh can write to /var/run/utmp (which can be queried with `who` to display currently connected user sessions).
20 Note, this will add a guid wrapper for the group utmp!
21 '';
22 default = true;
23 };
24 };
25
26 config = lib.mkIf cfg.enable {
27 environment.systemPackages = [ pkgs.mosh ];
28 networking.firewall.allowedUDPPortRanges = lib.optional cfg.openFirewall { from = 60000; to = 61000; };
29 security.wrappers = lib.mkIf cfg.withUtempter {
30 utempter = {
31 source = "${pkgs.libutempter}/lib/utempter/utempter";
32 owner = "root";
33 group = "utmp";
34 setuid = false;
35 setgid = true;
36 };
37 };
38 };
39}