Skip to content

Commit

Permalink
nixvim: support standalone nixvim
Browse files Browse the repository at this point in the history
This represents a major rearchitecture for nixvim, so I'm leaving this up to track the progress for now, and to serve as a reference for any breaking changes during transition.

The main change is, of course, being able to use nixvim standalone. To do this, you should use the new build function, which takes in two arguments: the system architecture (e.g. x86_64-linux) and the configuration. For the new configuration, do not use the programs.nixvim. prefix.

For module development, the main change is that you should no longer prefix your modules with programs.nixvim..
  • Loading branch information
pta2002 authored Sep 18, 2022
1 parent bd6f978 commit 4ddd396
Show file tree
Hide file tree
Showing 52 changed files with 1,394 additions and 888 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ You can now access the module using `inputs.nixvim.homeManagerModules.nixvim`,
for a home-manager instalation, and `inputs.nixvim.nixosModules.nixvim`, if
you're not using it.

## Usage
NixVim can be used in three ways: through the home-manager and NixOS modules,
and through the `build` function. To use the modules, just import the
`nixvim.homeManagerModules.${system}.nixvim` and
`nixvim.nixosModules.${system}.nixvim` modules, depending on which system
you're using.

If you want to use it standalone, you can use the `build` function:

```nix
{ pkgs, nixvim, ... }: {
environment.systemModules = [
(nixvim.build pkgs {
colorschemes.gruvbox.enable = true;
})
];
}
```

## How does it work?
When you build the module (probably using home-manager), it will install all
your plugins and generate a lua config for NeoVim with all the options
Expand Down
36 changes: 17 additions & 19 deletions docs/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{ pkgs ? import <nixpkgs> {}
{ pkgs ? import <nixpkgs> { }
, lib ? import <nixpkgs/lib>
, ... }:
, nmdSrc
, nixvimModules ? [ ]
, ...
}:
let
nmdSrc = pkgs.fetchFromGitLab {
name = "nmd";
owner = "rycee";
repo = "nmd";
rev = "527245ff605bde88c2dd2ddae21c6479bb7cf8aa";
sha256 = "1zi0f9y3wq4bpslx1py3sfgrgd9av41ahpandvs6rvkpisfsqqlp";
};
nmd = import nmdSrc { inherit pkgs lib; };
scrubbedPkgsModule = {
imports = [{
Expand All @@ -22,14 +18,13 @@ let
nmd.buildModulesDocs ({
moduleRootPaths = [ ./.. ];
mkModuleUrl = path:
"https://github.com/pta2002/nixvim/blob/master/${path}#blob-path";
"https://github.com/pta2002/nixvim/blob/main/${path}#blob-path";
channelName = "nixvim";
} // args);
nixvimDocs = buildModulesDocs {
modules = [
(import ../nixvim.nix {})
scrubbedPkgsModule
];
] ++ nixvimModules;
docBook.id = "nixvim-options";
};

Expand All @@ -39,12 +34,15 @@ let
documentsDirectory = ./.;
documentType = "book";
chunkToc = ''
<toc>
<d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-home-manager-manual"><?dbhtml filename="index.html"?>
<d:tocentry linkend="ch-options"><?dbhtml filename="options.html"?></d:tocentry>
<d:tocentry linkend="ch-release-notes"><?dbhtml filename="release-notes.html"?></d:tocentry>
</d:tocentry>
</toc>
<toc>
<d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-nixvim-manual"><?dbhtml filename="index.html"?>
<d:tocentry linkend="ch-options"><?dbhtml filename="options.html"?></d:tocentry>
<d:tocentry linkend="ch-release-notes"><?dbhtml filename="release-notes.html"?></d:tocentry>
</d:tocentry>
</toc>
'';
};
in docs.html
in
# TODO: Parse this json or something, since docbook isn't working (and it's kind of terrible anyway)
nixvimDocs.json

34 changes: 24 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

151 changes: 66 additions & 85 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,102 +1,83 @@
{
description = "A neovim configuration system for NixOS";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

inputs.nmdSrc.url = "gitlab:rycee/nmd";
inputs.nmdSrc.flake = false;

outputs = { self, nixpkgs, nmdSrc, ... }@inputs: rec {
packages."x86_64-linux".docs = import ./docs {
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = nixpkgs.lib;
};

nixosModules.nixvim = import ./nixvim.nix { nixos = true; };
homeManagerModules.nixvim = import ./nixvim.nix { homeManager = true; };

# This is a simple container for testing
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({ pkgs, ... }: {
boot.isContainer = true;
system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;

users.users.test = {
isNormalUser = true;
password = "";
};

imports = [ nixosModules.nixvim ];

programs.nixvim = {
enable = true;
package = pkgs.neovim;
colorschemes.tokyonight = { enable = true; };

extraPlugins = [ pkgs.vimPlugins.vim-nix ];

options = {
number = true;
mouse = "a";
tabstop = 2;
shiftwidth = 2;
expandtab = true;
smarttab = true;
autoindent = true;
cindent = true;
linebreak = true;
hidden = true;
};

maps.normalVisualOp."ç" = ":";
maps.normal."<leader>m" = {
silent = true;
action = "<cmd>make<CR>";
};

plugins.lualine = {
enable = true;
# TODO: Use flake-utils to support all architectures
outputs = { self, nixpkgs, nmdSrc, flake-utils, ... }@inputs:
with nixpkgs.lib;
with builtins;
let
# TODO: Support nesting
nixvimModules = map (f: ./modules + "/${f}") (attrNames (builtins.readDir ./modules));

modules = pkgs: nixvimModules ++ [
(rec {
_file = ./flake.nix;
key = _file;
config = {
_module.args = {
pkgs = mkForce pkgs;
lib = pkgs.lib;
helpers = import ./plugins/helpers.nix { lib = pkgs.lib; };
};
};
})

plugins.undotree.enable = true;
plugins.gitgutter.enable = true;
plugins.fugitive.enable = true;
plugins.commentary.enable = true;
plugins.startify = {
enable = true;
useUnicode = true;
};
plugins.goyo = {
enable = true;
showLineNumbers = true;
};
./plugins/default.nix
];

plugins.lsp = {
enable = true;
servers.clangd.enable = true;
nixvimOption = pkgs: mkOption {
type = types.submodule ((modules pkgs) ++ [{
options.enable = mkEnableOption "Enable nixvim";
}]);
};

build = pkgs:
configuration:
let
eval = evalModules {
modules = modules pkgs ++ [ configuration ];
};
in
eval.config.output;

flakeOutput =
flake-utils.lib.eachDefaultSystem
(system: rec {
packages.docs = import ./docs {
pkgs = import nixpkgs { inherit system; };
lib = nixpkgs.lib;
nixvimModules = nixvimModules;
inherit nmdSrc;
};

plugins.telescope = {
enable = true;
extensions = { frecency.enable = true; };
nixosModules.nixvim = { pkgs, config, lib, ... }: {
options.programs.nixvim = nixvimOption pkgs;
config = mkIf config.programs.nixvim.enable {
environment.systemPackages = [
config.programs.nixvim.output
];
};
};

plugins.nvim-autopairs = { enable = true; };

globals = {
vimsyn_embed = "l";
mapleader = " ";
homeManagerModules.nixvim = { pkgs, config, lib, ... }: {
options.programs.nixvim = nixvimOption pkgs;
config = mkIf config.programs.nixvim.enable {
home.packages = [
config.programs.nixvim.output
];
};
};

plugins.lspsaga.enable = true;

plugins.treesitter.enable = true;
plugins.ledger.enable = true;
};
})
];
});
in
flakeOutput // {
inherit build;
# TODO: Stuff for home-manager and nixos modules backwards compat, keeping the architecture as x86_64 if none is specified...
homeManagerModules.nixvim = flakeOutput.homeManagerModules.x86_64-linux.nixvim;
nixosModules.nixvim = flakeOutput.nixosModules.x86_64-linux.nixvim;
};
};
}
17 changes: 17 additions & 0 deletions modules/colorscheme.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ config, lib, ... }:
with lib;
{
options = {
colorscheme = mkOption {
type = types.nullOr types.str;
description = "The name of the colorscheme to use";
default = null;
};
};

config = {
extraConfigVim = optionalString (config.colorscheme != "" && config.colorscheme != null) ''
colorscheme ${config.colorscheme}
'';
};
}
Loading

0 comments on commit 4ddd396

Please sign in to comment.