Skip to content

Commit

Permalink
flake: add auto flake-parts module
Browse files Browse the repository at this point in the history
When enabled, automatically sets up packages and/or checks for all
`nixvimConfigurations`
  • Loading branch information
MattSturgeon committed Jan 20, 2025
1 parent 8fb2fe2 commit e793c5c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions flake/flake-modules/auto.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{ lib, config, ... }:
let
cfg = config.nixvim;
in
{
options.nixvim = {
packages = {
enable = lib.mkEnableOption "automatically installing packages for each nixvimConfigurations";
nameFunction = lib.mkOption {
type = lib.types.functionTo lib.types.str;
description = ''
A function to convert a nixvimConfiguration's name into a package name.
**Type**
```
String -> String
```
'';
default = name: "nixvim-" + name;
defaultText = lib.literalExpression ''name: "nixvim-" + name'';
example = lib.literalExpression ''name: name + "-nvim"'';
};
};
checks = {
enable = lib.mkEnableOption "automatically installing checks for each nixvimConfigurations";
nameFunction = lib.mkOption {
type = lib.types.functionTo lib.types.str;
description = ''
A function to convert a nixvimConfiguration's name into a check name.
**Type**
```
String -> String
```
'';
default = name: "nixvim-" + name;
defaultText = lib.literalExpression ''name: "nixvim-" + name'';
example = lib.literalExpression ''name: "nixvim-" + name + "-test"'';
};
};
};
config = {
perSystem =
{ config, ... }:
{
packages = lib.mkIf cfg.packages.enable (
lib.mapAttrs' (name: configuration: {
name = cfg.packages.nameFunction name;
value = configuration.config.build.package;
}) config.nixvimConfigurations
);
checks = lib.mkIf cfg.checks.enable (
lib.mapAttrs' (name: configuration: {
name = cfg.checks.nameFunction name;
value = configuration.config.build.test;
}) config.nixvimConfigurations
);
};
};
}
1 change: 1 addition & 0 deletions flake/flake-modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let
defaultModules = {
nixvimModules = ./nixvimModules.nix;
nixvimConfigurations = ./nixvimConfigurations.nix;
auto = ./auto.nix;
};

# Modules for the flakeModules output, but not the default module
Expand Down

0 comments on commit e793c5c

Please sign in to comment.