Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers: add mkPackageOption + refactoring #150

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
modules = nixvimModules;
};
runUpdates = pkgs.callPackage
({ pkgs, stdenv }: stdenv.mkDerivation {
({ pkgs, stdenv }: stdenv.mkDerivation {
pname = "run-updates";
version = pkgs.rust-analyzer.version;

Expand All @@ -67,7 +67,7 @@
nativeBuildInputs = with pkgs; [extractRustAnalyzerPkg alejandra nixpkgs-fmt];

buildPhase = ''
extract_rust_analyzer.py editors/code/package.json |
extract_rust_analyzer.py editors/code/package.json |
alejandra --quiet |
nixpkgs-fmt > rust-analyzer-config.nix
'';
Expand Down
12 changes: 7 additions & 5 deletions lib/helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ rec {
mkEnumFirstDefault = enum: mkEnum enum (head enum);
};

mkPackageOption = name: default: mkOption {
type = types.package;
inherit default;
description = "Plugin to use for ${name}";
};

mkPlugin = { config, lib, ... }: { name
, description
, package ? null
Expand All @@ -112,11 +118,7 @@ rec {
options;
# does this evaluate package?
packageOption = if package == null then { } else {
package = mkOption {
type = types.package;
default = package;
description = "Plugin to use for ${name}";
};
package = mkPackageOption name package;
};
in
{
Expand Down
2 changes: 1 addition & 1 deletion modules/highlights.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ config, lib, ... }:
let
helpers = import ../plugins/helpers.nix { inherit lib; };
helpers = import ../lib/helpers.nix { inherit lib; };
in
with lib;
{
Expand Down
2 changes: 1 addition & 1 deletion modules/keymaps.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, ... }:
with lib;
let
helpers = import ../plugins/helpers.nix { inherit lib; };
helpers = import ../lib/helpers.nix { inherit lib; };

mapOption = types.oneOf [
types.str
Expand Down
2 changes: 1 addition & 1 deletion modules/options.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, ... }:
with lib;
let
helpers = import ../plugins/helpers.nix { inherit lib; };
helpers = import ../lib/helpers.nix { inherit lib; };
in
{
options = {
Expand Down
7 changes: 2 additions & 5 deletions plugins/bufferlines/barbar.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
with lib;
let
cfg = config.plugins.barbar;
helpers = import ../helpers.nix { inherit lib; };
in
{
options.plugins.barbar = {
enable = mkEnableOption "barbar.nvim";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.barbar-nvim;
description = "Plugin to use for barbar";
};
package = helpers.mkPackageOption "barbar" pkgs.vimPlugins.barbar-nvim;

animations = mkOption {
type = types.nullOr types.bool;
Expand Down
6 changes: 1 addition & 5 deletions plugins/bufferlines/bufferline.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ in
options = {
plugins.bufferline = {
enable = mkEnableOption "bufferline";
package = mkOption {
type = types.package;
description = "Plugin to use for bufferline";
default = pkgs.vimPlugins.bufferline-nvim;
};
package = helpers.mkPackageOption "bufferline" pkgs.vimPlugins.bufferline-nvim;
numbers = mkOption {
type = types.nullOr types.lines;
description = "A lua function customizing the styling of numbers.";
Expand Down
7 changes: 2 additions & 5 deletions plugins/colorschemes/base16.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
with lib;
let
cfg = config.colorschemes.base16;
helpers = import ../helpers.nix { inherit lib; };
themes = import ./base16-list.nix;
in
{
options = {
colorschemes.base16 = {
enable = mkEnableOption "base16";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.base16-vim;
description = "Plugin to use for base16";
};
package = helpers.mkPackageOption "base16" pkgs.vimPlugins.base16-vim;

useTruecolor = mkOption {
type = types.bool;
Expand Down
7 changes: 2 additions & 5 deletions plugins/colorschemes/gruvbox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
with lib;
let
cfg = config.colorschemes.gruvbox;
helpers = import ../helpers.nix { inherit lib; };
colors = types.enum [ "bg" "red" "green" "yellow" "blue" "purple" "aqua" "gray" "fg" "bg0_h" "bg0" "bg1" "bg2" "bg3" "bg4" "gray" "orange" "bg0_s" "fg0" "fg1" "fg2" "fg3" "fg4" ];
in
{
options = {
colorschemes.gruvbox = {
enable = mkEnableOption "gruvbox";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.gruvbox-nvim;
description = "Plugin to use for gruvbox";
};
package = helpers.mkPackageOption "gruvbox" pkgs.vimPlugins.gruvbox-nvim;

italics = mkEnableOption "italics";
bold = mkEnableOption "bold";
Expand Down
7 changes: 2 additions & 5 deletions plugins/colorschemes/nord.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
with lib;
let
cfg = config.colorschemes.nord;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
colorschemes.nord = {
enable = mkEnableOption "nord";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.nord-nvim;
description = "Plugin to use for nord.nvim";
};
package = helpers.mkPackageOption "nord.vim" pkgs.vimPlugins.nord-nvim;

contrast = mkEnableOption
"Make sidebars and popup menus like nvim-tree and telescope have a different background";
Expand Down
7 changes: 2 additions & 5 deletions plugins/colorschemes/one.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
with lib;
let
cfg = config.colorschemes.one;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
colorschemes.one = {
enable = mkEnableOption "vim-one";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.vim-one;
description = "Plugin to use for one";
};
package = helpers.mkPackageOption "one" pkgs.vimPlugins.vim-one;
};
};

Expand Down
7 changes: 2 additions & 5 deletions plugins/colorschemes/onedark.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
with lib;
let
cfg = config.colorschemes.onedark;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
colorschemes.onedark = {
enable = mkEnableOption "onedark";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.onedark-vim;
description = "Plugin to use for one";
};
package = helpers.mkPackageOption "one" pkgs.vimPlugins.onedark-vim;
};
};

Expand Down
6 changes: 1 addition & 5 deletions plugins/colorschemes/tokyonight.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ in
options = {
colorschemes.tokyonight = {
enable = mkEnableOption "tokyonight";
package = mkOption {
type = types.package;
default = pkgs.vimPlugins.tokyonight-nvim;
description = "Plugin to use for tokyonight";
};
package = helpers.mkPackageOption "tokyonight" pkgs.vimPlugins.tokyonight-nvim;
style = mkOption {
type = style;
default = "storm";
Expand Down
7 changes: 2 additions & 5 deletions plugins/completion/copilot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
with lib;
let
cfg = config.plugins.copilot;
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
plugins.copilot = {
enable = mkEnableOption "copilot";
package = mkOption {
type = types.package;
description = "The copilot plugin package to use";
default = pkgs.vimPlugins.copilot-vim;
};
package = helpers.mkPackageOption "copilot" pkgs.vimPlugins.copilot-vim;
filetypes = mkOption {
type = types.attrsOf types.bool;
description = "A dictionary mapping file types to their enabled status";
Expand Down
8 changes: 2 additions & 6 deletions plugins/completion/coq.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
with lib;
let
cfg = config.plugins.coq-nvim;
helpers = import ../helpers.nix { lib = lib; };
helpers = import ../helpers.nix { inherit lib; };
plugins = import ../plugin-defs.nix { inherit pkgs; };

in
Expand All @@ -11,11 +11,7 @@ in
plugins.coq-nvim = {
enable = mkEnableOption "coq-nvim";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.coq-vim;
description = "Plugin to use for coq-nvim";
};
package = helpers.mkPackageOption "coq-nvim" pkgs.vimPlugins.coq_nvim;

installArtifacts = mkEnableOption "Install coq-artifacts";

Expand Down
6 changes: 1 addition & 5 deletions plugins/completion/lspkind.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ in
options.plugins.lspkind = {
enable = mkEnableOption "lspkind.nvim";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.lspkind-nvim;
description = "Plugin to use for lspkind.nvim";
};
package = helpers.mkPackageOption "lspkind" pkgs.vimPlugins.lspkind-nvim;

mode = mkOption {
type = with types; nullOr (enum [ "text" "text_symbol" "symbol_text" "symbol" ]);
Expand Down
2 changes: 1 addition & 1 deletion plugins/completion/nvim-cmp/cmp-helpers.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, pkgs, ... }@attrs:
let
helpers = import ../../helpers.nix { lib = lib; };
helpers = import ../../helpers.nix { inherit lib; };
in with helpers; with lib;
{
mkCmpSourcePlugin = { name, extraPlugins ? [], useDefaultPackage ? true, ... }: mkPlugin attrs {
Expand Down
8 changes: 2 additions & 6 deletions plugins/completion/nvim-cmp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
with lib;
let
cfg = config.plugins.nvim-cmp;
helpers = import ../../helpers.nix { lib = lib; };
helpers = import ../../helpers.nix { inherit lib; };
mkNullOrOption = helpers.mkNullOrOption;
cmpLib = import ./cmp-helpers.nix args;
# functionName should be a string
Expand All @@ -17,11 +17,7 @@ in
options.plugins.nvim-cmp = {
enable = mkEnableOption "nvim-cmp";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.nvim-cmp;
description = "Plugin to use for nvim-cmp";
};
package = helpers.mkPackageOption "nvim-cmp" pkgs.vimPlugins.nvim-cmp;

performance = mkOption {
default = null;
Expand Down
2 changes: 1 addition & 1 deletion plugins/git/fugitive.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, pkgs, ... }@attrs:
let
helpers = import ../helpers.nix { lib = lib; };
helpers = import ../helpers.nix { inherit lib; };
in with helpers; with lib;
mkPlugin attrs {
name = "fugitive";
Expand Down
6 changes: 1 addition & 5 deletions plugins/git/gitgutter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ in
plugins.gitgutter = {
enable = mkEnableOption "gitgutter";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.gitgutter;
description = "Plugin to use for gitgutter";
};
package = helpers.mkPackageOption "gitgutter" pkgs.vimPlugins.gitgutter;

recommendedSettings = mkOption {
type = types.bool;
Expand Down
6 changes: 1 addition & 5 deletions plugins/git/gitsigns.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ in
{
options.plugins.gitsigns = {
enable = mkEnableOption "Enable gitsigns plugin";
package = mkOption {
type = types.package;
default = pkgs.vimPlugins.gitsigns-nvim;
description = "Plugin to use for gitsigns";
};
package = helpers.mkPackageOption "gitsigns" pkgs.vimPlugins.gitsigns-nvim;
signs = {
add = signOptions {
hl = "GitSignsAdd";
Expand Down
6 changes: 1 addition & 5 deletions plugins/git/neogit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ in
plugins.neogit = {
enable = mkEnableOption "neogit";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.neogit;
description = "Plugin to use for neogit";
};
package = helpers.mkPackageOption "neogit" pkgs.vimPlugins.neogit;

disableSigns = mkOption {
description = "Disable signs";
Expand Down
1 change: 0 additions & 1 deletion plugins/helpers.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
args: import ../lib/helpers.nix args

2 changes: 1 addition & 1 deletion plugins/languages/ledger.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ pkgs, lib, ... }@args:
with lib; with import ../helpers.nix { lib = lib; };
with lib; with import ../helpers.nix { inherit lib; };
mkPlugin args {
name = "ledger";
description = "Enable ledger language features";
Expand Down
2 changes: 1 addition & 1 deletion plugins/languages/nix.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, pkgs, ... }@attrs:
let
helpers = import ../helpers.nix { lib = lib; };
helpers = import ../helpers.nix { inherit lib; };
in with helpers; with lib;
mkPlugin attrs {
name = "nix";
Expand Down
11 changes: 5 additions & 6 deletions plugins/languages/plantuml-syntax.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
, config
, ...
}:
with lib; {
with lib;
let
helpers = import ../helpers.nix { inherit lib; };
in {
options.plugins.plantuml-syntax = {
enable = mkEnableOption "plantuml syntax support";

package = mkOption {
type = types.package;
default = pkgs.vimPlugins.plantuml-syntax;
description = "Plugin to use for plantuml-syntax";
};
package = helpers.mkPackageOption "plantuml-syntax" pkgs.vimPlugins.plantuml-syntax;

setMakeprg = mkOption {
type = types.bool;
Expand Down
Loading