begin to modularise
This commit is contained in:
parent
bbd26675f8
commit
a1175ba492
10 changed files with 311 additions and 93 deletions
52
lib/modules/scripts.nix
Normal file
52
lib/modules/scripts.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{ user }: { lib, pkgs, config, ... }:
|
||||
with lib;
|
||||
let
|
||||
scripts = config.programs.scripts;
|
||||
|
||||
scriptType = types.submodule ({...}: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "name of the executable";
|
||||
};
|
||||
text = mkOption {
|
||||
description = "the text of the script";
|
||||
};
|
||||
hotkey = mkOption {
|
||||
description = "the key that run this script";
|
||||
default = "";
|
||||
};
|
||||
install = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
scriptToPackage = script: pkgs.writeShellScriptBin script.name script.text;
|
||||
installScripts = scripts: (map scriptToPackage (filter ( s: s.install ) scripts));
|
||||
|
||||
bindScript = script: if script.hotkey != "" then ''
|
||||
bind = SUPER, ${script.hotkey}, exec, ${scriptToPackage script}/bin/${script.name}
|
||||
'' else "";
|
||||
|
||||
bindScripts = scripts:
|
||||
"# === USER SCRIPTS MODULE ===\n"
|
||||
+ concatStringsSep "\n" (map bindScript scripts);
|
||||
|
||||
in
|
||||
{
|
||||
options.programs = {
|
||||
scripts = mkOption {
|
||||
type = types.listOf scriptType;
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
home-manager.users.${user}.imports = [{
|
||||
home.packages = installScripts scripts;
|
||||
wayland.windowManager.hyprland.extraConfig = bindScripts scripts;
|
||||
}];
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue