fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.9 KiB106 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.mangohud;
7
8  settingsType = with types;
9    (oneOf [ bool int float str path (listOf (oneOf [ int str ])) ]);
10
11  renderOption = option:
12    rec {
13      int = toString option;
14      float = int;
15      path = int;
16      bool = "false";
17      string = option;
18      list = concatStringsSep "," (lists.forEach option (x: toString x));
19    }.${builtins.typeOf option};
20
21  renderLine = k: v: (if isBool v && v then k else "${k}=${renderOption v}");
22  renderSettings = attrs:
23    strings.concatStringsSep "\n" (attrsets.mapAttrsToList renderLine attrs)
24    + "\n";
25
26in {
27  options = {
28    programs.mangohud = {
29      enable = mkEnableOption "Mangohud";
30
31      package = mkOption {
32        type = types.package;
33        default = pkgs.mangohud;
34        defaultText = literalExpression "pkgs.mangohud";
35        description = "The Mangohud package to install.";
36      };
37
38      enableSessionWide = mkOption {
39        type = types.bool;
40        default = false;
41        description = ''
42          Sets environment variables so that
43          MangoHud is started on any application that supports it.
44        '';
45      };
46
47      settings = mkOption {
48        type = with types; attrsOf settingsType;
49        default = { };
50        example = literalExpression ''
51          {
52            output_folder = ~/Documents/mangohud/;
53            full = true;
54          }
55        '';
56        description = ''
57          Configuration written to
58          {file}`$XDG_CONFIG_HOME/MangoHud/MangoHud.conf`. See
59          <https://github.com/flightlessmango/MangoHud/blob/master/data/MangoHud.conf>
60          for the default configuration.
61        '';
62      };
63
64      settingsPerApplication = mkOption {
65        type = with types; attrsOf (attrsOf settingsType);
66        default = { };
67        example = literalExpression ''
68          {
69            mpv = {
70              no_display = true;
71            }
72          }
73        '';
74        description = ''
75          Sets MangoHud settings per application.
76          Configuration written to
77          {file}`$XDG_CONFIG_HOME/MangoHud/{application_name}.conf`. See
78          <https://github.com/flightlessmango/MangoHud/blob/master/data/MangoHud.conf>
79          for the default configuration.
80        '';
81      };
82    };
83  };
84
85  config = mkIf cfg.enable {
86    assertions = [
87      (hm.assertions.assertPlatform "programs.mangohud" pkgs platforms.linux)
88    ];
89
90    home.packages = [ cfg.package ];
91
92    home.sessionVariables = mkIf cfg.enableSessionWide {
93      MANGOHUD = 1;
94      MANGOHUD_DLSYM = 1;
95    };
96
97    xdg.configFile = {
98      "MangoHud/MangoHud.conf" =
99        mkIf (cfg.settings != { }) { text = renderSettings cfg.settings; };
100    } // mapAttrs'
101      (n: v: nameValuePair "MangoHud/${n}.conf" { text = renderSettings v; })
102      cfg.settingsPerApplication;
103  };
104
105  meta.maintainers = with maintainers; [ zeratax ];
106}