diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ac1cb06b4..55d5239ac 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -104,6 +104,9 @@
/modules/programs/matplotlib.nix @rprospero
+/modules/programs/mangohud.nix @ZerataX
+/tests/modules/programs/mangohud @ZerataX
+
/modules/programs/mbsync.nix @KarlJoad
/tests/modules/programs/mbsync @KarlJoad
@@ -315,4 +318,4 @@
/modules/xresources.nix @rycee
-/modules/xsession.nix @rycee
\ No newline at end of file
+/modules/xsession.nix @rycee
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index 7a7912001..a94fa6c0e 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -2077,6 +2077,13 @@ in
A new module is available: 'services.pantalaimon'.
'';
}
+
+ {
+ time = "2021-06-12T05:00:22+00:00";
+ message = ''
+ A new module is available: 'programs.mangohud'.
+ '';
+ }
];
};
}
diff --git a/modules/modules.nix b/modules/modules.nix
index 8d0c46b7c..0e9c4327b 100644
--- a/modules/modules.nix
+++ b/modules/modules.nix
@@ -93,6 +93,7 @@ let
(loadModule ./programs/lf.nix { })
(loadModule ./programs/lsd.nix { })
(loadModule ./programs/man.nix { })
+ (loadModule ./programs/mangohud.nix { condition = hostPlatform.isLinux; })
(loadModule ./programs/matplotlib.nix { })
(loadModule ./programs/mbsync.nix { })
(loadModule ./programs/mcfly.nix { })
diff --git a/modules/programs/mangohud.nix b/modules/programs/mangohud.nix
new file mode 100644
index 000000000..3a2158e3d
--- /dev/null
+++ b/modules/programs/mangohud.nix
@@ -0,0 +1,105 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.programs.mangohud;
+
+ settingsType = with types;
+ (oneOf [ bool int float str path (listOf (oneOf [ int str ])) ]);
+
+ renderOption = option:
+ rec {
+ int = toString option;
+ float = int;
+ path = int;
+ bool = "false";
+ string = option;
+ list = concatStringsSep "," (lists.forEach option (x: toString x));
+ }.${builtins.typeOf option};
+
+ renderLine = k: v: (if isBool v && v then k else "${k}=${renderOption v}");
+ renderSettings = attrs:
+ strings.concatStringsSep "\n" (attrsets.mapAttrsToList renderLine attrs)
+ + "\n";
+
+in {
+ options = {
+ programs.mangohud = {
+ enable = mkEnableOption "Mangohud";
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.mangohud;
+ defaultText = literalExample "pkgs.mangohud";
+ description = "The Mangohud package to install.";
+ };
+
+ enableSessionWide = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Sets environment variables so that
+ MangoHud is started on any application that supports it.
+ '';
+ };
+
+ settings = mkOption {
+ type = with types; attrsOf settingsType;
+ default = { };
+ example = literalExample ''
+ {
+ output_folder = ~/Documents/mangohud/;
+ full = true;
+ }
+ '';
+ description = ''
+ Configuration written to
+ ~/.config/MangoHud/MangoHud.conf. See
+
+ for the default configuration.
+ '';
+ };
+
+ settingsPerApplication = mkOption {
+ type = with types; attrsOf (attrsOf settingsType);
+ default = { };
+ example = literalExample ''
+ {
+ mpv = {
+ no_display = true;
+ }
+ }
+ '';
+ description = ''
+ Sets MangoHud settings per application.
+ Configuration written to
+ ~/.config/MangoHud/{application_name}.conf. See
+
+ for the default configuration.
+ '';
+ };
+ };
+ };
+
+ config = mkIf cfg.enable (mkMerge [
+ {
+ home.packages = [ cfg.package ];
+
+ home.sessionVariables = mkIf cfg.enableSessionWide {
+ MANGOHUD = 1;
+ MANGOHUD_DLSYM = 1;
+ };
+
+ xdg.configFile."MangoHud/MangoHud.conf" =
+ mkIf (cfg.settings != { }) { text = renderSettings cfg.settings; };
+ }
+ {
+ xdg.configFile = mapAttrs'
+ (n: v: nameValuePair "MangoHud/${n}.conf" { text = renderSettings v; })
+ cfg.settingsPerApplication;
+ }
+ ]);
+
+ meta.maintainers = with maintainers; [ zeratax ];
+}
diff --git a/tests/default.nix b/tests/default.nix
index 2d855f5d3..4ec787280 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -101,6 +101,7 @@ import nmt {
./modules/programs/foot
./modules/programs/getmail
./modules/programs/i3status-rust
+ ./modules/programs/mangohud
./modules/programs/ncmpcpp-linux
./modules/programs/neovim # Broken package dependency on Darwin.
./modules/programs/rbw
diff --git a/tests/modules/programs/mangohud/basic-configuration-mpv.conf b/tests/modules/programs/mangohud/basic-configuration-mpv.conf
new file mode 100644
index 000000000..9cf2f34ef
--- /dev/null
+++ b/tests/modules/programs/mangohud/basic-configuration-mpv.conf
@@ -0,0 +1,2 @@
+no_display
+output_folder=/home/user/Documents/mpv-mangohud
diff --git a/tests/modules/programs/mangohud/basic-configuration.conf b/tests/modules/programs/mangohud/basic-configuration.conf
new file mode 100644
index 000000000..8ded2dbc0
--- /dev/null
+++ b/tests/modules/programs/mangohud/basic-configuration.conf
@@ -0,0 +1,13 @@
+cpu_load_change
+cpu_load_value
+cpu_mhz
+cpu_power
+cpu_stats
+cpu_temp
+cpu_text=CPU
+fps_limit=30,60
+legacy_layout=false
+media_player_name=spotify
+media_player_order=title,artist,album
+output_folder=/home/user/Documents/mangohud
+vsync=0
diff --git a/tests/modules/programs/mangohud/basic-configuration.nix b/tests/modules/programs/mangohud/basic-configuration.nix
new file mode 100644
index 000000000..7ff4a8901
--- /dev/null
+++ b/tests/modules/programs/mangohud/basic-configuration.nix
@@ -0,0 +1,40 @@
+{ config, pkgs, ... }:
+
+{
+ config = {
+ programs.mangohud = {
+ enable = true;
+ package = pkgs.writeScriptBin "dummy-mangohud" "";
+ settings = {
+ output_folder = /home/user/Documents/mangohud;
+ fps_limit = [ 30 60 ];
+ vsync = 0;
+ legacy_layout = false;
+ cpu_stats = true;
+ cpu_temp = true;
+ cpu_power = true;
+ cpu_text = "CPU";
+ cpu_mhz = true;
+ cpu_load_change = true;
+ cpu_load_value = true;
+ media_player_name = "spotify";
+ media_player_order = [ "title" "artist" "album" ];
+ };
+ settingsPerApplication = {
+ mpv = {
+ output_folder = /home/user/Documents/mpv-mangohud;
+ no_display = true;
+ };
+ };
+ };
+
+ nmt.script = ''
+ assertFileExists home-files/.config/MangoHud/MangoHud.conf
+ assertFileContent home-files/.config/MangoHud/MangoHud.conf \
+ ${./basic-configuration.conf}
+ assertFileExists home-files/.config/MangoHud/mpv.conf
+ assertFileContent home-files/.config/MangoHud/mpv.conf \
+ ${./basic-configuration-mpv.conf}
+ '';
+ };
+}
diff --git a/tests/modules/programs/mangohud/default.nix b/tests/modules/programs/mangohud/default.nix
new file mode 100644
index 000000000..87db32ed7
--- /dev/null
+++ b/tests/modules/programs/mangohud/default.nix
@@ -0,0 +1 @@
+{ mangohud-basic-configuration = ./basic-configuration.nix; }