sway: add settings option

This commit is contained in:
sinanmohd 2024-06-02 21:15:43 +05:30
parent 74acd4d937
commit fd6c12bfd7

View file

@ -272,7 +272,18 @@ let
${pkgs.xvfb-run}/bin/xvfb-run ${swayPackage}/bin/sway --config "$target" --validate --unsupported-gpu
'';
text = concatStringsSep "\n"
text = let
# include and set should be at the top of the configuration
setSettings = lib.filterAttrs (key: _: key == "set") cfg.settings;
includeSettings = lib.filterAttrs (key: _: key == "include") cfg.settings;
otherSettings =
lib.filterAttrs (key: _: key != "set" && key != "include") cfg.settings;
in lib.optionalString (setSettings != { })
(lib.hm.generators.toSwayConf { } setSettings)
+ lib.optionalString (includeSettings != { })
(lib.hm.generators.toSwayConf { } includeSettings)
+ lib.optionalString (otherSettings != { })
(lib.hm.generators.toSwayConf { } otherSettings) + concatStringsSep "\n"
((optional (cfg.extraConfigEarly != "") cfg.extraConfigEarly)
++ (if cfg.config != null then
with cfg.config;
@ -327,8 +338,7 @@ let
)
else
[ ]) ++ (optional cfg.systemd.enable systemdActivation)
++ (optional (!cfg.xwayland) "xwayland disable")
++ [ cfg.extraConfig ]);
++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ]);
};
defaultSwayPackage = pkgs.sway.override {
@ -473,6 +483,20 @@ in {
'';
};
settings = lib.mkOption {
type = with lib.types;
let
valueType =
oneOf [ int float str path (listOf str) (attrsOf valueType) ] // {
description = "Sway configuration value";
};
in valueType;
default = { };
description = ''
Configuration for `sway`. See `sway(5)` for supported values.
'';
};
config = mkOption {
type = types.nullOr configModule;
default = { };
@ -518,6 +542,14 @@ in {
assertions = [
(hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs
platforms.linux)
{
assertion = cfg.settings != { } -> cfg.extraConfigEarly == "";
message = ''
`wayland.windowManager.sway.extraConfigEarly` is not needed when
using `wayland.windowManager.sway.settings`, it'll properly handle
`set` and `include` configuration.
'';
}
];
home.packages = optional (cfg.package != null) cfg.package