summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/vellum.nix
blob: 9c8e045213b0a376719c1ae28b277585b6a87577 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.programs.vellum;

  inherit (lib)
    getExe
    literalExpression
    mkEnableOption
    mkIf
    mkOption
    mkPackageOption
    ;
  inherit (lib.types) separatedString;

  toml = pkgs.formats.toml { };
in
{
  options.programs.vellum = {
    enable = mkEnableOption "vellum, a live screen annotation overlay for Wayland";

    package = mkPackageOption pkgs "vellum" { };

    settings = mkOption {
      inherit (toml) type;
      default = { };
      description = ''
        Configuration options for vellum.
        See available options at <https://github.com/greyxp1/vellum/blob/master/docs/configuration.md>.
      '';
      example = literalExpression ''
        {
          default_tool = "arrow";
          remember_last_tool = false;
          feedback_duration_ms = 250;
        }
      '';
    };

    extraOptions = mkOption {
      type = separatedString " ";
      default = "";
      description = ''
        Extra command-line options to pass to
        the {command}`vellum` daemon.
      '';
      example = "--force-backend vulkan";
    };
  };

  config = mkIf cfg.enable {
    environment = {
      systemPackages = [ cfg.package ];

      etc."xdg/vellum/config.toml" = mkIf (cfg.settings != { }) {
        source = toml.generate "vellum-config.toml" cfg.settings;
      };
    };

    systemd.user.services.vellum = {
      description = "Vellum screen annotation overlay";
      after = [ "graphical-session.target" ];
      partOf = [ "graphical-session.target" ];
      wantedBy = [ "graphical-session.target" ];
      restartTriggers = [ config.environment.etc."xdg/vellum/config.toml".source ];
      serviceConfig = {
        ExecStart = "${getExe cfg.package} ${cfg.extraOptions}";
        Restart = "on-failure";
      };
    };
  };

  meta = {
    maintainers = with lib.maintainers; [ poz ];
  };
}