mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
hyprland: use lib.generators.toHyprconf
This commit is contained in:
parent
9fdd301a5e
commit
4fe1f064bd
7 changed files with 229 additions and 59 deletions
|
@ -9,7 +9,6 @@ let
|
||||||
systemdActivation = ''
|
systemdActivation = ''
|
||||||
exec-once = ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd ${variables} ${extraCommands}
|
exec-once = ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd ${variables} ${extraCommands}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ lib.maintainers.fufexan ];
|
meta.maintainers = [ lib.maintainers.fufexan ];
|
||||||
|
|
||||||
|
@ -178,6 +177,16 @@ in {
|
||||||
'' // {
|
'' // {
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
importantPrefixes = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
default = [ "$" "bezier" "name" ]
|
||||||
|
++ lib.optionals cfg.sourceFirst [ "source" ];
|
||||||
|
example = [ "$" "bezier" ];
|
||||||
|
description = ''
|
||||||
|
List of prefix of attributes to source at the top of the config.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
@ -199,65 +208,28 @@ in {
|
||||||
shouldGenerate = cfg.systemd.enable || cfg.extraConfig != ""
|
shouldGenerate = cfg.systemd.enable || cfg.extraConfig != ""
|
||||||
|| cfg.settings != { } || cfg.plugins != [ ];
|
|| cfg.settings != { } || cfg.plugins != [ ];
|
||||||
|
|
||||||
toHyprconf = with lib;
|
|
||||||
attrs: indentLevel:
|
|
||||||
let
|
|
||||||
indent = concatStrings (replicate indentLevel " ");
|
|
||||||
|
|
||||||
sections = filterAttrs (n: v: isAttrs v && n != "device") attrs;
|
|
||||||
|
|
||||||
mkSection = n: attrs: ''
|
|
||||||
${indent}${n} {
|
|
||||||
${toHyprconf attrs (indentLevel + 1)}${indent}}
|
|
||||||
'';
|
|
||||||
|
|
||||||
mkDeviceCategory = device: ''
|
|
||||||
${indent}device {
|
|
||||||
name=${device.name}
|
|
||||||
${
|
|
||||||
toHyprconf (filterAttrs (n: _: "name" != n) device)
|
|
||||||
(indentLevel + 1)
|
|
||||||
}${indent}}
|
|
||||||
'';
|
|
||||||
|
|
||||||
deviceCategory = lib.optionalString (hasAttr "device" attrs)
|
|
||||||
(if isList attrs.device then
|
|
||||||
(concatMapStringsSep "\n" (d: mkDeviceCategory d) attrs.device)
|
|
||||||
else
|
|
||||||
mkDeviceCategory attrs.device);
|
|
||||||
|
|
||||||
mkFields = generators.toKeyValue {
|
|
||||||
listsAsDuplicateKeys = true;
|
|
||||||
inherit indent;
|
|
||||||
};
|
|
||||||
allFields = filterAttrs (n: v: !(isAttrs v) && n != "device") attrs;
|
|
||||||
|
|
||||||
importantFields = filterAttrs (n: _:
|
|
||||||
(hasPrefix "$" n) || (hasPrefix "bezier" n)
|
|
||||||
|| (cfg.sourceFirst && (hasPrefix "source" n))) allFields;
|
|
||||||
|
|
||||||
fields = builtins.removeAttrs allFields
|
|
||||||
(mapAttrsToList (n: _: n) importantFields);
|
|
||||||
in mkFields importantFields + deviceCategory
|
|
||||||
+ concatStringsSep "\n" (mapAttrsToList mkSection sections)
|
|
||||||
+ mkFields fields;
|
|
||||||
|
|
||||||
pluginsToHyprconf = plugins:
|
pluginsToHyprconf = plugins:
|
||||||
toHyprconf {
|
lib.hm.generators.toHyprconf {
|
||||||
plugin = let
|
attrs = {
|
||||||
mkEntry = entry:
|
plugin = let
|
||||||
if lib.types.package.check entry then
|
mkEntry = entry:
|
||||||
"${entry}/lib/lib${entry.pname}.so"
|
if lib.types.package.check entry then
|
||||||
else
|
"${entry}/lib/lib${entry.pname}.so"
|
||||||
entry;
|
else
|
||||||
in map mkEntry cfg.plugins;
|
entry;
|
||||||
} 0;
|
in map mkEntry cfg.plugins;
|
||||||
|
};
|
||||||
|
inherit (cfg) importantPrefixes;
|
||||||
|
};
|
||||||
in lib.mkIf shouldGenerate {
|
in lib.mkIf shouldGenerate {
|
||||||
text = lib.optionalString cfg.systemd.enable systemdActivation
|
text = lib.optionalString cfg.systemd.enable systemdActivation
|
||||||
+ lib.optionalString (cfg.plugins != [ ])
|
+ lib.optionalString (cfg.plugins != [ ])
|
||||||
(pluginsToHyprconf cfg.plugins)
|
(pluginsToHyprconf cfg.plugins)
|
||||||
+ lib.optionalString (cfg.settings != { }) (toHyprconf cfg.settings 0)
|
+ lib.optionalString (cfg.settings != { })
|
||||||
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig;
|
(lib.hm.generators.toHyprconf {
|
||||||
|
attrs = cfg.settings;
|
||||||
|
inherit (cfg) importantPrefixes;
|
||||||
|
}) + lib.optionalString (cfg.extraConfig != "") cfg.extraConfig;
|
||||||
|
|
||||||
onChange = lib.mkIf (cfg.package != null) ''
|
onChange = lib.mkIf (cfg.package != null) ''
|
||||||
( # Execute in subshell so we don't poision environment with vars
|
( # Execute in subshell so we don't poision environment with vars
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
hyprland-simple-config = ./simple-config.nix;
|
hyprland-simple-config = ./simple-config.nix;
|
||||||
|
hyprland-multiple-devices-config = ./multiple-devices-config.nix;
|
||||||
|
hyprland-sourceFirst-false-config = ./sourceFirst-false-config.nix;
|
||||||
hyprland-inconsistent-config = ./inconsistent-config.nix;
|
hyprland-inconsistent-config = ./inconsistent-config.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
exec-once = /nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY XDG_CURRENT_DESKTOP && systemctl --user stop hyprland-session.target && systemctl --user start hyprland-session.target
|
||||||
|
plugin=/path/to/plugin1
|
||||||
|
plugin=/nix/store/00000000000000000000000000000000-foo/lib/libfoo.so
|
||||||
|
$mod=SUPER
|
||||||
|
bezier=smoothOut, 0.36, 0, 0.66, -0.56
|
||||||
|
bezier=smoothIn, 0.25, 1, 0.5, 1
|
||||||
|
bezier=overshot, 0.4,0.8,0.2,1.2
|
||||||
|
source=sourced.conf
|
||||||
|
animations {
|
||||||
|
animation=border, 1, 2, smoothIn
|
||||||
|
animation=fade, 1, 4, smoothOut
|
||||||
|
animation=windows, 1, 3, overshot, popin 80%
|
||||||
|
enabled=true
|
||||||
|
}
|
||||||
|
|
||||||
|
decoration {
|
||||||
|
col.shadow=rgba(00000099)
|
||||||
|
shadow_offset=0 5
|
||||||
|
}
|
||||||
|
|
||||||
|
device {
|
||||||
|
name=some:device
|
||||||
|
enable=true
|
||||||
|
}
|
||||||
|
|
||||||
|
device {
|
||||||
|
name=some:device-secondary
|
||||||
|
enable=true
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
touchpad {
|
||||||
|
scroll_factor=0.300000
|
||||||
|
}
|
||||||
|
accel_profile=flat
|
||||||
|
follow_mouse=1
|
||||||
|
kb_layout=ro
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin {
|
||||||
|
plugin1 {
|
||||||
|
section {
|
||||||
|
other=dummy setting
|
||||||
|
}
|
||||||
|
dummy=plugin setting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bindm=$mod, mouse:272, movewindow
|
||||||
|
bindm=$mod, mouse:273, resizewindow
|
||||||
|
bindm=$mod ALT, mouse:272, resizewindow
|
||||||
|
# window resize
|
||||||
|
bind = $mod, S, submap, resize
|
||||||
|
|
||||||
|
submap = resize
|
||||||
|
binde = , right, resizeactive, 10 0
|
||||||
|
binde = , left, resizeactive, -10 0
|
||||||
|
binde = , up, resizeactive, 0 -10
|
||||||
|
binde = , down, resizeactive, 0 10
|
||||||
|
bind = , escape, submap, reset
|
||||||
|
submap = reset
|
|
@ -0,0 +1,88 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
wayland.windowManager.hyprland = {
|
||||||
|
enable = true;
|
||||||
|
package = lib.makeOverridable
|
||||||
|
(attrs: config.lib.test.mkStubPackage { name = "hyprland"; }) { };
|
||||||
|
plugins =
|
||||||
|
[ "/path/to/plugin1" (config.lib.test.mkStubPackage { name = "foo"; }) ];
|
||||||
|
settings = {
|
||||||
|
source = [ "sourced.conf" ];
|
||||||
|
|
||||||
|
decoration = {
|
||||||
|
shadow_offset = "0 5";
|
||||||
|
"col.shadow" = "rgba(00000099)";
|
||||||
|
};
|
||||||
|
|
||||||
|
"$mod" = "SUPER";
|
||||||
|
|
||||||
|
animations = {
|
||||||
|
enabled = true;
|
||||||
|
animation = [
|
||||||
|
"border, 1, 2, smoothIn"
|
||||||
|
"fade, 1, 4, smoothOut"
|
||||||
|
"windows, 1, 3, overshot, popin 80%"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
bezier = [
|
||||||
|
"smoothOut, 0.36, 0, 0.66, -0.56"
|
||||||
|
"smoothIn, 0.25, 1, 0.5, 1"
|
||||||
|
"overshot, 0.4,0.8,0.2,1.2"
|
||||||
|
];
|
||||||
|
|
||||||
|
input = {
|
||||||
|
kb_layout = "ro";
|
||||||
|
follow_mouse = 1;
|
||||||
|
accel_profile = "flat";
|
||||||
|
touchpad = { scroll_factor = 0.3; };
|
||||||
|
};
|
||||||
|
|
||||||
|
bindm = [
|
||||||
|
# mouse movements
|
||||||
|
"$mod, mouse:272, movewindow"
|
||||||
|
"$mod, mouse:273, resizewindow"
|
||||||
|
"$mod ALT, mouse:272, resizewindow"
|
||||||
|
];
|
||||||
|
|
||||||
|
device = [
|
||||||
|
{
|
||||||
|
name = "some:device";
|
||||||
|
enable = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "some:device-secondary";
|
||||||
|
enable = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
plugin = {
|
||||||
|
plugin1 = {
|
||||||
|
dummy = "plugin setting";
|
||||||
|
section = { other = "dummy setting"; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
extraConfig = ''
|
||||||
|
# window resize
|
||||||
|
bind = $mod, S, submap, resize
|
||||||
|
|
||||||
|
submap = resize
|
||||||
|
binde = , right, resizeactive, 10 0
|
||||||
|
binde = , left, resizeactive, -10 0
|
||||||
|
binde = , up, resizeactive, 0 -10
|
||||||
|
binde = , down, resizeactive, 0 10
|
||||||
|
bind = , escape, submap, reset
|
||||||
|
submap = reset
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
config=home-files/.config/hypr/hyprland.conf
|
||||||
|
assertFileExists "$config"
|
||||||
|
|
||||||
|
normalizedConfig=$(normalizeStorePaths "$config")
|
||||||
|
assertFileContent "$normalizedConfig" ${./multiple-devices-config.conf}
|
||||||
|
'';
|
||||||
|
}
|
|
@ -6,10 +6,6 @@ bezier=smoothOut, 0.36, 0, 0.66, -0.56
|
||||||
bezier=smoothIn, 0.25, 1, 0.5, 1
|
bezier=smoothIn, 0.25, 1, 0.5, 1
|
||||||
bezier=overshot, 0.4,0.8,0.2,1.2
|
bezier=overshot, 0.4,0.8,0.2,1.2
|
||||||
source=sourced.conf
|
source=sourced.conf
|
||||||
device {
|
|
||||||
name=some:device
|
|
||||||
enable=true
|
|
||||||
}
|
|
||||||
animations {
|
animations {
|
||||||
animation=border, 1, 2, smoothIn
|
animation=border, 1, 2, smoothIn
|
||||||
animation=fade, 1, 4, smoothOut
|
animation=fade, 1, 4, smoothOut
|
||||||
|
@ -22,6 +18,11 @@ decoration {
|
||||||
shadow_offset=0 5
|
shadow_offset=0 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device {
|
||||||
|
name=some:device
|
||||||
|
enable=true
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
touchpad {
|
touchpad {
|
||||||
scroll_factor=0.300000
|
scroll_factor=0.300000
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
exec-once = /nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY XDG_CURRENT_DESKTOP && systemctl --user stop hyprland-session.target && systemctl --user start hyprland-session.target
|
||||||
|
bezier=smoothOut, 0.36, 0, 0.66, -0.56
|
||||||
|
bezier=smoothIn, 0.25, 1, 0.5, 1
|
||||||
|
bezier=overshot, 0.4,0.8,0.2,1.2
|
||||||
|
input {
|
||||||
|
touchpad {
|
||||||
|
scroll_factor=0.300000
|
||||||
|
}
|
||||||
|
accel_profile=flat
|
||||||
|
follow_mouse=1
|
||||||
|
kb_layout=ro
|
||||||
|
}
|
||||||
|
source=sourced.conf
|
|
@ -0,0 +1,34 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
wayland.windowManager.hyprland = {
|
||||||
|
enable = true;
|
||||||
|
package = lib.makeOverridable
|
||||||
|
(attrs: config.lib.test.mkStubPackage { name = "hyprland"; }) { };
|
||||||
|
settings = {
|
||||||
|
source = [ "sourced.conf" ];
|
||||||
|
|
||||||
|
bezier = [
|
||||||
|
"smoothOut, 0.36, 0, 0.66, -0.56"
|
||||||
|
"smoothIn, 0.25, 1, 0.5, 1"
|
||||||
|
"overshot, 0.4,0.8,0.2,1.2"
|
||||||
|
];
|
||||||
|
|
||||||
|
input = {
|
||||||
|
kb_layout = "ro";
|
||||||
|
follow_mouse = 1;
|
||||||
|
accel_profile = "flat";
|
||||||
|
touchpad = { scroll_factor = 0.3; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
sourceFirst = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
config=home-files/.config/hypr/hyprland.conf
|
||||||
|
assertFileExists "$config"
|
||||||
|
|
||||||
|
normalizedConfig=$(normalizeStorePaths "$config")
|
||||||
|
assertFileContent "$normalizedConfig" ${./sourceFirst-false-config.conf}
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Reference in a new issue