Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Add source scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Oct 1, 2019
1 parent 22ee431 commit 82f4031
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
50 changes: 50 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,58 @@ let
{ modules ? [] }: lib.evalModules {
check = true;
modules = builtinModules ++ modules;
specialArgs = { inherit scanProjectModules; };
};

scanProjectModules = scan "nix/project-module.nix";

# Like a PATH search, where filePath is like bin/somecommand
#
# scan : string -> sources -> listOf module
#
# Arguments
#
# filePath : string File to look for in the sources
#
# sources : attrsOf path Sources that may contain a file named ${filePath}
# or path or a path that has such a Nix expression
scan = filePath:
let
withAsserts =
assert builtins.typeOf filePath == "string";
x: x;

importify =
f: x:
if lib.types.path.check x
then builtins.addErrorContext
"while scanning for modules in ${toString x}"
(f (import x))
else builtins.addErrorContext
"while scanning for modules"
(f x);

scanAttrs = attrs:
lib.concatLists (
lib.mapAttrsToList (
key: value:
builtins.addErrorContext
"while scanning attribute ${key}"
(scanIfDirlike value)
)
attrs
);

scanIfDirlike = value:
if lib.types.path.check value
then let
potential = value + "/${filePath}";
in
if builtins.pathExists potential then [ potential ] else []
else [];
in
withAsserts (importify scanAttrs);

builtinModules = [
./modules/root.nix
./modules/nixpkgs.nix
Expand Down
7 changes: 2 additions & 5 deletions nix/project.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{ scanProjectModules, ... }:
{
# imports = scan "nix/project-module.nix" ./sources.nix;

imports = [
((import ./sources.nix).nix-pre-commit-hooks + "/nix/project-module.nix")
];
imports = scanProjectModules ./sources.nix;

root = ../.;
pinning.niv.enable = true;
Expand Down

0 comments on commit 82f4031

Please sign in to comment.