-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.nix
More file actions
397 lines (353 loc) · 12.1 KB
/
common.nix
File metadata and controls
397 lines (353 loc) · 12.1 KB
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
{
config,
lib,
pkgs,
inputs,
system,
...
}:
with lib; {
imports = [
modules/default.nix
modules/env.nix # Set XDG/config vars
modules/sway-desktop.nix # My sway desktop configuration
];
########################################
# Nix
########################################
system.stateVersion = mkDefault "25.05";
nix = {
settings = {
auto-allocate-uids = true;
auto-optimise-store = mkDefault true;
connect-timeout = mkDefault 2;
experimental-features = [
"auto-allocate-uids"
# "ca-derivations"
"cgroups"
"nix-command"
"flakes"
];
flake-registry = mkDefault ""; # instead of https://channels.nixos.org/flake-registry.json
keep-going = mkDefault true;
trusted-users = mkDefault ["root" "@wheel"];
use-cgroups = mkDefault true;
use-xdg-base-directories = true;
# warn-dirty = mkDefault false;
#
# allow-import-from-derivation = false;
#
# after https://github.com/NixOS/nix/pull/8323 and/or https://github.com/NixOS/nix/pull/3494
# print-build-logs = true
};
gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 30d";
};
channel.enable = mkDefault false;
daemonCPUSchedPolicy = "idle";
daemonIOSchedClass = "idle";
};
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) (import ./unfree.nix);
systemd.services."nix-daemon".serviceConfig = {
# It'd be nice if this could be 50% of all CPUs
# Re: https://github.com/systemd/systemd/issues/33136
CPUQuota = "200%";
ManagedOOMMemoryPressure = "kill";
ManagedOOMMemoryPressureLimit = "80%";
};
# Disable building man-cache as it's slow, slightly
# lower than default of 1000
documentation.man.cache.enable = mkOverride 999 false;
# Include current config:
environment.etc.current-nixos-config.source = ./.;
# From: github:etu/nixconfig/modules/base/default.nix
system.activationScripts.diff = {
supportsDryActivation = true;
text = ''
NO_FORMAT="\033[0m"
F_BOLD="\033[1m"
C_LIME="\033[38;5;10m"
if test -e /run/current-system; then
echo -e "''${F_BOLD}''${C_LIME}==> diff to current-system ''${NO_FORMAT}"
${pkgs.nvd}/bin/nvd --nix-bin-dir=${config.nix.package}/bin diff /run/current-system "$systemConfig"
fi
echo -e "''${F_BOLD}''${C_LIME}==> Indicate if a reboot is needed or not ''${NO_FORMAT}"
${pkgs.nixos-needsreboot}/bin/nixos-needsreboot || true
'';
};
########################################
# Hardware
########################################
hardware.cpu.intel.updateMicrocode = mkDefault true;
########################################
# Locale
########################################
time.timeZone = mkDefault "America/Halifax";
i18n.defaultLocale = mkDefault "en_CA.UTF-8";
########################################
# Boot
########################################
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = mkDefault true;
boot.kernelPackages = mkOverride (lib.modules.defaultOrderPriority - 1) pkgs.linuxPackages_6_18;
security.unprivilegedUsernsClone = mkDefault config.virtualisation.containers.enable;
boot.kernel.sysctl = {};
# Limit previous generations to avoid /boot filling up
boot.loader.systemd-boot.configurationLimit = mkDefault 10;
boot.loader.efi.canTouchEfiVariables = mkDefault true;
boot.tmp.useTmpfs = mkDefault true;
# Clean up old coredumps
systemd.services.clear-log = {
description = "Clear old coredumps";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.systemd}/bin/journalctl --vacuum-time=14d";
};
};
systemd.timers.clear-log = {
wantedBy = ["timers.target"];
partOf = ["clear-log.service"];
timerConfig.OnCalendar = "weekly UTC";
};
########################################
# Disk
########################################
services.fstrim.enable = mkDefault true;
########################################
# Network
########################################
networking.firewall.enable = mkDefault true;
networking.useDHCP = false; # deprecated
networking.usePredictableInterfaceNames = mkDefault false;
########################################
# User
########################################
# Enumerate all systems uids here:
ids.uids = {
kenny = 1001;
angela = 1002;
media = 1201;
sftp-yoga = 1301;
};
users.defaultUserShell = pkgs.fish;
users.users.kenny = {
isNormalUser = true;
uid = config.ids.uids.kenny;
createHome = true;
shell = pkgs.fish;
extraGroups = [
"wheel"
"wpa_supplicant" # For wifi config
"uinput" # For testing kanata
"tss" # Testing tpm2
];
# Podman runs out of subuids with large images (eg connectedhomeip)
subUidRanges = [
{
startUid = 100000;
count = 1048576;
}
];
subGidRanges = [
{
startGid = 100000;
count = 1048576;
}
];
# TODO: look at https://www.openssh.com/agent-restrict.html to see about
# limiting key to pam access without allowing it to be used to connect
# to further hosts
openssh.authorizedKeys.keys = [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCxdqQrcKwakfrGvXCRQ2mNM3c5CkbwSEMuUufIcO0Op0xJJkdb59v2iqkztZMNpJFbS61ymsyzeRCwDQ5xptUNrjvbnppL+tBzErKMdilHzadpLeGffUCJg9GcIVJxQzFVbt0tIGwPsBcVHb1WITmzQCoZ/O0p1NSFRovwU8TXCOhnuObDUisFiJyA2e3C8tNvlm0Rvgb7bIH0T+/W4VIc+7ZZWwP/UMCnBHE4azZAcDJ4e9XO+ZJwg6iUXu7lk5X+34ACeHkPu133cGesz8BMl7yoXT058RcEW5bfcN6Dpl/IODNjxbDeQ/dYiVNnSExUWOrCo1sN1RYUQrKCzCzqCZ+29A07czYJDPjUt8pZdBQV3z261zYqyeP/IOgdHp3LZobIm48XF/+Abp/tTu8e99TP1y3L+8XuAMeu1THwHdcnQLJgv4nGExXijlvI/NlPEWhDqs991hhD7eHkg9w7QfuTjxRvZIjAkeK7ByWqMTULMrQBeHSS095b0gdHG3PEGz9BW9J4gHxW/s/pa5Cya3AOv7DJPDAEgxjqhB4wAuzvNnuxNXZCBwrNr8rRr860eNsOOe1rilSKRojF5s2DRin5OzXxJGQkHb1lndxya6E2U5i/+PzGuuPxNmoRDMZ43z7FZWIFej6Vb6Xd1bc1Q8Izbg5M2ZXVgDVoUrY02Q=="
];
};
########################################
# Security
########################################
security.sudo = {
execWheelOnly = true;
extraConfig = ''
Defaults env_keep += "BORG_KEYS_DIR"
# Allow yubikey auth for sudo:
Defaults env_keep += "SSH_AUTH_SOCK"
Defaults env_keep += "GPG_TTY"
Defaults env_keep += "GNUPGHOME"
'';
};
services.openssh.settings.PasswordAuthentication = mkDefault false;
services.openssh.settings.KbdInteractiveAuthentication = mkDefault false;
# Allow more than the default 1024 open files
security.pam.loginLimits = [
{
domain = "*";
type = "soft";
item = "nofile";
value = "16384";
}
];
########################################
# Services
########################################
# NTP
services.timesyncd.enable = mkDefault true;
networking.timeServers = mkDefault ["time.cloudflare.com"];
# fwupd disable p2p by default
services.fwupd.daemonSettings = {
P2pPolicy = mkDefault "nothing";
};
########################################
# Programs
########################################
# TODO: look at other from https://github.com/arlohb/nixos/blob/910916a5e94b6192505a7535e071b7d025ac040c/conf/shell.nix#L37
programs.git.config = {
init.defaultBranch = "main";
url."https://github.com/".insteadOf = ["gh:" "github:"];
};
programs.fish = {
enable = true;
interactiveShellInit = ''
function whichreal
readlink (which $argv)
end
if set -q KITTY_INSTALLATION_DIR
set --global KITTY_SHELL_INTEGRATION enabled
source "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish"
set --prepend fish_complete_path "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_completions.d"
end
'';
};
# TODO: probably move to a separate module
# TODO: 0.11 adds vim.lsp.config()/vim.lsp.enable(), see if nixos uses
# https://gpanders.com/blog/whats-new-in-neovim-0-11/
programs.neovim = {
enable = true;
defaultEditor = true;
viAlias = true;
vimAlias = true;
withRuby = false;
configure = {
packages.myPlugins = with pkgs.vimPlugins; {
# To maybe try:
# vim-easymotion
# vim-json
# vim-yaml
# telescope
# vim-clap
start = [
editorconfig-vim # Settings in .editorconfig
leap-nvim
nerdtree # File path browsing
nvim-cmp
nvim-treesitter.withAllGrammars
nvim-lastplace
vim-sleuth
vim-buffergator # <leader>b to show buffers
vim-gnupg
# Snippet
cmp_luasnip
luasnip
friendly-snippets
];
opt = [];
};
# Use https://github.com/nix-community/nixvim ?
customRC = ''
" Function to source files if they exist
function! SourceIfExists(file)
if filereadable(expand(a:file))
exe 'source' a:file
endif
endfunction
" ignore case in search unless set
set ignorecase
set smartcase
" No directory editing please
" For some reason this isn't printing in NixOS/nvim. Not sure why
for f in argv()
if isdirectory(f)
echomsg "vimrc: Cowardly refusing to edit directory " . f
quit
endif
endfor
" Use the system clipboard
set clipboard+=unnamedplus
vnoremap <C-c> "+y
" Show nbsp characters
set listchars=nbsp:.
" gopass
au BufNewFile,BufRead /dev/shm/gopass.* setlocal noswapfile nobackup noundofile
" Enable treesitter
lua << EOF
require'nvim-treesitter'.setup {
highlight = {
enable = true,
},
}
-- 's' then two chars to jump to that
vim.keymap.set({'n', 'x', 'o'}, 's', '<Plug>(leap)')
vim.keymap.set('n', 'S', '<Plug>(leap-from-window)')
local cmp = require('cmp')
local luasnip = require('luasnip')
-- Load friendly-snippets if installed
require('luasnip.loaders.from_vscode').lazy_load()
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false }), -- select = false to avoid adding entry on just enter alone
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
}),
})
EOF
" Call user inits
let $MYVIMRC = expand('$XDG_CONFIG_HOME/nvim/init.vim')
call SourceIfExists("$MYVIMRC")
let $MYVIMLUA = expand('$XDG_CONFIG_HOME/nvim/init.lua')
call SourceIfExists("$MYVIMLUA")
'';
};
};
########################################
# Packages
########################################
environment.systemPackages = with pkgs; [
config.boot.kernelPackages.cpupower
kitty.terminfo
# Nix build packages
alejandra
git
gitui
just
];
system.extraDependencies = [
pkgs.nixVersions.stable # Always keep a stable nix version in the store
];
# Set RCLONE_FAST_LIST to always reduce costs
# when sending files to B2.
environment.variables.RCLONE_FAST_LIST = "1";
# Set SSL_CERT_FILE to avoid issues, expecially with 'uv run' python code
environment.variables.SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt";
}