mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 22:50:39 +00:00
hyprland: allow customizing systemd
Allows users to customize which environment variables to import in DBus and SystemD user environments, and to specify which commands will be run after the environment activation.
This commit is contained in:
parent
44635279a0
commit
ed0770e962
3 changed files with 58 additions and 22 deletions
|
@ -3,6 +3,13 @@ let
|
||||||
|
|
||||||
cfg = config.wayland.windowManager.hyprland;
|
cfg = config.wayland.windowManager.hyprland;
|
||||||
|
|
||||||
|
variables = builtins.concatStringsSep " " cfg.systemd.variables;
|
||||||
|
extraCommands = builtins.concatStringsSep " "
|
||||||
|
(map (f: "&& ${f}") cfg.systemd.extraCommands);
|
||||||
|
systemdActivation = ''
|
||||||
|
exec-once = ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd ${variables} ${extraCommands}
|
||||||
|
'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ lib.maintainers.fufexan ];
|
meta.maintainers = [ lib.maintainers.fufexan ];
|
||||||
|
|
||||||
|
@ -24,6 +31,10 @@ in {
|
||||||
(lib.mkRenamedOptionModule # \
|
(lib.mkRenamedOptionModule # \
|
||||||
[ "wayland" "windowManager" "hyprland" "nvidiaPatches" ] # \
|
[ "wayland" "windowManager" "hyprland" "nvidiaPatches" ] # \
|
||||||
[ "wayland" "windowManager" "hyprland" "enableNvidiaPatches" ])
|
[ "wayland" "windowManager" "hyprland" "enableNvidiaPatches" ])
|
||||||
|
|
||||||
|
(lib.mkRenamedOptionModule # \
|
||||||
|
[ "wayland" "windowManager" "hyprland" "systemdIntegration" ] # \
|
||||||
|
[ "wayland" "windowManager" "hyprland" "systemd" "enable" ])
|
||||||
];
|
];
|
||||||
|
|
||||||
options.wayland.windowManager.hyprland = {
|
options.wayland.windowManager.hyprland = {
|
||||||
|
@ -54,14 +65,14 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
systemdIntegration = lib.mkOption {
|
systemd = {
|
||||||
type = lib.types.bool;
|
enable = lib.mkEnableOption null // {
|
||||||
default = pkgs.stdenv.isLinux;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable {file}`hyprland-session.target` on
|
Whether to enable {file}`hyprland-session.target` on
|
||||||
hyprland startup. This links to `graphical-session.target`.
|
hyprland startup. This links to `graphical-session.target`.
|
||||||
Some important environment variables will be imported to systemd
|
Some important environment variables will be imported to systemd
|
||||||
and dbus user environment before reaching the target, including
|
and D-Bus user environment before reaching the target, including
|
||||||
- `DISPLAY`
|
- `DISPLAY`
|
||||||
- `HYPRLAND_INSTANCE_SIGNATURE`
|
- `HYPRLAND_INSTANCE_SIGNATURE`
|
||||||
- `WAYLAND_DISPLAY`
|
- `WAYLAND_DISPLAY`
|
||||||
|
@ -69,6 +80,31 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
variables = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
default = [
|
||||||
|
"DISPLAY"
|
||||||
|
"HYPRLAND_INSTANCE_SIGNATURE"
|
||||||
|
"WAYLAND_DISPLAY"
|
||||||
|
"XDG_CURRENT_DESKTOP"
|
||||||
|
];
|
||||||
|
example = [ "-all" ];
|
||||||
|
description = ''
|
||||||
|
Environment variables to be imported in the systemd & D-Bus user
|
||||||
|
environment.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
extraCommands = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
default = [
|
||||||
|
"systemctl --user stop hyprland-session.target"
|
||||||
|
"systemctl --user start hyprland-session.target"
|
||||||
|
];
|
||||||
|
description = "Extra commands to be run after D-Bus activation.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; };
|
xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; };
|
||||||
|
|
||||||
enableNvidiaPatches =
|
enableNvidiaPatches =
|
||||||
|
@ -148,10 +184,10 @@ in {
|
||||||
];
|
];
|
||||||
|
|
||||||
warnings = let
|
warnings = let
|
||||||
inconsistent = (cfg.systemdIntegration || cfg.plugins != [ ])
|
inconsistent = (cfg.systemd.enable || cfg.plugins != [ ])
|
||||||
&& cfg.extraConfig == "" && cfg.settings == { };
|
&& cfg.extraConfig == "" && cfg.settings == { };
|
||||||
warning =
|
warning =
|
||||||
"You have enabled hyprland.systemdIntegration or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake.";
|
"You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake.";
|
||||||
in lib.optional inconsistent warning;
|
in lib.optional inconsistent warning;
|
||||||
|
|
||||||
home.packages = lib.optional (cfg.package != null) cfg.finalPackage;
|
home.packages = lib.optional (cfg.package != null) cfg.finalPackage;
|
||||||
|
@ -167,7 +203,7 @@ in {
|
||||||
in map mkEntry cfg.plugins;
|
in map mkEntry cfg.plugins;
|
||||||
};
|
};
|
||||||
|
|
||||||
shouldGenerate = cfg.systemdIntegration || cfg.extraConfig != ""
|
shouldGenerate = cfg.systemd.enable || cfg.extraConfig != ""
|
||||||
|| combinedSettings != { };
|
|| combinedSettings != { };
|
||||||
|
|
||||||
toHyprconf = with lib;
|
toHyprconf = with lib;
|
||||||
|
@ -195,11 +231,11 @@ in {
|
||||||
+ concatStringsSep "\n" (mapAttrsToList mkSection sections)
|
+ concatStringsSep "\n" (mapAttrsToList mkSection sections)
|
||||||
+ mkFields fields;
|
+ mkFields fields;
|
||||||
in lib.mkIf shouldGenerate {
|
in lib.mkIf shouldGenerate {
|
||||||
text = lib.optionalString cfg.systemdIntegration ''
|
text = lib.optionalString cfg.systemd.enable systemdActivation
|
||||||
exec-once = ${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP && systemctl --user start hyprland-session.target
|
+ lib.optionalString (combinedSettings != { })
|
||||||
'' + lib.optionalString (combinedSettings != { })
|
|
||||||
(toHyprconf combinedSettings 0)
|
(toHyprconf combinedSettings 0)
|
||||||
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig;
|
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig;
|
||||||
|
|
||||||
onChange = lib.mkIf (cfg.package != null) ''
|
onChange = lib.mkIf (cfg.package != null) ''
|
||||||
( # execute in subshell so that `shopt` won't affect other scripts
|
( # execute in subshell so that `shopt` won't affect other scripts
|
||||||
shopt -s nullglob # so that nothing is done if /tmp/hypr/ does not exist or is empty
|
shopt -s nullglob # so that nothing is done if /tmp/hypr/ does not exist or is empty
|
||||||
|
@ -211,7 +247,7 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.user.targets.hyprland-session = lib.mkIf cfg.systemdIntegration {
|
systemd.user.targets.hyprland-session = lib.mkIf cfg.systemd.enable {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Hyprland compositor session";
|
Description = "Hyprland compositor session";
|
||||||
Documentation = [ "man:systemd.special(7)" ];
|
Documentation = [ "man:systemd.special(7)" ];
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
test.asserts.warnings.expected = [
|
test.asserts.warnings.expected = [
|
||||||
"You have enabled hyprland.systemdIntegration or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake."
|
"You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake."
|
||||||
];
|
];
|
||||||
test.asserts.warnings.enable = true;
|
test.asserts.warnings.enable = true;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
exec-once = /nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP && systemctl --user start hyprland-session.target
|
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
|
||||||
$mod=SUPER
|
$mod=SUPER
|
||||||
bezier=smoothOut, 0.36, 0, 0.66, -0.56
|
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
|
||||||
|
|
Loading…
Reference in a new issue