Skip to content

Commit 6152483

Browse files
authored
a bit of comments (#30)
1 parent e0cf6b8 commit 6152483

File tree

8 files changed

+175
-253
lines changed

8 files changed

+175
-253
lines changed

nix/aspects.nix

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
# Transpose aspects.<aspect>.<class> to modules.<class>.<aspect>
2+
# Resolves aspect dependencies and applies transformations during transposition
3+
14
lib: aspects:
25
let
6+
# Import transpose utility with custom emit function for aspect resolution
37
transpose = import ./. { inherit lib emit; };
4-
emit =
5-
transposed:
6-
let
7-
aspect = aspects.${transposed.child};
8-
in
9-
[
10-
{
11-
inherit (transposed) parent child;
12-
value = aspect.resolve { class = transposed.parent; };
13-
}
14-
];
8+
9+
# Emit function: resolves each aspect for its target class
10+
# Returns: [{ parent = class, child = aspect, value = resolved-module }]
11+
emit = transposed: [
12+
{
13+
inherit (transposed) parent child;
14+
value = aspects.${transposed.child}.resolve { class = transposed.parent; };
15+
}
16+
];
1517
in
1618
{
19+
# Exports: transposed.<class>.<aspect> = resolved-module
1720
transposed = transpose aspects;
1821
}

nix/default.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
# Generic 2-level attribute set transposition
2+
# Swaps parent/child levels: { a.b = 1; } → { b.a = 1; }
3+
# Parameterized via emit function for custom value handling
4+
15
{
26
lib,
7+
# emit: Customization function for each item during transpose
8+
# Signature: { child, parent, value } → [{ parent, child, value }]
9+
# Default: lib.singleton (identity transformation)
310
emit ? lib.singleton,
411
}:
512
let
13+
# Create transposition metadata by calling emit
614
transposeItem =
715
child: parent: value:
816
emit { inherit child parent value; };
17+
18+
# Fold accumulator: rebuilds transposed structure
919
accTransposed =
1020
acc: item:
1121
acc
@@ -14,9 +24,17 @@ let
1424
${item.child} = item.value;
1525
};
1626
};
27+
28+
# Process all children of a parent
1729
transposeItems = parent: lib.mapAttrsToList (transposeItem parent);
30+
31+
# Flatten input into transposition items
1832
deconstruct = lib.mapAttrsToList transposeItems;
33+
34+
# Fold items back into swapped structure
1935
reconstruct = lib.foldl accTransposed { };
36+
37+
# Main transpose: deconstruct → flatten → reconstruct
2038
transpose =
2139
attrs:
2240
lib.pipe attrs [

nix/flakeModule.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
# Flake-parts integration for aspect-oriented configuration
2+
# Provides flake.aspects (input) and flake.modules (output)
3+
14
{
25
lib,
36
config,
47
...
58
}:
9+
# Invoke new() factory to create flake.aspects and flake.modules
610
import ./new.nix lib (option: transposed: {
11+
# User-facing aspects input
712
options.flake.aspects = option;
13+
14+
# Computed modules output organized by class
815
config.flake.modules = transposed;
916
}) config.flake.aspects

nix/lib.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
# Public API entry point for flake-aspects library
2+
# Exports: types, transpose, aspects, new, new-scope
13
lib:
24
let
5+
# Type system: aspectsType, aspectSubmodule, providerType
36
types = import ./types.nix lib;
7+
8+
# Generic transposition utility: parameterized by emit function
49
transpose =
510
{
611
emit ? lib.singleton,
712
}:
813
import ./default.nix { inherit lib emit; };
14+
15+
# Aspect transposition with resolution
916
aspects = import ./aspects.nix lib;
17+
18+
# Low-level scope factory: parameterized by callback
1019
new = import ./new.nix lib;
20+
21+
# High-level named scope factory
1122
new-scope = import ./new-scope.nix new;
1223
in
1324
{

nix/new-scope.nix

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
# usage:
2-
#
3-
# { inputs, ... }: {
4-
# imports = [ (new-scope "foo") ];
5-
# foo.aspects.<aspect> = ...;
6-
# # and use foo.modules.<class>.<aspect>
7-
# }
8-
#
9-
# returns a nix module that defines the ${name} option having:
10-
#
11-
# options.${name}.aspects # for user
12-
# options.${name}.modules # read-only resolved modules.
13-
#
14-
# for lower-level usage like using other option names, see new.nix.
1+
# Creates named aspect scopes: ${name}.aspects and ${name}.modules
2+
# Enables multiple independent aspect namespaces
153
new: name:
164
{ config, lib, ... }:
5+
# Invoke new() to create ${name}.aspects and ${name}.modules
176
new (option: transposed: {
187
options.${name} = {
8+
# User-facing aspects input
199
aspects = option;
10+
11+
# Computed modules output (read-only)
2012
modules = lib.mkOption {
2113
readOnly = true;
2214
default = transposed;

nix/new.nix

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# creates a new aspects option.
2-
# See flakeModule for usage.
1+
# Low-level aspect scope factory
2+
# Creates aspect integration via callback pattern for maximum flexibility
33
lib: cb: cfg:
44
let
5+
# Import aspects transposer: validates and transposes aspect config
56
aspects = import ./aspects.nix lib cfg;
7+
8+
# Import type system for aspect validation
69
types = import ./types.nix lib;
10+
11+
# Create aspects input option
712
option = lib.mkOption {
813
default = { };
9-
description = ''
10-
Attribute set of `<aspect>.<class>` modules.
11-
12-
Convenience transposition of `flake.modules.<class>.<aspect>`.
13-
'';
14+
description = "Aspect definitions organized as <aspect>.<class>";
1415
type = types.aspectsType;
1516
};
1617
in
18+
# Invoke callback with option and transposed results
1719
cb option aspects.transposed

nix/resolve.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
# Core aspect resolution algorithm
2+
# Resolves aspect definitions into nixpkgs modules with dependency resolution
3+
14
lib:
25
let
3-
6+
# Process a single provider: invoke with context and resolve
47
include =
58
class: aspect-chain: provider:
69
let
710
provided = provider { inherit aspect-chain class; };
811
in
912
resolve class aspect-chain provided;
1013

14+
# Main resolution: extract class config and recursively resolve includes
1115
resolve = class: aspect-chain: provided: {
1216
imports = lib.flatten [
1317
(provided.${class} or { })

0 commit comments

Comments
 (0)