Skip to content

Commit

Permalink
nix: init home-manager module
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf committed Feb 17, 2024
1 parent a3855cb commit 722a1c0
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
84 changes: 84 additions & 0 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
};
}

0 comments on commit 722a1c0

Please sign in to comment.