From f77f0c2fd67bb4aafc9b0041b79a3c37a602ade5 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Fri, 31 Jan 2025 18:28:24 -0500 Subject: [PATCH] more updates --- .../presets/programs/rofi/brightness.nix | 19 ++-- .../nmasur/presets/programs/rofi/default.nix | 5 ++ .../nmasur/presets/programs/rofi/power.nix | 15 ++-- .../modules/nmasur/presets/services/i3.nix | 89 ++++++++++++++----- platforms/nixos/modules/hostnames.nix | 8 ++ 5 files changed, 104 insertions(+), 32 deletions(-) mode change 100755 => 100644 platforms/home-manager/modules/nmasur/presets/programs/rofi/brightness.nix mode change 100755 => 100644 platforms/home-manager/modules/nmasur/presets/programs/rofi/power.nix create mode 100644 platforms/nixos/modules/hostnames.nix diff --git a/platforms/home-manager/modules/nmasur/presets/programs/rofi/brightness.nix b/platforms/home-manager/modules/nmasur/presets/programs/rofi/brightness.nix old mode 100755 new mode 100644 index 5ea54ef..c966f68 --- a/platforms/home-manager/modules/nmasur/presets/programs/rofi/brightness.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/rofi/brightness.nix @@ -1,14 +1,19 @@ -{ config, pkgs, ... }: +{ + config, + pkgs, + lib, + ... +}: let - rofi = config.home-manager.users.${config.user}.programs.rofi.finalPackage; + rofi = config.programs.rofi.finalPackage; in { # Adapted from: # A rofi powered menu to execute brightness choices. - config.brightnessCommand = builtins.toString ( + config.brightnessCommand = lib.mkIf config.nmasur.presets.programs.rofi.enable builtins.toString ( pkgs.writeShellScript "brightness" '' dimmer="󰃝" @@ -19,7 +24,7 @@ in "$dimmer" \ "$medium" \ "$brighter" \ - | ${rofi}/bin/rofi \ + | ${lib.getExe rofi} \ -theme-str '@import "brightness.rasi"' \ -hover-select \ -me-select-entry ''' \ @@ -31,15 +36,15 @@ in case "$chosen" in "$dimmer") - ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 25; ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 25 + ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 25; ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 25 ;; "$medium") - ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 75; ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 75 + ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 75; ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 75 ;; "$brighter") - ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 100; ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 100 + ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 100; ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 100 ;; *) exit 1 ;; diff --git a/platforms/home-manager/modules/nmasur/presets/programs/rofi/default.nix b/platforms/home-manager/modules/nmasur/presets/programs/rofi/default.nix index fcd5cac..5d26411 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/rofi/default.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/rofi/default.nix @@ -11,6 +11,11 @@ in { + imports = [ + ./power.nix + ./brightness.nix + ]; + options.nmasur.presets.programs.rofi.enable = lib.mkEnableOption "Rofi quick launcher"; config = lib.mkIf cfg.enable { diff --git a/platforms/home-manager/modules/nmasur/presets/programs/rofi/power.nix b/platforms/home-manager/modules/nmasur/presets/programs/rofi/power.nix old mode 100755 new mode 100644 index 7af928c..433fcbf --- a/platforms/home-manager/modules/nmasur/presets/programs/rofi/power.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/rofi/power.nix @@ -1,7 +1,12 @@ -{ config, pkgs, ... }: +{ + config, + pkgs, + lib, + ... +}: let - rofi = config.home-manager.users.${config.user}.programs.rofi.finalPackage; + rofi = config.programs.rofi.finalPackage; in { @@ -9,7 +14,7 @@ in # https://gitlab.com/vahnrr/rofi-menus/-/blob/b1f0e8a676eda5552e27ef631b0d43e660b23b8e/scripts/rofi-power # A rofi powered menu to execute power related action. - config.powerCommand = builtins.toString ( + config.powerCommand = lib.mkIf config.nmasur.presets.programs.rofi.enable builtins.toString ( pkgs.writeShellScript "powermenu" '' power_off='' reboot='' @@ -23,7 +28,7 @@ in "$lock" \ "$suspend" \ "$log_out" \ - | ${rofi}/bin/rofi \ + | ${lib.getExe rofi} \ -theme-str '@import "power.rasi"' \ -hover-select \ -me-select-entry "" \ @@ -46,7 +51,7 @@ in ;; "$lock") - ${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span + ${lib.getExe pkgs.betterlockscreen} --lock --display 1 --blur 0.5 --span ;; "$suspend") diff --git a/platforms/home-manager/modules/nmasur/presets/services/i3.nix b/platforms/home-manager/modules/nmasur/presets/services/i3.nix index 579ad1d..9797537 100644 --- a/platforms/home-manager/modules/nmasur/presets/services/i3.nix +++ b/platforms/home-manager/modules/nmasur/presets/services/i3.nix @@ -7,13 +7,62 @@ let cfg = config.nmasur.presets.services.i3; - lockCmd = "${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span"; - lockUpdate = "${pkgs.betterlockscreen}/bin/betterlockscreen --update ${config.wallpaper} --display 1 --span"; in { - options.nmasur.presets.services.i3.enable = lib.mkEnableOption "i3 window manager"; + options.nmasur.presets.services.i3 = { + enable = lib.mkEnableOption "i3 window manager"; + commands = { + launcher = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Application launcher"; + default = null; + }; + lockScreen = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Screen lock"; + default = "${lib.getExe pkgs.betterlockscreen} --lock --display 1 --blur 0.5 --span"; + }; + updateLockScreen = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Update lock screen cache"; + default = "${lib.getExe pkgs.betterlockscreen} --update ${config.wallpaper} --display 1 --span"; + }; + toggleBar = lib.mkOption { + }; + systemdSearch = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Search systemd"; + default = null; + }; + audioSwitch = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Switch audio output"; + default = null; + }; + applicationSwitch = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Application switcher"; + default = null; + }; + power = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Launch power options menu"; + default = null; + }; + brightness = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Launch brightness adjuster"; + default = null; + }; + calculator = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Launch calculator"; + default = null; + }; + }; + }; config = lib.mkIf cfg.enable { xsession.windowManager.i3 = { @@ -105,36 +154,36 @@ in "Shift+F12" = # Disable dynamic sleep # https://github.com/rockowitz/ddcutil/issues/323 - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 + 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 + 30"; + "exec ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 + 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 + 30"; "Shift+F11" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 - 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 - 30"; + "exec ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 - 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 - 30"; "XF86MonBrightnessUp" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 + 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 + 30"; + "exec ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 + 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 + 30"; "XF86MonBrightnessDown" = - "exec ${pkgs.ddcutil}/bin/ddcutil --display 1 setvcp 10 - 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 - 30"; + "exec ${lib.getExe pkgs.ddcutil} --display 1 setvcp 10 - 30 && sleep 1; exec ${pkgs.ddcutil}/bin/ddcutil --disable-dynamic-sleep --display 2 setvcp 10 - 30"; # Media player controls - "XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause"; - "XF86AudioStop" = "exec ${pkgs.playerctl}/bin/playerctl stop"; - "XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl next"; - "XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl previous"; + "XF86AudioPlay" = "exec ${lib.getExe pkgs.playerctl} play-pause"; + "XF86AudioStop" = "exec ${lib.getExe pkgs.playerctl} stop"; + "XF86AudioNext" = "exec ${lib.getExe pkgs.playerctl} next"; + "XF86AudioPrev" = "exec ${lib.getExe pkgs.playerctl} previous"; # Launchers "${modifier}+Return" = "exec --no-startup-id ${ config.home-manager.users.${config.user}.programs.rofi.terminal }; workspace ${ws2}; layout tabbed"; - "${modifier}+space" = "exec --no-startup-id ${config.launcherCommand}"; - "${modifier}+Shift+s" = "exec --no-startup-id ${config.systemdSearch}"; - "${modifier}+Shift+a" = "exec --no-startup-id ${config.audioSwitchCommand}"; - "Mod1+Tab" = "exec --no-startup-id ${config.altTabCommand}"; - "${modifier}+Shift+period" = "exec --no-startup-id ${config.powerCommand}"; - "${modifier}+Shift+m" = "exec --no-startup-id ${config.brightnessCommand}"; - "${modifier}+c" = "exec --no-startup-id ${config.calculatorCommand}"; + "${modifier}+space" = "exec --no-startup-id ${cfg.commands.launcher}"; + "${modifier}+Shift+s" = "exec --no-startup-id ${cfg.commands.systemdSearch}"; + "${modifier}+Shift+a" = "exec --no-startup-id ${cfg.commands.audioSwitch}"; + "Mod1+Tab" = "exec --no-startup-id ${cfg.commands.altTab}"; + "${modifier}+Shift+period" = "exec --no-startup-id ${cfg.commands.power}"; + "${modifier}+Shift+m" = "exec --no-startup-id ${cfg.commands.brightness}"; + "${modifier}+c" = "exec --no-startup-id ${cfg.commands.calculator}"; "${modifier}+Shift+c" = "reload"; "${modifier}+Shift+r" = "restart"; "${modifier}+Shift+q" = ''exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'"''; - "${modifier}+Shift+x" = "exec ${lockCmd}"; + "${modifier}+Shift+x" = "exec ${cfg.commands.lockScreen}"; "${modifier}+Mod1+h" = "exec --no-startup-id ${ config.home-manager.users.${config.user}.programs.rofi.terminal @@ -262,7 +311,7 @@ in cacheDir = "${config.homePath}/.cache/betterlockscreen/current"; in lib.mkIf config.services.xserver.enable ( - config.home-manager.users.${config.user}.lib.dag.entryAfter [ "writeBoundary" ] '' + config.lib.dag.entryAfter [ "writeBoundary" ] '' if [ ! -d ${cacheDir} ] || [ -z "$(ls ${cacheDir})" ]; then $DRY_RUN_CMD ${lockUpdate} fi diff --git a/platforms/nixos/modules/hostnames.nix b/platforms/nixos/modules/hostnames.nix new file mode 100644 index 0000000..a00aa02 --- /dev/null +++ b/platforms/nixos/modules/hostnames.nix @@ -0,0 +1,8 @@ +{ lib, ... }: + +{ + + options.hostnames = lib.mkOption { + type = lib.types.attrsOf lib.types.str; + }; +}