Skip to content

Commit

Permalink
flake.nix: refactoring using flake-parts
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 5, 2024
1 parent 1f1065d commit 31284dd
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 202 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,38 @@ can use the following:
description = "A very basic flake";
inputs.nixvim.url = "github:nix-community/nixvim";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = {
self,
nixpkgs,
nixvim,
flake-utils,
}: let
flake-parts,
} @ inputs: let
config = {
colorschemes.gruvbox.enable = true;
};
in
flake-utils.lib.eachDefaultSystem (system: let
nixvim' = nixvim.legacyPackages."${system}";
nvim = nixvim'.makeNixvim config;
in {
packages = {
inherit nvim;
default = nvim;
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
perSystem = {
pkgs,
system,
...
}: let
nixvim' = nixvim.legacyPackages."${system}";
nvim = nixvim'.makeNixvim config;
in {
packages = {
inherit nvim;
default = nvim;
};
};
});
};
}
```
</details>
Expand Down
31 changes: 31 additions & 0 deletions flake-modules/checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
perSystem = {
pkgs,
makeNixvimWithModuleUnfree,
makeNixvimWithModule,
...
}: {
checks = {
tests = import ../tests {
inherit pkgs;
inherit (pkgs) lib;
makeNixvim = configuration:
makeNixvimWithModuleUnfree {
module = {
config = configuration;
};
};
};

extra-args-tests = import ../tests/extra-args.nix {
inherit pkgs;
inherit makeNixvimWithModule;
};

lib-tests = import ../tests/lib-tests.nix {
inherit pkgs;
inherit (pkgs) lib;
};
};
};
}
26 changes: 26 additions & 0 deletions flake-modules/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{inputs, ...}: {
imports = [
./checks.nix
./dev.nix
./lib.nix
./legacy-packages.nix
./modules.nix
./overlays.nix
./packages.nix
./templates.nix
./wrappers.nix
];

perSystem = {
pkgs,
system,
...
}: {
_module.args = {
pkgsUnfree = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
};
};
}
29 changes: 29 additions & 0 deletions flake-modules/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{inputs, ...}: {
imports = [
inputs.pre-commit-hooks.flakeModule
];

perSystem = {
pkgs,
config,
...
}: {
devShells.default = pkgs.mkShellNoCC {
shellHook = config.pre-commit.installationScript;
};

formatter = pkgs.alejandra;

pre-commit = {
settings.hooks = {
alejandra.enable = true;
statix = {
enable = true;
excludes = [
"plugins/lsp/language-servers/rust-analyzer-config.nix"
];
};
};
};
};
}
18 changes: 18 additions & 0 deletions flake-modules/legacy-packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
perSystem = {
pkgs,
config,
makeNixvimWithModule,
...
}: {
legacyPackages = rec {
inherit makeNixvimWithModule;
makeNixvim = configuration:
makeNixvimWithModule {
module = {
config = configuration;
};
};
};
};
}
20 changes: 20 additions & 0 deletions flake-modules/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
config,
lib,
withSystem,
...
}: {
flake.lib = lib.genAttrs config.systems (
lib.flip withSystem (
{
pkgs,
config,
...
}:
import ../lib {
inherit pkgs lib;
inherit (config.legacyPackages) makeNixvim;
}
)
);
}
47 changes: 47 additions & 0 deletions flake-modules/modules.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
modules,
inputs,
...
}: {
_module.args = let
nixvimModules = with builtins;
map
(f: ../modules + "/${f}")
(
attrNames (readDir ../modules)
);
in {
modules = pkgs: let
nixpkgsMaintainersList = pkgs.path + "/nixos/modules/misc/meta.nix";

nixvimExtraArgsModule = rec {
_file = ./flake.nix;
key = _file;
config = {
_module.args = {
pkgs = pkgs.lib.mkForce pkgs;
inherit (pkgs) lib;
helpers = import ../lib/helpers.nix {inherit (pkgs) lib;};
# TODO: Not sure why the modules need to access the whole flake inputs...
inherit inputs;
};
};
};
in
nixvimModules
++ [
nixpkgsMaintainersList
nixvimExtraArgsModule
];
};

perSystem = {
pkgs,
config,
...
}: {
_module.args = {
modules = modules pkgs;
};
};
}
21 changes: 21 additions & 0 deletions flake-modules/overlays.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{inputs, ...}: {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];
perSystem = {
config,
pkgs,
final,
...
}: {
overlayAttrs = {
nixvim = {
inherit
(config.legacyPackages)
makeNixvim
makeNixvimWithModule
;
};
};
};
}
28 changes: 28 additions & 0 deletions flake-modules/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
perSystem = {
pkgs,
pkgsUnfree,
config,
modules,
...
}: {
packages = let
docs = {
docs = pkgsUnfree.callPackage (import ../docs) {
inherit modules;
};
};

man-docs = import ../man-docs {
pkgs = pkgsUnfree;
inherit modules;
};

# TODO: deprecate (unused)
helpers = import ../helpers pkgs;
in
docs
// man-docs
// helpers;
};
}
8 changes: 8 additions & 0 deletions flake-modules/templates.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
flake.templates = {
default = {
path = ../templates/simple;
description = "A simple nix flake template for getting started with nixvim";
};
};
}
35 changes: 35 additions & 0 deletions flake-modules/wrappers.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
modules,
self,
...
}: let
wrapperArgs = {
inherit modules;
inherit self;
};
in {
perSystem = {
pkgs,
pkgsUnfree,
config,
...
}: {
_module.args = {
makeNixvimWithModule =
import ../wrappers/standalone.nix
pkgs
wrapperArgs;

makeNixvimWithModuleUnfree =
import ../wrappers/standalone.nix
pkgsUnfree
wrapperArgs;
};
};

flake = {
nixosModules.nixvim = import ./nixos.nix wrapperArgs;
homeManagerModules.nixvim = import ./wrappers/hm.nix wrapperArgs;
nixDarwinModules.nixvim = import ./wrappers/darwin.nix wrapperArgs;
};
}
Loading

0 comments on commit 31284dd

Please sign in to comment.