-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
305 lines (266 loc) · 10.3 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
{
description = "A very basic flake";
# If not specifies, flake inputs default to the main / master branch.
inputs = {
# https://github.com/nixos/nixpkgs
# Nix Packages collection & NixOS
# This is the main input of the flake and specifies the NixOS version.
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# https://github.com/NixOS/nixos-hardware
# A collection of NixOS modules covering hardware quirks.
nixos-hardware.url = "github:NixOS/nixos-hardware";
# https://github.com/nix-community/home-manager
# Manage a user environment using Nix
home-manager = {
# Make sure the branch is correct for the version of nixpkgs you are using!
# For example, if you are using nixpkgs-unstable, you should use the master branch.
# For nixos-23.05, you should use the release-23.05 branch.
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
# https://github.com/nix-community/disko
# Format disks with nix-config
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
# https://github.com/pjones/plasma-manager
# Manage Kde Plasma configuration using Nix
plasma-manager = {
url = "github:pjones/plasma-manager";
inputs.nixpkgs.follows = "nixpkgs";
inputs.home-manager.follows = "home-manager";
};
# https://github.com/numtide/flake-utils
# Pure Nix flake utility functions
# Todo: completly get rid of those and use nixpkgs builtins
flake-utils.url = "github:numtide/flake-utils";
# https://github.com/nix-community/nixos-vscode-server
# Visual Studio Code Server support in NixOS
vscode-server = {
url = "github:msteen/nixos-vscode-server";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
# https://github.com/musnix/musnix/
# A collection of optimization options for realtime audio
musnix.url = "github:musnix/musnix";
# https://github.com/mayniklas/nixos
# @MayNiklas NixOS configuration
# We use a few modules from this flake as well as @MayNiklas home manager config
mayniklas = {
url = "github:mayniklas/nixos";
inputs = {
nixpkgs.follows = "nixpkgs";
home-manager.follows = "home-manager";
flake-utils.follows = "flake-utils";
nixos-hardware.follows = "nixos-hardware";
vscode-server.follows = "vscode-server";
};
};
# https://github.com/pinpox/lollypops/
# NixOS Deployment Tool
lollypops = {
url = "github:pinpox/lollypops";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, ... }@inputs:
with inputs;
{
# Expose overlay to flake outputs, to allow using it from other flakes.
# Flake inputs are passed to the overlay so that the packages defined in
# it can use the sources pinned in flake.lock
overlays.default = final: prev: (import ./overlays inputs) final prev;
# I don't think we need this anymore
# It seems completly unused
# To verify: build with it deleted
pi = {
pi4b = { config, pkgs, lib, ... }: {
imports = [
# https://github.com/NixOS/nixos-hardware/tree/master/raspberry-pi/4
nixos-hardware.nixosModules.raspberry-pi-4
];
networking = {
wireguard.interfaces = {
wg0 = {
privateKeyFile = toString /var/src/secrets/wireguard/private;
generatePrivateKeyFile = true;
};
};
};
hardware = { raspberry-pi."4".poe-hat.enable = true; };
# Assuming this is installed on top of the disk image.
fileSystems = {
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
options = [ "noatime" ];
};
};
};
};
# Output all modules in ./modules to flake. Modules should be in
# individual subdirectories and contain a default.nix file
nixosModules = builtins.listToAttrs
(map
(x: {
name = x;
value = import (./modules + "/${x}");
})
(builtins.attrNames (builtins.readDir ./modules)))
//
{
# lgoette.mayniklas
# -> imports used flake inputs
# -> this way, they can easily be imported to different flake outputs
mayniklas = { ... }: {
imports = [
# https://github.com/MayNiklas/nixos/tree/main/modules
mayniklas.nixosModules.cloud-provider
mayniklas.nixosModules.docker
mayniklas.nixosModules.home-manager
mayniklas.nixosModules.iperf
mayniklas.nixosModules.locale
mayniklas.nixosModules.minecraft
mayniklas.nixosModules.monitoring
mayniklas.nixosModules.nix-common
mayniklas.nixosModules.openssh
mayniklas.nixosModules.options
mayniklas.nixosModules.sound
mayniklas.nixosModules.user
mayniklas.nixosModules.zsh
];
};
};
# Each subdirectory in ./machines is a host. Add them all to
# nixosConfiguratons. Host configurations need a file called
# configuration.nix that will be read first
nixosConfigurations = builtins.listToAttrs (map
(x: {
name = x;
value = nixpkgs.lib.nixosSystem {
# Make inputs and the flake itself accessible as module parameters.
# Technically, adding the inputs is redundant as they can be also
# accessed with flake-self.inputs.X, but adding them individually
# allows to only pass what is needed to each module.
specialArgs = { flake-self = self; } // inputs;
modules = builtins.attrValues self.nixosModules
++ [ lollypops.nixosModules.lollypops ] ++ [
{
nixpkgs.overlays =
[ self.overlays.default mayniklas.overlays.mayniklas ];
}
(import "${./.}/machines/${x}/configuration.nix" { inherit self; })
];
};
})
(builtins.attrNames (builtins.readDir ./machines)));
homeConfigurations = {
desktop = { pkgs, lib, username, ... }: {
imports = [
./home-manager/profiles/common.nix
./home-manager/profiles/desktop.nix
plasma-manager.homeManagerModules.plasma-manager
] ++ (builtins.attrValues self.homeManagerModules);
};
desktop-audio = { pkgs, lib, username, ... }: {
imports = [
./home-manager/profiles/common.nix
./home-manager/profiles/desktop-audio.nix
plasma-manager.homeManagerModules.plasma-manager
] ++ (builtins.attrValues self.homeManagerModules);
};
server = { pkgs, lib, username, ... }: {
imports = [
./home-manager/profiles/common.nix
./home-manager/profiles/server.nix
vscode-server.nixosModules.home
plasma-manager.homeManagerModules.plasma-manager
] ++ (builtins.attrValues self.homeManagerModules);
# Visual Studio Code Server support
services.vscode-server.enable = true;
};
# nix run .#[email protected]
# home-manager switch --flake .
"lasse@Lasse-Laptop" =
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
config = { allowUnfree = true; };
overlays = [ ];
};
in
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
{ targets.genericLinux.enable = true; }
./home-manager/profiles/common.nix
] ++ (builtins.attrValues self.homeManagerModules);
# Optionally use extraSpecialArgs
# to pass through arguments to home.nix
extraSpecialArgs = { } // inputs;
};
};
homeManagerModules = builtins.listToAttrs
(map
(name: {
inherit name;
value = import (./home-manager/modules + "/${name}");
})
(builtins.attrNames (builtins.readDir ./home-manager/modules))) // {
nix = { pkgs, ... }: {
# this module is appended to the list of home-manager modules
# by defining it here, it's easier for us to access the flake inputs
nixpkgs.overlays =
[ self.overlays.default mayniklas.overlays.mayniklas ];
};
};
}
//
(flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ]) (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default mayniklas.overlays.mayniklas ];
config = {
allowUnsupportedSystem = true;
allowUnfree = true;
};
};
in
rec {
# Use nixpkgs-fmt for `nix fmt'
formatter = pkgs.nixpkgs-fmt;
# Custom packages added via the overlay are selectively exposed here, to
# allow using them from other flakes that import this one.
packages = flake-utils.lib.flattenTree {
build_outputs = pkgs.callPackage
mayniklas.packages.${system}.build_outputs.override
{
inherit self;
output_path = "~/.keep-nix-outputs-lgoette";
};
woodpecker-pipeline =
pkgs.callPackage ./packages/woodpecker-pipeline {
inputs = inputs;
flake-self = self;
};
bukkit-spigot = pkgs.bukkit-spigot;
minecraft-backup = pkgs.minecraft-backup;
minecraft-controller = pkgs.minecraft-controller;
};
apps = {
lollypops =
lollypops.apps.${pkgs.system}.default { configFlake = self; };
# Allow custom packages to be run using `nix run`
bukkit-spigot =
flake-utils.lib.mkApp { drv = packages.bukkit-spigot; };
minecraft-backup =
flake-utils.lib.mkApp { drv = packages.minecraft-backup; };
minecraft-controller =
flake-utils.lib.mkApp { drv = packages.minecraft-controller; };
};
});
}