-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
243 lines (225 loc) · 7.19 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
{
description = "Home Manager Configuration Flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgsUnstable.url = "github:nixos/nixpkgs/nixos-unstable"; # for latest
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
inputs.nixpkgs.follows = "nixpkgs";
};
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
blesh = {
url = "https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly-20220825+793dfad.tar.xz";
flake = false;
};
};
outputs = { self, nixpkgs, nixpkgsUnstable, home-manager, flake-utils, devshell, blesh, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
};
pkgsUnstable = import nixpkgsUnstable {
inherit system;
config = {
allowUnfree = true;
};
};
hostname = "tars";
in
{
formatter.${system} = pkgs.nixpkgs-fmt;
nixosConfigurations.${hostname} = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./nixos/configuration.nix ];
};
homeConfigurations.${hostname} = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home.nix
];
extraSpecialArgs = {
inherit blesh;
inherit pkgsUnstable;
};
};
# https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-run.html?highlight=apps.%3Csystem%3E#apps
# https://nix-community.github.io/home-manager/index.html#sec-flakes-standalone
apps.${system} = {
"activate/${hostname}" =
let
drv = self.outputs.homeConfigurations.${hostname}.activationPackage;
exePath = "/activate";
in
{
type = "app";
program = "${drv}${exePath}";
};
# just for fun
"figlet" = {
type = "app";
program = "${pkgs.figlet}/bin/figlet";
};
};
} //
flake-utils.lib.eachDefaultSystem
(system: {
# Trying devShells and devshell as a better alternative to Makefile.
# https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html
# https://github.com/numtide/devshell
devShells.default = pkgs.devshell.mkShell {
devshell.motd = ''
{bold}{14}🔨 My home conigs 🔨{reset}
$(type -p menu &>/dev/null && menu)
'';
commands = [
# --- Fun ---
{
name = "dev:hello";
category = "Fun";
help = "Print a nice hello world";
command = ''
nix run '.#figlet' -- -f isometric1 -c "Hello World"
'';
}
# --- Initial Setup ---
{
name = "dev:install";
category = "Initial Setup";
help = "Install home-manager itself and apply the home configuration";
command = ''
export HOME_MANAGER_BACKUP_EXT=old
nix run '.#activate/tars'
direnv allow
'';
}
# --- Home Environment ---
{
name = "dev:ls-pkg";
category = "Home";
help = "List all packages installed in home-manager-path";
command = ''
home-manager packages
'';
}
{
name = "dev:ls-gen";
category = "Home";
help = "List all home environment generations";
command = ''
home-manager generations
'';
}
{
name = "dev:switch";
category = "Home";
help = "Switch home-manager to apply home config changes";
command = ''
home-manager switch --flake '.#tars' -b bck --impure
'';
}
{
name = "dev:update";
category = "Home";
help = "Update things";
command = ''
home-manager switch --flake '.#tars' -b bck --impure --recreate-lock-file
'';
}
{
name = "dev:update-nixpkgs";
category = "Home";
help = "Update nixpkgs only";
command = ''
nix flake lock --update-input nixpkgs
dev:switch
'';
}
{
name = "dev:update-lock-only";
category = "Home";
help = "Update the flake lock file only";
command = ''
nix flake update
'';
}
# --- NixOS ---
{
name = "dev:os-switch";
category = "NixOS";
help = "Switch nixos to rebuild and apply `configuration.nix` changes";
command = ''
sudo nixos-rebuild switch --flake '.#tars' --impure
'';
}
{
name = "dev:os-ls-gen";
category = "NixOS";
help = "List all nixos generations";
command = ''
sudo nix-env --list-generations --profile /nix/var/nix/profiles/system
'';
}
# --- Utility ---
{
name = "dev:fmt";
category = "Utility";
help = "Format nix files";
command = ''
nix fmt
'';
}
{
name = "dev:du-svg";
category = "Utility";
help = "Show what gc-roots are taking space (svg)";
command = ''
nix-du -s=500MB | tred | dot -Tsvg > store.svg
'';
}
{
name = "dev:du-png";
category = "Utility";
help = "Show what gc-roots are taking space (png)";
command = ''
nix-du -s=500MB | tred | dot -Tpng > store.png
'';
}
{
name = "dev:show-gc-roots";
category = "Utility";
help = "Show gc-roots";
command = ''
nix-store --gc --print-roots
'';
}
{
name = "dev:gc";
category = "Utility";
help = "Garbage collection";
command = ''
sudo nix-collect-garbage
'';
}
{
name = "dev:gc-stale";
category = "Utility";
help = ''Perform garbage collection and delete all generations older than 5 days'';
command = ''
sudo nix-collect-garbage -d --delete-older-than 5d
'';
}
{
name = "dev:gc-all";
category = "Utility";
help = ''Perform garbage collection and delete all old generations'';
command = ''
sudo nix-collect-garbage -d
'';
}
];
};
});
}