-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{ | ||
lib, | ||
osConfig, | ||
config, | ||
... | ||
}: let | ||
inherit (lib.attrsets) filterAttrs mapAttrsToList; | ||
inherit (lib.lists) any isList; | ||
inherit (lib.modules) mkIf; | ||
inherit (lib.options) mkEnableOption mkOption; | ||
inherit (lib.rum.generators) toHyprconf; | ||
inherit (lib.strings) concatStringsSep hasPrefix optionalString stringLength; | ||
inherit (lib.types) attrs either listOf package path; | ||
|
||
inherit (osConfig.programs) hyprland; | ||
|
||
cfg = config.rum.programs.hyprland; | ||
|
||
toEnv = env: | ||
if isList env | ||
then concatStringsSep ":" (map toString env) | ||
else toString env; | ||
|
||
filterEnvVars = filterPrefixes: vars: let | ||
filteredVars = | ||
if filterPrefixes == [] | ||
then vars | ||
else | ||
filterAttrs | ||
(name: _: any (prefix: hasPrefix prefix name) filterPrefixes) | ||
vars; | ||
in | ||
concatStringsSep "\n" | ||
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") filteredVars); | ||
|
||
# taken from https://github.com/hyprwm/Hyprland/blob/f4b148df1e2d8edc96bd878a4cfde32ca6515ac8/nix/module.nix#L185-L197 | ||
pluginsToHyprconf = plugins: | ||
toHyprconf { | ||
attrs = { | ||
plugin = let | ||
mkEntry = entry: | ||
if lib.types.package.check entry | ||
then "${entry}/lib/lib${entry.pname}.so" | ||
else entry; | ||
in | ||
map mkEntry cfg.plugins; | ||
}; | ||
inherit (cfg) importantPrefixes; | ||
}; | ||
in { | ||
options.rum.programs.hyprland = { | ||
enable = mkEnableOption '' | ||
Hyprland | ||
''; | ||
|
||
settings = mkOption { | ||
type = attrs; | ||
example = { | ||
"$mod" = "SUPER"; | ||
decoration = { | ||
rounding = "3"; | ||
}; | ||
}; | ||
default = {}; | ||
description = '' | ||
Hyprland configuration written in Nix. Entries with the same key | ||
should be written as lists. Variables' and colors' names should be | ||
quoted. See <https://wiki.hyprland.org> for more examples. | ||
''; | ||
}; | ||
|
||
plugins = mkOption { | ||
type = listOf (either package path); | ||
default = []; | ||
description = '' | ||
List of Hyprland plugins to use. Can either be packages or | ||
absolute plugin paths. | ||
''; | ||
}; | ||
|
||
importantPrefixes = lib.mkOption { | ||
type = with lib.types; listOf str; | ||
default = ["$" "bezier" "name"]; | ||
example = ["$" "bezier"]; | ||
description = '' | ||
List of prefix of attributes to source at the top of the config. | ||
''; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
files = { | ||
".config/hypr/hyprland.conf".text = | ||
optionalString (cfg.plugins != []) | ||
(pluginsToHyprconf cfg.plugins) | ||
+ optionalString (cfg.settings != {}) | ||
(toHyprconf { | ||
attrs = cfg.settings; | ||
inherit (cfg) importantPrefixes; | ||
}) | ||
+ optionalString (config.environment.sessionVariables != {} && (!hyprland.withUWSM)) | ||
(toHyprconf { | ||
attrs.env = mapAttrsToList (key: value: "${key},${value}") config.environment.sessionVariables; | ||
}); | ||
|
||
/* | ||
uwsm environment variables are advised to be separated | ||
(see https://wiki.hyprland.org/Configuring/Environment-variables/) | ||
*/ | ||
".config/uwsm/env".text = | ||
mkIf ( | ||
(config.environment.sessionVariables != {}) | ||
&& hyprland.withUWSM | ||
) | ||
(filterEnvVars [] | ||
config.environment.sessionVariables); | ||
|
||
".config/uwsm/env-hyprland".text = let | ||
/* | ||
this is needed as we're using a predicate so we don't create an empty file | ||
(improvements are welcome) | ||
*/ | ||
filteredVars = | ||
filterEnvVars ["HYPRLAND_" "AQ_"] config.environment.sessionVariables; | ||
in | ||
mkIf ( | ||
(config.environment.sessionVariables != {}) | ||
&& hyprland.withUWSM | ||
&& stringLength filteredVars != 0 | ||
) | ||
filteredVars; | ||
}; | ||
}; | ||
} |