move more modules to home
This commit is contained in:
parent
9f0cee2627
commit
f893e3b8e2
18 changed files with 443 additions and 484 deletions
76
lib/modules/home/scripts.nix
Normal file
76
lib/modules/home/scripts.nix
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
scripts = config.programs.scripts;
|
||||
|
||||
hotkeyType = types.submodule ({...}: {
|
||||
options = {
|
||||
key = mkOption {
|
||||
description = "the key";
|
||||
};
|
||||
modifier = mkOption {
|
||||
description = "modifiers for the key";
|
||||
default = "SUPER";
|
||||
example = "SUPER_SHIFT";
|
||||
};
|
||||
args = mkOption {
|
||||
description = "args for the script when use this key";
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
scriptType = types.submodule ({...}: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "name of the executable";
|
||||
};
|
||||
text = mkOption {
|
||||
description = "the text of the script";
|
||||
};
|
||||
hotkeys = mkOption {
|
||||
type = types.listOf hotkeyType;
|
||||
description = "keys that run this script";
|
||||
default = [];
|
||||
};
|
||||
install = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
scriptToPackage = script:
|
||||
pkgs.writeShellScriptBin script.name script.text;
|
||||
|
||||
scriptExec = {
|
||||
script,
|
||||
hotkey,
|
||||
}: "${scriptToPackage script}/bin/${script.name} ${hotkey.args}";
|
||||
|
||||
installScripts = scripts: (map scriptToPackage (filter (s: s.install) scripts));
|
||||
|
||||
bindScript = script: (
|
||||
map
|
||||
(
|
||||
hotkey: "${hotkey.modifier}, ${hotkey.key}, exec, ${scriptExec {inherit script hotkey;}}"
|
||||
)
|
||||
script.hotkeys
|
||||
);
|
||||
in {
|
||||
options.programs = {
|
||||
scripts = mkOption {
|
||||
type = types.listOf scriptType;
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
home.packages = installScripts scripts;
|
||||
wayland.windowManager.hyprland.settings.bind = builtins.concatMap bindScript scripts;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue