mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-23 17:20:31 +03:00
refactor(flake-parts): use perSystem for defining inputs, drop makeFlakeOutputs usage
This commit is contained in:
parent
e98ca58528
commit
759b662e02
@ -17,10 +17,12 @@
|
||||
flake-parts.lib.mkFlake {inherit self;} {
|
||||
systems = ["x86_64-linux"];
|
||||
imports = [dream2nix.flakeModuleBeta];
|
||||
dream2nix = {
|
||||
config.projectRoot = ./.;
|
||||
|
||||
dream2nix.config.projectRoot = ./.;
|
||||
|
||||
perSystem = {config, ...}: {
|
||||
# define an input for dream2nix to generate outputs for
|
||||
inputs."ripgrep" = {
|
||||
dream2nix.inputs."ripgrep" = {
|
||||
source = src;
|
||||
settings = [{builder = "crane";}];
|
||||
};
|
||||
|
@ -5,44 +5,50 @@
|
||||
}: 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;
|
||||
};
|
||||
|
||||
outputsRaw =
|
||||
l.mapAttrs
|
||||
(_: attrs: attrs.${system})
|
||||
(
|
||||
l.filterAttrs
|
||||
(_: attrs: l.isAttrs attrs && l.hasAttr system attrs)
|
||||
outputs
|
||||
(_: args: instance.makeOutputs args)
|
||||
config.dream2nix.inputs;
|
||||
|
||||
getAttrFromOutputs = attrName:
|
||||
d2n.lib.dlib.mergeFlakes (
|
||||
l.mapAttrsToList
|
||||
(_: attrs: attrs.${attrName})
|
||||
outputsRaw
|
||||
);
|
||||
in {
|
||||
config = {
|
||||
dream2nix.outputs = systemizedOutputs;
|
||||
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");
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -22,28 +22,7 @@ in {
|
||||
};
|
||||
default = {};
|
||||
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 +31,27 @@ 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.either (t.attrsOf t.raw) (t.attrsOf (t.attrsOf 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.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user