Files
nixos-setup/modules/nixos/desktop/tiler/hyprland.nix
T
2026-09-08 16:06:49 -04:00

112 lines
3.6 KiB
Nix

{ config
, lib
, pkgs
, skygUtils
, hyprland
, ...
}:
let
cfg = config.skyg.nixos.desktop.tiler.hyprland;
system = pkgs.stdenv.hostPlatform.system;
hyprlandPkg = hyprland.packages.${system}.hyprland;
hyprlandPortal = hyprland.packages.${system}.xdg-desktop-portal-hyprland;
# When mountAsSource is set, build a real, GC-protected copy of the hypr config
# dir. The flake self-source path (skyg.rootDir) is not referenced by the system
# closure, so it gets garbage-collected and the ~/.config/hypr symlink dangles.
# This derivation is added to the system profile, pinning it against GC.
bakedHyprConfig = pkgs.stdenv.mkDerivation {
pname = "${cfg.configName}-hypr-config";
version = "1";
src = "${config.skyg.rootDir}/configs/${cfg.configName}/hypr";
buildPhase = "true";
installPhase = ''
mkdir -p "$out/${cfg.configName}"
cp -r "$src" "$out/${cfg.configName}/hypr"
'';
};
in
{
options = {
skyg.nixos.desktop.tiler.hyprland = {
enable = lib.mkEnableOption "hyprland";
configName = lib.mkOption {
type = lib.types.str;
default = config.skyg.core.hostName;
description = ''
Name of the per-host Hyprland config directory under `configs/`.
The module symlinks `~/.config/hypr` -> `configs/<configName>/hypr`.
Defaults to the machine's hostName (e.g. `fwbook` -> `configs/fwbook/hypr`).
'';
};
configLink = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to symlink `~/.config/hypr` -> `configs/<configName>/hypr`.
Disable on hosts that manage their own Hyprland config elsewhere.
'';
};
mountAsSource = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
If `configLink.enable` is true, embed the config dir in the build.
A GC-protected copy of the config is baked into the system closure
(via a derivation added to the system profile) instead of symlinking
to the live `~/nixos-setup/configs` checkout, making the config part
of the built system and reproducible.
'';
};
};
tools = {
enable = lib.mkEnableOption "Hyprland shell tools (hypridle, wofi, rofi, grim, slurp, satty)";
};
};
};
config = lib.mkIf cfg.enable {
skyg.nixos.desktop.tiler.enable = true;
programs.hyprland = {
enable = true;
withUWSM = true;
xwayland.enable = true;
package = hyprlandPkg;
portalPackage = hyprlandPortal;
};
programs.uwsm.enable = true;
xdg.portal = {
enable = true;
extraPortals = [ hyprlandPortal ];
};
# wl-clipboard is always needed; the rest are opt-in so headless-style
# configs (e.g. hl-pi1) don't pull the whole shell toolchain.
environment.systemPackages = with pkgs; [
wl-clipboard
] ++ (lib.optionals cfg.tools.enable [
hypridle
wofi
rofi
grim
slurp
satty
]) ++ (lib.optionals cfg.configLink.mountAsSource [ bakedHyprConfig ]);
# Symlink ~/.config/hypr -> configs/<configName>/hypr (host-specific).
system.userActivationScripts.hyprlandConfig = lib.mkIf cfg.configLink.enable {
text = skygUtils.makeHyperlinkScriptToConfigs {
filePath = "${cfg.configName}/hypr";
targetPath = "hypr";
configSource =
if cfg.configLink.mountAsSource then
"${bakedHyprConfig}"
else
"/home/${config.skyg.user.name}/nixos-setup/configs";
};
};
};
}