-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
198 lines (184 loc) · 6.18 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
# this flake has gotten rather unwieldy and I need to refactor it severely
# a couple of improvements I need to make are:
# - refactor modules to not depend on pkgs
# - refactor configurations to be platform independent
# - refactor to allow the same host to be built for different targets, e.g. hyperion on a vm
# - allow the flake itself to be more command-based, e.g. "build a vm image of hyperion"
{
description = "My Nix system configurations.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs.url = "github:serokell/deploy-rs";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
flake-utils.url = "github:numtide/flake-utils";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
emacs-overlay = {
url = "github:nix-community/emacs-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ {
self,
nixpkgs,
home-manager,
deploy-rs,
nixos-hardware,
flake-utils,
nixos-generators,
nix-darwin,
emacs-overlay,
...
}: let
inherit (lib.my) mapModules mkPkgs;
pkgs = mkPkgs nixpkgs [];
# TODO import lib functions that don't depend on pkgs
lib = nixpkgs.lib.extend (self: super: {
my = import ./nix/lib {
inherit inputs pkgs;
lib = self;
};
});
in
{
templates = {
rust = {
path = ./nix/templates/rust;
description = "Rust project template";
};
emacs-lisp = {
path = ./nix/templates/emacs-lisp;
description = "Emacs Lisp template";
};
};
# TODO utilize top-level nixosModules
# TODO remove from flake-level overlays, pass into hosts in a different manner
overlays =
{
# very silly way of specifying this, but will throw very bizarre error when you run nix flake check
# this should be the same as just: `import emacs-overlay`
emacs-overlay = final: prev: import emacs-overlay final prev;
}
// (mapModules ./nix/overlays import);
# these are the actual system configurations
# any particular system can be build with nixos-rebuild of course, but also:
# nix build .#nixosConfigurations.<hostname>.config.system.build.toplevel
# TODO refactor as packages, configurations can be built as packages
# like so: packages.<platform>.nixosConfigurations.<hostname>.config.system.build.toplevel
nixosConfigurations = let
mkHost = lib.my.mkNixOSHost;
in {
hyperion = mkHost ./nix/hosts/hyperion/configuration.nix {
system = "x86_64-linux";
};
atlas = mkHost ./nix/hosts/atlas/configuration.nix {
system = "x86_64-linux";
};
helios = mkHost ./nix/hosts/helios/configuration.nix {
system = "x86_64-linux";
};
pallas = mkHost ./nix/hosts/pallas/configuration.nix {
system = "aarch64-linux";
};
};
# TODO add darwin configurations
# TODO write a mapHosts function, like here: https://github.com/hlissner/dotfiles/blob/master/lib/nixos.nix
# nixosConfigurations = mapHosts ./nix/hosts { };
# TODO make deployment nodes their own files
deploy = {
sshUser = "ryan";
autoRollback = true;
magicRollback = true;
interactiveSudo = true;
nodes = {
# run with: nix run '.#deploy-rs' '.#atlas'
atlas = {
hostname = "atlas";
profiles.system = {
user = "root";
path =
deploy-rs.lib.x86_64-linux.activate.nixos
self.nixosConfigurations.atlas;
};
};
pallas = {
hostname = "pallas";
profiles.system = {
user = "root";
path =
deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.pallas;
};
};
};
};
}
# x86_64-linux-specific packages
# TODO custom packages should be added to pkgs, made available globally
# right now, my custom aarch64 installer can only be built on x86_64 linux
// {
packages.x86_64-linux = let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
in {
roc-rk3328-cc-bootloader = import ./nix/pkgs/roc-rk3328-cc-bootloader {
inherit pkgs;
lib = pkgs.lib;
};
# run with:
# nix build .#arm-installer --system aarch64-linux
arm-installer = nixos-generators.nixosGenerate {
system = "aarch64-linux";
modules = [
./nix/installers/aarch64-linux/configuration.nix
];
specialArgs = {
inherit inputs;
};
customFormats.aarch64-linux-roc = import ./nix/formats/aarch64-linux-roc/configuration.nix {
inherit pkgs;
bootloader = self.packages.x86_64-linux.roc-rk3328-cc-bootloader;
};
format = "aarch64-linux-roc";
};
};
}
# cross-platform applications and packages
// flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};
in {
formatter = pkgs.alejandra;
# I re-export deploy-rs due to an issue with running `nix flake github:serokell/deploy-rs ...`
# per a conversation I had here: https://github.com/serokell/deploy-rs/issues/155
apps.deploy-rs = deploy-rs.defaultApp."${system}";
devShells = {
deploy-rs = pkgs.mkShell {
buildInputs = [deploy-rs.defaultPackage."${system}"];
};
luaDev = pkgs.mkShell {
buildInputs = with pkgs; [
lua-language-server
luajitPackages.fennel
luajitPackages.luasocket
stylua
fnlfmt
];
};
default = self.devShells.${system}.luaDev;
};
});
}