diff options
author | Maximilian Bosch <maximilian@mbosch.me> | 2018-07-10 15:52:30 +0200 |
---|---|---|
committer | Maximilian Bosch <maximilian@mbosch.me> | 2018-08-05 23:01:18 +0200 |
commit | 39b85451de2daa7927629dbac7b641becffc839e (patch) | |
tree | eb3239d4ec300266c11a4e4336ce3ec442125356 /nixos | |
parent | efc9511c1645b77227a9df140c9861c6e6b4faaf (diff) | |
download | nixlib-39b85451de2daa7927629dbac7b641becffc839e.tar nixlib-39b85451de2daa7927629dbac7b641becffc839e.tar.gz nixlib-39b85451de2daa7927629dbac7b641becffc839e.tar.bz2 nixlib-39b85451de2daa7927629dbac7b641becffc839e.tar.lz nixlib-39b85451de2daa7927629dbac7b641becffc839e.tar.xz nixlib-39b85451de2daa7927629dbac7b641becffc839e.tar.zst nixlib-39b85451de2daa7927629dbac7b641becffc839e.zip |
nixos/oh-my-zsh: add `customPkgs` option to allow multiple derivations for `ZSH_CUSTOM`
If multiple third-party modules shall be used for `oh-my-zsh` it has to be possible to create another env which composes all the packages. Now it can be done like this: ``` { pkgs, ... }: { programs.zsh.enable = true; programs.zsh.ohMyZsh = { enable = true; customPkgs = with pkgs; [ lambda-mod-zsh-theme nix-zsh-completions ]; theme = "lambda-mod"; plugins = [ "nix" ]; }; } ``` Please keep in mind that this is not compatible with `programs.zsh.ohMyZsh.custom`, only one of these options can be used ATM. Each package should store its outputs into `$out/share/zsh/<output-name>`. Completions (and ZSH-only) extensions should live in the `fpath` (`$out/share/zsh/site-functions`), plugins in `.../plugins` and themes in `.../themes` (please refer to fdb6bf6ed68c2f089ae6c729dfeaa3eddea2ce6a and 406d64aad162b3a4881747be4e24705fb5182573). All scripts in `customPkgs` will be linked together using `linkFarm` to provide a single directory for all scripts from all derivations in `customPkgs` as suggested in https://github.com/NixOS/nixpkgs/pull/43282#issuecomment-410396365.
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/programs/zsh/oh-my-zsh.nix | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/nixos/modules/programs/zsh/oh-my-zsh.nix b/nixos/modules/programs/zsh/oh-my-zsh.nix index b995d390b279..8435e0eb9f0f 100644 --- a/nixos/modules/programs/zsh/oh-my-zsh.nix +++ b/nixos/modules/programs/zsh/oh-my-zsh.nix @@ -3,7 +3,30 @@ with lib; let + cfg = config.programs.zsh.ohMyZsh; + + mkLinkFarmEntry = name: dir: + let + env = pkgs.buildEnv { + name = "zsh-${name}-env"; + paths = cfg.customPkgs; + pathsToLink = "/share/zsh/${dir}"; + }; + in + { inherit name; path = "${env}/share/zsh/${dir}"; }; + + mkLinkFarmEntry' = name: mkLinkFarmEntry name name; + + custom = + if cfg.custom != null then cfg.custom + else if length cfg.customPkgs == 0 then null + else pkgs.linkFarm "oh-my-zsh-custom" [ + (mkLinkFarmEntry' "themes") + (mkLinkFarmEntry "completions" "site-functions") + (mkLinkFarmEntry' "plugins") + ]; + in { options = { @@ -34,10 +57,19 @@ in }; custom = mkOption { - default = ""; - type = types.str; + default = null; + type = with types; nullOr str; description = '' Path to a custom oh-my-zsh package to override config of oh-my-zsh. + (Can't be used along with `customPkgs`). + ''; + }; + + customPkgs = mkOption { + default = []; + type = types.listOf types.package; + description = '' + List of custom packages that should be loaded into `oh-my-zsh`. ''; }; @@ -67,7 +99,7 @@ in environment.systemPackages = [ cfg.package ]; - programs.zsh.interactiveShellInit = with builtins; '' + programs.zsh.interactiveShellInit = '' # oh-my-zsh configuration generated by NixOS export ZSH=${cfg.package}/share/oh-my-zsh @@ -75,8 +107,8 @@ in "plugins=(${concatStringsSep " " cfg.plugins})" } - ${optionalString (stringLength(cfg.custom) > 0) - "ZSH_CUSTOM=\"${cfg.custom}\"" + ${optionalString (custom != null) + "ZSH_CUSTOM=\"${custom}\"" } ${optionalString (stringLength(cfg.theme) > 0) @@ -92,5 +124,13 @@ in source $ZSH/oh-my-zsh.sh ''; + + assertions = [ + { + assertion = cfg.custom != null -> cfg.customPkgs == []; + message = "If `cfg.custom` is set for `ZSH_CUSTOM`, `customPkgs` can't be used!"; + } + ]; + }; } |