fork/home-manager

git clone https://git.julia.blue/fork/home-manager

nikp123boxxy: add module (#4075)0945875a

master
2.6 KiB110 linesraw
1{ config, lib, pkgs, ... }:
2with lib;
3let
4  cfg = config.programs.boxxy;
5
6  configPath = "${config.xdg.configHome}/boxxy/boxxy.yaml";
7  settingsFormat = pkgs.formats.yaml { };
8
9  boxxyRulesOpts = types.submodule {
10    freeformType = settingsFormat.type;
11
12    options = {
13      name = mkOption {
14        type = types.str;
15        description = ''
16          Unique identifier of the boxxy rule. This can be any single-line string.
17        '';
18      };
19
20      target = mkOption {
21        type = types.str;
22        default = "";
23        example = "~/.ssh";
24        description = ''
25          What directory/file to redirect.
26        '';
27      };
28
29      rewrite = mkOption {
30        type = types.str;
31        default = "";
32        example = literalExpression ''"''${config.xdg.configHome}/ssh"'';
33        description = ''
34          Where that file/directory should be rewritten to.
35        '';
36      };
37
38      mode = mkOption {
39        type = types.enum [ "file" "directory" ];
40        default = "directory";
41        description = ''
42          Does the current path redirect a file or a directory?
43        '';
44      };
45
46      only = mkOption {
47        type = types.listOf types.str;
48        default = [ ];
49        example = literalExpression ''
50          [
51            "bash"
52            "/usr/bin/sh"
53          ]
54        '';
55        description = ''
56          Apply redirection ONLY to specified executable names.
57        '';
58      };
59
60      context = mkOption {
61        type = types.listOf types.str;
62        default = [ ];
63        example = [ "/home/example/Projects/my-project" ];
64        description = ''
65          Apply redirection ONLY when in a certain directory.
66        '';
67      };
68
69      env = mkOption {
70        type = types.attrsOf types.str;
71        default = { };
72        example = literalExpression ''
73          {
74            MY_ENV_VAR = "my_env_var_value";
75          }
76        '';
77        description = ''
78          Give certain environment variables for said match.
79        '';
80      };
81    };
82  };
83in {
84  options.programs.boxxy = {
85    enable = mkEnableOption "boxxy: Boxes in badly behaving applications";
86
87    package = mkPackageOption pkgs "boxxy" { };
88
89    rules = mkOption {
90      type = types.listOf boxxyRulesOpts;
91      default = [ ];
92      description = "List of boxxy rules";
93    };
94  };
95
96  config = mkIf cfg.enable {
97    assertions =
98      [ (hm.assertions.assertPlatform "programs.boxxy" pkgs platforms.linux) ];
99
100    home.file = mkIf (cfg.rules != [ ]) {
101      "${configPath}".source =
102        settingsFormat.generate "boxxy-config.yaml" { rules = cfg.rules; };
103    };
104
105    home.packages = [ cfg.package ];
106  };
107
108  meta.maintainers = with lib.hm.maintainers; [ nikp123 ];
109}
110