diff --git a/flake.nix b/flake.nix index dccbe24..2ccba12 100644 --- a/flake.nix +++ b/flake.nix @@ -23,11 +23,8 @@ nixpkgs, nix-unit, }: let - # TODO: implement mix.extend and mix.isolate inherit (mix) - extend - # isolate newMixture ; @@ -35,6 +32,9 @@ inputs = { inherit mix; flake = self; + # flake dependencies + # NOTE: the NixTypes library has no dependencies + # NOTE: but the developer tooling (for me) does # XXX: TODO: implement mix.extend instead of this deps = { inherit nixpkgs nix-unit; @@ -42,20 +42,11 @@ }; }; - # flake dependencies - # NOTE: the NixTypes library has no dependencies - # NOTE: but the developer tooling (for me) does - deps = { - inherit systems nixpkgs nix-unit; - }; - - bootstrap = import ./nt/primitives/std; + bootstrap = import ./nt/precursor/bootstrap; mix = import ./nt/mix/bootstrap.nix {this = bootstrap;}; in newMixture inputs (mixture: { includes.public = [ - # XXX: TODO: implement mix.extend - # (extend ./flake deps) ./flake ./nt ]; diff --git a/nt/default.nix b/nt/default.nix index 9359fc1..5ddda99 100644 --- a/nt/default.nix +++ b/nt/default.nix @@ -1,7 +1,10 @@ {mix, ...} @ inputs: mix.newMixture inputs (mixture: { + isolated = true; includes.public = [ ./precursor + + # (mix.isolate mix) ]; submods.public = [ ./mix diff --git a/nt/mix/import.nix b/nt/mix/import.nix index 1d9af68..86f0990 100644 --- a/nt/mix/import.nix +++ b/nt/mix/import.nix @@ -1,9 +1,12 @@ {nt, ...}: let inherit (builtins) + foldl' isAttrs isFunction - listToAttrs + isList + isPath + mapAttrs typeOf ; @@ -11,11 +14,15 @@ (nt) enfIsPrimitive hasInfix - mergeAttrsList - nameValuePair removeSuffix ; + inherit + (nt.naive.terminal) + isTerminal + unwrapTerminal + ; + modNameFromPath = path: let name = baseNameOf path |> removeSuffix ".nix"; in @@ -40,22 +47,47 @@ in rec { # TODO: create a better version of toString that can handle sets, lists, and null assert isFunction mod || throw '' - Mix modules expect primitive type "set" or "lambda" (returning "set"). + Imported Mix modules must be provided as primitive types "set" or "lambda" (returning "set"). Got primitive type "${typeOf mod}" instead. ''; assert isAttrs modResult || throw '' - Mix module provided as primitive type "lambda" must return primitive type "set"! + Imported Mix module provided as primitive type "lambda" must return primitive type "set"! Got primitive return type "${typeOf modResult} instead." ''; modResult; - mkIncludes = list: inputs: - list - |> map (path: (importMod path inputs)) - |> mergeAttrsList; + mkMod = pathDelegate: target: extraInputs: let + this = delegate target; + inputs = {inherit this;} // extraInputs; - mkSubMods = list: inputs: - list - |> map (path: nameValuePair (modNameFromPath path) (importMod path inputs)) - |> listToAttrs; + delegate = target: + # PATH + if isPath target + then pathDelegate target inputs + # LIST + else if isList target + then target |> foldl' (acc: el: acc // delegate el) {} + # TERMINAL + else if isTerminal target + then unwrapTerminal target + # ATTRS + else if isAttrs target + then target |> mapAttrs (_: value: delegate value) + # FUNCTION (OR FAIL) + else + assert isFunction target + || throw '' + Mix module provided as invalid primitive type "${typeOf target}". + ''; + target inputs; + in + this; + + mkIncludes = target: inputs: mkMod importMod target inputs; + mkSubMods = target: inputs: + mkMod (path: inputs': { + ${modNameFromPath path} = importMod path inputs'; + }) + target + inputs; } diff --git a/nt/precursor/default.nix b/nt/precursor/default.nix index 66b0cc2..934bf0d 100644 --- a/nt/precursor/default.nix +++ b/nt/precursor/default.nix @@ -4,10 +4,12 @@ mix.newMixture inputs (mixture: { includes = { public = [ ./nt + # XXX: DEBUG: make this protected + ./bootstrap ]; protected = [ # XXX: WARNING: reimplement std but typesafe - ./bootstrap + # ./bootstrap ]; }; })