From 6855ebdf3dbad94e8f3c3618ca0de0ca0033cb38 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 18 Feb 2024 01:02:47 +0300 Subject: [PATCH] nix: init home-manager module --- flake.nix | 5 +++ nix/hm-module.nix | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 nix/hm-module.nix diff --git a/flake.nix b/flake.nix index f95356d..fbc5dd5 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,11 @@ default = inputs.self.packages.${system}.hypridle; }); + homeManagerModules = { + hypridle = import ./nix/hm-module.nix inputs.self; + default = inputs.self.homeManagerModules.hypridle; + }; + checks = genSystems (system: inputs.self.packages.${system}); formatter = genSystems (system: pkgsFor.${system}.alejandra); diff --git a/nix/hm-module.nix b/nix/hm-module.nix new file mode 100644 index 0000000..7fa8ab3 --- /dev/null +++ b/nix/hm-module.nix @@ -0,0 +1,84 @@ +self: { + config, + pkgs, + lib, + ... +}: let + inherit (builtins) toString; + inherit (lib.types) str int package; + inherit (lib.modules) mkIf; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.meta) getExe; + + cfg = config.services.hypridle; +in { + options.services.hypridle = { + enable = mkEnableOption "Hypridle, Hyprland's idle daemon"; + + package = mkOption { + description = "The hypridle package"; + type = package; + default = self.packages.${pkgs.stdenv.hostPlatform.system}.hypridle; + }; + + timeout = { + description = "The timeout for the hypridle service, in seconds"; + type = int; + default = 500; + }; + + onTimeout = { + description = "The command to run when the timeout is reached"; + type = str; + default = "echo 'timeout reached'"; + }; + + onResume = { + description = "The command to run when the service resumes"; + type = str; + default = "echo 'service resumed'"; + }; + + lockCmd = { + description = "The command to run when the service locks"; + type = str; + default = "echo 'lock!'"; + }; + + unlockCmd = { + description = "The command to run when the service unlocks"; + type = str; + default = "echo 'unlock!'"; + }; + + beforeSleepCmd = { + description = "The command to run before the service sleeps"; + type = str; + default = "echo 'Zzz...'"; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."hypr/hypridle.conf".text = '' + listener { + timeout = ${toString cfg.timeout}; + on-timeout = ${cfg.onTimeout} + on-resume = ${cfg.onResume} + lock_cmd = ${cfg.lockCmd} + unlock_cmd = ${cfg.unlockCmd} + before_sleep_cmd = ${cfg.beforeSleepCmd} + } + ''; + + systemd.user.services.hypridle = { + description = "Hypridle"; + after = ["graphical-session.target"]; + wantedBy = ["default.target"]; + serviceConfig = { + ExecStart = "${getExe cfg.package}"; + Restart = "always"; + RestartSec = "10"; + }; + }; + }; +}