diff --git a/extra.nix b/extra.nix new file mode 100644 index 00000000..620efe1f --- /dev/null +++ b/extra.nix @@ -0,0 +1,166 @@ +inputs: let + modulesWithInputs = import ./modules inputs; + + neovimConfiguration = { + modules ? [], + pkgs, + lib ? pkgs.lib, + check ? true, + extraSpecialArgs ? {}, + }: + modulesWithInputs { + inherit pkgs lib check extraSpecialArgs; + configuration.imports = modules; + }; + + mainConfig = isMaximal: { + config = { + vim = { + viAlias = true; + vimAlias = true; + }; + + vim.lsp = { + enable = true; + formatOnSave = true; + lightbulb.enable = true; + lspsaga.enable = false; + nvimCodeActionMenu.enable = true; + trouble.enable = true; + lspSignature.enable = true; + rust.enable = isMaximal; + python = isMaximal; + clang.enable = isMaximal; + sql = isMaximal; + ts = isMaximal; + go = isMaximal; + zig.enable = isMaximal; + nix = { + enable = true; + formatter = "alejandra"; + }; + }; + + vim.visuals = { + enable = true; + nvimWebDevicons.enable = true; + scrollBar.enable = true; + smoothScroll.enable = true; + cellularAutomaton.enable = true; + lspkind.enable = true; + indentBlankline = { + enable = true; + fillChar = ""; + eolChar = ""; + showCurrContext = true; + }; + cursorWordline = { + enable = true; + lineTimeout = 0; + }; + }; + + vim.statusline.lualine = { + enable = true; + theme = "catppuccin"; + }; + + vim.theme = { + enable = true; + name = "catppuccin"; + style = "mocha"; + }; + vim.autopairs.enable = true; + + vim.autocomplete = { + enable = true; + type = "nvim-cmp"; + }; + + vim.filetree = { + nvimTreeLua = { + enable = true; + view = { + width = 25; + }; + }; + }; + + vim.tabline = { + nvimBufferline.enable = true; + }; + + vim.treesitter = { + enable = true; + context.enable = true; + }; + + vim.binds = { + whichKey.enable = true; + cheatsheet.enable = true; + }; + + vim.telescope = { + enable = true; + }; + + vim.markdown = { + enable = true; + glow.enable = true; + }; + + vim.git = { + enable = true; + gitsigns.enable = true; + }; + + vim.minimap = { + minimap-vim.enable = false; + codewindow.enable = true; # lighter, faster, and uses lua for configuration + }; + + vim.dashboard = { + dashboard-nvim.enable = false; + alpha.enable = true; + }; + + vim.notify = { + nvim-notify.enable = true; + }; + + vim.utility = { + colorizer.enable = true; + icon-picker.enable = true; + venn-nvim.enable = false; # FIXME throws an error when its commands are ran manually + }; + + vim.notes = { + obsidian.enable = false; # FIXME neovim fails to build if obsidian is enabled + orgmode.enable = true; + }; + + vim.terminal = { + toggleterm.enable = true; + }; + + vim.ui = { + noice.enable = true; + }; + + vim.assistant = { + copilot.enable = false; + tabnine.enable = false; # FIXME: this is not working because the plugin depends on an internal script to be ran by the package manager + }; + + vim.session = { + nvim-session-manager.enable = false; + }; + + vim.gestures = { + gesture-nvim.enable = false; + }; + }; + }; +in { + inherit neovimConfiguration mainConfig; +} diff --git a/flake.lock b/flake.lock index 0c74fd21..97fc37cd 100644 --- a/flake.lock +++ b/flake.lock @@ -305,6 +305,24 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1675295133, + "narHash": "sha256-dU8fuLL98WFXG0VnRgM00bqKX6CEPBLybhiIDIgO45o=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "bf53492df08f3178ce85e0c9df8ed8d03c030c9f", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1667395993, @@ -557,6 +575,24 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1672350804, + "narHash": "sha256-jo6zkiCabUBn3ObuKXHGqqORUMH27gYDIFFfLq5P4wg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "677ed08a50931e38382dbef01cba08a8f7eac8f6", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1656753965, @@ -1014,6 +1050,7 @@ "dashboard-nvim": "dashboard-nvim", "discord-nvim": "discord-nvim", "dressing-nvim": "dressing-nvim", + "flake-parts": "flake-parts", "flake-utils": "flake-utils", "gesture-nvim": "gesture-nvim", "gitsigns-nvim": "gitsigns-nvim", diff --git a/flake.nix b/flake.nix index 18cdb89e..764f8c32 100644 --- a/flake.nix +++ b/flake.nix @@ -2,286 +2,50 @@ description = "A neovim flake with a modular configuration"; outputs = { nixpkgs, - flake-utils, + flake-parts, ... - } @ inputs: let - modulesWithInputs = import ./modules {inherit inputs;}; + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; - neovimConfiguration = { - modules ? [], - pkgs, - lib ? pkgs.lib, - check ? true, - extraSpecialArgs ? {}, - }: - modulesWithInputs { - inherit pkgs lib check extraSpecialArgs; - configuration = {...}: { - imports = modules; - }; - }; + imports = [ + # add lib to module args + {_module.args = {inherit (nixpkgs) lib;};} + ./flake/apps.nix + ./flake/legacyPackages.nix + ./flake/overlays.nix + ./flake/packages.nix + ]; - nvimBin = pkg: "${pkg}/bin/nvim"; - - buildPkg = pkgs: modules: - (neovimConfiguration { - inherit pkgs modules; - }) - .neovim; - - tidalConfig = { - config = { - vim.tidal.enable = true; - }; - }; - - mainConfig = isMaximal: { - config = { - vim = { - viAlias = true; - vimAlias = true; + flake = { + lib = { + inherit (import ./lib/stdlib-extended.nix nixpkgs.lib) nvim; + inherit (import ./extra.nix inputs) neovimConfiguration; }; - vim.lsp = { - enable = true; - formatOnSave = true; - lightbulb.enable = true; - lspsaga.enable = false; - nvimCodeActionMenu.enable = true; - trouble.enable = true; - lspSignature.enable = true; - rust.enable = isMaximal; - python = isMaximal; - clang.enable = isMaximal; - sql = isMaximal; - ts = isMaximal; - go = isMaximal; - zig.enable = isMaximal; - nix = { - enable = true; - formatter = "alejandra"; - }; - }; - - vim.visuals = { - enable = true; - nvimWebDevicons.enable = true; - scrollBar.enable = true; - smoothScroll.enable = true; - cellularAutomaton.enable = true; - lspkind.enable = true; - indentBlankline = { - enable = true; - fillChar = ""; - eolChar = ""; - showCurrContext = true; - }; - cursorWordline = { - enable = true; - lineTimeout = 0; - }; - }; - - vim.statusline.lualine = { - enable = true; - theme = "catppuccin"; - }; - - vim.theme = { - enable = true; - name = "catppuccin"; - style = "mocha"; - }; - vim.autopairs.enable = true; - - vim.autocomplete = { - enable = true; - type = "nvim-cmp"; - }; - - vim.filetree = { - nvimTreeLua = { - enable = true; - view = { - width = 25; - }; - }; - }; - - vim.tabline = { - nvimBufferline.enable = true; - }; - - vim.treesitter = { - enable = true; - context.enable = true; - }; - - vim.binds = { - whichKey.enable = true; - cheatsheet.enable = true; - }; - - vim.telescope = { - enable = true; - }; - - vim.markdown = { - enable = true; - glow.enable = true; - }; - - vim.git = { - enable = true; - gitsigns.enable = true; - }; - - vim.minimap = { - minimap-vim.enable = false; - codewindow.enable = true; # lighter, faster, and uses lua for configuration - }; - - vim.dashboard = { - dashboard-nvim.enable = false; - alpha.enable = true; - }; - - vim.notify = { - nvim-notify.enable = true; - }; - - vim.utility = { - colorizer.enable = true; - icon-picker.enable = true; - venn-nvim.enable = false; # FIXME throws an error when its commands are ran manually - }; - - vim.notes = { - obsidian.enable = false; # FIXME neovim fails to build if obsidian is enabled - orgmode.enable = true; - }; - - vim.terminal = { - toggleterm.enable = true; - }; - - vim.ui = { - noice.enable = true; - }; - - vim.assistant = { - copilot.enable = false; - tabnine.enable = false; # FIXME: this is not working because the plugin depends on an internal script to be ran by the package manager - }; - - vim.session = { - nvim-session-manager.enable = false; - }; - - vim.gestures = { - gesture-nvim.enable = false; - }; - }; - }; - - nixConfig = mainConfig false; - maximalConfig = mainConfig true; - in - { - lib = { - nvim = (import ./lib/stdlib-extended.nix nixpkgs.lib).nvim; - inherit neovimConfiguration; - }; - - overlays.default = final: prev: { - inherit neovimConfiguration; - neovim-nix = buildPkg prev [nixConfig]; - neovim-maximal = buildPkg prev [maximalConfig]; - neovim-tidal = buildPkg prev [tidalConfig]; - }; - } - // (flake-utils.lib.eachDefaultSystem ( - system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ + nixosModules.default = { + imports = [./lib/hm-module.nix]; + nixpkgs.overlays = [ inputs.tidalcycles.overlays.default - (final: prev: { - rnix-lsp = inputs.rnix-lsp.defaultPackage.${system}; - nil = inputs.nil.packages.${system}.default; - }) + inputs.self.overlays.default ]; }; + }; - docs = import ./docs { - inherit pkgs; - nmdSrc = inputs.nmd; - }; - - # Available Configurations - tidalPkg = buildPkg pkgs [tidalConfig]; - nixPkg = buildPkg pkgs [nixConfig]; - maximalPkg = buildPkg pkgs [maximalConfig]; - in { - apps = - rec { - nix = { - type = "app"; - program = nvimBin nixPkg; - }; - maximal = { - type = "app"; - program = nvimBin maximalPkg; - }; - default = nix; - } - // ( - if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) - then { - tidal = { - type = "app"; - program = nvimBin tidalPkg; - }; - } - else {} - ); - - devShells.default = pkgs.mkShell {nativeBuildInputs = [nixPkg];}; - - packages = - { - # Documentation - docs = docs.manual.html; - docs-html = docs.manual.html; - docs-manpages = docs.manPages; - docs-json = docs.options.json; - - # Available Configurations - default = nixPkg; - nix = nixPkg; - maximal = maximalPkg; - } - // ( - if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) - then { - tidal = tidalPkg; - } - else {} - ); - - nixosModules.hm-module = { - imports = [ - ./lib/hm.nix - # {nixpkgs.overlays = [inputs.self.overlays.default];} what? - ]; - }; - } - )); + perSystem = { + config, + pkgs, + ... + }: { + devShells.default = pkgs.mkShell {nativeBuildInputs = [config.packages.nix];}; + }; + }; # Flake inputs inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; # For generating documentation website nmd = { diff --git a/flake/apps.nix b/flake/apps.nix new file mode 100644 index 00000000..6b53adf9 --- /dev/null +++ b/flake/apps.nix @@ -0,0 +1,21 @@ +{lib, ...}: { + perSystem = { + system, + config, + ... + }: { + apps = + { + nix.program = lib.getExe config.packages.nix; + maximal.program = lib.getExe config.packages.maximal; + default = config.apps.nix; + } + // ( + if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) + then { + tidal.program = lib.getExe config.packages.tidal; + } + else {} + ); + }; +} diff --git a/flake/legacyPackages.nix b/flake/legacyPackages.nix new file mode 100644 index 00000000..d6fb73c7 --- /dev/null +++ b/flake/legacyPackages.nix @@ -0,0 +1,19 @@ +{inputs, ...}: { + perSystem = { + system, + inputs', + ... + }: { + legacyPackages = import inputs.nixpkgs { + inherit system; + overlays = [ + inputs.tidalcycles.overlays.default + inputs.self.overlays.default + (_: _: { + rnix-lsp = inputs'.rnix-lsp.defaultPackage; + nil = inputs'.nil.packages.default; + }) + ]; + }; + }; +} diff --git a/flake/overlays.nix b/flake/overlays.nix new file mode 100644 index 00000000..44002b5d --- /dev/null +++ b/flake/overlays.nix @@ -0,0 +1,23 @@ +{inputs, ...}: let + inherit (import ../extra.nix inputs) neovimConfiguration mainConfig; + + tidalConfig = { + config.vim.tidal.enable = true; + }; + + buildPkg = pkgs: modules: + (neovimConfiguration { + inherit pkgs modules; + }) + .neovim; + + nixConfig = mainConfig false; + maximalConfig = mainConfig true; +in { + flake.overlays.default = final: prev: { + inherit neovimConfiguration; + neovim-nix = buildPkg prev [nixConfig]; + neovim-maximal = buildPkg prev [maximalConfig]; + neovim-tidal = buildPkg prev [tidalConfig]; + }; +} diff --git a/flake/packages.nix b/flake/packages.nix new file mode 100644 index 00000000..b43f9648 --- /dev/null +++ b/flake/packages.nix @@ -0,0 +1,32 @@ +{inputs, ...}: { + perSystem = { + system, + config, + pkgs, + lib, + ... + }: { + packages = let + docs = import ../docs { + inherit pkgs; + nmdSrc = inputs.nmd; + }; + in + { + # Documentation + docs = docs.manual.html; + docs-html = docs.manual.html; + docs-manpages = docs.manPages; + docs-json = docs.options.json; + + # nvim configs + nix = config.legacyPackages.neovim-nix; + maximal = config.legacyPackages.neovim-maximal; + } + // ( + if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) + then {tidal = config.legacyPackages.neovim-tidal;} + else {} + ); + }; +} diff --git a/modules/default.nix b/modules/default.nix index edf22bd7..d8b45158 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,4 +1,4 @@ -{inputs}: { +inputs: { configuration, pkgs, lib ? pkgs.lib, @@ -6,7 +6,7 @@ extraSpecialArgs ? {}, }: let inherit (pkgs) neovim-unwrapped wrapNeovim vimPlugins; - inherit (builtins) map filter isString toString getAttr hasAttr attrNames; + inherit (builtins) map filter isString toString getAttr; inherit (pkgs.vimUtils) buildVimPluginFrom2Nix; extendedLib = import ../lib/stdlib-extended.nix lib;