-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
265 lines (240 loc) · 8.73 KB
/
flake.nix
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
{
description = "M1cr0man Nix Configurations";
inputs = {
nixpkgs.url = "github:m1cr0man/nixpkgs/rfc108-minimal";
sops-nix.url = "github:Mic92/sops-nix";
sops-nix.inputs.nixpkgs.follows = "nixpkgs";
nixos-nspawn.url = "github:m1cr0man/python-nixos-nspawn";
nixos-nspawn.inputs.nixpkgs.follows = "nixpkgs";
snm.url = "git+https://gitlab.com/simple-nixos-mailserver/nixos-mailserver.git?ref=master";
snm.inputs.nixpkgs.follows = "nixpkgs";
nixos-vscode-server.url = "github:msteen/nixos-vscode-server";
nixos-vscode-server.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
imhumane-rs.url = "github:m1cr0man/imhumane-rs";
imhumane-rs.inputs.nixpkgs.follows = "nixpkgs";
mailform-rs.url = "github:m1cr0man/mailform-rs";
mailform-rs.inputs = {
nixpkgs.follows = "nixpkgs";
crane.follows = "imhumane-rs/crane";
fenix.follows = "imhumane-rs/fenix";
advisory-db.follows = "imhumane-rs/advisory-db";
};
dnssync-rs.url = "github:m1cr0man/dnssync-rs";
dnssync-rs.inputs = {
nixpkgs.follows = "nixpkgs";
crane.follows = "imhumane-rs/crane";
fenix.follows = "imhumane-rs/fenix";
advisory-db.follows = "imhumane-rs/advisory-db";
};
};
outputs = { self, sops-nix, ... }@inputs:
with import ./lib/output.nix
{
inherit inputs;
domain = "m1cr0man.com";
system = "x86_64-linux";
};
let
devDeps = [
pkgs.nix-prefetch-git
pkgs.gnupg
# For VS Code Nix IDE plugin
pkgs.nix-instantiate
pkgs.nixpkgs-fmt
# Sops related packages. Took me a moment to realise sops
# is an independent thing from sops-nix ;)
pkgs.age
pkgs.sops
pkgs.ssh-to-age
];
in
{
# All hosts managed by this repository should be added here
# nixosConfigurations is read by `nixos-rebuild`
nixosConfigurations = {
bgrs = mkConfiguration {
name = "bgrs";
};
chuck = mkConfiguration {
name = "chuck";
modules = [
inputs.nixos-vscode-server.nixosModules.default
inputs.nixos-nspawn.nixosModules.hypervisor
];
};
sarah = mkConfiguration {
name = "sarah";
modules = [ inputs.nixos-vscode-server.nixosModules.default ];
};
gelandewagen = mkConfiguration {
name = "gelandewagen";
};
optiplexxx = mkConfiguration {
name = "optiplexxx";
};
unimog = mkConfiguration {
name = "unimog";
modules = [
inputs.nixos-vscode-server.nixosModules.default
inputs.nixos-nspawn.nixosModules.hypervisor
inputs.dnssync-rs.nixosModules.dnssync
];
};
phoenix = mkConfiguration {
name = "phoenix";
modules = [
inputs.nixos-vscode-server.nixosModules.default
inputs.dnssync-rs.nixosModules.dnssync
];
};
netboot = mkConfiguration {
name = "netboot";
modules = [
({ modulesPath, ... }: {
imports = [ "${modulesPath}/installer/netboot/netboot-minimal.nix" ];
})
];
};
kexec = { address, prefixLength, defaultGateway }: mkConfiguration {
name = "kexec";
modules = [
({ modulesPath, ... }: {
imports = [ "${modulesPath}/installer/netboot/netboot-minimal.nix" ];
networking = {
inherit defaultGateway;
usePredictableInterfaceNames = false;
interfaces.eth0 = {
ipv4.addresses = [{
inherit address prefixLength;
}];
};
};
})
];
};
};
nixosContainers.${system} = {
database = mkContainer {
name = "database";
modules = [
sops-nix.nixosModules.sops
];
};
email = mkContainer {
name = "email";
modules = [
sops-nix.nixosModules.sops
inputs.snm.nixosModules.mailserver
];
};
web = mkContainer {
name = "web";
modules = [
sops-nix.nixosModules.sops
];
};
gaming = mkContainer {
name = "gaming";
modules = [
sops-nix.nixosModules.sops
];
};
technae = mkContainer {
name = "technae";
modules = [
sops-nix.nixosModules.sops
];
};
tailscale = mkContainer {
name = "tailscale";
modules = [
sops-nix.nixosModules.sops
];
};
monitoring = mkContainer {
name = "monitoring";
modules = [
sops-nix.nixosModules.sops
];
};
vccemail = mkContainer {
name = "vccemail";
modules = [
sops-nix.nixosModules.sops
inputs.snm.nixosModules.mailserver
];
};
};
homeConfigurations = {
phoenix-george = inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./homes/phoenix-george ];
};
unimog-lucas = inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./homes/unimog-lucas ];
};
};
# Exported modules, for use in other people's flakes and nixosConfigurations
nixosModules = {
inherit systemLabelModule;
# Best way I could think of to export the lib folder. Technically these
# aren't modules but they aren't packages either, and really the user could
# just use "${myflake}/lib/module.nix" but why do that if you are
# also importing this?
lib = {
module = import ./lib/module.nix;
polkit = import ./lib/polkit.nix;
output = import ./lib/output.nix;
};
} // autoExportedModules;
# Exported overlays, for use in dependent flakes and nixosConfigurations
# Added to pkgs in lib/output.nix
# Usually packages will be declared here since we need a nixpkgs env
# to work from to build them.
overlays = {
# It's best practice to put all the packages you plan to put in the packages output (last lines)
# into overlays first. That way, people can override the nixpkgs that is being used to build
# the package by using the overlay directly.
extraPackages = final: prev: {
"${pkgRoot}" = import ./packages { callPackage = final.callPackage; };
# It's a bit more complex to extend lib since it's self-referential
# If needed you can replace import with `final.callPackage` here
lib = prev.lib.extend (f: p: { "${pkgRoot}" = import ./lib/helpers.nix { inherit domain; lib = final.lib; }; });
};
nixos-nspawn = inputs.nixos-nspawn.overlays.default;
imhumane-rs = inputs.imhumane-rs.overlays.imhumane-rs-nixpkgs;
mailform-rs = inputs.mailform-rs.overlays.mailform-rs-nixpkgs;
dnssync-rs = inputs.dnssync-rs.overlays.dnssync-rs-nixpkgs;
};
# Re-export nixpkgs as legacyPackages so that we can do `nix run .#<pkg name>` for any nixpkg.
legacyPackages.${system} = pkgs;
# Exported packages, for use in dependent flakes
# Re-exports packages defined in overlays above
# e.g. can be used with `nix build .#<pkgname>`
# system and pkgs come from lib/output.nix
packages.${system} = pkgs."${pkgRoot}" // {
# Required for adding a gcroot to stop the devshell getting GC'd
# See https://github.com/NixOS/nix/issues/2208
# Usage: nix build .#devShellPackages -o /nix/var/nix/gcroots/per-user/$USER/devdeps
devShellPackages = pkgs.symlinkJoin {
name = "dev-shell-packages";
paths = devDeps;
};
# As defined by https://github.com/NixOS/nixpkgs/blob/104f09f2e4a84a9845da4c0131dac34b090c4b02/nixos/modules/installer/kexec/kexec-boot.nix#L22
# To build, run nix repl and then:
# :lf .
# :b packages.x86_64-linux.kexec { address = "1.2.3.4"; prefixLength = 24; defaultGateway = "1.2.3.1"; }
kexec = args: (self.nixosConfigurations.kexec args).config.system.build.kexecTree;
home-manager = inputs.home-manager.packages.${system}.home-manager;
};
# Configure devShell
# Usable with `nix develop`. shell.nix provides nix-shell compat.
# system and pkgs come from lib/output.nix
devShell.${system} = pkgs.mkShell {
packages = devDeps;
};
};
}