aboutsummaryrefslogtreecommitdiffstats
path: root/modules/lib
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-08-29 03:45:10 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-08-29 03:50:33 +0530
commit1a39cf221e3f647df0767c88d89a54e3813e7019 (patch)
treeb3df1afb0bcc0942a364f267f993ed1a9bfb9434 /modules/lib
parente9e375f5f5263964fe89479a2610081000959774 (diff)
downloadhome-manager-config-1a39cf221e3f647df0767c88d89a54e3813e7019.tar.gz
home-manager-config-1a39cf221e3f647df0767c88d89a54e3813e7019.zip
refactor: adding explicit options to enable scripts
- some scripts that are not critical to the functioning of other options, can be enabled/disabled
Diffstat (limited to 'modules/lib')
-rw-r--r--modules/lib/default.nix48
-rw-r--r--modules/lib/script.nix199
2 files changed, 0 insertions, 247 deletions
diff --git a/modules/lib/default.nix b/modules/lib/default.nix
deleted file mode 100644
index fd54fa2..0000000
--- a/modules/lib/default.nix
+++ /dev/null
@@ -1,48 +0,0 @@
-# Internal aggregation for script modules registered via mkScriptModule
-{
- config,
- lib,
- ...
-}:
-{
- options.scriptPaths = lib.mkOption {
- type = lib.types.listOf (lib.types.listOf lib.types.str);
- default = [ ];
- internal = true;
- description = "Attr paths of script modules registered via mkScriptModule.";
- };
-
- config = {
- home.packages = lib.filter (p: p != null) (
- map (path: (lib.getAttrFromPath path config).package) config.scriptPaths
- );
-
- xdg.desktopEntries = lib.listToAttrs (
- map
- (
- path:
- let
- name = lib.last path;
- sc = lib.getAttrFromPath path config;
- in
- lib.nameValuePair name {
- name = sc.desktop.displayName;
- exec = "${lib.getExe config.terminal.kitty.package} --class ${name} -e ${lib.getExe sc.package}";
- icon = sc.desktop.icon;
- categories = [ "Utility" ];
- terminal = false;
- type = "Application";
- }
- )
- (
- lib.filter (
- path:
- let
- sc = lib.getAttrFromPath path config;
- in
- sc.enable && sc.desktop.enable
- ) config.scriptPaths
- )
- );
- };
-}
diff --git a/modules/lib/script.nix b/modules/lib/script.nix
deleted file mode 100644
index 0586762..0000000
--- a/modules/lib/script.nix
+++ /dev/null
@@ -1,199 +0,0 @@
-# Library for creating script modules
-{
- lib,
- pkgs,
-}:
-let
- shellArgs = {
- zsh = name: file: "--zsh --name _${name} ${file}";
- bash = name: file: "--bash --name ${name}.bash ${file}";
- };
-
- mkScript =
- name: path: description: env: deps: completion:
- let
- descLines = lib.filter (s: s != "") (lib.splitString "\n" description);
- descComment =
- if descLines == [ ] then "" else lib.concatMapStringsSep "\n" (line: "# ${line}") descLines + "\n";
- envVars = lib.concatStringsSep "\n" (
- lib.mapAttrsToList (n: v: "export ${n}=${lib.escapeShellArg (toString v)}") env
- );
- base = pkgs.writeShellApplication {
- inherit name;
- runtimeInputs = deps;
- text = ''
- ${descComment}${envVars}
- ${builtins.readFile path}
- '';
- };
- completionDrv =
- pkgs.runCommand "${name}-completion"
- {
- nativeBuildInputs = [ pkgs.installShellFiles ];
- }
- (
- "mkdir -p $out\n"
- + lib.concatStringsSep "\n" (
- lib.mapAttrsToList (shell: content: ''
- installShellCompletion ${shellArgs.${shell} name (pkgs.writeText "_${name}.${shell}" content)}
- '') completion
- )
- );
- in
- if completion == { } then
- base
- else
- pkgs.symlinkJoin {
- name = name;
- paths = [
- base
- completionDrv
- ];
- meta = base.meta or { };
- };
-
- mkPythonScript =
- {
- name,
- path,
- description ? "",
- python ? pkgs.python3,
- pythonPackages ? (ps: [ ]),
- deps ? [ ],
- gobjectIntrospection ? false,
- }:
- let
- pythonEnv = python.withPackages pythonPackages;
- pathPrefix = lib.concatStringsSep ":" (
- [ "${pythonEnv}/bin" ] ++ map (p: "${lib.getBin p}/bin") deps
- );
- in
- pkgs.stdenv.mkDerivation {
- pname = name;
- version = "0.1.0";
- src = path;
- dontUnpack = true;
- meta = lib.optionalAttrs (description != "") { inherit description; } // {
- mainProgram = name;
- };
-
- nativeBuildInputs =
- lib.optionals gobjectIntrospection [
- pkgs.wrapGAppsHook3
- pkgs.gobject-introspection
- ]
- ++ lib.optional (!gobjectIntrospection) pkgs.makeWrapper;
- buildInputs = lib.optionals gobjectIntrospection [ pkgs.gtk3 ];
-
- installPhase = ''
- mkdir -p $out/bin
- install -m755 $src $out/bin/${name}
- patchShebangs $out/bin/${name}
- '';
-
- # wrapGAppsHook3 wraps every executable in $out/bin automatically,
- # setting GI_TYPELIB_PATH etc. from buildInputs' closure. With
- # gobjectIntrospection = false a plain wrapProgram only extends PATH.
- preFixup =
- if gobjectIntrospection then
- ''
- gappsWrapperArgs+=(--prefix PATH : "${pathPrefix}")
- ''
- else
- ''
- wrapProgram $out/bin/${name} --prefix PATH : "${pathPrefix}"
- '';
- };
-
- mkScriptModule =
- {
- scope ? [ ],
- name,
- path,
- env ? { },
- deps ? [ ],
- desktop ? null,
- extraLinks ? [ ],
- config,
- description ? "",
- completion ? { },
- }:
- let
- scriptAttrs = scope ++ [ name ];
- dottedName = lib.concatStringsSep "." scriptAttrs;
- c = lib.getAttrFromPath scriptAttrs config;
- scriptDrv = mkScript name path description env deps completion;
- in
- {
- options = lib.setAttrByPath scriptAttrs {
- enable = lib.mkOption {
- type = lib.types.bool;
- default = true;
- description = "Whether to enable the ${name} script.";
- };
- package = lib.mkOption {
- type = lib.types.nullOr lib.types.package;
- readOnly = true;
- description = "The derivation for the ${name} script.";
- };
- completion.enable = lib.mkOption {
- type = lib.types.bool;
- default = completion != { };
- description = "Whether to install completions for the ${name} script.";
- };
- desktop = {
- enable = lib.mkOption {
- type = lib.types.bool;
- default = false;
- description = "Whether to create a .desktop entry for this script.";
- };
- displayName = lib.mkOption {
- type = lib.types.str;
- default = name;
- description = "Display name for the .desktop entry.";
- };
- icon = lib.mkOption {
- type = lib.types.str;
- default = "kitty";
- description = "Icon for the .desktop entry.";
- };
- };
- };
-
- config =
- lib.setAttrByPath scriptAttrs (
- lib.mkIf c.enable (
- {
- package = scriptDrv;
- }
- // lib.optionalAttrs (desktop != null) { inherit desktop; }
- )
- )
- // {
- home.file = lib.mkIf c.enable (
- builtins.listToAttrs (
- map (linkPath: {
- name = lib.removePrefix "~/" linkPath;
- value = {
- source = "${scriptDrv}/bin/${name}";
- };
- }) extraLinks
- )
- );
- assertions = [
- {
- assertion = !c.enable || !c.desktop.enable || config.terminal.kitty.enable;
- message = "${dottedName}.desktop.enable requires terminal.kitty.enable because desktop entries launch scripts in kitty.";
- }
- {
- assertion = !c.completion.enable || completion != { };
- message = "${dottedName}.completion.enable is true but no completion text was provided to mkScriptModule.";
- }
- ];
- scriptPaths = [ scriptAttrs ];
- };
- };
-in
-{
- inherit mkPythonScript mkScript mkScriptModule;
-}