diff --git a/flake.nix b/flake.nix index b07caec..c2b08aa 100644 --- a/flake.nix +++ b/flake.nix @@ -93,6 +93,8 @@ inputs.rust-overlay.overlays.default inputs.nixfiles-assets.overlays.default inputs.nix-minecraft.overlays.default + # inputs.hypridle.overlays.default + (final: prev: { inherit (inputs.hypridle.packages.${prev.system}) hypridle; }) ]; ### Configuration diff --git a/home/default.nix b/home/default.nix index 5915139..9cb0eef 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, options, osConfig ? { }, nixpkgs, home-manager, ... }@args: +{ pkgs, config, lib, options, osConfig ? { }, nixpkgs, home-manager, inputs, ... }@args: let isStandalone = with builtins; !( (typeOf osConfig == "set") && hasAttr "home-manager" osConfig ); cfg = config.nixfiles; @@ -11,6 +11,8 @@ in ./profile ./programs ./sessions + + inputs.hypridle.homeManagerModules.default ]; config = {}; options.nixfiles = { diff --git a/home/programs/default.nix b/home/programs/default.nix index 72cfdfc..beaae9d 100644 --- a/home/programs/default.nix +++ b/home/programs/default.nix @@ -3,5 +3,6 @@ imports = [ ./comma.nix ./mopidy.nix + ./hypridle.nix ]; } diff --git a/home/programs/hypridle.nix b/home/programs/hypridle.nix new file mode 100644 index 0000000..a016e0e --- /dev/null +++ b/home/programs/hypridle.nix @@ -0,0 +1,90 @@ +{ pkgs, config, lib, ... }: +let + cfg = config.nixfiles.services.hypridle; + inherit (lib.types) str int; +in +{ + options.nixfiles.services.hypridle = { + enable = lib.mkEnableOption "the hypridle configuration"; + timeouts = let + mkTimeout = timeout: desc: lib.mkOption { + description = "${desc}"; + type = int; + default = timeout; + }; + in { + dpms = mkTimeout (300) "DPMS timeout"; + lock = mkTimeout (360) "Lock timeout"; + locked-dpms = mkTimeout (10) "DPMS timeout while locked"; + }; + commands = { + dpms-off = lib.mkOption { + description = "DPMS off command"; + default = "hyprctl dispatch dpms off"; + type = str; + }; + dpms-on = lib.mkOption { + description = "DPMS on command"; + default = "hyprctl dispatch dpms on"; + type = str; + }; + + # lock = lib.mkOption { + # description = "Lock command"; + # default = "${pkgs.swaylock}/bin/swaylock"; + # type = str; + # }; + # unlock = lib.mkOption { + # description = "Unlock command"; + # default = "${pkgs.procps}/bin/pkill -USR1 swaylock"; + # type = str; + # }; + }; + }; + config = lib.mkMerge [ + (lib.mkIf cfg.enable { + services.hypridle = { + enable = true; + listeners = let + dpms-wrapped = pkgs.writeShellScript "dpms-wrapped" '' + exec ${cfg.commands.dpms-off} + ''; + lock-dpms = pkgs.writeShellScript "lock-dpms" '' + ${pkgs.procps}/bin/pgrep swaylock > /dev/null && "${dpms-wrapped}" + ''; + + in [ + { + timeout = cfg.timeouts.dpms; + onTimeout = cfg.commands.dpms-off; + onResume = cfg.commands.dpms-on; + } + { + timeout = cfg.timeouts.locked-dpms; + onTimeout = "${lock-dpms}"; + onResume = cfg.commands.dpms-on; + } + { + timeout = cfg.timeouts.lock; + onTimeout = "${config.programs.swaylock.package}/bin/swaylock"; + } + { + timeout = cfg.timeouts.lock + cfg.timeouts.locked-dpms; + onTimeout = cfg.commands.dpms-off; + onResume = cfg.commands.dpms-on; + } + ]; + + lockCmd = "${config.programs.swaylock.package}"; + unlockCmd = "${pkgs.procps}/bin/pkill -x -USR1 swaylock"; + beforeSleepCmd = "${config.programs.swaylock.package}"; + }; + }) + # why isn't this handled automatically?? + (lib.mkIf config.services.hypridle.enable { + home.packages = with pkgs; [ + hypridle + ]; + }) + ]; +} diff --git a/home/sessions/hyprland/default.nix b/home/sessions/hyprland/default.nix index 6489b81..e838d41 100644 --- a/home/sessions/hyprland/default.nix +++ b/home/sessions/hyprland/default.nix @@ -13,23 +13,26 @@ let polkit-agent = "${pkgs.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1"; grimblast = "${inputs.hyprwm-contrib.packages.${pkgs.system}.grimblast}/bin/grimblast"; swayidle = "${pkgs.swayidle}/bin/swayidle"; - swaylock = "${pkgs.swaylock}/bin/swaylock"; + swaylock = "${config.programs.swaylock.package}/bin/swaylock"; hyprctl = "${hyprland-pkg}/bin/hyprctl"; pkill = "${pkgs.procps}/bin/pkill"; swaybg = "${pkgs.swaybg}/bin/swaybg"; + hypridle = "${config.services.hypridle.package}/bin/hypridle"; - # lock-cmd = "${swaylock}"; + lock-cmd = "${swaylock}"; - lock-cmd = let - cmd = pkgs.writeShellScript "lock-script" '' - ${swayidle} -w timeout 10 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on' & - ${swaylock} - kill %% - ''; - in "${cmd}"; + + # lock-cmd = let + # cmd = pkgs.writeShellScript "lock-script" '' + # ${swayidle} -w timeout 10 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on' & + # ${swaylock} + # kill %% + # ''; + # in "${cmd}"; # idle-cmd = "${swayidle} -w timeout 315 '${lock-cmd}' timeout 300 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on' before-sleep '${lock-cmd}' lock '${lock-cmd}' unlock '${pkill} -USR1 -x swaylock'"; - idle-cmd = "${swayidle} -w timeout 300 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on'"; + # idle-cmd = "${swayidle} -w timeout 300 '${hyprctl} dispatch dpms off' resume '${hyprctl} dispatch dpms on'"; + idle-cmd = "${hypridle}"; hypr-dispatcher-package = pkgs.callPackage ./dispatcher { hyprland = hyprland-pkg; }; hypr-dispatcher = "${hypr-dispatcher-package}/bin/hypr-dispatcher"; @@ -76,6 +79,7 @@ in }; config = lib.mkIf cfg.enable { + nixfiles.services.hypridle.enable = true; nixfiles.common.wm.enable = true; home.packages = with pkgs; [ kitty