diff --git a/src/atom/fromManifest.nix b/src/atom/fromManifest.nix index 1fe91c5..887ca92 100644 --- a/src/atom/fromManifest.nix +++ b/src/atom/fromManifest.nix @@ -11,6 +11,7 @@ let file = builtins.readFile path; config = builtins.fromTOML file; atom = config.atom or { }; + src = config.src or { }; name = atom.name or (mod.errors.missingName path); features' = @@ -25,9 +26,9 @@ let compose = config.compose or { }; root = atom.path or name; - extern = + fetches = let - fetcher = nix.fetcher or "native"; # native doesn't exist yet + fetcher = nix.fetcher or "native"; # TODO: native doesn't exist yet conf = config.fetcher or { }; f = conf.${fetcher} or { }; root = f.root or "npins"; @@ -55,6 +56,22 @@ let else { }; + srcs = + let + filter = scopedImport { + std = builtins // { + string.split = import ../std/string/split.nix; + }; + } ../std/path/filter.nix; + in + mod.filterMap ( + name: paths: if builtins.isList paths != true then null else filter paths (dirOf path) + ) src; + + extern = fetches // { + src = srcs; + }; + meta = atom.meta or { }; composeFeatures = compose.features or { }; diff --git a/src/atom/mod.nix b/src/atom/mod.nix index 3989fec..e17c2b6 100644 --- a/src/atom/mod.nix +++ b/src/atom/mod.nix @@ -49,14 +49,22 @@ rec { if s == k then null else { ${s} = v; } ); - rmNixSrcs = l.filterSource ( - path: type: + rmNixSrcs = + path: let - file = parse (baseNameOf path); + name = baseNameOf path; in - (type == "regular" && file.ext or null != "nix") - || (type == "directory" && !l.pathExists "${path}/mod.nix") - ); + l.path { + inherit name path; + filter = ( + path: type: + let + file = parse name; + in + (type == "regular" && file.ext or null != "nix") + || (type == "directory" && !l.pathExists "${path}/mod.nix") + ); + }; readStd = opts: fromManifest { inherit (opts) __internal__test features; }; diff --git a/src/std/path/filter.nix b/src/std/path/filter.nix new file mode 100644 index 0000000..38c9c24 --- /dev/null +++ b/src/std/path/filter.nix @@ -0,0 +1,29 @@ +paths: path: +let + f = + dir: + let + pred = builtins.elem dir paths; + next = f (dirOf dir); + in + dir != "." && (pred || next); + + type = builtins.readFileType path; + name = + let + s = std.string.split "-" path; + pred = builtins.match "^${builtins.storeDir}/.*" (toString path) == null; + in + if pred || builtins.length s < 2 then baseNameOf path else builtins.elemAt s 1; +in +builtins.path { + inherit path name; + filter = + p: t: + let + frag = builtins.match "^${toString path}/(.*)" p; + frag' = builtins.head frag; + pred = if frag == null then false else builtins.elem frag' paths; + in + (t == "directory" && type == "directory" && pred) || f (dirOf frag'); +} diff --git a/src/std/string/split.nix b/src/std/string/split.nix new file mode 100644 index 0000000..d8b7e2c --- /dev/null +++ b/src/std/string/split.nix @@ -0,0 +1,5 @@ +sep: str: +let + p = builtins.split sep (toString str); +in +builtins.filter (x: builtins.typeOf x == "string") p