Skip to content

Commit

Permalink
add vim-airline
Browse files Browse the repository at this point in the history
  • Loading branch information
pta2002 committed Jan 5, 2021
1 parent 005df95 commit 7122ccd
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tmp/
2 changes: 1 addition & 1 deletion .tmp
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
package = pkgs.neovim-nightly;
colorschemes.gruvbox.enable = true;

plugins.lightline.enable = true;
options.number = true;

plugins.airline = {
enable = true;
powerline = true;
};
};
})
];
Expand Down
48 changes: 47 additions & 1 deletion nixvim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ let
};
};
};

helpers = import ./plugins/helpers.nix { lib = lib; };
in
{
options = {
Expand Down Expand Up @@ -60,6 +62,18 @@ in
type = types.attrsOf types.anything;
default = { };
};

options = mkOption {
type = types.attrsOf types.anything;
default = { };
description = "The configuration options, e.g. line numbers";
};

globals = mkOption {
type = types.attrsOf types.anything;
default = {};
description = "Global variables";
};
};
};

Expand All @@ -85,7 +99,11 @@ in
environment.systemPackages = [ wrappedNeovim ];
programs.nixvim = {
configure = {
customRC = cfg.extraConfigVim + (optionalString (cfg.colorscheme != "") ''
customRC = ''
lua <<EOF
${cfg.extraConfigLua}
EOF
'' + cfg.extraConfigVim + (optionalString (cfg.colorscheme != "") ''
colorscheme ${cfg.colorscheme}
'');
Expand All @@ -98,6 +116,34 @@ in
cfg.extraPlugins);
};
};

extraConfigLua = optionalString (cfg.globals != {}) ''
-- Set up globals {{{
local __nixvim_globals = ${helpers.toLuaObject cfg.globals}
for k,v in pairs(__nixvim_globals) do
vim.g[k] = v
end
-- }}}
'' + optionalString (cfg.options != {}) ''
-- Set up options {{{
local __nixvim_options = ${helpers.toLuaObject cfg.options}
for k,v in pairs(__nixvim_options) do
-- Here we use the set command because, as of right now, neovim has
-- no equivalent using the lua API. You have to sort through the
-- options and know which options are local to what
if type(v) == "boolean" then
local no
if v then no = "" else no = "no" end
vim.cmd("set " .. no .. k)
else
vim.cmd("set " .. k .. "=" .. tostring(v))
end
end
-- }}}
'';
};

environment.etc."xdg/nvim/sysinit.vim".text = neovimConfig.neovimRcContent;
Expand Down
1 change: 1 addition & 0 deletions plugins/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
imports = [
./statuslines/lightline.nix
./statuslines/airline.nix
./colorschemes/gruvbox.nix
];
}
2 changes: 1 addition & 1 deletion plugins/helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rec {
"{" + (concatStringsSep ","
(mapAttrsToList
(n: v: "[${toLuaObject n}] = " + (toLuaObject v))
args)) + "}"
(filterAttrs (n: v: !isNull v || v == {}) args))) + "}"
else if builtins.isList args then
"{" + concatMapStringsSep "," toLuaObject args + "}"
else if builtins.isString args then
Expand Down
75 changes: 75 additions & 0 deletions plugins/statuslines/airline.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.programs.nixvim.plugins.airline;
helpers = import ../helpers.nix { inherit lib; };

sectionType = with types; nullOr (oneOf [ str (listOf str)]);
sectionOption = mkOption {
default = null;
type = sectionType;
description = "Configuration for this section. Can be either a statusline-format string or a list of modules to be passed to airline#section#create_*.";
};
in {
options = {
programs.nixvim.plugins.airline = {
enable = mkEnableOption "Enable airline";

extensions = mkOption {
default = null;
type = with types; nullOr attrs;
description = "A list of extensions and their configuration";
};

onTop = mkOption {
default = false;
type = types.bool;
description = "Whether to show the statusline on the top instead of the bottom";
};

sections = mkOption {
default = null;
type = with types; nullOr (submodule {
options = {
a = sectionOption;
b = sectionOption;
c = sectionOption;
x = sectionOption;
y = sectionOption;
z = sectionOption;
};
});
};

powerline = mkOption {
default = null;
type = with types; nullOr bool;
description = "Whether to use powerline symbols";
};

theme = mkOption {
default = config.programs.nixvim.colorscheme;
type = with types; nullOr str;
description = "The theme to use for vim-airline. If set, vim-airline-themes will be installed.";
};
};
};

config = let
sections = {};
in mkIf cfg.enable {
programs.nixvim = {
extraPlugins = with pkgs.vimPlugins; [
vim-airline
] ++ optional (!isNull cfg.theme) vim-airline-themes;
globals = {
airline.extensions = cfg.extensions;

airline_statusline_ontop = mkIf cfg.onTop 1;
airline_powerline_fonts = mkIf (cfg.powerline) 1;

airline_theme = mkIf (!isNull cfg.theme) cfg.theme;
} // sections;
};
};
}
16 changes: 2 additions & 14 deletions plugins/statuslines/lightline.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,17 @@ in {
description = "Mode name mappings";
default = null;
};

extraConfig = mkOption {
type = types.lines;
default = "";
description = "Extra configuration for this plugin";
};
};
};

config = let
configString = helpers.toVimDict {
configAttrs = {
inherit (cfg) colorscheme active component componentFunction modeMap;
};
in mkIf cfg.enable {
programs.nixvim = {
extraPlugins = [ pkgs.vimPlugins.lightline-vim ];
extraConfigVim = ''
""" lightline {{{
let g:lightline = ${configString}
${cfg.extraConfig}
""" }}}
'';
globals.lightline = configAttrs;
};
};
}
8 changes: 8 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
# Creates a container and then runs the resulting neovim executable with the configuration
set -e

sudo nixos-container destroy nvim-test
sudo nixos-container create nvim-test --flake .

.tmp/sw/bin/nvim -u .tmp/etc/xdg/nvim/sysinit.vim .tmp/etc/xdg/nvim/sysinit.vim

0 comments on commit 7122ccd

Please sign in to comment.