Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
182 lines (165 loc) · 7.3 KB
/
Copy pathflake.nix
File metadata and controls
182 lines (165 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# ii/nix — Shared NixOS module library for ii infrastructure
#
# Layer 1 of the three-tier composition:
# Layer 1: ii/nix — shared modules (this repo)
# Layer 2: ii/dev — machine depot (who's on this box)
# Layer 3: hh/hh — per-user depot (how I want my env)
#
# Usage in a machine depot's flake.nix:
# inputs.ii-nix.url = "github:ii/nix";
# modules = [ ii-nix.nixosModules.default ];
#
# Then declare:
# ii.domains = { "ii.dev" = { gid = 3000; }; };
# ii.users = { hh = { uid = 1000; domains = ["dev"]; isAdmin = true; }; };
{
description = "ii shared NixOS modules — domain=user infrastructure";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
# Newer pin used ONLY to pull technitium-dns-server 14.3.0 (with
# cluster + cluster-catalog support, which doesn't exist in
# nixos-24.11's 13.0.2 build). Anchor systems still build against
# nixos-24.11 for everything else; the overlay below substitutes
# just the technitium-dns-server package out of unstable.
# Why a separate pin: 14.3.0 needs .NET 9; 24.11 packages 13.0.2
# against .NET 8 with a regenerated nuget-deps.json. Pulling the
# whole derivation (including the nuget-deps + libmsquic 9.x +
# .NET 9 runtime closure) from a tree that has them is much
# easier than back-porting.
#
# nixpkgs-unstable (NOT master) so cache.nixos.org has all the
# closure built — master HEAD often isn't fully cached yet.
nixpkgs-master.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
# sops-nix is transitively bundled by nixosModules.secrets so consumers
# get the federation-canonical secrets layer in a single import. Pin
# tested-against version here; consumers don't have to remember.
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixpkgs-master, disko, sops-nix }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in
{
# ============================================================
# Machine configurations (nixos-anywhere targets)
# ============================================================
nixosConfigurations.dev = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
disko.nixosModules.disko
self.nixosModules.default
./machines/dev/configuration.nix
];
};
# ============================================================
# NixOS Modules (the main export)
# ============================================================
nixosModules = {
# ===== Federation interface modules (the abstraction layer) =====
# The keystone — generates users, groups, DNS, web, email, TLS
# from a simple ii.domains + ii.users declaration
domain-users = ./modules/domain-users.nix;
# sops-nix-backed encrypted secrets convention (federation primitive).
# Bundles sops-nix transitively — a single import wires both.
secrets = {
imports = [
sops-nix.nixosModules.sops
./modules/secrets.nix
];
};
# Federation DNS — wraps services.technitium with zone lists,
# TSIG-from-secrets, ACLs. Consumers import this for the
# ii-federation.dns.* options.
dns = ./modules/dns.nix;
# Federation wildcard TLS — wraps services.acme-dns01 with
# auto-resolved DNS-01 target + shared TSIG key from dns.nix.
certs = ./modules/certs.nix;
# ===== Bare service modules (concrete implementations) =====
ghost = ./modules/services/ghost.nix;
smtprelay = ./modules/services/smtprelay.nix;
caddy-multi = ./modules/services/caddy-multi.nix;
technitium = ./modules/services/technitium.nix;
maddy = ./modules/services/maddy.nix;
acme-dns01 = ./modules/services/acme-dns01.nix;
# Overlay: replace nixos-24.11's technitium-dns-server (13.0.2,
# no clustering) with nixpkgs-master's (14.3.0, has clustering).
# Pulled in by the anchor bundle below; consumers that don't
# need clustering can skip it and keep 13.0.2.
technitium-14 = { ... }: {
nixpkgs.overlays = [
(final: prev: {
technitium-dns-server =
nixpkgs-master.legacyPackages.${prev.system}.technitium-dns-server;
})
];
};
# Overlay: replace nixos-24.11's maddy (0.7.1) with nixpkgs-
# master's (0.8.x). The federation maddy.conf (ii-mx 2026-05-14,
# anchors/machines/mail/maddy.conf) uses 0.8+ idioms — bare-string
# regex tables, `target.dispatch` module, etc. — that 0.7.1
# rejects with parse errors. Same overlay pattern as
# technitium-14; pulled in by the anchor bundle below.
maddy-08 = { ... }: {
nixpkgs.overlays = [
(final: prev: {
maddy = nixpkgs-master.legacyPackages.${prev.system}.maddy;
})
];
};
# Convenience: import everything legacy + federation
default = { imports = [
./modules/domain-users.nix
./modules/services/ghost.nix
./modules/services/smtprelay.nix
./modules/services/caddy-multi.nix
]; };
# Convenience: federation anchor bundle (DNS + MX + ACME).
# 'Anchor' replaces the original 'edge' framing: these boxes ARE the
# federation's authoritative outermost point (a stable bind target +
# identity anchor), not proxies between internal/external. Naming
# decision per architect 2026-05-11.
anchor = { imports = [
./modules/secrets.nix
./modules/dns.nix
./modules/certs.nix
./modules/services/technitium.nix
./modules/services/maddy.nix
./modules/services/acme-dns01.nix
# Pull technitium-dns-server 14.3.0 from nixpkgs-master via
# overlay. 14.x is the first version with cluster + cluster
# catalog (required for the federation sync model in
# dns.nix); nixos-24.11's 13.0.2 doesn't have either.
self.nixosModules.technitium-14
# Pull maddy 0.8.x from nixpkgs-master via overlay. 0.8+
# introduced target.dispatch + bare-string regex tables that
# the federation maddy.conf depends on; 0.7.1 in 24.11 can't
# parse it. Sets up federation MX + DKIM signing + OCI
# smarthost end-to-end.
self.nixosModules.maddy-08
]; };
};
# ============================================================
# Library functions
# ============================================================
lib = import ./lib { inherit (nixpkgs) lib; };
# ============================================================
# Dev shell for working on these modules
# ============================================================
devShells = forAllSystems (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = pkgs.mkShell {
packages = with pkgs; [ nil nixpkgs-fmt ];
};
}
);
};
}