refactor(greetd): separate code in multiple files
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-02-10 21:27:29 -05:00
parent 9170942eac
commit 341b75c689
5 changed files with 202 additions and 149 deletions

59
modules/greetd/ags.nix Normal file
View file

@ -0,0 +1,59 @@
{
ags,
config,
pkgs,
...
}: let
inherit (config.vars) mainUser;
hyprland = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.finalPackage;
in {
# Add home folder for home-manager to work
users.users.greeter = {
home = "/var/lib/greeter";
createHome = true;
};
home-manager.users.greeter = {
imports = [
ags.homeManagerModules.default
../../common/vars
../../home/theme.nix
];
programs.ags.enable = true;
home = {
packages = [
hyprland
pkgs.bun
pkgs.sassc
pkgs.swww
pkgs.gtk3
pkgs.glib
];
file = {
".config/ags/.wallpaper".source = "${pkgs.dracula-theme}/wallpapers/waves.png";
".config/ags" = {
source = ../ags/config;
recursive = true;
};
".config/ags/config.js".text =
/*
javascript
*/
''
import { transpileTypeScript } from './js/utils.js';
export default (await transpileTypeScript('greeter')).default;
'';
};
};
vars = config.vars;
home.stateVersion = "24.05";
};
}

View file

@ -1,120 +1,18 @@
{
ags,
config,
lib,
pkgs,
...
}: let
inherit (lib) optionals readFile;
inherit (config.vars) mainUser greetdDupe mainMonitor;
inherit (config.vars) mainUser;
inherit (import ./hyprland.nix {inherit config lib pkgs;}) hyprConf;
# Nix stuff
isNvidia = config.hardware.nvidia.modesetting.enable;
isTouchscreen = config.hardware.sensor.iio.enable;
hyprland = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.finalPackage;
monitors = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.settings.monitor;
# Show Regreet on all monitors
dupeMonitors = pkgs.writeShellApplication {
name = "dupeMonitors";
runtimeInputs = [hyprland pkgs.jq];
text = ''
main="${mainMonitor}"
names="($(hyprctl -j monitors | jq -r '.[] .description'))"
if [[ "$main" == "null" ]]; then
main="''${names[0]}"
fi
for (( i=0; i<''${#names[@]}; i++ )); do
# shellcheck disable=SC2001
name=$(echo "''${names[$i]}" | sed 's/.*(\(.*\))/\1/')
# shellcheck disable=SC2001
desc=$(echo "''${names[$i]}" | sed 's/ (.*//')
if [[ "$name" != "$main" && "desc:$desc" != "$main" ]]; then
hyprctl keyword monitor "$name",preferred,auto,1,mirror,"$main"
fi
done
'';
};
# Check if user wants the greeter only on main monitor
setupMonitors =
if (mainMonitor != "null" && !greetdDupe)
then "hyprctl dispatch focusmonitor ${mainMonitor}"
else "dupeMonitors";
# Setup Hyprland as the greeter's compositor
hyprConf =
pkgs.writeText "greetd-hypr-config"
(lib.strings.concatStrings ((optionals isNvidia [
"env = LIBVA_DRIVER_NAME,nvidia\n"
"env = XDG_SESSION_TYPE,wayland\n"
"env = GBM_BACKEND,nvidia-drm\n"
"env = __GLX_VENDOR_LIBRARY_NAME,nvidia\n"
"env = WLR_NO_HARDWARE_CURSORS,1\n"
])
++ map (x: "monitor=${x}\n") monitors
++ [
"exec-once = ${setupMonitors}\n"
"${readFile ./hyprland.conf}\n"
"exec-once = ags -b greeter &> /tmp/ags.log; hyprctl dispatch exit"
]));
in {
# Add home folder for home-manager to work
users.users.greeter = {
home = "/var/lib/greeter";
createHome = true;
};
home-manager.users.greeter = {
imports = [
ags.homeManagerModules.default
../../common/vars
../../home/theme.nix
];
programs.ags.enable = true;
home = {
packages = [
hyprland
dupeMonitors
pkgs.bun
pkgs.sassc
pkgs.swww
pkgs.gtk3
pkgs.glib
];
file = {
".config/ags/.wallpaper".source = "${pkgs.dracula-theme}/wallpapers/waves.png";
".config/ags" = {
source = ../ags/config;
recursive = true;
};
".config/ags/config.js".text =
/*
javascript
*/
''
import { transpileTypeScript } from './js/utils.js';
export default (await transpileTypeScript('greeter')).default;
'';
};
};
vars = config.vars;
home.stateVersion = "24.05";
};
imports = [./ags.nix];
services = {
xserver = {

View file

@ -1,44 +0,0 @@
input {
kb_layout = ca
kb_variant = multix
kb_model =
kb_options =
kb_rules =
follow_mouse = 1
touchpad {
natural_scroll = yes
}
sensitivity = 0 # -1.0 - 1.0, 0 means no modification.
}
device:razer-razer-naga-pro {
sensitivity = -0.5
accel_profile = "flat"
}
device:razer-razer-naga-pro-1 {
sensitivity = -0.5
accel_profile = "flat"
}
env = XCURSOR_SIZE,24
exec-once=hyprctl setcursor Dracula-cursors 24
misc {
disable_hyprland_logo = true
disable_splash_rendering = true
vfr = true
}
general {
border_size = 0
}
decoration {
blur {
enabled = false
}
drop_shadow = false
}

100
modules/greetd/hyprland.nix Normal file
View file

@ -0,0 +1,100 @@
{
config,
lib,
pkgs,
...
}: let
inherit
(lib)
boolToString
concatStringsSep
filterAttrs
hasPrefix
isAttrs
isBool
mapAttrsToList
optionalString
;
inherit (config.vars) mainUser;
inherit (import ./setupMonitors.nix {inherit config pkgs;}) setupMonitors;
# Nix stuff
isNvidia = config.hardware.nvidia.modesetting.enable;
cfgHypr = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland;
devices = filterAttrs (n: v: hasPrefix "device:" n) cfgHypr.settings;
monitors = cfgHypr.settings.monitor;
inputs = cfgHypr.settings.input;
misc = cfgHypr.settings.misc;
mkHyprBlock = attrs:
concatStringsSep "\n" (mapAttrsToList (
n: v:
if (isAttrs v)
then ''
${n} {
${mkHyprBlock v}
}
''
else if (isBool v)
then " ${n}=${boolToString v}"
else " ${n}=${toString v}"
)
attrs);
in {
hyprConf = pkgs.writeText "greetd-hypr-config" (
(optionalString isNvidia
/*
hyprlang
*/
''
env = LIBVA_DRIVER_NAME,nvidia
env = XDG_SESSION_TYPE,wayland
env = GBM_BACKEND,nvidia-drm
env = __GLX_VENDOR_LIBRARY_NAME,nvidia
env = WLR_NO_HARDWARE_CURSORS,1
'')
+ (concatStringsSep "\n" (map (x: "monitor=${x}") monitors))
+
/*
hyprlang
*/
''
misc {
${mkHyprBlock misc}
}
# Devices
${mkHyprBlock devices}
input {
${mkHyprBlock inputs}
}
''
+
/*
hyprlang
*/
''
env = XCURSOR_SIZE,24
exec-once = hyprctl setcursor Dracula-cursors 24
general {
border_size = 0
}
decoration {
blur {
enabled = false
}
drop_shadow = false
}
exec-once = ${setupMonitors}
exec-once = ags -b greeter &> /tmp/ags.log; hyprctl dispatch exit
''
);
}

View file

@ -0,0 +1,40 @@
{
config,
pkgs,
...
}: let
inherit (config.vars) mainUser greetdDupe mainMonitor;
hyprland = config.home-manager.users.${mainUser}.wayland.windowManager.hyprland.finalPackage;
# Show Regreet on all monitors
dupeMonitors = pkgs.writeShellApplication {
name = "dupeMonitors";
runtimeInputs = [hyprland pkgs.jq];
text = ''
main="${mainMonitor}"
names="($(hyprctl -j monitors | jq -r '.[] .description'))"
if [[ "$main" == "null" ]]; then
main="''${names[0]}"
fi
for (( i=0; i<''${#names[@]}; i++ )); do
# shellcheck disable=SC2001
name=$(echo "''${names[$i]}" | sed 's/.*(\(.*\))/\1/')
# shellcheck disable=SC2001
desc=$(echo "''${names[$i]}" | sed 's/ (.*//')
if [[ "$name" != "$main" && "desc:$desc" != "$main" ]]; then
hyprctl keyword monitor "$name",preferred,auto,1,mirror,"$main"
fi
done
'';
};
# Check if user wants the greeter only on main monitor
in {
setupMonitors =
if (mainMonitor != "null" && !greetdDupe)
then "hyprctl dispatch focusmonitor ${mainMonitor}"
else "${dupeMonitors}/bin/dupeMonitors";
}