From 7517509f2abba8915e30a8b164bc18ed510fcfc5 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 18 Jan 2025 06:37:02 +0000 Subject: [PATCH 1/4] lib: export `evalNixvim` as top-level alias - `lib.nixvim.evalNixvim` - `.lib.evalNixvim` (flake output) --- flake-modules/lib.nix | 4 ++++ lib/default.nix | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/flake-modules/lib.nix b/flake-modules/lib.nix index 2e606f5128..25e90ec6ca 100644 --- a/flake-modules/lib.nix +++ b/flake-modules/lib.nix @@ -21,6 +21,10 @@ overlay = lib.makeOverridable (import ../lib/overlay.nix) { flake = self; }; + # Top-top-level aliases + inherit (self.lib.nixvim) + evalNixvim + ; } // lib.genAttrs config.systems ( lib.flip withSystem ( diff --git a/lib/default.nix b/lib/default.nix index 64b92a667e..c0d1b935ad 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -44,6 +44,10 @@ lib.makeExtensible ( transitionType ; + inherit (self.modules) + evalNixvim + ; + inherit (self.options) defaultNullOpts mkAutoLoadOption From 9f71591158972790086af3c02b64c4d7952ec617 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 18 Jan 2025 08:21:23 +0000 Subject: [PATCH 2/4] flake: add public nixvimConfigurations flake-module Can be used by end-users to define `perSystem.nixvimConfigurations` using flake-parts. --- flake-modules/default.nix | 7 +++++++ flake-modules/legacy-packages.nix | 8 ++----- flake-modules/nixvim-configurations.nix | 14 +++++++++++++ flake-modules/public/default.nix | 5 +++++ flake-modules/public/nixvimConfigurations.nix | 21 +++++++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 flake-modules/nixvim-configurations.nix create mode 100644 flake-modules/public/default.nix create mode 100644 flake-modules/public/nixvimConfigurations.nix diff --git a/flake-modules/default.nix b/flake-modules/default.nix index 69df8a41e2..86d38bf2fa 100644 --- a/flake-modules/default.nix +++ b/flake-modules/default.nix @@ -2,15 +2,22 @@ { imports = [ ./dev + ./public ./lib.nix ./legacy-packages.nix + ./nixvim-configurations.nix ./overlays.nix ./packages.nix ./templates.nix ./tests.nix ./wrappers.nix + inputs.flake-parts.flakeModules.flakeModules ]; + flake.flakeModules = { + default = ./public; + }; + perSystem = { system, ... }: { diff --git a/flake-modules/legacy-packages.nix b/flake-modules/legacy-packages.nix index 323decc7a6..ac83fd99fd 100644 --- a/flake-modules/legacy-packages.nix +++ b/flake-modules/legacy-packages.nix @@ -1,19 +1,15 @@ -{ helpers, ... }: { perSystem = { + config, makeNixvimWithModule, - system, ... }: { legacyPackages = rec { inherit makeNixvimWithModule; makeNixvim = module: makeNixvimWithModule { inherit module; }; - - nixvimConfiguration = helpers.modules.evalNixvim { - inherit system; - }; + nixvimConfiguration = config.nixvimConfigurations.default; }; }; } diff --git a/flake-modules/nixvim-configurations.nix b/flake-modules/nixvim-configurations.nix new file mode 100644 index 0000000000..bb47b5341a --- /dev/null +++ b/flake-modules/nixvim-configurations.nix @@ -0,0 +1,14 @@ +{ helpers, ... }: +{ + flake.flakeModules = { + nixvimConfigurations = ./public/nixvimConfigurations.nix; + }; + + perSystem = + { system, ... }: + { + nixvimConfigurations.default = helpers.modules.evalNixvim { + inherit system; + }; + }; +} diff --git a/flake-modules/public/default.nix b/flake-modules/public/default.nix new file mode 100644 index 0000000000..946cd8c3a0 --- /dev/null +++ b/flake-modules/public/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./nixvimConfigurations.nix + ]; +} diff --git a/flake-modules/public/nixvimConfigurations.nix b/flake-modules/public/nixvimConfigurations.nix new file mode 100644 index 0000000000..89830e0f59 --- /dev/null +++ b/flake-modules/public/nixvimConfigurations.nix @@ -0,0 +1,21 @@ +{ lib, flake-parts-lib, ... }: +let + configurationType = lib.mkOptionType { + name = "configuration"; + description = "configuration"; + descriptionClass = "noun"; + merge = lib.options.mergeOneOption; + check = x: x._type or null == "configuration"; + }; +in +flake-parts-lib.mkTransposedPerSystemModule { + name = "nixvimConfigurations"; + option = lib.mkOption { + type = lib.types.lazyAttrsOf configurationType; + default = { }; + description = '' + An attribute set of Nixvim configurations. + ''; + }; + file = ./nixvimConfigurations.nix; +} From c6eb1858b0b7458738edebb03b6105f73409da1b Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 18 Jan 2025 06:55:28 +0000 Subject: [PATCH 3/4] templates: inherit `checks` from _all_ templates --- flake-modules/templates.nix | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/flake-modules/templates.nix b/flake-modules/templates.nix index c8338d6cb7..7de4151fb1 100644 --- a/flake-modules/templates.nix +++ b/flake-modules/templates.nix @@ -25,7 +25,7 @@ args@{ inputs, outputs, - sourceInfo, + sourceInfo ? { }, }: let outputs = args.outputs (inputs // { self = result; }); @@ -39,18 +39,21 @@ in result; - templateFlakeOutputs = callFlake { - inputs = { - inherit (inputs) flake-parts nixpkgs; - nixvim = self; - }; - # Import and read the `outputs` field of the template flake. - inherit (import ../templates/simple/flake.nix) outputs; - sourceInfo = { }; - }; - - templateChecks = templateFlakeOutputs.checks.${system}; + flakes = lib.mapAttrs ( + name: template: + callFlake { + # Use inputs from our flake + inputs = { + inherit (inputs) flake-parts nixpkgs; + nixvim = self; + }; + # Use outputs from the template flake + inherit (import "${template.path}/flake.nix") outputs; + } + ) self.templates; in - lib.concatMapAttrs (checkName: check: { "template-${checkName}" = check; }) templateChecks; + lib.concatMapAttrs (name: flake: { + "template-${name}" = pkgs.linkFarm name flake.checks.${system}; + }) flakes; }; } From 94fd1ae0f969d555a34848a79eee2be9df9c0eda Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 18 Jan 2025 06:38:54 +0000 Subject: [PATCH 4/4] templates: add experimental `evalNixvim` template --- flake-modules/templates.nix | 4 +++ templates/new/README.md | 31 +++++++++++++++++++ templates/new/config/bufferline.nix | 6 ++++ templates/new/config/default.nix | 4 +++ templates/new/flake.nix | 48 +++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 templates/new/README.md create mode 100644 templates/new/config/bufferline.nix create mode 100644 templates/new/config/default.nix create mode 100644 templates/new/flake.nix diff --git a/flake-modules/templates.nix b/flake-modules/templates.nix index 7de4151fb1..0bf17f41fa 100644 --- a/flake-modules/templates.nix +++ b/flake-modules/templates.nix @@ -5,6 +5,10 @@ path = ../templates/simple; description = "A simple nix flake template for getting started with nixvim"; }; + new = { + path = ../templates/new; + description = "An experimental flake template for configuring nixvim directly with evalNixvim"; + }; }; # The following adds the template flake's checks to the main (current) flake's checks. diff --git a/templates/new/README.md b/templates/new/README.md new file mode 100644 index 0000000000..7f1d4650c1 --- /dev/null +++ b/templates/new/README.md @@ -0,0 +1,31 @@ +# New Nixvim template + +This template gives you a good starting point for configuring nixvim as a standalone module configuration. + +## Configuring + +To start configuring, just add or modify the module files in `./config`. +If you add new modules, remember to import them in [`./config/default.nix`](./config/default.nix). + +## Using your vim configuration + +To use your configuration simply run the following command + +``` +nix run +``` + +## Configurations and packages + +Your nixvim configuration is created using `evalNixvim`. +This is outputted as the `nixvimConfigurations..default` flake output. + +You can access your configuration's package outputs `.config.build.package`. +This is exported as the flake output `packages..default`. +This package can be run using `nix run`. + +A test is also available as `.config.build.test`. +This is exported as the flake output `checks..default`. +This test can be run using `nix flake check`. + + diff --git a/templates/new/config/bufferline.nix b/templates/new/config/bufferline.nix new file mode 100644 index 0000000000..2dfee9eefb --- /dev/null +++ b/templates/new/config/bufferline.nix @@ -0,0 +1,6 @@ +{ + plugins = { + bufferline.enable = true; + web-devicons.enable = true; + }; +} diff --git a/templates/new/config/default.nix b/templates/new/config/default.nix new file mode 100644 index 0000000000..fb318aba7e --- /dev/null +++ b/templates/new/config/default.nix @@ -0,0 +1,4 @@ +{ + # Import all your configuration modules here + imports = [ ./bufferline.nix ]; +} diff --git a/templates/new/flake.nix b/templates/new/flake.nix new file mode 100644 index 0000000000..09e87ca2f3 --- /dev/null +++ b/templates/new/flake.nix @@ -0,0 +1,48 @@ +{ + description = "A nixvim configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixvim.url = "github:nix-community/nixvim"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = + { nixvim, flake-parts, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + imports = [ + # Import nixvim's flake-parts module, to enable defining `nixvimConfigurations` + nixvim.flakeModules.default + ]; + + perSystem = + { config, system, ... }: + { + nixvimConfigurations = { + default = nixvim.lib.evalNixvim { + inherit system; + modules = [ + ./config + ]; + }; + }; + + checks = { + # Run `nix flake check .` to verify that your config is not broken + default = config.nixvimConfigurations.default.config.build.test; + }; + + packages = { + # Lets you run `nix run .` to start nixvim + default = config.nixvimConfigurations.default.config.build.package; + }; + }; + }; +}