Skip to content

Commit d850fd0

Browse files
authored
Documented Layers, created example layer and template for it. (#8)
- Layers are now automatically discovered from directories in ./dev/layers. - Added an example vix layer which imports features from vic/vix repo. - Added an example vix template that includes said layer to test it all.
1 parent 28f5660 commit d850fd0

File tree

17 files changed

+288
-46
lines changed

17 files changed

+288
-46
lines changed

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let
1515

1616
module = inputs.import-tree [
1717
./dev/community
18-
((inputs.import-tree.addPath ./dev/layers).match ".+/dev/layers/[^/]+.nix")
18+
./dev/layers/options.nix
1919
];
2020

2121
ev = lib.modules.evalModules {

dev/book/src/Dendrix-Layers.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,36 @@ If you were to use the example AI layer (from below), you'd do the following on
2222

2323
## Creating Layers
2424

25+
A Dendrix Layer is defined at `./dev/layers/<name>/modules/**.nix`. If you create one, make sure you
26+
also provide a `./dev/layers/<name>/README.md` with details about usage or input requirements.
27+
2528
For example, if the community comes up with an `ai` aspect shared across different repos, we
2629
could have a _blessed_ ai layer providing files from both repos and community-managed configurations.
2730

2831
```nix
2932
# This is an example of how an AI Layer might be defined in our Dendrix community repository.
3033
#
31-
# ./dev/layers/ai.nix
32-
{ inputs, config, ... }:
34+
# ./dev/layers/ai/modules/default.nix
35+
{ inputs, lib, ... }:
3336
let
34-
ai-one = config.dendrix.community.repo-one.import-tree.ai; # import-tree for AI aspect from repo-one.
35-
ai-two = config.dendrix.community.repo-two.import-tree.ai; # import-tree for AI aspect from repo-two.
36-
ai-community = inputs.import-tree.addPath ./ai; # community-managed AI from ./dev/layers/ai/**.nix
37+
ai-one = inputs.dendrix.repo-one.ai; # import-tree for AI aspect from repo-one.
38+
ai-two = inputs.dendrix.repo-two.ai; # import-tree for AI aspect from repo-two.
3739
in
3840
{
39-
dendrix.layers.ai = {lib, ...}: {
40-
imports = [ ai-one ai-two ai-community ];
41-
options.ai.something.enable = lib.mkEnableOption "Enable something for AI";
41+
imports = [ ai-one ai-two ];
42+
43+
# flake-level community options.
44+
options.ai.something.enable = lib.mkEnableOption "Enable something for AI";
45+
46+
# packages,checks,devshells,etc for AI
47+
perSystem = {pkgs, ...}: {
48+
packages.ai-cli = { };
4249
};
50+
51+
# extensions to the ai aspect.
52+
flake.modules.nixos.ai = { };
53+
flake.modules.darwin.ai = { };
54+
flake.modules.homeManager.ai = { };
4355
}
4456
```
4557

dev/book/src/Getting-Started.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
## Usage (for existing flake-parts setups)
44

5+
Add the `dendrix` input to your flake:
6+
7+
```nix
8+
# flake.nix -- add the dendrix input:
9+
{
10+
inputs.dendrix.url = "github:vic/dendrix";
11+
12+
# Flatten dependencies.
13+
#inputs.dendrix.inputs.import-tree.follows = "import-tree";
14+
#inputs.dendrix.inputs.nixpkgs-lib.follows = "nixpkgs-lib";
15+
}
16+
```
17+
18+
Then import Dendrix trees/layers on any flake-parts module of yours:
19+
20+
```nix
21+
{ inputs, ... }:
22+
{
23+
imports = [
24+
# inputs.dendrix.vic-vix.macos-keys # example <macos-keys> aspect.
25+
# inputs.dendrix.vix # example layer, see https://github.com/vic/dendrix/tree/main/dev/layers
26+
];
27+
}
28+
```
29+
530
See usage instructions for either [Dendrix Trees](Dendrix-Trees.html#using-community-import-trees) or [Dendrix Layers](Dendrix-Layers.html#using-existing-layers).
631

732
## Quick Start (for NixOS newcomers)

dev/book/theme/elm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ inputs.flake-parts.lib.mkFlake { inherit inputs; } (
33
inputs.import-tree [
44
./modules
55
./community
6-
((inputs.import-tree.addPath ./layers).match ".+/layers/[^/]+.nix")
6+
./layers/options.nix
77
]
88
)

dev/elm/src/Results.elm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import Browser
44
import Data
55
import Deco
66
import Dict exposing (Dict)
7-
import Html exposing (Html, button, code, div, p, pre, text)
8-
import Html.Attributes exposing (class, id)
7+
import Html exposing (Html, a, button, code, div, p, pre, text)
8+
import Html.Attributes exposing (class, href, id)
99
import Html.Events exposing (onClick)
1010
import Json.Decode as D
1111
import Json.Encode as E
@@ -121,11 +121,12 @@ viewSelectedRepos model =
121121
, p []
122122
[ text "Add the following to your "
123123
, code [] [ text "flake.nix" ]
124-
, text " to include these configuration modules."
124+
, text " to include these configuration modules. See also: "
125+
, a [ href "Getting-Started.html" ] [ text "Usage for Dendrix Trees/Layers" ]
125126
]
126127
, viewUsageCode model.repos
127128
, p []
128-
[ text "Then on any flake module of yours, extend any of these aspects with your custom configs, like:"
129+
[ text "On a flake module of yours, extend any of these aspects with your custom configs, like:"
129130
, div []
130131
[ pre []
131132
[ code [ class "language-nix" ]
@@ -168,20 +169,19 @@ viewUsageCode repos =
168169
repoImports =
169170
List.map
170171
(\( repoName, treeName ) ->
171-
String.concat [ " inputs.dendrix.", repoName, ".", treeName, "\n" ]
172+
String.concat [ " inputs.dendrix.", repoName, ".", treeName, "\n" ]
172173
)
173174
trees
174175

175176
codes =
176-
[ """# flake.nix
177+
[ """# modules/dendrix-imports.nix -- on any module of yours.
178+
{ inputs, ... }:
177179
{
178-
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; }
179-
(inputs.import-tree [
180-
./modules # your modules"""
180+
imports = ["""
181181
, "\n"
182182
]
183183
++ repoImports
184-
++ [ " ]);\n}", "\n" ]
184+
++ [ " ];\n}", "\n" ]
185185
in
186186
text (String.concat codes)
187187
]

dev/flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/layers/options.nix

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
{ lib, ... }:
1+
{ lib, inputs, ... }:
22
let
33

4-
moduleType = lib.types.oneOf [
5-
lib.types.path
6-
lib.types.attrs
7-
(lib.types.functionTo lib.types.attrs)
8-
];
9-
104
layersOption = lib.mkOption {
11-
description = "a flake-parts module";
12-
default = { };
13-
type = lib.types.attrsOf moduleType;
5+
description = "layers flake-parts modules";
6+
default = discoverLayers;
7+
readOnly = true;
8+
type = lib.types.attrsOf lib.types.attrs;
149
};
1510

11+
discoverLayers = lib.pipe ./. [
12+
builtins.readDir
13+
(lib.mapAttrsToList (name: type: { inherit name type; }))
14+
(lib.filter (x: x.type == "directory"))
15+
(lib.map (x: x.name))
16+
(lib.map (name: {
17+
${name} = {
18+
imports = [
19+
(inputs.import-tree ./${name}/modules)
20+
];
21+
};
22+
}))
23+
lib.mergeAttrsList
24+
];
25+
1626
in
1727
{
1828
options.dendrix.layers = layersOption;

dev/layers/vix.nix

Lines changed: 0 additions & 11 deletions
This file was deleted.

dev/layers/vix/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# vix layer.

0 commit comments

Comments
 (0)