Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental configuration-based nixvim template #2854

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flake-modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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, ... }:
{
Expand Down
8 changes: 2 additions & 6 deletions flake-modules/legacy-packages.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
4 changes: 4 additions & 0 deletions flake-modules/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
14 changes: 14 additions & 0 deletions flake-modules/nixvim-configurations.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ helpers, ... }:
{
flake.flakeModules = {
nixvimConfigurations = ./public/nixvimConfigurations.nix;
};

perSystem =
{ system, ... }:
{
nixvimConfigurations.default = helpers.modules.evalNixvim {
inherit system;
};
};
}
5 changes: 5 additions & 0 deletions flake-modules/public/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
imports = [
./nixvimConfigurations.nix
];
}
21 changes: 21 additions & 0 deletions flake-modules/public/nixvimConfigurations.nix
Original file line number Diff line number Diff line change
@@ -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;
}
33 changes: 20 additions & 13 deletions flake-modules/templates.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,7 +29,7 @@
args@{
inputs,
outputs,
sourceInfo,
sourceInfo ? { },
}:
let
outputs = args.outputs (inputs // { self = result; });
Expand All @@ -39,18 +43,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;
};
}
4 changes: 4 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ lib.makeExtensible (
transitionType
;

inherit (self.modules)
evalNixvim
;

inherit (self.options)
defaultNullOpts
mkAutoLoadOption
Expand Down
31 changes: 31 additions & 0 deletions templates/new/README.md
Original file line number Diff line number Diff line change
@@ -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.<system>.default` flake output.

You can access your configuration's package outputs `<configuration>.config.build.package`.
This is exported as the flake output `packages.<system>.default`.
This package can be run using `nix run`.

A test is also available as `<configuration>.config.build.test`.
This is exported as the flake output `checks.<system>.default`.
This test can be run using `nix flake check`.

<!-- TODO: figure out how to _wrap_ an existing configuration as a nixos/hm module -->
6 changes: 6 additions & 0 deletions templates/new/config/bufferline.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
plugins = {
bufferline.enable = true;
web-devicons.enable = true;
};
}
4 changes: 4 additions & 0 deletions templates/new/config/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# Import all your configuration modules here
imports = [ ./bufferline.nix ];
}
48 changes: 48 additions & 0 deletions templates/new/flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
}