flake: export raw modules

This commit is contained in:
Pedro Alves 2023-04-21 01:34:40 +01:00
parent a6eec507cc
commit ffe3b6d3d8

303
flake.nix
View file

@ -10,175 +10,184 @@
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
outputs = { outputs =
self, { self
nixpkgs, , nixpkgs
flake-utils, , flake-utils
pre-commit-hooks, , pre-commit-hooks
... , ...
} @ inputs: } @ inputs:
with nixpkgs.lib; with nixpkgs.lib;
with builtins; let with builtins; let
# TODO: Support nesting # TODO: Support nesting
nixvimModules = map (f: ./modules + "/${f}") (attrNames (builtins.readDir ./modules)); nixvimModules = map (f: ./modules + "/${f}") (attrNames (builtins.readDir ./modules));
modules = pkgs: modules = pkgs:
nixvimModules nixvimModules
++ [ ++ [
rec { rec {
_file = ./flake.nix; _file = ./flake.nix;
key = _file; key = _file;
config = { config = {
_module.args = { _module.args = {
pkgs = mkForce pkgs; pkgs = mkForce pkgs;
inherit (pkgs) lib; inherit (pkgs) lib;
helpers = import ./plugins/helpers.nix {inherit (pkgs) lib;}; helpers = import ./plugins/helpers.nix { inherit (pkgs) lib; };
inputs = inputs; inputs = inputs;
};
}; };
}; }
}
# ./plugins/default.nix # ./plugins/default.nix
]; ];
flakeOutput = flakeOutput =
flake-utils.lib.eachDefaultSystem flake-utils.lib.eachDefaultSystem
(system: let (system:
pkgs = import nixpkgs {inherit system;}; let
extractRustAnalyzer = { pkgs = import nixpkgs { inherit system; };
stdenv, extractRustAnalyzer =
pkgs, { stdenv
}: , pkgs
stdenv.mkDerivation { ,
pname = "extract_rust_analyzer"; }:
version = "master"; stdenv.mkDerivation {
pname = "extract_rust_analyzer";
version = "master";
dontUnpack = true; dontUnpack = true;
dontBuild = true; dontBuild = true;
buildInputs = [pkgs.python3]; buildInputs = [ pkgs.python3 ];
installPhase = '' installPhase = ''
ls -la ls -la
mkdir -p $out/bin mkdir -p $out/bin
cp ${./helpers/extract_rust_analyzer.py} $out/bin/extract_rust_analyzer.py cp ${./helpers/extract_rust_analyzer.py} $out/bin/extract_rust_analyzer.py
''; '';
}; };
extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer {}; extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer { };
in { in
checks = {
(import ./tests { checks =
inherit pkgs; (import ./tests {
inherit (pkgs) lib; inherit pkgs;
makeNixvim = self.legacyPackages."${system}".makeNixvim; inherit (pkgs) lib;
}) makeNixvim = self.legacyPackages."${system}".makeNixvim;
// { })
lib-tests = import ./tests/lib-tests.nix { // {
inherit (pkgs) pkgs lib; lib-tests = import ./tests/lib-tests.nix {
}; inherit (pkgs) pkgs lib;
pre-commit-check = pre-commit-hooks.lib.${system}.run { };
src = ./.; pre-commit-check = pre-commit-hooks.lib.${system}.run {
hooks = { src = ./.;
alejandra = { hooks = {
enable = true; alejandra = {
excludes = ["plugins/_sources"]; enable = true;
excludes = [ "plugins/_sources" ];
};
};
};
};
devShells = {
default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
}; };
}; };
}; packages = {
}; docs = pkgs.callPackage (import ./docs.nix) {
devShells = { modules = nixvimModules;
default = pkgs.mkShell { };
inherit (self.checks.${system}.pre-commit-check) shellHook; runUpdates =
}; pkgs.callPackage
}; ({ pkgs
packages = { , stdenv
docs = pkgs.callPackage (import ./docs.nix) { ,
modules = nixvimModules; }:
}; stdenv.mkDerivation {
runUpdates = pname = "run-updates";
pkgs.callPackage version = pkgs.rust-analyzer.version;
({
pkgs,
stdenv,
}:
stdenv.mkDerivation {
pname = "run-updates";
version = pkgs.rust-analyzer.version;
src = pkgs.rust-analyzer.src; src = pkgs.rust-analyzer.src;
nativeBuildInputs = with pkgs; [extractRustAnalyzerPkg alejandra]; nativeBuildInputs = with pkgs; [ extractRustAnalyzerPkg alejandra ];
buildPhase = '' buildPhase = ''
extract_rust_analyzer.py editors/code/package.json | extract_rust_analyzer.py editors/code/package.json |
alejandra --quiet > rust-analyzer-config.nix alejandra --quiet > rust-analyzer-config.nix
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/share mkdir -p $out/share
cp rust-analyzer-config.nix $out/share cp rust-analyzer-config.nix $out/share
''; '';
}) })
{}; { };
# Used to updates plugins, launch 'nix run .#nvfetcher' in the 'plugins' directory # Used to updates plugins, launch 'nix run .#nvfetcher' in the 'plugins' directory
nvfetcher = pkgs.nvfetcher; nvfetcher = pkgs.nvfetcher;
};
legacyPackages = rec {
makeNixvimWithModule = import ./wrappers/standalone.nix pkgs modules;
makeNixvim = configuration:
makeNixvimWithModule {
module = {
config = configuration;
}; };
}; legacyPackages = rec {
}; makeNixvimWithModule = import ./wrappers/standalone.nix pkgs modules;
formatter = let makeNixvim = configuration:
# We need to exclude the plugins/_sources/* files as they are autogenerated makeNixvimWithModule {
# nix formatter only takes a derivation so we need to make a proxy that passes module = {
# the correct flags config = configuration;
excludeWrapper = { };
stdenv, };
alejandra, };
writeShellScript, formatter =
... let
}: # We need to exclude the plugins/_sources/* files as they are autogenerated
stdenv.mkDerivation { # nix formatter only takes a derivation so we need to make a proxy that passes
pname = "alejandra-excludes"; # the correct flags
version = alejandra.version; excludeWrapper =
{ stdenv
, alejandra
, writeShellScript
, ...
}:
stdenv.mkDerivation {
pname = "alejandra-excludes";
version = alejandra.version;
dontUnpack = true; dontUnpack = true;
dontBuild = true; dontBuild = true;
installPhase = let installPhase =
script = writeShellScript "alejandra-excludes.sh" '' let
${alejandra}/bin/alejandra --exclude ./plugins/_sources "$@" script = writeShellScript "alejandra-excludes.sh" ''
''; ${alejandra}/bin/alejandra --exclude ./plugins/_sources "$@"
in '' '';
mkdir -p $out/bin in
cp ${script} $out/bin/alejandra-excludes ''
''; mkdir -p $out/bin
}; cp ${script} $out/bin/alejandra-excludes
in '';
pkgs.callPackage excludeWrapper {}; };
in
pkgs.callPackage excludeWrapper { };
lib = import ./lib { lib = import ./lib {
inherit pkgs; inherit pkgs;
inherit (pkgs) lib; inherit (pkgs) lib;
}; };
}); });
in in
flakeOutput flakeOutput
// { // {
nixosModules.nixvim = import ./wrappers/nixos.nix modules; nixosModules.nixvim = import ./wrappers/nixos.nix modules;
homeManagerModules.nixvim = import ./wrappers/hm.nix modules; homeManagerModules.nixvim = import ./wrappers/hm.nix modules;
nixDarwinModules.nixvim = import ./wrappers/darwin.nix modules; nixDarwinModules.nixvim = import ./wrappers/darwin.nix modules;
rawModules.nixvim = modules;
templates = let templates =
simple = { let
path = ./templates/simple; simple = {
description = "A simple nix flake template for getting started with nixvim"; path = ./templates/simple;
description = "A simple nix flake template for getting started with nixvim";
};
in
{
default = simple;
}; };
in {
default = simple;
};
}; };
} }