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

View File

@ -25,30 +25,24 @@ in {
inherit (d2n) config;
};
outputsRaw =
outputs =
l.mapAttrs
(_: args: instance.makeOutputs args)
config.dream2nix.inputs;
getAttrFromOutputs = attrName:
d2n.lib.dlib.mergeFlakes (
l.mkMerge (
l.mapAttrsToList
(_: attrs: attrs.${attrName})
outputsRaw
(_: output: mkDefaultRecursive output.${attrName})
outputs
);
in {
config = {
dream2nix = {
inherit instance;
outputs =
# if only one input was defined, then only export outputs from
# that since there is nothing else
if l.length (l.attrNames outputsRaw) != 1
then outputsRaw
else l.head (l.attrValues outputsRaw);
};
devShells = mkDefaultRecursive (getAttrFromOutputs "devShells");
packages = mkDefaultRecursive (getAttrFromOutputs "packages");
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";
};
};
};

View File

@ -1,4 +1,5 @@
{
self,
lib,
flake-parts-lib,
...
@ -20,7 +21,9 @@ in {
type = t.submoduleWith {
modules = [../config];
};
default = {};
default = {
projectRoot = self;
};
description = ''
The dream2nix config.
'';
@ -47,11 +50,10 @@ in {
'';
};
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;
description = ''
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.
'';
};
};