From e3938e9464c2f860bfe303dd986243880c0b4075 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 18 Jan 2025 06:55:28 +0000 Subject: [PATCH 1/2] templates: inherit `checks` from _all_ templates --- flake/templates.nix | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/flake/templates.nix b/flake/templates.nix index c8338d6cb7..7de4151fb1 100644 --- a/flake/templates.nix +++ b/flake/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 342161bf525dd64eb53fea295a2180f71ed06de1 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 18 Jan 2025 06:38:54 +0000 Subject: [PATCH 2/2] templates: add experimental-flake-parts template This template uses the lower-level `evalNixvim` function to work directly with nixvim configurations, instead of the prior idiom of using `makeNixvim` to produce nixvim packages. Additionally, the template is build on flake.parts, and demonstrates using our recently added flakeModules. --- flake/templates.nix | 4 ++ templates/experimental-flake-parts/README.md | 31 +++++++++++ .../config/bufferline.nix | 6 +++ .../config/default.nix | 4 ++ templates/experimental-flake-parts/flake.nix | 54 +++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 templates/experimental-flake-parts/README.md create mode 100644 templates/experimental-flake-parts/config/bufferline.nix create mode 100644 templates/experimental-flake-parts/config/default.nix create mode 100644 templates/experimental-flake-parts/flake.nix diff --git a/flake/templates.nix b/flake/templates.nix index 7de4151fb1..c0f25e8492 100644 --- a/flake/templates.nix +++ b/flake/templates.nix @@ -5,6 +5,10 @@ path = ../templates/simple; description = "A simple nix flake template for getting started with nixvim"; }; + new = { + path = ../templates/experimental-flake-parts; + description = "An experimental flake template for configuring nixvim using evalNixvim and flake.parts"; + }; }; # The following adds the template flake's checks to the main (current) flake's checks. diff --git a/templates/experimental-flake-parts/README.md b/templates/experimental-flake-parts/README.md new file mode 100644 index 0000000000..7f1d4650c1 --- /dev/null +++ b/templates/experimental-flake-parts/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/experimental-flake-parts/config/bufferline.nix b/templates/experimental-flake-parts/config/bufferline.nix new file mode 100644 index 0000000000..2dfee9eefb --- /dev/null +++ b/templates/experimental-flake-parts/config/bufferline.nix @@ -0,0 +1,6 @@ +{ + plugins = { + bufferline.enable = true; + web-devicons.enable = true; + }; +} diff --git a/templates/experimental-flake-parts/config/default.nix b/templates/experimental-flake-parts/config/default.nix new file mode 100644 index 0000000000..fb318aba7e --- /dev/null +++ b/templates/experimental-flake-parts/config/default.nix @@ -0,0 +1,4 @@ +{ + # Import all your configuration modules here + imports = [ ./bufferline.nix ]; +} diff --git a/templates/experimental-flake-parts/flake.nix b/templates/experimental-flake-parts/flake.nix new file mode 100644 index 0000000000..3ebd75870e --- /dev/null +++ b/templates/experimental-flake-parts/flake.nix @@ -0,0 +1,54 @@ +{ + 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 = + { self, 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; + # Adds `flake.nixvimModules` and `perSystem.nixvimConfigurations` + inputs.nixvim.flakeModules.default + ]; + + nixvim = { + # Automatically install corresponding packages for each nixvimConfiguration + # Lets you run `nix run .#`, or simply `nix run` if you have a default + packages.enable = true; + # Automatically install checks for each nixvimConfiguration + # Run `nix flake check` to verify that your config is not broken + checks.enable = true; + }; + + # You can define your reusable Nixvim modules here + flake.nixvimModules = { + default = ./config; + }; + + perSystem = + { system, ... }: + { + # You can define actual Nixvim configurations here + nixvimConfigurations = { + default = inputs.nixvim.lib.evalNixvim { + inherit system; + modules = [ + self.nixvimModules.default + ]; + }; + }; + }; + }; +}