1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-26 03:39:47 +01:00
home-manager/modules/programs/boxxy.nix
nikp123 0945875a2a
boxxy: add module (#4075)
* boxxy: add module

 * boxxy: added nikp123 to maintainers list

* boxxy: use mkPackageOption instead for the package

Co-authored-by: Naïm Favier <n@monade.li>

* boxxy: use yaml generator instead of json

Co-authored-by: Naïm Favier <n@monade.li>

* boxxy: various fixes

* boxxy: various fixes (part 2)

* boxxy: various fixes (part 3)

* boxxy: various fixes (part 4)

forgot to run ./format, whoops

* boxxy: use literalExpression for the rewrite example

Co-authored-by: Naïm Favier <n@monade.li>

* boxxy: add news entry

---------

Co-authored-by: Naïm Favier <n@monade.li>
2023-06-09 22:32:11 +02:00

110 lines
2.6 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.boxxy;
configPath = "${config.xdg.configHome}/boxxy/boxxy.yaml";
settingsFormat = pkgs.formats.yaml { };
boxxyRulesOpts = types.submodule {
freeformType = settingsFormat.type;
options = {
name = mkOption {
type = types.str;
description = ''
Unique identifier of the boxxy rule. This can be any single-line string.
'';
};
target = mkOption {
type = types.str;
default = "";
example = "~/.ssh";
description = ''
What directory/file to redirect.
'';
};
rewrite = mkOption {
type = types.str;
default = "";
example = literalExpression ''"''${config.xdg.configHome}/ssh"'';
description = ''
Where that file/directory should be rewritten to.
'';
};
mode = mkOption {
type = types.enum [ "file" "directory" ];
default = "directory";
description = ''
Does the current path redirect a file or a directory?
'';
};
only = mkOption {
type = types.listOf types.str;
default = [ ];
example = literalExpression ''
[
"bash"
"/usr/bin/sh"
]
'';
description = ''
Apply redirection ONLY to specified executable names.
'';
};
context = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "/home/example/Projects/my-project" ];
description = ''
Apply redirection ONLY when in a certain directory.
'';
};
env = mkOption {
type = types.attrsOf types.str;
default = { };
example = literalExpression ''
{
MY_ENV_VAR = "my_env_var_value";
}
'';
description = ''
Give certain environment variables for said match.
'';
};
};
};
in {
options.programs.boxxy = {
enable = mkEnableOption "boxxy: Boxes in badly behaving applications";
package = mkPackageOption pkgs "boxxy" { };
rules = mkOption {
type = types.listOf boxxyRulesOpts;
default = [ ];
description = "List of boxxy rules";
};
};
config = mkIf cfg.enable {
assertions =
[ (hm.assertions.assertPlatform "programs.boxxy" pkgs platforms.linux) ];
home.file = mkIf (cfg.rules != [ ]) {
"${configPath}".source =
settingsFormat.generate "boxxy-config.yaml" { rules = cfg.rules; };
};
home.packages = [ cfg.package ];
};
meta.maintainers = with lib.hm.maintainers; [ nikp123 ];
}