-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
206 lines (180 loc) · 6.75 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
{
description = "A very basic flake";
# Unsure where exactly this needs to live, as I am probably duplicating it in modules/common/default.nix too
# It's probably required here for when I build on a non-NixOS machine
nixConfig = {
extra-substituters = [ "https://numtide.cachix.org" ];
extra-trusted-public-keys =
[ "numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE=" ];
};
inputs = {
agenix.url = "github:ryantm/agenix";
argononed = {
url = "gitlab:DarkElvenAngel/argononed";
flake = false;
};
catppuccin.url = "github:catppuccin/nix";
darwin.url = "github:lnl7/nix-darwin";
darwin.inputs.nixpkgs.follows = "nixpkgs-unstable";
deploy-rs.url = "github:serokell/deploy-rs";
flake-utils.url = "github:numtide/flake-utils";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "github:numtide/nixpkgs-unfree";
nixpkgs.inputs.nixpkgs.follows = "nixpkgs-unstable";
};
outputs =
{ self
, ...
}@inputs:
with inputs;
let
isDarwin = system: builtins.elem system [ "aarch64-darwin" ];
isNixOS = system: builtins.elem system [ "x86_64-linux" "aarch64-linux" ];
inherit (flake-utils.lib) eachSystemMap system;
catalog = import ./catalog.nix { inherit nixos-hardware; };
# Modules to import to hosts
## Common modules to apply to everything
common = [ ./common agenix.nixosModules.default ];
## Modules under ./modules
nixosModules = builtins.listToAttrs (map
(module: {
name = module;
value = import (./modules + "/${module}");
})
(builtins.attrNames (builtins.readDir ./modules)));
## home-manager modules and users
homeFeatures = system: users:
let
homeManager =
if (isDarwin system) then
home-manager.darwinModules.home-manager
else
home-manager.nixosModules.home-manager;
# Only create root user on nixOS machines, I might hate this way of declaring it
additionalUsers = nixpkgs.lib.optional (!isDarwin system) "root";
in
[
homeManager
(mkHomeManager ((map (user: user.name) users) ++ additionalUsers))
];
# End of modules
mkUserImports = user: [
catppuccin.homeManagerModules.catppuccin
./home/common
(./home/users + "/${user}")
];
mkHomeManager = usernames: {
# Fixes https://github.com/divnix/digga/issues/30
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = { inherit system inputs; };
home-manager.users = builtins.listToAttrs (map
(
username: {
name = username;
value = {
imports = mkUserImports username;
};
}
)
usernames
);
};
# Platform agnostic function for creating a system
mkSystem = system: users: extraModules:
let
systemManager =
if (isDarwin system) then
darwin.lib.darwinSystem
else
nixpkgs.lib.nixosSystem;
in
systemManager {
inherit system;
specialArgs = {
inherit catalog;
flake-self = self;
} // inputs;
modules =
# Imports home-manager
(homeFeatures system users)
++ extraModules;
};
darwinNodes = (nixpkgs.lib.attrValues (nixpkgs.lib.filterAttrs (node_name: node_def: node_def ? "system" && isDarwin node_def.system) catalog.nodes));
nixOSNodes = (nixpkgs.lib.attrValues (nixpkgs.lib.filterAttrs (node_name: node_def: node_def ? "system" && isNixOS node_def.system) catalog.nodes));
in
{
overlays.default = final: prev: (import ./overlays inputs) final prev;
# home-manager standalone installations
homeConfigurations = builtins.listToAttrs (map
(user: {
name = user.name;
value = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages."x86_64-linux";
# TODO roles shouldn't be appended here, should be defined similar to modules
modules = (mkUserImports user.name) ++ [ ./home/roles/desktop ];
};
})
# Currently hardcoded to jdheyburn, for paddys
[ catalog.users.jdheyburn ]);
# macOS installations
darwinConfigurations = builtins.listToAttrs (map
(node:
let
modules = [
(./hosts + "/${node.hostName}/configuration.nix")
];
in
{
name = node.hostName;
value = mkSystem node.system node.users modules;
})
darwinNodes);
# good old NixOS installations
nixosConfigurations = builtins.listToAttrs (map
(node:
let
modules =
# Top level common that should be applied to all Nix
common
++ [
# Imports my own nixOS mdules
{ imports = builtins.attrValues nixosModules; }
# Host level configuration
(./hosts + "/${node.hostName}/configuration.nix")
] ++ nixpkgs.lib.optional (node ? "nixosHardware") node.nixosHardware;
in
{
name = node.hostName;
value = mkSystem node.system node.users modules;
})
nixOSNodes);
deploy.nodes = builtins.listToAttrs (map
(node: {
name = node.hostName;
value = {
hostname = node.ip.tailscale;
profiles.system = {
user = "root";
path = deploy-rs.lib.${node.system}.activate.nixos
self.nixosConfigurations.${node.hostName};
sshOpts = [ "-o" "IdentitiesOnly=yes" ];
};
};
})
nixOSNodes);
checks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy-rs.lib;
# allows nix fmt
formatter = builtins.listToAttrs (map
(system: {
name = system;
value = nixpkgs.legacyPackages.${system}.nixpkgs-fmt;
})
flake-utils.lib.defaultSystems);
};
}