From 1b210e7143547ce0f41e8082b8d27e9c7d220351 Mon Sep 17 00:00:00 2001 From: s1341 Date: Fri, 20 Mar 2020 12:02:58 +0200 Subject: [PATCH] zplug: add module This adds initial support for the zsh package manager "zplug". PR #1105 --- modules/modules.nix | 1 + modules/programs/zplug.nix | 57 ++++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/zplug/default.nix | 1 + tests/modules/programs/zplug/modules.nix | 48 ++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 modules/programs/zplug.nix create mode 100644 tests/modules/programs/zplug/default.nix create mode 100644 tests/modules/programs/zplug/modules.nix diff --git a/modules/modules.nix b/modules/modules.nix index 09d08970dc6..16ce233e054 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -119,6 +119,7 @@ let (loadModule ./programs/z-lua.nix { }) (loadModule ./programs/zathura.nix { }) (loadModule ./programs/zoxide.nix { }) + (loadModule ./programs/zplug.nix { }) (loadModule ./programs/zsh.nix { }) (loadModule ./services/blueman-applet.nix { }) (loadModule ./services/cbatticon.nix { condition = hostPlatform.isLinux; }) diff --git a/modules/programs/zplug.nix b/modules/programs/zplug.nix new file mode 100644 index 00000000000..0df395292a7 --- /dev/null +++ b/modules/programs/zplug.nix @@ -0,0 +1,57 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.zsh.zplug; + + pluginModule = types.submodule ({ config, ... }: { + options = { + name = mkOption { + type = types.str; + description = "The name of the plugin."; + }; + + tags = mkOption { + type = types.listOf types.str; + default = [ ]; + description = "The plugin tags."; + }; + }; + + }); + +in { + options.programs.zsh.zplug = { + enable = mkEnableOption "zplug - a zsh plugin manager"; + + plugins = mkOption { + default = [ ]; + type = types.listOf pluginModule; + description = "List of zplug plugins."; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.zplug ]; + + programs.zsh.initExtraBeforeCompInit = '' + source ${pkgs.zplug}/init.zsh + + ${optionalString (cfg.plugins != [ ]) '' + ${concatStrings (map (plugin: '' + zplug "${plugin.name}"${ + optionalString (plugin.tags != [ ]) '' + ${concatStrings (map (tag: ", ${tag}") plugin.tags)} + '' + } + '') cfg.plugins)} + ''} + + zplug install + zplug load + ''; + + }; +} diff --git a/tests/default.nix b/tests/default.nix index 6cc79413032..53cb7367ec6 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -62,6 +62,7 @@ import nmt { ./modules/programs/starship ./modules/programs/texlive ./modules/programs/tmux + ./modules/programs/zplug ./modules/programs/zsh ./modules/xresources ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ diff --git a/tests/modules/programs/zplug/default.nix b/tests/modules/programs/zplug/default.nix new file mode 100644 index 00000000000..172f7cd5981 --- /dev/null +++ b/tests/modules/programs/zplug/default.nix @@ -0,0 +1 @@ +{ zplug-modules = ./modules.nix; } diff --git a/tests/modules/programs/zplug/modules.nix b/tests/modules/programs/zplug/modules.nix new file mode 100644 index 00000000000..8ebf82b861f --- /dev/null +++ b/tests/modules/programs/zplug/modules.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.zsh = { + enable = true; + zplug = { + enable = true; + plugins = [ + { + name = "plugins/git"; + tags = [ "from:oh-my-zsh" ]; + } + { + name = "lib/clipboard"; + tags = [ "from:oh-my-zsh" ''if:"[[ $OSTYPE == *darwin* ]]"'' ]; + } + ]; + }; + }; + + nixpkgs.overlays = [ + (self: super: { + zsh = pkgs.writeScriptBin "dummy-zsh" ""; + zplug = pkgs.writeScriptBin "dummy-zplug" ""; + }) + ]; + + nmt.script = '' + assertFileRegex home-files/.zshrc \ + '^source ${builtins.storeDir}/.*zplug.*/init\.zsh$' + + assertFileContains home-files/.zshrc \ + 'zplug "plugins/git", from:oh-my-zsh' + + assertFileContains home-files/.zshrc \ + 'zplug "lib/clipboard", from:oh-my-zsh, if:"[[ $OSTYPE == *darwin* ]]"' + + assertFileRegex home-files/.zshrc \ + '^zplug install$' + + assertFileRegex home-files/.zshrc \ + '^zplug load$' + ''; + }; +}