1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-20 10:09:45 +01:00

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>
This commit is contained in:
nikp123 2023-06-09 22:32:11 +02:00 committed by GitHub
parent 2a69182c56
commit 0945875a2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 183 additions and 0 deletions

View file

@ -159,6 +159,12 @@
github = "mifom"; github = "mifom";
githubId = 23462908; githubId = 23462908;
}; };
nikp123 = {
name = "nikp123";
email = "nikp123@users.noreply.github.com";
github = "nikp123";
githubId = 4696350;
};
nilp0inter = { nilp0inter = {
name = "Roberto Abdelkader Martínez Pérez"; name = "Roberto Abdelkader Martínez Pérez";
email = "robertomartinezp@gmail.com"; email = "robertomartinezp@gmail.com";

View file

@ -1062,6 +1062,14 @@ in
A new module is available: 'programs.imv'. A new module is available: 'programs.imv'.
''; '';
} }
{
time = "2023-06-09T19:13:39+00:00";
condition = hostPlatform.isLinux;
message = ''
A new module is available: 'programs.boxxy'.
'';
}
]; ];
}; };
} }

View file

@ -60,6 +60,7 @@ let
./programs/beets.nix ./programs/beets.nix
./programs/borgmatic.nix ./programs/borgmatic.nix
./programs/bottom.nix ./programs/bottom.nix
./programs/boxxy.nix
./programs/broot.nix ./programs/broot.nix
./programs/browserpass.nix ./programs/browserpass.nix
./programs/btop.nix ./programs/btop.nix

110
modules/programs/boxxy.nix Normal file
View file

@ -0,0 +1,110 @@
{ 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 ];
}

View file

@ -156,6 +156,7 @@ import nmt {
./modules/programs/autorandr ./modules/programs/autorandr
./modules/programs/beets # One test relies on services.mpd ./modules/programs/beets # One test relies on services.mpd
./modules/programs/borgmatic ./modules/programs/borgmatic
./modules/programs/boxxy
./modules/programs/browserpass # TODO re-enable on Darwin when https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 is fixed ./modules/programs/browserpass # TODO re-enable on Darwin when https://github.com/NixOS/nixpkgs/pull/236258#issuecomment-1583450593 is fixed
./modules/programs/firefox ./modules/programs/firefox
./modules/programs/foot ./modules/programs/foot

View file

@ -0,0 +1,4 @@
{
boxxy-empty-settings = ./empty-settings.nix;
boxxy-example-settings = ./example-settings.nix;
}

View file

@ -0,0 +1,15 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.boxxy.enable = true;
test.stubs.boxxy = { };
nmt.script = ''
assertPathNotExists home-files/.config/boxxy
'';
};
}

View file

@ -0,0 +1,12 @@
rules:
- context:
- /home/test_user/your_project_repo
env:
ENVIRONMENT_THING: some value
mode: directory
name: example rule
only:
- arduino
- Arduino
rewrite: ~/.local/share/boxxy
target: ~/Arduino

View file

@ -0,0 +1,26 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.boxxy.enable = true;
programs.boxxy.rules = [{
name = "example rule";
target = "~/Arduino";
rewrite = "~/.local/share/boxxy";
mode = "directory";
only = [ "arduino" "Arduino" ];
env = { "ENVIRONMENT_THING" = "some value"; };
context = [ "/home/test_user/your_project_repo" ];
}];
test.stubs.boxxy = { };
nmt.script = ''
boxxyyaml=home-files/.config/boxxy/boxxy.yaml
assertFileExists $boxxyyaml
assertFileContent $boxxyyaml ${./example-boxxy.yaml}
'';
};
}