refactor(flake-parts): make outputs option more consistent, use mkMerge for merging, default projectRoot to self

This commit is contained in:
Yusuf Bera Ertan 2022-11-12 01:01:19 +03:00
parent 759b662e02
commit 19933dbcf0
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
3 changed files with 15 additions and 21 deletions

View File

@ -1,6 +1,6 @@
{ {
inputs = { inputs = {
dream2nix.url = "github:nix-community/dream2nix"; dream2nix.url = "path:../..";
nixpkgs.follows = "dream2nix/nixpkgs"; nixpkgs.follows = "dream2nix/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
src.url = "github:BurntSushi/ripgrep/13.0.0"; src.url = "github:BurntSushi/ripgrep/13.0.0";
@ -18,8 +18,6 @@
systems = ["x86_64-linux"]; systems = ["x86_64-linux"];
imports = [dream2nix.flakeModuleBeta]; imports = [dream2nix.flakeModuleBeta];
dream2nix.config.projectRoot = ./.;
perSystem = {config, ...}: { perSystem = {config, ...}: {
# define an input for dream2nix to generate outputs for # define an input for dream2nix to generate outputs for
dream2nix.inputs."ripgrep" = { dream2nix.inputs."ripgrep" = {

View File

@ -25,30 +25,24 @@ in {
inherit (d2n) config; inherit (d2n) config;
}; };
outputsRaw = outputs =
l.mapAttrs l.mapAttrs
(_: args: instance.makeOutputs args) (_: args: instance.makeOutputs args)
config.dream2nix.inputs; config.dream2nix.inputs;
getAttrFromOutputs = attrName: getAttrFromOutputs = attrName:
d2n.lib.dlib.mergeFlakes ( l.mkMerge (
l.mapAttrsToList l.mapAttrsToList
(_: attrs: attrs.${attrName}) (_: output: mkDefaultRecursive output.${attrName})
outputsRaw outputs
); );
in { in {
config = { config = {
dream2nix = { dream2nix = {inherit instance outputs;};
inherit instance; # TODO(yusdacra): we could combine all the resolveImpure here if there are multiple
outputs = # TODO(yusdacra): maybe we could rename outputs with the same name to avoid collisions?
# if only one input was defined, then only export outputs from packages = getAttrFromOutputs "packages";
# that since there is nothing else devShells = getAttrFromOutputs "devShells";
if l.length (l.attrNames outputsRaw) != 1
then outputsRaw
else l.head (l.attrValues outputsRaw);
};
devShells = mkDefaultRecursive (getAttrFromOutputs "devShells");
packages = mkDefaultRecursive (getAttrFromOutputs "packages");
}; };
}; };
}; };

View File

@ -1,4 +1,5 @@
{ {
self,
lib, lib,
flake-parts-lib, flake-parts-lib,
... ...
@ -20,7 +21,9 @@ in {
type = t.submoduleWith { type = t.submoduleWith {
modules = [../config]; modules = [../config];
}; };
default = {}; default = {
projectRoot = self;
};
description = '' description = ''
The dream2nix config. The dream2nix config.
''; '';
@ -47,11 +50,10 @@ in {
''; '';
}; };
outputs = l.mkOption { outputs = l.mkOption {
type = t.either (t.attrsOf t.raw) (t.attrsOf (t.attrsOf t.raw)); type = t.lazyAttrsOf (t.lazyAttrsOf t.raw);
readOnly = true; readOnly = true;
description = '' description = ''
The raw outputs that were generated for each input. The raw outputs that were generated for each input.
If only one input was specified, then this will be the outputs for only that input.
''; '';
}; };
}; };