nix/home/modules/niri.nix
2025-07-20 13:29:04 +10:00

288 lines
7.1 KiB
Nix

{
pkgs,
lib,
config,
rice,
inputs,
...
}:
let
services =
let
inherit (pkgs) swaynotificationcenter;
in
[
swaynotificationcenter
];
errata =
let
inherit (pkgs) avizo playerctl;
in
[
avizo
playerctl
];
extraServices =
let
inherit (pkgs)
swayidle
swaybg
systemd
avizo
;
inherit (inputs.niri.packages.x86_64-linux) niri-unstable;
in
[
{
name = "swaybg";
value = "${lib.getExe swaybg} -m fill -i ${rice.bg.src}";
}
{
name = "avizo-service";
value = "${lib.getExe' avizo "avizo-service"}";
}
{
name = "swayidle";
value =
let
niri = lib.getExe niri-unstable;
systemctl = lib.getExe' systemd "systemctl";
in
''
${lib.getExe swayidle} -w \
timeout 1800 '${systemctl} suspend' \
timeout 600 '${niri} msg action power-off-monitors'
'';
}
];
in
{
home.packages = errata;
ezServices = builtins.listToAttrs (
(map (entry: {
name = "${lib.strings.toLower entry.pname}";
value = "${lib.getExe entry}";
}) services)
++ extraServices
);
programs.niri.settings =
let
inherit (lib)
range
nameValuePair
mapAttrs'
mergeAttrsList
;
inherit (builtins) listToAttrs replaceStrings;
inherit (config.lib.niri) actions;
in
{
binds =
let
hBinds = {
H = "left";
L = "right";
};
vBinds = {
J = "down";
K = "up";
};
makeDirBind =
mods: cmd: keys:
mapAttrs' (
key: dir:
nameValuePair "${mods}+${key}" {
action = actions."${replaceStrings [ "$DIR" ] [ "${dir}" ] "${cmd}"}";
}
) keys;
makeWsBind =
mods: cmd:
listToAttrs (
map (num: {
name = "${mods}+${builtins.toString num}";
value = {
action."${cmd}" = num;
};
}) (range 1 6)
);
tagctl = lib.getExe' inputs.niri-tag.packages.${pkgs.system}.unstable "tagctl";
makeTagBind =
mods: cmd:
listToAttrs (
map (num: {
name = "${mods}+${builtins.toString num}";
value = {
action.spawn = [
tagctl
cmd
(builtins.toString num)
];
};
}) (range 1 6)
);
in
mergeAttrsList [
{
"Mod+D".action.spawn = [
"qs"
"ipc"
"call"
"launch"
"toggle"
];
"Mod+F".action.spawn = "firefox";
"Mod+E".action.spawn = "nautilus";
"Mod+Return".action.spawn = "kitty";
"Mod+Shift+E".action.spawn = "wlogout";
"Mod+Equal".action.spawn = "bitwarden";
"Mod+Shift+Q".action = actions.close-window;
"Mod+Shift+S".action = actions.screenshot;
"Mod+R".action = actions.switch-preset-column-width;
"Mod+Shift+R".action = actions.maximize-column;
"XF86AudioRaiseVolume".action.spawn = [
"volumectl"
"-u"
"up"
];
"XF86AudioLowerVolume".action.spawn = [
"volumectl"
"-u"
"down"
];
"XF86AudioMute".action.spawn = [
"volumectl"
"toggle-mute"
];
"XF86AudioStop".action.spawn = [
"playerctl"
"stop"
];
"XF86AudioPlay".action.spawn = [
"playerctl"
"play-pause"
];
"XF86AudioNext".action.spawn = [
"playerctl"
"next"
];
"XF86AudioPrev".action.spawn = [
"playerctl"
"previous"
];
"Mod+Space".action = actions.toggle-window-floating;
}
(makeDirBind "Mod" "focus-window-$DIR" vBinds)
(makeDirBind "Mod" "focus-column-or-monitor-$DIR" hBinds)
(makeDirBind "Mod+Shift" "move-column-$DIR-or-to-monitor-$DIR" hBinds)
(makeDirBind "Mod+Ctrl" "consume-or-expel-window-$DIR" hBinds)
(makeDirBind "Mod+Ctrl" "move-window-$DIR" vBinds)
(makeTagBind "Mod" "toggle-tag")
(makeTagBind "Mod+Shift" "toggle")
(makeTagBind "Mod+Ctrl" "exclusive-tag")
];
outputs = {
# "Unknown-1".enable = false;
"DP-1" = {
transform.rotation = 90;
scale = 1;
};
"DP-2" = {
variable-refresh-rate = true;
scale = 1;
};
};
input = {
warp-mouse-to-focus.enable = true;
};
cursor = {
hide-after-inactive-ms = 5000;
hide-when-typing = true;
size = 16;
theme = rice.cursor.name;
};
layout = {
always-center-single-column = true;
gaps = 24;
default-column-width.proportion = 0.5;
preset-column-widths = map (p: { proportion = p; }) [
(2.0 / 3.0)
0.5
(1.0 / 3.0)
];
focus-ring =
let
pal = rice.palette.hex;
in
{
active = {
color = pal.bright.yellow;
};
inactive = {
color = pal.normal.black;
};
};
};
prefer-no-csd = true;
hotkey-overlay.skip-at-startup = true;
window-rules =
let
v = 10.0;
in
[
{
geometry-corner-radius = {
bottom-left = v;
bottom-right = 0.0;
top-left = 0.0;
top-right = v;
};
clip-to-geometry = true;
}
];
};
# programs.ironbar = {
# enable = true;
# systemd = true;
# config = {
# monitors."DP-1" = {
# position = "top";
# height = 16;
# start = [
# {
# type = "music";
# player_type = "mpris";
# }
# ];
# center = [
# {
# type = "focused";
# icon_size = 16;
# truncate = "middle";
# }
# ];
# end = [
# { type = "clock"; }
# { type = "tray"; }
# ];
# };
# };
# };
systemd.user.services.quickshell = {
Unit.PartOf = [ "graphical-session.target" ];
Unit.After = [
"graphical-session.target"
"niri.service"
];
Install.WantedBy = [ "graphical-session.target" ];
Service = {
ExecStart = "${lib.getExe' (inputs.quickshell.packages.${pkgs.system}.default.override {
withHyprland = false;
withI3 = false;
}) "qs"}";
};
};
}