-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
307 lines (301 loc) · 12.1 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
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
304
305
306
307
{
description = "NixOS + Home Manager configuration of chayleaf";
inputs = {
nix-community-infra.url = "github:nix-community/infra";
nixpkgs-kernel.url = "github:NixOS/nixpkgs/a58bc8ad779655e790115244571758e8de055e3d";
nixpkgs.url = "github:chayleaf/nixpkgs";
nixvim.url = "github:nix-community/nixvim";
nixos-hardware.url = "github:NixOS/nixos-hardware";
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
mobile-nixos = {
url = "github:chayleaf/mobile-nixos/sdm845";
flake = false;
};
osu-wine = {
url = "github:chayleaf/osu-wine.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
impermanence.url = "github:nix-community/impermanence";
nur.url = "github:nix-community/NUR";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
coop-fd = {
url = "github:chayleaf/coop-fd";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:chayleaf/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-gaming = {
url = "github:fufexan/nix-gaming";
inputs.nixpkgs.follows = "nixpkgs";
};
notlua = {
url = "github:chayleaf/notlua";
inputs.nixpkgs.follows = "nixpkgs";
};
notnft = {
url = "github:chayleaf/notnft";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-router = {
url = "github:chayleaf/nixos-router";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-mailserver = {
url = "gitlab:simple-nixos-mailserver/nixos-mailserver";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-24_05.follows = "nixpkgs";
};
unbound-rust-mod = {
url = "github:chayleaf/unbound-rust-mod";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = base-inputs@{ self, nixpkgs, ... }:
let
# --impure required for developing
# it takes the paths for modules from filesystem as opposed to flake inputs
dev = {
# coop-fd = true;
# home-manager = true;
# mobile-nixos = true;
# nixos-router = true;
# notnft = true;
# nixpkgs = true;
# unbound-rust-mod = true;
};
# IRL-related stuff I'd rather not put into git
priv =
if builtins.pathExists ./private.nix then import ./private.nix { }
else if builtins.pathExists ./private/default.nix then import ./private { }
# workaround for git flakes not having access to non-checked out files
else if builtins?extraBuiltins.secrets then builtins.extraBuiltins.secrets
# yes, this is impure, this is a last ditch effort at getting access to secrets
else import /secrets/nixos { };
devPath = priv.devPath or ../.;
inputs = builtins.mapAttrs
(name: input:
if dev.${name} or false then
(if input._type or null == "flake"
then let inputs = input.inputs // { self = (import /${devPath}/${name}/flake.nix).outputs inputs; };
in { __toString = _: "/${toString devPath}/${name}"; } // inputs.self
else /${devPath}/${name})
else input)
base-inputs;
# if x has key s, get it. Otherwise return def
# All private config for hostname
getPriv = hostname: priv.${hostname} or { };
# Private NixOS config for hostname
getPrivSys = hostname: (getPriv hostname).system or { };
# Private home-manager config for hostname and username
getPrivUser = hostname: user: (getPriv hostname).${user} or { };
# extended lib
lib = inputs.nixpkgs.lib // import ./lib.nix { inherit (nixpkgs) lib; };
# can't use callPackage ./pkgs here, idk why; use import instead
overlay' = args: self: super: import (if args.pluginsOverlay or false then ./pkgs/nix-plugins-overlay.nix else ./pkgs) ({
pkgs = super;
pkgs' = self;
lib = super.lib;
inherit inputs;
} // args);
overlay = overlay' { };
nix-plugins-overlay = overlay' { pluginsOverlay = true; };
all-overlays = [ nix-plugins-overlay overlay ];
# I override some settings down the line, but overlays always stay the same
mkPkgs = config: import (config.flake or nixpkgs) (builtins.removeAttrs config ["flake"] // {
overlays = config.overlays or ([ ] ++ all-overlays);
});
# this is actual config, it gets processed below
config = let
mkBpiR3 = args: config: config // {
system = "aarch64-linux";
modules = config.modules or [ ] ++ [
(import ./system/devices/bpi-r3-router.nix args)
];
};
routerConfig = rec {
system = "aarch64-linux";
modules = [
{ _module.args.server-config = self.nixosConfigurations.server.config;
_module.args.notnft = inputs.notnft.lib.${system}; }
inputs.nixos-router.nixosModules.default
];
};
in {
router-emmc = mkBpiR3 "emmc" routerConfig;
router-sd = mkBpiR3 "sd" routerConfig;
ereader = {
# TODO uncom
flake = inputs.nixpkgs-kernel;
system = "aarch64-linux";
modules = [
./system/devices/kobo-clara-hd-ereader.nix
{
nixpkgs.crossSystem.system = "armv7l-linux";
# nixpkgs.localSystem.system = "aarch64-linux";
}
];
home.user = [ ./home/hosts/ereader.nix ];
home.common.enableNixosModule = true;
};
server = {
system = "aarch64-linux";
modules = [
{ _module.args.router-config = self.nixosConfigurations.router-emmc.config; }
./system/devices/radxa-rock5a-server.nix
];
};
nixmsi = rec {
system = "x86_64-linux";
modules = [ ./system/devices/msi-delta-15-workstation.nix ];
home.common.modules = [ inputs.nixvim.homeManagerModules.default ];
home.common.extraSpecialArgs = {
notlua = inputs.notlua.lib.${system};
};
home.user = [ ./home/hosts/nixmsi.nix ];
};
phone = rec {
system = "aarch64-linux";
modules = [ ./system/devices/oneplus-6-phone.nix ];
home.common.modules = [ inputs.nixvim.homeManagerModules.default ];
home.common.extraSpecialArgs = {
notlua = inputs.notlua.lib.${system};
};
home.user = [ ./home/hosts/phone.nix ];
};
};
in {
overlays = {
default = overlay;
nix-plugins = nix-plugins-overlay;
};
packages = lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"armv7l-linux"
] (system: let self = overlay' { isOverlay = false; } (mkPkgs { inherit system; } // self) (import nixpkgs { inherit system; }); in self);
nixosImages.router = let pkgs = mkPkgs { inherit (config.router-emmc) system; }; in {
emmcImage = pkgs.callPackage ./system/hardware/bpi-r3/image.nix {
inherit (self.nixosConfigurations.router-emmc) config;
rootfsImage = self.nixosConfigurations.router-emmc.config.system.build.rootfsImage;
bpiR3Stuff = pkgs.bpiR3StuffEmmc;
};
sdImage = pkgs.callPackage ./system/hardware/bpi-r3/image.nix {
inherit (self.nixosConfigurations.router-sd) config;
rootfsImage = self.nixosConfigurations.router-sd.config.system.build.rootfsImage;
bpiR3Stuff = pkgs.bpiR3StuffSd;
};
};
hydraJobs = {
server.${config.server.system} = self.nixosConfigurations.server.config.system.build.toplevel;
router.${config.router-emmc.system} = self.nixosConfigurations.router-emmc.config.system.build.toplevel;
phone.${config.phone.system} = self.nixosConfigurations.phone.config.system.build.toplevel;
phone-home.${config.phone.system} = self.homeConfigurations."user@phone".activation-script;
workstation.${config.nixmsi.system} = self.nixosConfigurations.nixmsi.config.system.build.toplevel;
workstation-home.${config.nixmsi.system} = self.homeConfigurations."user@nixmsi".activation-script;
};
# this is the system config processing part
nixosConfigurations = lib.flip builtins.mapAttrs config (hostname: args @ { modules, nixpkgs ? {}, home ? {}, ... }:
(args.flake or base-inputs.nixpkgs).lib.nixosSystem {
inherit (args) system;
# allow modules to access nixpkgs directly, use customized lib,
# and pass nixos-harware to let hardware modules import parts of nixos-hardware
specialArgs = {
inherit lib;
hardware = inputs.nixos-hardware.nixosModules;
inputs = inputs // lib.optionalAttrs (args?flake) {
nixpkgs = args.flake;
};
} // args.specialArgs or { };
modules = [
({ config, ... }: {
_module.args = {
pkgs-kernel = import inputs.nixpkgs-kernel { inherit (args) system; overlays = all-overlays ++ config.nixpkgs.overlays; };
};
})
(getPrivSys hostname)
{ networking.hostName = lib.mkDefault hostname;
nixpkgs.overlays = all-overlays; }
inputs.impermanence.nixosModule
]
++ args.modules or [ ]
++ map (x: ./system/modules/${x}) (builtins.attrNames (builtins.readDir ./system/modules))
# the following is NixOS home-manager module configuration. Currently unused, but I might start using it for some hosts later.
++ lib.optionals (home != { } && home.common.enableNixosModule or false) [
inputs.home-manager.nixosModules.home-manager
{ home-manager = builtins.removeAttrs (home.common or { }) [ "nixpkgs" "nix" "enableNixosModule" ]; }
{
home-manager.extraSpecialArgs = {
inputs = inputs // lib.optionalAttrs (args?flake) {
nixpkgs = args.flake;
};
};
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users = builtins.mapAttrs (username: modules: {
imports = modules ++ [
# { nixpkgs = home.common.nixpkgs or { };
# nix = home.common.nix or { }; }
# ({ config, pkgs, lib, ...}: {
# nixpkgs.overlays = all-overlays;
# nix.package = lib.mkDefault pkgs.nixForNixPlugins; })
(getPrivUser hostname username)
];
}) (builtins.removeAttrs home [ "common" ]); }
];
});
# for each hostname, for each user, generate an attribute "${user}@${hostname}"
homeConfigurations =
{
"chayleaf@hysteria" = inputs.home-manager.lib.homeManagerConfiguration {
pkgs = mkPkgs {
system = "x86_64-linux";
overlays = [ overlay ];
};
extraSpecialArgs = { inherit inputs; };
modules = [
./home/hosts/remote.nix
({ pkgs, ... }: {
home.file.hysteria.source = pkgs.hysteria;
home.file.shadowsocks-libev.source = pkgs.shadowsocks-libev;
home.file.shadowsocks-rust.source = pkgs.shadowsocks-rust;
})
];
};
}
// builtins.listToAttrs (builtins.concatLists
(lib.flip lib.mapAttrsToList config
(hostname: { system, home ? {}, ... }:
let
common' = builtins.removeAttrs (home.common or { }) [ "nix" "nixpkgs" "enableNixosModule" ];
pkgs = mkPkgs ({ inherit system; } // home.common.nixpkgs or { });
common = common' // { inherit pkgs; };
in
lib.flip lib.mapAttrsToList (builtins.removeAttrs home [ "common" ])
# this is where actual config takes place
(user: homeConfig: lib.nameValuePair "${user}@${hostname}"
(inputs.home-manager.lib.homeManagerConfiguration (common // {
extraSpecialArgs = (common.extraSpecialArgs or { }) // { inherit inputs; };
modules =
homeConfig
++ common.modules or [ ]
++ [
(getPrivUser hostname user)
({ pkgs, lib, ... }: {
nix.package = lib.mkDefault pkgs.nixForNixPlugins;
})
];
}))))));
};
}