chore: reorganize lib folder hierarchy
parent
bf329e5f42
commit
44bfef1f1c
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
pkgs,
|
||||
sloth,
|
||||
...
|
||||
}: let
|
||||
inherit (pkgs.lib) evalModules;
|
||||
sLib = sloth.lib;
|
||||
in {
|
||||
evalSlothModules = {
|
||||
modules ? [],
|
||||
specialArgs ? {},
|
||||
}: let
|
||||
moduleConfig = evalModules {
|
||||
specialArgs = specialArgs // {inherit pkgs;};
|
||||
modules = modules ++ [sLib.defaultModule];
|
||||
};
|
||||
in
|
||||
moduleConfig.config;
|
||||
|
||||
mkNeovimPkg = {
|
||||
modules ? [],
|
||||
specialArgs ? {},
|
||||
}:
|
||||
(sLib.evalSlothModules {inherit modules specialArgs;}).neovimPackage;
|
||||
}
|
||||
148
lib/lib.nix
148
lib/lib.nix
|
|
@ -1,140 +1,16 @@
|
|||
{version, ...}: {pkgs, ...}: let
|
||||
inherit (builtins) concatLists;
|
||||
inherit (pkgs) bash lib;
|
||||
inherit
|
||||
(lib)
|
||||
callPackageWith
|
||||
concatMap
|
||||
evalModules
|
||||
fix
|
||||
flip
|
||||
literalExample
|
||||
mkEnableOption
|
||||
mkOption
|
||||
mkPackageOption
|
||||
optional
|
||||
optionalString
|
||||
types
|
||||
;
|
||||
{version, ...}: {pkgs, ...}:
|
||||
pkgs.lib.fix (lib: let
|
||||
inherit (pkgs.lib) callPackageWith mergeAttrsList;
|
||||
|
||||
callModule = callPackageWith {inherit pkgs callModule;};
|
||||
|
||||
modules = {
|
||||
init = callModule ./init.nix {};
|
||||
plugin = callModule ./plugin {};
|
||||
runtime = callModule ./runtime.nix {};
|
||||
sloth = callModule ./sloth.nix {};
|
||||
callModule = callPackageWith {
|
||||
inherit pkgs callModule;
|
||||
sloth = {inherit lib version;};
|
||||
};
|
||||
|
||||
extraLuaPackagesType =
|
||||
(with types; functionTo (listOf package))
|
||||
// {
|
||||
merge = loc: defs: let
|
||||
fnList = map (def: def.value) defs;
|
||||
concatPackages = ps: fn: fn ps;
|
||||
in
|
||||
ps: concatMap (concatPackages ps) fnList;
|
||||
};
|
||||
|
||||
mkDiffAlias = name:
|
||||
(flip optionalString) ''
|
||||
cat <<SH > $out/bin/${name}
|
||||
#!${bash}/bin/bash
|
||||
exec $out/bin/nvim -d "\''${@}"
|
||||
SH
|
||||
chmod 555 $out/bin/${name}
|
||||
'';
|
||||
|
||||
defaultModule = {
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
pkg = pkgs.wrapNeovimUnstable config.package config.neovimOptions;
|
||||
|
||||
customLuaRC = modules.init.mkCustomLuaRc config.init;
|
||||
|
||||
plugins = concatLists [
|
||||
(map modules.plugin.extract config.plugins)
|
||||
(optional (! isNull config.runtime) (modules.runtime.mkPlugin config.runtime))
|
||||
[(modules.sloth.mkPlugin version config.plugins)]
|
||||
];
|
||||
|
||||
neovimOptions = pkgs.neovimUtils.makeNeovimConfig {
|
||||
inherit (config) extraLuaPackages viAlias vimAlias;
|
||||
inherit customLuaRC plugins;
|
||||
wrapRc = customLuaRC != null;
|
||||
# inherit customRC;
|
||||
};
|
||||
|
||||
neovimPackage = pkg.overrideAttrs (final: super: {
|
||||
postBuild =
|
||||
super.postBuild
|
||||
+ (mkDiffAlias "vimdiff" config.vimdiffAlias)
|
||||
+ (mkDiffAlias "nvimdiff" config.nvimdiffAlias);
|
||||
});
|
||||
in {
|
||||
options = {
|
||||
package = mkPackageOption pkgs "neovim-unwrapped" {};
|
||||
|
||||
# Will probably be not needed
|
||||
# dependenciesExtraArgs = mkOption {
|
||||
# default = {};
|
||||
# };
|
||||
|
||||
extraLuaPackages = mkOption {
|
||||
description = ''
|
||||
function to define extra lua packages that should be included in
|
||||
neovim environment.
|
||||
'';
|
||||
type = extraLuaPackagesType;
|
||||
example = literalExample "p: [p.nvim-nio]";
|
||||
defaultText = literalExample "_: []";
|
||||
default = _: [];
|
||||
};
|
||||
|
||||
init = modules.init.option;
|
||||
runtime = modules.runtime.option;
|
||||
plugins = modules.plugin.option;
|
||||
|
||||
viAlias = mkEnableOption "creation on `vi` alias";
|
||||
vimAlias = mkEnableOption "creation on `vim` alias";
|
||||
vimdiffAlias = mkEnableOption "creation on `vimdiff` alias";
|
||||
nvimdiffAlias = mkEnableOption "creation on `nvimdiff` alias";
|
||||
|
||||
neovimOptions = mkOption {
|
||||
type = types.attrs;
|
||||
description = "The resulting configuration passed to `pkgs.wrapNeovimUnstable`";
|
||||
default = neovimOptions;
|
||||
};
|
||||
|
||||
neovimPackage = mkOption {
|
||||
type = types.package;
|
||||
description = "The neovim package generated from your configuration.";
|
||||
# defaultText = lib.literalExpression "pkgs.hello";
|
||||
default = neovimPackage;
|
||||
};
|
||||
};
|
||||
};
|
||||
callModules = modules: mergeAttrsList (map (path: callModule path {}) modules);
|
||||
in
|
||||
fix (sLib: {
|
||||
inherit defaultModule;
|
||||
mkPluginsFromInputs = import ./mkPluginsFromInputs.nix {inherit pkgs;};
|
||||
|
||||
evalSlothModules = {
|
||||
modules ? [],
|
||||
specialArgs ? {},
|
||||
}: let
|
||||
moduleConfig = evalModules {
|
||||
specialArgs = specialArgs // {inherit pkgs;};
|
||||
modules = modules ++ [sLib.defaultModule];
|
||||
};
|
||||
in
|
||||
moduleConfig.config;
|
||||
|
||||
mkNeovimPkg = {
|
||||
modules ? [],
|
||||
specialArgs ? {},
|
||||
}:
|
||||
(sLib.evalSlothModules {inherit modules specialArgs;}).neovimPackage;
|
||||
})
|
||||
callModules [
|
||||
./evalModules.nix
|
||||
./mkPluginsFromInputs.nix
|
||||
./modules
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
{pkgs, ...}: {
|
||||
inputs,
|
||||
predicate ? pkgs.lib.strings.hasPrefix "plugin-",
|
||||
nameMap ? builtins.substring 7 (-1),
|
||||
buildVimPlugin ? pkgs.vimUtils.buildVimPlugin,
|
||||
}: let
|
||||
{pkgs, ...}: let
|
||||
inherit (builtins) attrNames filter foldl' mapAttrs;
|
||||
|
||||
names = filter predicate (attrNames inputs);
|
||||
mkPlugin = m: k: let
|
||||
name = nameMap k;
|
||||
pluginDef = {
|
||||
inherit name;
|
||||
src = inputs.${k};
|
||||
};
|
||||
in {
|
||||
mkPluginsFromInputs = {
|
||||
inputs,
|
||||
predicate ? pkgs.lib.strings.hasPrefix "plugin-",
|
||||
nameMap ? builtins.substring 7 (-1),
|
||||
buildVimPlugin ? pkgs.vimUtils.buildVimPlugin,
|
||||
}: let
|
||||
names = filter predicate (attrNames inputs);
|
||||
mkPlugin = m: k: let
|
||||
name = nameMap k;
|
||||
pluginDef = {
|
||||
inherit name;
|
||||
src = inputs.${k};
|
||||
};
|
||||
in
|
||||
m // {${name} = pluginDef;};
|
||||
plugins = foldl' mkPlugin {} names;
|
||||
in
|
||||
m // {${name} = pluginDef;};
|
||||
plugins = foldl' mkPlugin {} names;
|
||||
in
|
||||
mapAttrs (_: buildVimPlugin) plugins
|
||||
mapAttrs (_: buildVimPlugin) plugins;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
{
|
||||
pkgs,
|
||||
callModule,
|
||||
sloth,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) concatLists;
|
||||
inherit (pkgs) bash lib;
|
||||
inherit
|
||||
(lib)
|
||||
concatMap
|
||||
flip
|
||||
literalExample
|
||||
mkEnableOption
|
||||
mkOption
|
||||
mkPackageOption
|
||||
optional
|
||||
optionalString
|
||||
types
|
||||
;
|
||||
|
||||
modules = {
|
||||
init = callModule ./init.nix {};
|
||||
plugin = callModule ./plugin {};
|
||||
runtime = callModule ./runtime.nix {};
|
||||
sloth = callModule ./sloth.nix {};
|
||||
};
|
||||
|
||||
extraLuaPackagesType =
|
||||
(with types; functionTo (listOf package))
|
||||
// {
|
||||
merge = loc: defs: let
|
||||
fnList = map (def: def.value) defs;
|
||||
concatPackages = ps: fn: fn ps;
|
||||
in
|
||||
ps: concatMap (concatPackages ps) fnList;
|
||||
};
|
||||
|
||||
mkDiffAlias = name:
|
||||
(flip optionalString) ''
|
||||
cat <<SH > $out/bin/${name}
|
||||
#!${bash}/bin/bash
|
||||
exec $out/bin/nvim -d "\''${@}"
|
||||
SH
|
||||
chmod 555 $out/bin/${name}
|
||||
'';
|
||||
in {
|
||||
defaultModule = {
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
pkg = pkgs.wrapNeovimUnstable config.package config.neovimOptions;
|
||||
|
||||
customLuaRC = modules.init.mkCustomLuaRc config.init;
|
||||
|
||||
plugins = concatLists [
|
||||
(map modules.plugin.extract config.plugins)
|
||||
(optional (! isNull config.runtime) (modules.runtime.mkPlugin config.runtime))
|
||||
[(modules.sloth.mkPlugin sloth.version config.plugins)]
|
||||
];
|
||||
|
||||
neovimOptions = pkgs.neovimUtils.makeNeovimConfig {
|
||||
inherit (config) extraLuaPackages viAlias vimAlias;
|
||||
inherit customLuaRC plugins;
|
||||
wrapRc = customLuaRC != null;
|
||||
# inherit customRC;
|
||||
};
|
||||
|
||||
neovimPackage = pkg.overrideAttrs (final: super: {
|
||||
postBuild =
|
||||
super.postBuild
|
||||
+ (mkDiffAlias "vimdiff" config.vimdiffAlias)
|
||||
+ (mkDiffAlias "nvimdiff" config.nvimdiffAlias);
|
||||
});
|
||||
in {
|
||||
options = {
|
||||
package = mkPackageOption pkgs "neovim-unwrapped" {};
|
||||
|
||||
# Will probably be not needed
|
||||
# dependenciesExtraArgs = mkOption {
|
||||
# default = {};
|
||||
# };
|
||||
|
||||
extraLuaPackages = mkOption {
|
||||
description = ''
|
||||
function to define extra lua packages that should be included in
|
||||
neovim environment.
|
||||
'';
|
||||
type = extraLuaPackagesType;
|
||||
example = literalExample "p: [p.nvim-nio]";
|
||||
defaultText = literalExample "_: []";
|
||||
default = _: [];
|
||||
};
|
||||
|
||||
init = modules.init.option;
|
||||
runtime = modules.runtime.option;
|
||||
plugins = modules.plugin.option;
|
||||
|
||||
viAlias = mkEnableOption "creation on `vi` alias";
|
||||
vimAlias = mkEnableOption "creation on `vim` alias";
|
||||
vimdiffAlias = mkEnableOption "creation on `vimdiff` alias";
|
||||
nvimdiffAlias = mkEnableOption "creation on `nvimdiff` alias";
|
||||
|
||||
neovimOptions = mkOption {
|
||||
type = types.attrs;
|
||||
description = "The resulting configuration passed to `pkgs.wrapNeovimUnstable`";
|
||||
default = neovimOptions;
|
||||
};
|
||||
|
||||
neovimPackage = mkOption {
|
||||
type = types.package;
|
||||
description = "The neovim package generated from your configuration.";
|
||||
# defaultText = lib.literalExpression "pkgs.hello";
|
||||
default = neovimPackage;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
fs = pkgs.lib.fileset;
|
||||
|
||||
lua = import ./lua.nix {};
|
||||
lua = import ../lua.nix {};
|
||||
|
||||
versionLua = version: with lua; nix2lua (return (lambda (return version)));
|
||||
pluginsLuaDef = plugins:
|
||||
|
|
@ -61,8 +61,8 @@ in
|
|||
inherit version;
|
||||
pname = "sloth-flake";
|
||||
src = fs.toSource {
|
||||
root = ../.;
|
||||
fileset = ../lua/sloth-flake;
|
||||
root = ../..;
|
||||
fileset = ../../lua/sloth-flake;
|
||||
};
|
||||
nvimRequireCheck = "sloth-flake";
|
||||
buildPhase = ''
|
||||
Loading…
Reference in New Issue