-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor for readability & tracability
The default.nix logic should now be easier to follow with core concerns factored out into a seperate `src` directory. Also, a better error is reported to the user in the event a module is not in a valid format, showing the exact location on disk where the failed module resides.
- Loading branch information
Showing
4 changed files
with
118 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# to avoid excessive recursion that can lead to inefficiency or errors | ||
# we cannot compose the individual pieces of the module composer as a regular module | ||
# so instead we abstract them out here, into a manually specified "psuedo-module" | ||
# to keep the core impelementation clean | ||
let | ||
compose = import ../.; | ||
fix = import ../std/fix.nix; | ||
cond = import ../std/set/cond.nix; | ||
filterMap = scopedImport { std = builtins; } ../std/set/filterMap.nix; | ||
strToPath = scopedImport { std = builtins; } ../std/path/strToPath.nix; | ||
parse = scopedImport { std = builtins; } ../std/file/parse.nix; | ||
toLowerCase = scopedImport rec { | ||
std = builtins; | ||
mod = scopedImport { inherit std mod; } ../std/string/mod.nix; | ||
} ../std/string/toLowerCase.nix; | ||
stdFilter = import ./stdFilter.nix; | ||
in | ||
{ | ||
inherit | ||
parse | ||
fix | ||
filterMap | ||
strToPath | ||
cond | ||
; | ||
lowerKeys = filterMap (k: v: { ${toLowerCase k} = v; }); | ||
filterPub = filterMap ( | ||
k: v: | ||
let | ||
s = toLowerCase k; | ||
in | ||
if s == k then null else { ${s} = v; } | ||
); | ||
filterMod = builtins.filterSource ( | ||
path: type: | ||
let | ||
file = parse (baseNameOf path); | ||
in | ||
(type == "regular" && file.ext or null != "nix") | ||
|| (type == "directory" && !builtins.pathExists "${path}/mod.nix") | ||
); | ||
errors = import ./errors.nix; | ||
composeStd = path: compose { } path // filterMap stdFilter builtins; | ||
|
||
modIsValid = | ||
mod: dir: | ||
builtins.isAttrs mod | ||
|| throw '' | ||
The following module does not evaluate to a valid attribute set: | ||
${toString dir}/mod.nix | ||
''; | ||
|
||
injectPrevious = | ||
pre: set: | ||
set | ||
// cond { | ||
_if = pre != null; | ||
inherit pre; | ||
}; | ||
|
||
hasMod = contents: contents."mod.nix" or null == "regular"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
import = abort "Importing arbitrary Nix files is forbidden. Declare your dependencies via the module system instead."; | ||
builtins = abort "Please access builtins uniformly via the `std` scope."; | ||
fetch = abort "Ad hoc fetching is illegal. Declare dependencies statically in the manifest instead."; | ||
system = abort "Accessing the current system is impure. Declare supported systems in the manifest."; | ||
time = abort "Accessing the current time is impure & illegal."; | ||
nixPath = abort "The NIX_PATH is an impure feature, and therefore illegal."; | ||
storePath = abort "Making explicit dependencies on store paths is illegal."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
k: v: | ||
if | ||
builtins.match "^import|^scopedImport|^builtins|^fetch.*|^current.*|^nixPath|^storePath" k != null | ||
then | ||
null | ||
else | ||
{ ${k} = v; } |