diff --git a/examples/_d2n-flake-parts/flake.nix b/examples/_d2n-flake-parts/flake.nix index 5cb1ef62..9956932d 100644 --- a/examples/_d2n-flake-parts/flake.nix +++ b/examples/_d2n-flake-parts/flake.nix @@ -17,10 +17,10 @@ flake-parts.lib.mkFlake {inherit self;} { systems = ["x86_64-linux"]; imports = [dream2nix.flakeModuleBeta]; - dream2nix = { - config.projectRoot = ./.; + + perSystem = {config, ...}: { # define an input for dream2nix to generate outputs for - inputs."ripgrep" = { + dream2nix.inputs."ripgrep" = { source = src; settings = [{builder = "crane";}]; }; diff --git a/src/modules/flake-parts/implementation.nix b/src/modules/flake-parts/implementation.nix index c6a4c922..347f9861 100644 --- a/src/modules/flake-parts/implementation.nix +++ b/src/modules/flake-parts/implementation.nix @@ -5,44 +5,44 @@ }: let l = lib // builtins; d2n = config.dream2nix; - makeArgs = p: - { - inherit (config) systems; - inherit (d2n) config; - } - // p; - outputs = d2n.lib.dlib.mergeFlakes ( - l.map - (p: d2n.lib.makeFlakeOutputs (makeArgs p)) - (l.attrValues d2n.inputs) - ); + + # make attrs default, so that users can override them without + # needing to use lib.mkOverride (usually, lib.mkForce) + mkDefaultRecursive = attrs: + l.mapAttrsRecursiveCond + d2n.lib.dlib.isNotDrvAttrs + (_: l.mkDefault) + attrs; in { config = { - flake = - # make attrs default, so that users can override them without - # needing to use lib.mkOverride (usually, lib.mkForce) - l.mapAttrsRecursiveCond - d2n.lib.dlib.isNotDrvAttrs - (_: l.mkDefault) - outputs; - dream2nix.outputs = outputs; perSystem = { config, - system, + pkgs, ... }: let - # get output attrs that have systems - systemizedOutputs = + instance = d2n.lib.init { + inherit pkgs; + inherit (d2n) config; + }; + + outputs = l.mapAttrs - (_: attrs: attrs.${system}) - ( - l.filterAttrs - (_: attrs: l.isAttrs attrs && l.hasAttr system attrs) + (_: args: instance.makeOutputs args) + config.dream2nix.inputs; + + getAttrFromOutputs = attrName: + l.mkMerge ( + l.mapAttrsToList + (_: output: mkDefaultRecursive output.${attrName}) outputs ); in { config = { - dream2nix.outputs = systemizedOutputs; + dream2nix = {inherit instance outputs;}; + # TODO(yusdacra): we could combine all the resolveImpure here if there are multiple + # TODO(yusdacra): maybe we could rename outputs with the same name to avoid collisions? + packages = getAttrFromOutputs "packages"; + devShells = getAttrFromOutputs "devShells"; }; }; }; diff --git a/src/modules/flake-parts/interface.nix b/src/modules/flake-parts/interface.nix index 8b84d8d6..211ad9f5 100644 --- a/src/modules/flake-parts/interface.nix +++ b/src/modules/flake-parts/interface.nix @@ -1,4 +1,5 @@ { + self, lib, flake-parts-lib, ... @@ -20,30 +21,11 @@ in { type = t.submoduleWith { modules = [../config]; }; - default = {}; + default = { + projectRoot = self; + }; description = '' - The dream2nix config. This will be applied to all defined `sources`. - You can override this per `source` by specifying `config` for that source: - ```nix - sources."name" = { - config.projectSource = ./source; - }; - ``` - ''; - }; - inputs = l.mkOption { - type = t.attrsOf t.attrs; - default = {}; - description = '' - A list of inputs to generate outputs from. - Each one takes the same arguments `makeFlakeOutputs` takes. - ''; - }; - outputs = l.mkOption { - type = t.attrsOf t.raw; - readOnly = true; - description = '' - The raw outputs that were generated. + The dream2nix config. ''; }; }; @@ -52,11 +34,26 @@ in { ({...}: { options = { dream2nix = { - outputs = l.mkOption { - type = t.attrsOf t.raw; + instance = l.mkOption { + type = t.raw; readOnly = true; description = '' - The raw outputs that were generated. + The dream2nix instance. + ''; + }; + inputs = l.mkOption { + type = t.attrsOf t.attrs; + default = {}; + description = '' + A list of inputs to generate outputs from. + Each one takes the same arguments `makeOutputs` takes. + ''; + }; + outputs = l.mkOption { + type = t.lazyAttrsOf (t.lazyAttrsOf t.raw); + readOnly = true; + description = '' + The raw outputs that were generated for each input. ''; }; };