ctucx.git: nixfiles

ctucx' nixfiles

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.ctucx.skhd;
in

{
  options = {
    services.ctucx.skhd.enable = mkOption {
      type = types.bool;
      default = false;
      description = lib.mdDoc "Whether to enable the skhd hotkey daemon.";
    };

    services.ctucx.skhd.package = mkOption {
      type = types.package;
      default = pkgs.skhd;
      description = lib.mdDoc "This option specifies the skhd package to use.";
    };

    services.ctucx.skhd.skhdConfig = mkOption {
      type = types.lines;
      default = "";
      example = "alt + shift - r   :   chunkc quit";
      description = lib.mdDoc "Config to use for {file}`skhdrc`.";
    };
  };

  config = mkIf cfg.enable {

    environment.etc."skhdrc".text = cfg.skhdConfig;

    launchd.user.agents.skhd = {
      path = [ config.environment.systemPath ];

      serviceConfig.ProgramArguments = [
        "/bin/sh" "-c"
        "/bin/wait4path /nix/store && exec ${cfg.package}/bin/skhd ${optionalString (cfg.skhdConfig != "") "-c /etc/skhdrc"}"
      ];
      serviceConfig.KeepAlive = true;
      serviceConfig.ProcessType = "Interactive";
    };

  };
}