/ lib / default.nix
default.nix
 1  {
 2    callPackage,
 3    inputs,
 4    neovim-unwrapped,
 5    stdenv,
 6    makeWrapper,
 7    writeText,
 8    lib,
 9    ...
10  }:
11  let
12    inherit (builtins)
13      isAttrs
14      isList
15      isString
16      readFile
17      ;
18    inherit (stdenv) mkDerivation;
19  
20    plugins = callPackage ../plugins { inherit inputs; };
21  
22    toLua =
23      value:
24      if isAttrs value then
25        "{ ${lib.concatStringsSep ", " (lib.mapAttrsToList (k: v: "${toLua k} = ${toLua v}") value)} }"
26      else if isList value then
27        "{ ${lib.concatStringsSep ", " (map toLua value)} }"
28      else if isString value then
29        "[[${value}]]"
30      else
31        toString value;
32  
33    mapSpec = p: ''
34      __nv.setup_plugin(
35        ${toLua p.name},
36        ${toLua p.depends},
37        function()
38          ${p.config}
39        end
40      )'';
41  
42    initFile = ''
43      vim.opt.packpath:append(${toLua "${plugins}/share/nightvim"})
44  
45      local __nv = (function()
46        ${readFile ./lua/init.lua}
47      end)()
48  
49      ${lib.concatStringsSep "\n" (map mapSpec plugins.specs)}
50  
51      __nv.finish()
52    '';
53  in
54  mkDerivation {
55    inherit (neovim-unwrapped) meta lua;
56  
57    name = "nightvim";
58    src = neovim-unwrapped;
59  
60    nativeBuildInputs = [ makeWrapper ];
61  
62    dontBuild = true;
63  
64    installPhase = ''
65      mkdir $out
66      cp -rf * $out
67  
68      wrapProgram $out/bin/nvim \
69        --suffix PATH : ${plugins}/bin \
70        --set VIMRUNTIME ${neovim-unwrapped}/share/nvim/runtime \
71        --set NVIM_APPNAME nightvim \
72        --set NIGHTVIM_ROOT ${plugins}/share/nightvim \
73        --add-flags "-u ${writeText "init.lua" initFile}"
74    '';
75  
76    passthru = { inherit plugins; };
77  }