Skip to content

Commit bd226d3

Browse files
committed
feat(flake): expose examples as packages + eval checks
Each entry in the `examples` attrset is materialised three ways: `nixosConfigurations.example-<name>` (the full system), `packages.<system>.<name>` (the qemu-runnable VM, so `nix run .#<name>`), and `checks.<system>.example-<name>` (eval-only, so option-name drift fails CI without paying for a full VM test).
1 parent cdcf048 commit bd226d3

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ live in the per-pairing README:
9191
service-account bootstrap flow and the operator-supplied client
9292
override.
9393

94+
### Runnable examples
95+
96+
Each entry under [`examples/`](examples/) is a complete NixOS
97+
configuration with its own walkthrough. `nix run .#<example>` builds
98+
and boots the example as a QEMU VM (host ports forwarded so you can
99+
hit the services from a browser).
100+
101+
- [`keycloak-forgejo`](examples/keycloak-forgejo/README.md) — both
102+
pairings together, a custom Keycloak login theme, SSO from Forgejo
103+
into Keycloak, a private internal repo, and per-user avatars served
104+
over a side nginx. `nix run .#keycloak-forgejo`.
105+
94106
### Secrets
95107

96108
Secrets should never enter the world-readable Nix store. The admin token and
@@ -103,7 +115,7 @@ path — prefer it over the literal for any real secret.
103115
## Repository layout
104116

105117
```
106-
flake.nix # outputs: nixosModules, checks, formatter
118+
flake.nix # outputs: nixosModules, packages (examples), checks, formatter
107119
treefmt.nix # treefmt + nixfmt config
108120
modules/
109121
default.nix # aggregates per-pairing modules into nixosModules.default
@@ -120,6 +132,8 @@ services/ # one directory per service<->provider pairing
120132
lib.nix # ~95 typed resourceTypes + the value-tree renderer
121133
checks.nix # 1 VM + 4 nspawn-container tests, one per resource family
122134
README.md # usage docs
135+
examples/ # runnable demos; one configuration.nix + README per example
136+
keycloak-forgejo/ # both pairings together with theme, SSO, avatar
123137
```
124138

125139
## Development

flake.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@
2828
}
2929
);
3030
treefmtEval = forAllSystems ({ pkgs, ... }: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
31+
# runnable examples (see ./examples/<name>/README.md). each `name`
32+
# surfaces as `nix run .#<name>` (the qemu vm) and as an eval-only
33+
# check, so option-name drift fails CI without paying for a full vm test.
34+
examples = {
35+
keycloak-forgejo = ./examples/keycloak-forgejo/configuration.nix;
36+
};
37+
exampleSystem =
38+
system: cfg:
39+
nixpkgs.lib.nixosSystem {
40+
inherit system;
41+
modules = [
42+
self.nixosModules.default
43+
cfg
44+
];
45+
};
3146
in
3247
{
3348
# NixOS module entrypoint: enables a Nixpkgs service and reconciles its
@@ -36,11 +51,24 @@
3651
nixosModules.forgejo = ./services/forgejo/module.nix;
3752
nixosModules.keycloak = ./services/keycloak/module.nix;
3853

54+
nixosConfigurations = nixpkgs.lib.mapAttrs' (
55+
name: cfg: nixpkgs.lib.nameValuePair "example-${name}" (exampleSystem "x86_64-linux" cfg)
56+
) examples;
57+
58+
packages = forAllSystems (
59+
{ system, ... }:
60+
nixpkgs.lib.mapAttrs (name: cfg: (exampleSystem system cfg).config.system.build.vm) examples
61+
);
62+
3963
checks = forAllSystems (
4064
{ pkgs, system }:
4165
# Per-service checks (one attrset per pairing under ./services/<svc>).
4266
(import ./services/forgejo/checks.nix { inherit pkgs self; })
4367
// (import ./services/keycloak/checks.nix { inherit pkgs self; })
68+
// (nixpkgs.lib.mapAttrs' (
69+
name: cfg:
70+
nixpkgs.lib.nameValuePair "example-${name}" (exampleSystem system cfg).config.system.build.toplevel
71+
) examples)
4472
// {
4573
formatting = treefmtEval.${system}.config.build.check self;
4674
}

0 commit comments

Comments
 (0)