-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
303 lines (275 loc) · 9.55 KB
/
flake.nix
File metadata and controls
303 lines (275 loc) · 9.55 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
{
description = "NixOS configuration with categorized hosts and multi-architecture support";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
nixvim = {
url = "github:nix-community/nixvim";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, home-manager, sops-nix, deploy-rs, nixvim, ... }@inputs:
let
# Machine-agnostic identity defaults (override via env when needed).
defaultUser =
let u = builtins.getEnv "NIXCFG_USER";
in if u != "" then u else "giovanni";
defaultGitName =
let n = builtins.getEnv "NIXCFG_GIT_NAME";
in if n != "" then n else defaultUser;
defaultGitEmail =
let e = builtins.getEnv "NIXCFG_GIT_EMAIL";
in if e != "" then e else "${defaultUser}@localhost";
# Supported architectures
supportedSystems = [
"x86_64-linux" # Intel/AMD 64-bit
"aarch64-linux" # ARM 64-bit (including Ampere)
"x86_64-darwin" # Intel Mac
"aarch64-darwin" # Apple Silicon (M1/M2/M3)
];
# Helper to generate attribute sets for all systems
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Per-system package sets
pkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
config.allowUnfree = true;
}
);
# Helper function to create NixOS configurations with architecture support
mkHost =
{ hostname
, category
, system ? "x86_64-linux"
, # Default to x86_64-linux for backwards compatibility
userName ? defaultUser
, userGitName ? defaultGitName
, userGitEmail ? defaultGitEmail
, extraModules ? [ ]
}:
nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
inherit
inputs
userName
userGitName
userGitEmail
;
};
modules = [
./hosts/${category}/${hostname}/configuration.nix
home-manager.nixosModules.home-manager
sops-nix.nixosModules.sops
{
nixpkgs.config.allowUnfree = true;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = {
inherit userName userGitName userGitEmail;
};
home-manager.users.${userName} = import ./modules/users/giovanni.nix;
home-manager.sharedModules = [
nixvim.homeManagerModules.nixvim
];
}
] ++ extraModules;
};
# Helper to create deploy-rs nodes with architecture awareness
mkDeployNode =
{ hostname
, configName
, system ? "x86_64-linux"
, # Default to x86_64-linux
sshUser ? defaultUser
}:
{
# Use SSH config hostname (managed by our ssh-config module)
hostname = "${hostname}";
profiles.system = {
user = "root";
inherit sshUser;
# Dynamically select the correct deploy-rs lib based on system
path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.${configName};
};
};
in
{
# NixOS Configurations organized by category and architecture
nixosConfigurations = {
# === LAPTOPS (x86_64) ===
bit = mkHost {
hostname = "bit";
category = "laptops";
system = "x86_64-linux";
};
spark = mkHost {
hostname = "spark";
category = "laptops";
system = "x86_64-linux";
};
hermes = mkHost {
hostname = "hermes";
category = "laptops";
system = "x86_64-linux";
};
# === LAPTOPS (ARM - Apple Silicon example) ===
# Uncomment when you have ARM laptops
# macbook = mkHost {
# hostname = "macbook";
# category = "laptops";
# system = "aarch64-darwin";
# };
# === VPS (x86_64) ===
vps-alpha = mkHost {
hostname = "example-vps";
category = "vps";
system = "x86_64-linux";
};
# === VPS (ARM/Ampere - Example) ===
# Uncomment when you have ARM-based VPS (e.g., Oracle Ampere, AWS Graviton)
# vps-arm = mkHost {
# hostname = "vps-arm";
# category = "vps";
# system = "aarch64-linux";
# };
# === SERVERS (x86_64) ===
server-alpha = mkHost {
hostname = "example-server";
category = "servers";
system = "x86_64-linux";
};
# === SERVERS (ARM - Example for Raspberry Pi, Ampere, etc.) ===
# server-arm = mkHost {
# hostname = "server-arm";
# category = "servers";
# system = "aarch64-linux";
# };
# === EXPERIMENTS ===
experiment-alpha = mkHost {
hostname = "example-experiment";
category = "experiments";
system = "x86_64-linux";
};
};
# Deploy-rs configuration for remote deployments
# Architecture is automatically handled based on host system
deploy.nodes = {
# Laptops (x86_64)
bit = mkDeployNode {
hostname = "bit";
configName = "bit";
system = "x86_64-linux";
};
spark = mkDeployNode {
hostname = "spark";
configName = "spark";
system = "x86_64-linux";
};
hermes = mkDeployNode {
hostname = "hermes";
configName = "hermes";
system = "x86_64-linux";
};
# VPS (x86_64)
vps-alpha = mkDeployNode {
hostname = "vps-alpha";
configName = "vps-alpha";
system = "x86_64-linux";
};
# Servers (x86_64)
server-alpha = mkDeployNode {
hostname = "server-alpha";
configName = "server-alpha";
system = "x86_64-linux";
};
# Experiments
experiment-alpha = mkDeployNode {
hostname = "experiment-alpha";
configName = "experiment-alpha";
system = "x86_64-linux";
};
# Example ARM deployments (uncomment as needed)
# vps-arm = mkDeployNode {
# hostname = "vps-arm";
# configName = "vps-arm";
# system = "aarch64-linux";
# };
};
# Deploy-rs checks
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
# Development shells for all supported architectures
devShells = forAllSystems (system:
let
pkgs = pkgsFor.${system};
in
{
default = pkgs.mkShell {
buildInputs = with pkgs; [
deploy-rs.packages.${system}.deploy-rs
just
nixos-anywhere
git
openssh
sops
age
gnupg
pre-commit
jq
asciinema
mkpasswd
];
shellHook = ''
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ NixOS Configuration Development Environment ║"
echo "║ Architecture: ${system} ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
echo "Available Hosts by Architecture:"
echo " x86_64-linux:"
echo " Laptops: bit, spark, hermes"
echo " VPS: vps-alpha"
echo " Servers: server-alpha"
echo " Experiments: experiment-alpha"
echo ""
echo " aarch64-linux:"
echo " (Add ARM hosts in flake.nix)"
echo ""
echo "Quick Start:"
echo " just --list - Show all commands"
echo " just install spark laptops IP - Install new host"
echo " just deploy bit - Deploy to host"
echo " just check - Validate configuration"
echo ""
echo "Adding ARM hosts:"
echo " Edit flake.nix and set system = \"aarch64-linux\""
echo ""
echo "Documentation:"
echo " docs/WORKFLOW.md - Complete workflow guide"
echo " docs/MULTI_ARCH.md - Multi-architecture guide"
echo " docs/SOPS_GPG_SETUP.md - Secrets management"
echo ""
'';
};
}
);
# Expose package sets for all systems
packages = forAllSystems (system: {
# Expose useful packages per-system
default = pkgsFor.${system}.hello;
});
# Formatter for all systems
formatter = forAllSystems (system: pkgsFor.${system}.nixpkgs-fmt);
};
}