forked from extern/flakelight
Split up builtinModule into multiple modules
This commit is contained in:
parent
9c40724207
commit
1c8ac213b0
7
builtin-modules/default-formatters.nix
Normal file
7
builtin-modules/default-formatters.nix
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
_: {
|
||||||
|
devTools = pkgs: with pkgs; [ nixpkgs-fmt nodePackages.prettier ];
|
||||||
|
formatters = {
|
||||||
|
"*.nix" = "nixpkgs-fmt";
|
||||||
|
"*.md | *.json | *.yml" = "prettier --write";
|
||||||
|
};
|
||||||
|
}
|
13
builtin-modules/editorconfig.nix
Normal file
13
builtin-modules/editorconfig.nix
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ src, lib }:
|
||||||
|
let
|
||||||
|
inherit (lib) getExe optionalAttrs optionalString pathExists;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
checks = optionalAttrs (pathExists (src + /.editorconfig)) {
|
||||||
|
# By default, high false-positive flags are disabled.
|
||||||
|
editorconfig = { editorconfig-checker }:
|
||||||
|
"${getExe editorconfig-checker}"
|
||||||
|
+ optionalString (!pathExists (src + /.ecrc))
|
||||||
|
" -disable-indent-size -disable-max-line-length";
|
||||||
|
};
|
||||||
|
}
|
10
builtin-modules/pre-commit-hook.nix
Normal file
10
builtin-modules/pre-commit-hook.nix
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
_: {
|
||||||
|
shellHook = { lib, flakelite }: ''
|
||||||
|
if [ -f flake.nix ] && [ -d .git/hooks ] &&
|
||||||
|
[ ! -f .git/hooks/pre-commit ]; then
|
||||||
|
echo Installing git pre-commit hook...
|
||||||
|
cp ${lib.getExe flakelite.inputs'.flakelite.packages.pre-commit
|
||||||
|
} .git/hooks
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
}
|
87
default.nix
87
default.nix
@ -5,12 +5,12 @@
|
|||||||
localInputs:
|
localInputs:
|
||||||
let
|
let
|
||||||
inherit (builtins) intersectAttrs isPath readDir;
|
inherit (builtins) intersectAttrs isPath readDir;
|
||||||
inherit (localInputs.nixpkgs.lib) attrNames attrVals callPackageWith
|
inherit (localInputs.nixpkgs.lib) attrNames attrVals attrValues
|
||||||
composeManyExtensions concat concatStringsSep filter filterAttrs foldAttrs
|
callPackageWith composeManyExtensions concat concatStringsSep filter
|
||||||
foldl functionArgs genAttrs hasSuffix isFunction isList isString listToAttrs
|
filterAttrs foldAttrs foldl functionArgs genAttrs hasSuffix isFunction
|
||||||
mapAttrs mapAttrsToList mapAttrs' mergeAttrs nameValuePair optional
|
isList isString listToAttrs mapAttrs mapAttrsToList mapAttrs' mergeAttrs
|
||||||
optionalAttrs optionalString parseDrvName pathExists pipe recursiveUpdate
|
nameValuePair optional optionalAttrs parseDrvName pathExists pipe
|
||||||
removePrefix removeSuffix zipAttrsWith;
|
recursiveUpdate removePrefix removeSuffix zipAttrsWith;
|
||||||
|
|
||||||
/* Attributes in flakelite's lib output.
|
/* Attributes in flakelite's lib output.
|
||||||
*/
|
*/
|
||||||
@ -23,60 +23,39 @@ let
|
|||||||
|
|
||||||
/* Module which is always included as first module.
|
/* Module which is always included as first module.
|
||||||
*/
|
*/
|
||||||
builtinModule = { src, inputs, root }: {
|
baseModule = { inputs, root, args }: {
|
||||||
# Ensures nixpkgs and flakelite are available for modules.
|
# Ensures nixpkgs and flakelite are available for modules.
|
||||||
inputs = {
|
inputs = {
|
||||||
flakelite = localInputs.self;
|
flakelite = localInputs.self;
|
||||||
inherit (localInputs) nixpkgs;
|
inherit (localInputs) nixpkgs;
|
||||||
};
|
};
|
||||||
withOverlays = params: [
|
withOverlay = final: prev: {
|
||||||
(final: prev: {
|
# Allows access to flakelite lib functions from package sets.
|
||||||
# Allows access to flakelite lib functions from package sets.
|
# Also adds pkgs-specific additional args.
|
||||||
# Also adds pkgs-specific additional args.
|
flakelite = args // {
|
||||||
flakelite = params // {
|
# Inputs with system auto-selected.
|
||||||
# Inputs with system auto-selected.
|
# i.e. inputs.self.packages.${system} -> inputs'.self.packages
|
||||||
# i.e. inputs.self.packages.${system} -> inputs'.self.packages
|
inputs' = mapAttrs
|
||||||
inputs' = mapAttrs
|
(_: mapAttrs
|
||||||
(_: mapAttrs
|
(_: v: v.${prev.system} or { }))
|
||||||
(_: v: v.${prev.system} or { }))
|
inputs;
|
||||||
inputs;
|
# Default package meta attribute generated from root module attrs.
|
||||||
# Default package meta attribute generated from root module attrs.
|
meta = {
|
||||||
meta = {
|
platforms = root.systems;
|
||||||
platforms = root.systems;
|
} // optionalAttrs (root ? description) {
|
||||||
} // optionalAttrs (root ? description) {
|
inherit (root) description;
|
||||||
inherit (root) description;
|
} // optionalAttrs (root ? license) {
|
||||||
} // optionalAttrs (root ? license) {
|
license =
|
||||||
license =
|
if isList root.license
|
||||||
if isList root.license
|
then attrVals root.license final.lib.licenses
|
||||||
then attrVals root.license final.lib.licenses
|
else final.lib.licenses.${root.license};
|
||||||
else final.lib.licenses.${root.license};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
})
|
};
|
||||||
];
|
|
||||||
checks = { pkgs, lib, ... }:
|
|
||||||
# Enable editorconfig support if detected.
|
|
||||||
# By default, high false-positive flags are disabled.
|
|
||||||
(optionalAttrs (pathExists (src + /.editorconfig)) {
|
|
||||||
editorconfig = "${lib.getExe pkgs.editorconfig-checker}"
|
|
||||||
+ optionalString (!pathExists (src + /.ecrc))
|
|
||||||
" -disable-indent-size -disable-max-line-length";
|
|
||||||
});
|
|
||||||
shellHook = { lib, flakelite }: ''
|
|
||||||
if [ -f flake.nix ] && [ -d .git/hooks ] &&
|
|
||||||
[ ! -f .git/hooks/pre-commit ]; then
|
|
||||||
echo Installing git pre-commit hook...
|
|
||||||
cp ${lib.getExe flakelite.inputs'.flakelite.packages.pre-commit
|
|
||||||
} .git/hooks
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
devTools = pkgs: with pkgs; [ nixpkgs-fmt nodePackages.prettier ];
|
|
||||||
formatters = {
|
|
||||||
"*.nix" = "nixpkgs-fmt";
|
|
||||||
"*.md | *.json | *.yml" = "prettier --write";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
builtinModules = attrValues (importDir ./builtin-modules);
|
||||||
|
|
||||||
/* Import each nix file in a directory as attrs. Attr name is file name with
|
/* Import each nix file in a directory as attrs. Attr name is file name with
|
||||||
extension stripped. To allow use in an importable directory, default.nix is
|
extension stripped. To allow use in an importable directory, default.nix is
|
||||||
skipped. To provide a file that will result in a "default" attr, name the
|
skipped. To provide a file that will result in a "default" attr, name the
|
||||||
@ -376,10 +355,12 @@ let
|
|||||||
raw = root;
|
raw = root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
modules = [ baseModule ] ++ builtinModules ++ root'.modules;
|
||||||
|
|
||||||
# Merge result of all the modules.
|
# Merge result of all the modules.
|
||||||
merged = foldl mergeModules moduleAttrDefaults
|
merged = foldl mergeModules moduleAttrDefaults
|
||||||
((map (m: normalizeModule (applyNonSysArgs m))
|
((map (m: normalizeModule (applyNonSysArgs m)) modules)
|
||||||
([ builtinModule ] ++ root'.modules)) ++ [ root' ]);
|
++ [ root' ]);
|
||||||
|
|
||||||
# Returns package set for a system.
|
# Returns package set for a system.
|
||||||
pkgsFor = system: import merged.inputs.nixpkgs {
|
pkgsFor = system: import merged.inputs.nixpkgs {
|
||||||
|
Loading…
Reference in New Issue
Block a user