Redid hyprscrolling.nix

This commit is contained in:
2026-02-24 15:40:40 +01:00
parent b90f61c8d9
commit 4125f23bd1
2 changed files with 104 additions and 80 deletions
+52 -40
View File
@@ -1768,18 +1768,12 @@ This Nix module integrates the hyprscrolling plugin into a Home-Manager managed
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
cfg = config.programs.hyprscrolling; cfg = config.programs.hyprscrolling;
# Render plugin settings into: # Render plugin settings into:
# plugin:hyprscrolling { # plugin:hyprscrolling {
# key = value # key = value
# } # }
# renderValue = v:
# Values:
# - strings become "..."
# - bools become true/false
# - ints/floats stay numeric
# - lists become [ a b c ] (Hyprland-style arrays)
renderValue =
v:
if lib.isString v then "\"${v}\"" if lib.isString v then "\"${v}\""
else if lib.isBool v then (if v then "true" else "false") else if lib.isBool v then (if v then "true" else "false")
else if lib.isInt v || lib.isFloat v then toString v else if lib.isInt v || lib.isFloat v then toString v
@@ -1788,8 +1782,7 @@ let
else else
throw "programs.hyprscrolling.settings: unsupported value type: ${builtins.typeOf v}"; throw "programs.hyprscrolling.settings: unsupported value type: ${builtins.typeOf v}";
renderSettings = renderSettings = settings:
settings:
let let
lines = lib.mapAttrsToList (k: v: " ${k} = ${renderValue v}") settings; lines = lib.mapAttrsToList (k: v: " ${k} = ${renderValue v}") settings;
in in
@@ -1800,15 +1793,31 @@ let
} }
''; '';
defaultPluginPkg = defaultPluginPkg = (pkgs.hyprlandPlugins.hyprscrolling or null);
# In nixpkgs this is typically available as pkgs.hyprlandPlugins.hyprscrolling
# (names may vary by channel; override via programs.hyprscrolling.pluginPackage if needed).
(pkgs.hyprlandPlugins.hyprscrolling or null);
# Stable paths (avoid pinning /nix/store/... in your hyprland.conf)
stableSoPath = "/etc/hypr/plugins/libhyprscrolling.so";
dropInConfPath = "/etc/hypr/conf.d/90-hyprscrolling.conf";
dropInConf = ''
# Managed by Nix: programs.hyprscrolling
# Load plugin shared object (.so)
plugin = ${stableSoPath}
${lib.optionalString cfg.setAsDefaultLayout ''
general {
layout = scrolling
}
''}
${renderSettings cfg.settings}
${cfg.extraConfig}
'';
in in
{ {
options.programs.hyprscrolling = { options.programs.hyprscrolling = {
enable = lib.mkEnableOption "Hyprland hyprscrolling (scrolling layout) plugin"; enable = lib.mkEnableOption "Hyprland hyprscrolling (scrolling layout) plugin (NixOS-friendly)";
pluginPackage = lib.mkOption { pluginPackage = lib.mkOption {
type = lib.types.nullOr lib.types.package; type = lib.types.nullOr lib.types.package;
@@ -1822,56 +1831,59 @@ in
setAsDefaultLayout = lib.mkOption { setAsDefaultLayout = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;
description = "Whether to set `general:layout = scrolling` in Hyprland."; description = "Whether to set `general { layout = scrolling }` in the generated drop-in config.";
}; };
settings = lib.mkOption { settings = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
default = { }; default = { };
example = {
# Example keys (actual keys depend on plugin version)
# See hyprscrolling README for supported options.
# swipe_fingers = 3;
# natural_scroll = true;
};
description = '' description = ''
Attribute set rendered into a `plugin:hyprscrolling { ... }` block. Attribute set rendered into a `plugin:hyprscrolling { ... }` block
Keys/values must match hyprscrolling config options. in the generated drop-in config.
''; '';
}; };
extraConfig = lib.mkOption { extraConfig = lib.mkOption {
type = lib.types.lines; type = lib.types.lines;
default = ""; default = "";
description = "Extra Hyprland config appended after the generated plugin config."; description = "Extra Hyprland config appended to the generated drop-in config.";
};
# Where we install the generated config snippet (so you can `source = ...` it)
dropInPath = lib.mkOption {
type = lib.types.str;
default = dropInConfPath;
description = "Path to the generated Hyprland drop-in config file (needs to be sourced by your hyprland.conf).";
};
# Where we install a stable symlink to the plugin .so
stablePluginSoPath = lib.mkOption {
type = lib.types.str;
default = stableSoPath;
description = "Stable path for the plugin shared object (symlinked to the Nix store).";
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{
assertion = config.wayland.windowManager.hyprland.enable or false;
message = "programs.hyprscrolling.enable requires wayland.windowManager.hyprland.enable = true;";
}
{ {
assertion = cfg.pluginPackage != null; assertion = cfg.pluginPackage != null;
message = '' message = ''
Could not find a default hyprscrolling plugin package in this nixpkgs. Could not find hyprscrolling plugin package in this nixpkgs.
Set programs.hyprscrolling.pluginPackage explicitly (either from pkgs or a flake input). Set programs.hyprscrolling.pluginPackage explicitly (e.g. pkgs.hyprlandPlugins.hyprscrolling).
''; '';
} }
]; ];
wayland.windowManager.hyprland = { # Ensure the plugin is built and available.
plugins = [ cfg.pluginPackage ]; environment.systemPackages = [ cfg.pluginPackage ];
extraConfig = lib.mkAfter '' # Provide a stable .so path under /etc (no /nix/store hardcoding in hyprland.conf)
${lib.optionalString cfg.setAsDefaultLayout "general { layout = scrolling }"} environment.etc."hypr/plugins/libhyprscrolling.so".source =
"${cfg.pluginPackage}/lib/libhyprscrolling.so";
${renderSettings cfg.settings} # Provide a drop-in config file under /etc.
environment.etc."hypr/conf.d/90-hyprscrolling.conf".text = dropInConf;
${cfg.extraConfig}
'';
};
}; };
} }
#+end_src #+end_src
+52 -40
View File
@@ -1,18 +1,12 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
cfg = config.programs.hyprscrolling; cfg = config.programs.hyprscrolling;
# Render plugin settings into: # Render plugin settings into:
# plugin:hyprscrolling { # plugin:hyprscrolling {
# key = value # key = value
# } # }
# renderValue = v:
# Values:
# - strings become "..."
# - bools become true/false
# - ints/floats stay numeric
# - lists become [ a b c ] (Hyprland-style arrays)
renderValue =
v:
if lib.isString v then "\"${v}\"" if lib.isString v then "\"${v}\""
else if lib.isBool v then (if v then "true" else "false") else if lib.isBool v then (if v then "true" else "false")
else if lib.isInt v || lib.isFloat v then toString v else if lib.isInt v || lib.isFloat v then toString v
@@ -21,8 +15,7 @@ let
else else
throw "programs.hyprscrolling.settings: unsupported value type: ${builtins.typeOf v}"; throw "programs.hyprscrolling.settings: unsupported value type: ${builtins.typeOf v}";
renderSettings = renderSettings = settings:
settings:
let let
lines = lib.mapAttrsToList (k: v: " ${k} = ${renderValue v}") settings; lines = lib.mapAttrsToList (k: v: " ${k} = ${renderValue v}") settings;
in in
@@ -33,15 +26,31 @@ let
} }
''; '';
defaultPluginPkg = defaultPluginPkg = (pkgs.hyprlandPlugins.hyprscrolling or null);
# In nixpkgs this is typically available as pkgs.hyprlandPlugins.hyprscrolling
# (names may vary by channel; override via programs.hyprscrolling.pluginPackage if needed).
(pkgs.hyprlandPlugins.hyprscrolling or null);
# Stable paths (avoid pinning /nix/store/... in your hyprland.conf)
stableSoPath = "/etc/hypr/plugins/libhyprscrolling.so";
dropInConfPath = "/etc/hypr/conf.d/90-hyprscrolling.conf";
dropInConf = ''
# Managed by Nix: programs.hyprscrolling
# Load plugin shared object (.so)
plugin = ${stableSoPath}
${lib.optionalString cfg.setAsDefaultLayout ''
general {
layout = scrolling
}
''}
${renderSettings cfg.settings}
${cfg.extraConfig}
'';
in in
{ {
options.programs.hyprscrolling = { options.programs.hyprscrolling = {
enable = lib.mkEnableOption "Hyprland hyprscrolling (scrolling layout) plugin"; enable = lib.mkEnableOption "Hyprland hyprscrolling (scrolling layout) plugin (NixOS-friendly)";
pluginPackage = lib.mkOption { pluginPackage = lib.mkOption {
type = lib.types.nullOr lib.types.package; type = lib.types.nullOr lib.types.package;
@@ -55,55 +64,58 @@ in
setAsDefaultLayout = lib.mkOption { setAsDefaultLayout = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;
description = "Whether to set `general:layout = scrolling` in Hyprland."; description = "Whether to set `general { layout = scrolling }` in the generated drop-in config.";
}; };
settings = lib.mkOption { settings = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
default = { }; default = { };
example = {
# Example keys (actual keys depend on plugin version)
# See hyprscrolling README for supported options.
# swipe_fingers = 3;
# natural_scroll = true;
};
description = '' description = ''
Attribute set rendered into a `plugin:hyprscrolling { ... }` block. Attribute set rendered into a `plugin:hyprscrolling { ... }` block
Keys/values must match hyprscrolling config options. in the generated drop-in config.
''; '';
}; };
extraConfig = lib.mkOption { extraConfig = lib.mkOption {
type = lib.types.lines; type = lib.types.lines;
default = ""; default = "";
description = "Extra Hyprland config appended after the generated plugin config."; description = "Extra Hyprland config appended to the generated drop-in config.";
};
# Where we install the generated config snippet (so you can `source = ...` it)
dropInPath = lib.mkOption {
type = lib.types.str;
default = dropInConfPath;
description = "Path to the generated Hyprland drop-in config file (needs to be sourced by your hyprland.conf).";
};
# Where we install a stable symlink to the plugin .so
stablePluginSoPath = lib.mkOption {
type = lib.types.str;
default = stableSoPath;
description = "Stable path for the plugin shared object (symlinked to the Nix store).";
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{
assertion = config.wayland.windowManager.hyprland.enable or false;
message = "programs.hyprscrolling.enable requires wayland.windowManager.hyprland.enable = true;";
}
{ {
assertion = cfg.pluginPackage != null; assertion = cfg.pluginPackage != null;
message = '' message = ''
Could not find a default hyprscrolling plugin package in this nixpkgs. Could not find hyprscrolling plugin package in this nixpkgs.
Set programs.hyprscrolling.pluginPackage explicitly (either from pkgs or a flake input). Set programs.hyprscrolling.pluginPackage explicitly (e.g. pkgs.hyprlandPlugins.hyprscrolling).
''; '';
} }
]; ];
wayland.windowManager.hyprland = { # Ensure the plugin is built and available.
plugins = [ cfg.pluginPackage ]; environment.systemPackages = [ cfg.pluginPackage ];
extraConfig = lib.mkAfter '' # Provide a stable .so path under /etc (no /nix/store hardcoding in hyprland.conf)
${lib.optionalString cfg.setAsDefaultLayout "general { layout = scrolling }"} environment.etc."hypr/plugins/libhyprscrolling.so".source =
"${cfg.pluginPackage}/lib/libhyprscrolling.so";
${renderSettings cfg.settings} # Provide a drop-in config file under /etc.
environment.etc."hypr/conf.d/90-hyprscrolling.conf".text = dropInConf;
${cfg.extraConfig}
'';
};
}; };
} }