From 2761e11d622ba4e0e55e219b894557e8e810836e Mon Sep 17 00:00:00 2001 From: LeMarsu Date: Wed, 11 Mar 2026 22:37:33 +0100 Subject: [PATCH] chore: remove all API code --- flake.lock | 52 +-------- flake.nix | 4 +- lib/default.nix | 23 +--- lib/deps.nix | 200 --------------------------------- lib/legacyLua.nix | 92 --------------- lib/mkNeovimPkg.nix | 117 ------------------- lib/oldMkPluginsFromInputs.nix | 20 ---- lib/types.nix | 138 ----------------------- 8 files changed, 8 insertions(+), 638 deletions(-) delete mode 100644 lib/deps.nix delete mode 100644 lib/legacyLua.nix delete mode 100644 lib/mkNeovimPkg.nix delete mode 100644 lib/oldMkPluginsFromInputs.nix delete mode 100644 lib/types.nix diff --git a/flake.lock b/flake.lock index 75643cd..b627cd3 100644 --- a/flake.lock +++ b/flake.lock @@ -49,60 +49,10 @@ "type": "github" } }, - "nixpkgs-lib_2": { - "locked": { - "lastModified": 1754788789, - "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "a73b9c743612e4244d865a2fdee11865283c04e6", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1660438583, - "narHash": "sha256-rJUTYxFKlWUJI3njAwEc1pKAVooAViZGJvsgqfh/q/E=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "bbd8f7cd87d0b29294ef3072ffdbd61d60f05da4", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, "root": { "inputs": { "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs", - "nixpkgs-lib": "nixpkgs-lib_2", - "yants": "yants" - } - }, - "yants": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1686863218, - "narHash": "sha256-kooxYm3/3ornWtVBNHM3Zh020gACUyFX2G0VQXnB+mk=", - "owner": "divnix", - "repo": "yants", - "rev": "8f0da0dba57149676aa4817ec0c880fbde7a648d", - "type": "github" - }, - "original": { - "owner": "divnix", - "repo": "yants", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 183db16..0067efb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,8 @@ { - description = "My neovim configuration"; + description = "Sloth-flake - a nix power neovim plugin manager"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - nixpkgs-lib.url = "github:nix-community/nixpkgs.lib"; - yants.url = "github:divnix/yants"; flake-parts.url = "github:hercules-ci/flake-parts"; }; diff --git a/lib/default.nix b/lib/default.nix index 8c0461f..9ebb611 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,22 +1,11 @@ -{ - self, - inputs, - ... -}: let +{self, ...}: let inherit (builtins) readFile replaceStrings; versionFile = replaceStrings ["\n"] [""] (readFile ../VERSION); - version = + dirty = if self.sourceInfo ? dirtyShortRev - then "${versionFile}-${self.sourceInfo.dirtyShortRev}" - else versionFile; - - types = import ./types.nix {inherit (inputs) yants;}; + then "-${self.sourceInfo.dirtyShortRev}" + else ""; + version = "${versionFile}${dirty}"; in { - flake = { - lib = { - mkNeovimPkg = import ./mkNeovimPkg.nix {inherit version types;}; - mkPluginsFromInputs = import ./oldMkPluginsFromInputs.nix; - }; - mkLib = import ./lib.nix {inherit version;}; - }; + flake.mkLib = import ./lib.nix {inherit version;}; } diff --git a/lib/deps.nix b/lib/deps.nix deleted file mode 100644 index 5004ba1..0000000 --- a/lib/deps.nix +++ /dev/null @@ -1,200 +0,0 @@ -{ - pkgs, - lib, - vimUtils, - dependenciesExtraArgs, - types, - ... -}: let - inherit (builtins) foldl' isPath isList isString mapAttrs match elemAt; - inherit (lib.attrsets) attrNames optionalAttrs; - inherit (lib.lists) concatMap; - inherit (lib.strings) fileContents splitString; - lua = callPackage ./legacyLua.nix {}; - callPackage = lib.callPackageWith (pkgs // dependenciesExtraArgs); - - hasMatch = pattern: str: isList (match pattern str); - wrapArray = value: - if isList value - then value - else [value]; - - defaultPlugin = { - enabled = true; - init = null; - config = null; - dependencies = []; - lazy = false; - cmd = []; - ft = []; - events = []; - keymaps = []; - }; - - remotePluginToNeovimPlugin = p: - vimUtils.buildVimPlugin rec { - inherit (p) src name; - pname = name; - }; - - defaultKeymap = {mode = "n";}; - normalizeKeymap = keymap: let - value = ( - if isString keymap - then {mapping = keymap;} - else keymap - ); - in - mapAttrs (_: wrapArray) (defaultKeymap // value); - normalizeKeymaps = keymaps: - if isList keymaps - then map normalizeKeymap keymaps - else [(normalizeKeymap keymaps)]; - - normalizeEvent = event: let - value = - if ! isString event - then event - else if ! hasMatch ".* .*" event - then {name = event;} - else let - part = elemAt (splitString " " event); - in { - name = part 0; - pattern = part 1; - }; - in - mapAttrs (_: wrapArray) value; - normalizeEvents = events: - if isList events - then map normalizeEvent events - else [(normalizeEvent events)]; - - withPluginDefaults = dep: defaultPlugin // dep; - normalizePlugin = d: let - dep = types.dependency d; - plugin = - if ! dep ? plugin - then {plugin = dep;} - else let - inherit (dep) plugin; - in - if attrNames plugin == ["name" "src"] - then dep // {plugin = remotePluginToNeovimPlugin plugin;} - else dep; - p = withPluginDefaults plugin; - in - p - // rec { - hasCommands = p.cmd != []; - hasFileTypes = p.ft != []; - keymaps = normalizeKeymaps p.keymaps; - hasKeymaps = p.keymaps != []; - events = normalizeEvents p.events; - hasEvents = p.events != []; - lazy = p.lazy || hasCommands || hasFileTypes || hasEvents || hasKeymaps; - optional = lazy || p.init != null; - }; - - normalizeOrImportPlugin = dep: - if isPath dep - then normalizePlugins (callPackage dep {}) - else [(normalizePlugin dep)]; - normalizePlugins = concatMap normalizeOrImportPlugin; - - mkRuntimePlugin = { - src, - version, - ... - }@opts: - vimUtils.buildVimPlugin ({ - inherit src; - } - // (optionalAttrs (opts ? nvimRequireCheck) { - inherit (opts) nvimRequireCheck; - }) - // (optionalAttrs (isNull version) { - name = "runtime"; - }) - // (optionalAttrs (! isNull version) { - inherit version; - pname = "runtime"; - })); - - mkSlothFlakePlugin = version: plugins: - vimUtils.buildVimPlugin { - inherit version; - pname = "sloth-flake"; - src = with lib.fileset; - toSource { - root = ../.; - fileset = ../lua/sloth-flake; - }; - nvimRequireCheck = "sloth-flake"; - buildPhase = '' - dir=lua/sloth-flake - - cat <<'LUA' > $dir/dependencies.lua - ${pluginsLuaDef plugins} - LUA - - cat <<'LUA' > $dir/version.lua - ${versionLua version} - LUA - ''; - }; - - versionLua = version: with lua; nix2lua (return (lambda [] (return version))); - - textOrContent = content: - if isPath content - then fileContents content - else content; - - pluginLuaDef = memo: plugin: let - mkTypeFn = type: let - content = textOrContent plugin.${type}; - in - optionalAttrs (! isNull plugin.${type}) { - ${type} = with lua; lambda [] (raw content); - }; - pluginName = plugin: - if plugin ? pname - then plugin.pname - else plugin.name; - name = pluginName plugin.plugin; - in - memo - // { - ${name} = - { - name = pluginName plugin.plugin; - dependencies = map pluginName plugin.dependencies; - } - // (mkTypeFn "init") - // (mkTypeFn "config") - // (optionalAttrs plugin.lazy { - lazy = true; - }) - // (optionalAttrs plugin.hasCommands { - inherit (plugin) cmd; - }) - // (optionalAttrs plugin.hasFileTypes { - inherit (plugin) ft; - }) - // (optionalAttrs plugin.hasEvents { - inherit (plugin) events; - }) - // (optionalAttrs plugin.hasKeymaps { - inherit (plugin) keymaps; - }); - }; - pluginsLuaDef = plugins: - with lua; nix2lua (return (foldl' pluginLuaDef {} plugins)); -in { - inherit normalizePlugin; - inherit normalizePlugins; - inherit mkSlothFlakePlugin; - inherit mkRuntimePlugin; - inherit textOrContent; -} diff --git a/lib/legacyLua.nix b/lib/legacyLua.nix deleted file mode 100644 index 76bf8f3..0000000 --- a/lib/legacyLua.nix +++ /dev/null @@ -1,92 +0,0 @@ -{...}: let - inherit (builtins) match isNull typeOf concatStringsSep attrNames concatMap; - fix = f: let x = f x; in x; - - commaJoin = concatStringsSep ", "; - wrapNotNull' = val: value: - if isNull val - then [] - else [value]; - wrapNotNull = val: wrapNotNull' val val; - - toLua = { - ast = { - raw = {data, ...}: data; - return = {data, ...}: "return ${nix2lua data}"; - fn = { - data, - name, - args, - ... - }: "function ${name}(${commaJoin args})\n${nix2lua data}\nend"; - }; - - type = fix (type: { - null = _: "nil"; - string = data: ''"${data}"''; - path = type.string; - lambda = data: builtins.trace "Skipping function" null; - int = data: toString data; - - bool = data: - if data - then "true" - else "false"; - - ast = data: let - astType = data.__ast; - in - if toLua.ast ? ${astType} - then toLua.ast.${astType} data - else abort ''Unknown ast type ${astType}''; - - list = data: let - nix2luaList = val: wrapNotNull (nix2lua val); - listContent = commaJoin (concatMap nix2luaList data); - in "{ ${listContent} }"; - - set = data: let - mkKeyValue = key: let - value = data.${key}; - luaKey = - if isNull (match "[a-zA-Z_][a-zA-Z_0-9]+" key) - then ''["${key}"]'' - else key; - luaValue = nix2lua value; - in - wrapNotNull' luaValue '' - ${luaKey} = ${luaValue}, - ''; - attrsContent = concatMap mkKeyValue (attrNames data); - in '' - { - ${concatStringsSep "" attrsContent}} - ''; - }); - }; - - newAst = type: set: set // {__ast = type;}; - - nix2lua = data: let - type = typeOf data; - in - if data ? __ast - then toLua.type.ast data - else if toLua.type ? ${type} - then toLua.type.${type} data - else abort ''Type "${type}"''; -in - fix (lua: { - inherit nix2lua; - - raw = data: newAst "raw" {inherit data;}; - - function = name: args: data: - newAst "fn" { - inherit name data args; - }; - - lambda = lua.function ""; - - return = data: newAst "return" {inherit data;}; - }) diff --git a/lib/mkNeovimPkg.nix b/lib/mkNeovimPkg.nix deleted file mode 100644 index 9852686..0000000 --- a/lib/mkNeovimPkg.nix +++ /dev/null @@ -1,117 +0,0 @@ -{ - version, - types, -}: { - pkgs, - package ? pkgs.neovim-unwrapped, - dependencies ? [], - dependenciesExtraArgs ? {}, - extraLuaPackages ? (_: []), - runtime ? null, - init ? null, - viAlias ? false, - vimAlias ? false, - vimdiffAlias ? false, - nvimdiffAlias ? false, - ... -} @ config: let - inherit (builtins) isString isPath map; - inherit (pkgs) callPackage bash lib; - inherit (lib.strings) optionalString; - inherit (lib.lists) concatMap optional; - inherit (lib.trivial) flip; - inherit (lib.attrsets) optionalAttrs; - - deps = callPackage ./deps.nix {inherit dependenciesExtraArgs types;}; - - normalizedPlugins = deps.normalizePlugins dependencies; - sloth-flake = deps.mkSlothFlakePlugin version normalizedPlugins; - runtimePlugin = deps.mkRuntimePlugin runtime; - plugins = - normalizedPlugins - ++ ( - deps.normalizePlugins - ([sloth-flake] ++ (optional (runtime != null) runtimePlugin)) - ); - - extractPlugin = p: {inherit (p) optional plugin;}; - extractPlugins = map extractPlugin; - - extractLuaPackageFn = plugin: - optional (plugin ? extraLuaPackages) plugin.extraLuaPackages; - extractLuaPackagesFn = plugins: let - fnList = concatMap extractLuaPackageFn plugins; - concatPackages = ps: fn: fn ps; - in - ps: concatMap (concatPackages ps) fnList; - - buildInit = { - init ? null, - postInit ? null, - config ? null, - }: let - initStr = optionalString (! isNull init) '' - (function() - ${deps.textOrContent init} - end)(); - - ''; - - slothCall = - if isNull postInit - then "require('sloth-flake').setup {}" - else '' - require('sloth-flake').setup { - post_init = function() - ${deps.textOrContent postInit} - end, - }; - ''; - - configStr = optionalString (! isNull config) '' - - (function() - ${deps.textOrContent config} - end)() - ''; - in '' - -- Generated by sloth-flake - ${initStr} - ${slothCall} - ${configStr} - ''; - - customRC = - if isString init || isPath init - then deps.textOrContent init - else buildInit (optionalAttrs (! isNull init) init); - - neovimConfig = pkgs.neovimUtils.makeNeovimConfig { - # inherit customRC; - customLuaRC = customRC; - plugins = extractPlugins plugins; - extraLuaPackages = ps: - (extractLuaPackagesFn plugins ps) ++ (extraLuaPackages ps); - inherit viAlias vimAlias; - # autoconfigure = false; - }; - # // {luaRcContent = customRC;}; - # params = - # removeAttrs neovimConfig ["neovimRcContent"] - # // {inherit viAlias vimAlias;}; - pkg = pkgs.wrapNeovimUnstable package neovimConfig; - mkDiffAlias = name: - (flip optionalString) '' - cat < $out/bin/${name} - #!${bash}/bin/bash - exec $out/bin/nvim -d "\''${@}" - SH - chmod 555 $out/bin/${name} - ''; -in - builtins.seq (types.mkNeovimPkgOptions config) (pkg.overrideAttrs (final: super: { - postBuild = - super.postBuild - + (mkDiffAlias "vimdiff" vimdiffAlias) - + (mkDiffAlias "nvimdiff" nvimdiffAlias); - })) diff --git a/lib/oldMkPluginsFromInputs.nix b/lib/oldMkPluginsFromInputs.nix deleted file mode 100644 index df450aa..0000000 --- a/lib/oldMkPluginsFromInputs.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - pkgs, - inputs, - predicate ? pkgs.lib.strings.hasPrefix "plugin-", - nameMap ? builtins.substring 7 (-1), - buildVimPlugin ? pkgs.vimUtils.buildVimPlugin, -}: 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 - m // {${name} = pluginDef;}; - plugins = foldl' mkPlugin {} names; -in - mapAttrs (_: buildVimPlugin) plugins diff --git a/lib/types.nix b/lib/types.nix deleted file mode 100644 index acb3bd6..0000000 --- a/lib/types.nix +++ /dev/null @@ -1,138 +0,0 @@ -{yants, ...}: let - stringList = with yants; list string; - stringOrStringList = with yants; either string stringList; - stringOrStringListOr = type: - with yants; - option (eitherN [string type (list (either string type))]); -in rec { - # The runtime object - runtimeType = with yants; - openStruct "runtime" { - # The version of the runtime - version = option string; - - # The content of the runtime directory - src = any; - }; - - neovimInitType = with yants; - struct "neovimInit" { - # Lua code to call before plugins loaded - init = option (either string path); - # Lua code called after init but before import - postInit = option (either string path); - # Lua code called after all plugins are loaded - config = option (either string path); - }; - - # As simple remote plugin definition - basicPluginType = with yants; - struct "basicPlugin" { - # The name of your plugin. - name = string; - # The sources of your plugin - # TODO What is the type of a source ? - src = any; - }; - - eventType = with yants; - struct "event" { - # The name of the event - name = stringOrStringList; - # The pattern of the event - pattern = stringOrStringList; - }; - - keymapType = with yants; - struct "keymap" { - # The mode of the keymap - mode = option stringOrStringList; - # The mapping of the keymap - mapping = stringOrStringList; - }; - - # The plugin type of dependencies - pluginType = with yants; - struct "plugin" { - # Whether this plugin should be enabled. This option allows specific - # plugins to be disabled. - # enable = option bool; - - # The init configuration of your plugin. - # This should be called before loading your plugin. - init = option (either path string); - - # The configuration of your plugin. - # This should be called after loading your plugin. - config = option (either path string); - - # Ensure thoses plugins are loaded before the current one - plugin = either drv basicPluginType; - - # Ensure thoses plugins are loaded before the current one - dependencies = option (list drv); - - # Ensure those packages are available - extraLuaPackages = option function; - - # Should this plugin be load lazily ? - lazy = option bool; - - # List of events on which the plugin should be loaded - events = option (stringOrStringListOr eventType); - - # List of commands on which the plugin should be loaded - cmd = option stringList; - - # List of filetypes on which the plugin should be loaded - ft = option stringList; - - # List of keystrokes on which the plugin should be loaded - keymaps = option (stringOrStringListOr keymapType); - - # Priority of the module. Influence the order of loading plugins. - # Highest values get loaded before. - # priority = option int; - }; - - # A dependency. - # TODO Complete doc - dependency = with yants; eitherN [path drv pluginType]; - - mkNeovimPkgOptions = with yants; - struct "mkNeovimPkgOptions" { - # The configuration of mkNeovimPkg - pkgs = attrs any; - - # The neovim package to wrap with your conifguration. - # Default is pkgs.neovim-unwrapped - package = option drv; - - # init.lua configuration - init = option (eitherN [string path neovimInitType]); - - # An array of dependencies. - dependencies = option (list dependency); - - # Extra argument to pass to dependencies files - dependenciesExtraArgs = option (attrs any); - - # Ensure those packages are available - extraLuaPackages = option function; - - # Runtime configuration - runtime = option runtimeType; - - # Create a vi alias - viAlias = option bool; - - # Create a vim alias - vimAlias = option bool; - - # Create a vimdiff alias to run neovim in diff mode - vimdiffAlias = option bool; - - # Create a nvimdiff alias to run neovim in diff mode - nvimdiffAlias = option bool; - }; -}