Rewrite of hyprscrolling.nix

This commit is contained in:
2026-02-25 15:52:13 +01:00
parent 8d841cfcd0
commit 4c6a2fd8e3
+35 -33
View File
@@ -1764,56 +1764,58 @@ in
** hyprscrolling
This Nix module integrates the hyprscrolling plugin into a Home-Manager managed Hyprland setup in a declarative and reproducible way. It ensures the plugin is installed, optionally switches Hyprland to the scrolling layout, and renders user-defined plugin settings directly into the Hyprland configuration. The goal is to manage the scrolling workspace behavior entirely from Nix instead of maintaining manual edits inside hyprland.conf.
#+begin_src nix :tangle home/desktop/hyprscrolling.nix :noweb tangle :mkdirp yes
# home/desktop/hyprscrolling.nix (Home-Manager module)
{ config, lib, pkgs, flakeRoot, ... }:
let
cfg = config.programs.hyprscrolling;
defaultPluginPkg = (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";
# Read drop-in config from your repo (flake root)
dropInConfSourcePath = flakeRoot + "/assets/conf/desktop/hypr/hyprscrolling.conf";
dropInConf = builtins.readFile dropInConfSourcePath;
# where your repo keeps the config
defaultConfPath = builtins.path {
path = flakeRoot + "/assets/conf/desktop/hypr/hyprscrolling.conf";
name = "hyprscrolling.conf";
};
# where we place it in ~/.config
targetRel = "hypr/conf.d/90-hyprscrolling.conf";
in
{
options.programs.hyprscrolling = {
enable = lib.mkEnableOption "Hyprland hyprscrolling (scrolling layout) plugin (NixOS-friendly)";
enable = lib.mkEnableOption "Hyprland hyprscrolling plugin (Home-Manager)";
pluginPackage = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = defaultPluginPkg;
description = ''
Package that provides the hyprscrolling plugin.
Defaults to pkgs.hyprlandPlugins.hyprscrolling when available.
'';
type = lib.types.package;
default = pkgs.hyprlandPlugins.hyprscrolling;
description = "Hyprscrolling plugin package to load via Hyprland HM module.";
};
# 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 Hyprland drop-in config file (needs to be sourced by your hyprland.conf).";
confSource = lib.mkOption {
type = lib.types.path;
default = defaultConfPath;
description = "Path to hyprscrolling.conf in your repo (flakeRoot).";
};
# Where we install a stable symlink to the plugin .so
stablePluginSoPath = lib.mkOption {
confTargetRel = lib.mkOption {
type = lib.types.str;
default = stableSoPath;
description = "Stable path for the plugin shared object (symlinked to the Nix store).";
default = targetRel;
description = "Relative path under ~/.config where the config will be placed.";
};
};
config = lib.mkIf cfg.enable {
# Ensure the file exists and Hyprland can load plugins
assertions = [
{
assertion = cfg.pluginPackage != null;
message = ''
Could not find hyprscrolling plugin package in this nixpkgs.
Set programs.hyprscrolling.pluginPackage explicitly (e.g. pkgs.hyprlandPlugins.hyprscrolling).
'';
assertion = builtins.pathExists cfg.confSource;
message = "programs.hyprscrolling.confSource does not exist: ${toString cfg.confSource}";
}
];
environment.systemPackages = [ cfg.pluginPackage ];
environment.etc."hypr/plugins/libhyprscrolling.so".source =
"${cfg.pluginPackage}/lib/libhyprscrolling.so";
# Now /etc/hypr/conf.d/90-hyprscrolling.conf is exactly your files contents
environment.etc."hypr/conf.d/90-hyprscrolling.conf".text = dropInConf;
# 1) Install + load plugin (HM-supported)
wayland.windowManager.hyprland = {
enable = lib.mkDefault true;
# Hyprland HM module supports packages or absolute .so paths here
plugins = [ cfg.pluginPackage ];
# 2) Source the drop-in so your plugin config is actually applied
extraConfig = lib.mkAfter ''
# hyprscrolling drop-in
source = ~/.config/${cfg.confTargetRel}
'';
};
# 3) Put your repo conf at ~/.config/hypr/conf.d/90-hyprscrolling.conf
xdg.configFile."${cfg.confTargetRel}".source = cfg.confSource;
};
}
#+end_src