Move NixOS infrastructure into subdirectory
This commit is contained in:
parent
2d6db9f952
commit
4e39b5395b
10 changed files with 0 additions and 0 deletions
270
nixos/common.nix
Normal file
270
nixos/common.nix
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
# This module presumes impermanence and BTRFS.
|
||||
|
||||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
i18n.defaultLocale = "en_GB.UTF-8";
|
||||
|
||||
environment = {
|
||||
systemPackages = with pkgs; [
|
||||
dust
|
||||
lm_sensors
|
||||
lsof
|
||||
nix-diff
|
||||
nix-tree
|
||||
pv
|
||||
usbutils
|
||||
tealdeer
|
||||
tree
|
||||
wget
|
||||
];
|
||||
|
||||
sessionVariables = {
|
||||
XDG_CONFIG_HOME = "$HOME/.config";
|
||||
XDG_CACHE_HOME = "$HOME/.cache";
|
||||
XDG_DATA_HOME = "$HOME/.local/share";
|
||||
XDG_STATE_HOME = "$HOME/.local/state";
|
||||
};
|
||||
|
||||
# Feel free to comment this out during initial install.
|
||||
|
||||
persistence = {
|
||||
"/mnt/persistent-data" = {
|
||||
hideMounts = true;
|
||||
directories = [
|
||||
"/etc/NetworkManager/system-connections"
|
||||
"/etc/nixos"
|
||||
"/var/lib/nixos"
|
||||
"/var/log"
|
||||
];
|
||||
files = [
|
||||
"/etc/machine-id"
|
||||
"/etc/ssh/ssh_host_ed25519_key"
|
||||
"/etc/ssh/ssh_host_ed25519_key.pub"
|
||||
"/etc/ssh/ssh_host_rsa_key"
|
||||
"/etc/ssh/ssh_host_rsa_key.pub"
|
||||
];
|
||||
users.rei.directories = [
|
||||
".ssh"
|
||||
];
|
||||
};
|
||||
"/mnt/machine-state" = {
|
||||
hideMounts = true;
|
||||
users.rei.directories = [
|
||||
".cache"
|
||||
".local/state"
|
||||
];
|
||||
users.root.directories = [
|
||||
".cache"
|
||||
".local/state"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
shellAliases = {
|
||||
# Default arguments.
|
||||
|
||||
cp = "cp -r";
|
||||
rsync = "rsync -r --info=progress2";
|
||||
mkdir = "mkdir -p";
|
||||
rm = "rm -rf";
|
||||
less = "less -S";
|
||||
lsblk = "lsblk -o +fstype,uuid";
|
||||
df = "df -h";
|
||||
wipefs = "wipefs -a";
|
||||
dust = "dust --limit-filesystem";
|
||||
"mkfs.ntfs" = "mkfs.ntfs --quick";
|
||||
nix-shell = "nix-shell --run $SHELL";
|
||||
|
||||
# Command shortcuts.
|
||||
|
||||
s = "sudo ";
|
||||
v = "vim";
|
||||
vd = "vimdiff";
|
||||
lns = "ln -s";
|
||||
headc = "head -c";
|
||||
chmodr = "chmod -R";
|
||||
chownr = "chown -R";
|
||||
sc = "systemctl";
|
||||
scu = "systemctl --user";
|
||||
jc = "journalctl";
|
||||
jcu = "journalctl --user";
|
||||
jck = "journalctl -k";
|
||||
jcli = "journalctl-last-invocation";
|
||||
ipl = "ip -br l";
|
||||
ip4a = "ip -br -4 a";
|
||||
ip6a = "ip -br -6 a";
|
||||
ip4r = "ip -4 r s t all";
|
||||
ip6r = "ip -6 r s t all";
|
||||
ip4n = "ip -4 n";
|
||||
ip6n = "ip -6 n";
|
||||
nrs = "nixos-rebuild switch";
|
||||
nrb = "nixos-rebuild boot";
|
||||
nrt = "nixos-rebuild test";
|
||||
ncg = "nix-collect-garbage";
|
||||
nsff = "nix-store-fuzzy-find";
|
||||
nbp = "nix-build-pkg";
|
||||
nd = "nix develop --command $SHELL";
|
||||
|
||||
# New commands.
|
||||
|
||||
nixos-cleanup-generations = ''
|
||||
zsh -c "nix-env --profile /nix/var/nix/profiles/system --delete-generations +20 && \
|
||||
/run/current-system/bin/switch-to-configuration boot"
|
||||
'';
|
||||
};
|
||||
|
||||
etc.vimrc.text = ''
|
||||
" $XDG_CONFIG_HOME/vim has to exist for this module to work.
|
||||
runtime! xdg.vim
|
||||
|
||||
" NetRW always uses the first directory in runtimepath which is $HOME/.vim, so we manually
|
||||
" set it to the XDG state directory because the only thing it should create anyway is its
|
||||
" history file.
|
||||
let g:netrw_home = '$XDG_STATE_HOME/vim'
|
||||
|
||||
" Sublime settings files can have comments.
|
||||
autocmd BufNewFile,BufRead *.sublime-settings set filetype=jsonc
|
||||
" Most software that reads JSON with comments also accepts trailing commas.
|
||||
autocmd FileType jsonc highlight link jsonTrailingCommaError Normal
|
||||
|
||||
set nowrap
|
||||
set hlsearch
|
||||
set tabstop=2
|
||||
set noexpandtab
|
||||
set autoindent
|
||||
|
||||
command W w
|
||||
command Q q
|
||||
command Wq wq
|
||||
command Qa qa
|
||||
command Wqa wqa
|
||||
'';
|
||||
};
|
||||
|
||||
hardware.enableAllFirmware = true;
|
||||
|
||||
users = {
|
||||
defaultUserShell = pkgs.zsh;
|
||||
mutableUsers = false;
|
||||
users.rei = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" "wireshark" ];
|
||||
openssh.authorizedKeys.keyFiles = [ assets/openssh-authorized-keys ];
|
||||
};
|
||||
};
|
||||
|
||||
nix.settings = {
|
||||
auto-optimise-store = true;
|
||||
experimental-features = [ "flakes" "nix-command" ];
|
||||
use-xdg-base-directories = true;
|
||||
};
|
||||
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
|
||||
programs = {
|
||||
git.enable = true;
|
||||
|
||||
htop = {
|
||||
enable = true;
|
||||
# Not read directly, instead these are copied into the user config file when htop is run.
|
||||
settings = {
|
||||
hide_userland_threads = true;
|
||||
highlight_base_name = true;
|
||||
};
|
||||
};
|
||||
|
||||
vim = {
|
||||
enable = true;
|
||||
defaultEditor = true;
|
||||
# Default Vim package does not read /etc/vimrc, plus this one has better Nix language support.
|
||||
package = pkgs.vim-full.override {
|
||||
guiSupport = false;
|
||||
};
|
||||
};
|
||||
|
||||
zsh = {
|
||||
enable = true;
|
||||
histFile = "$XDG_STATE_HOME/zsh/history";
|
||||
shellInit = ''
|
||||
ZDOTDIR=$XDG_CONFIG_HOME/zsh
|
||||
ZSH_COMPDUMP=$XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION
|
||||
'';
|
||||
interactiveShellInit = ''
|
||||
# Add newline to prompt, but only after the first command.
|
||||
precmd() { precmd() { echo } }
|
||||
|
||||
# Disable lack of newline indicator.
|
||||
PROMPT_EOL_MARK=""
|
||||
'';
|
||||
ohMyZsh = {
|
||||
enable = true;
|
||||
theme = "robbyrussell";
|
||||
plugins = [ "git" ];
|
||||
preLoaded = ''
|
||||
COMPLETION_WAITING_DOTS=true
|
||||
HYPHEN_INSENSITIVE=true
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
nix-index-database.comma.enable = true;
|
||||
};
|
||||
|
||||
# TODO: Check if we should use systemd.user.tmpfiles with %h and default options, also to
|
||||
# deduplicate rules between users.
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /home/rei/.config 0700 rei users"
|
||||
# Vim needs this to exist in order to use XDG dirs.
|
||||
"d /home/rei/.config/vim 0755 rei users"
|
||||
|
||||
"d /root/.config 0700 root root"
|
||||
# See above.
|
||||
"d /root/.config/vim 0755 root root"
|
||||
];
|
||||
|
||||
networking = {
|
||||
hostName = "ruysch";
|
||||
networkmanager.enable = true;
|
||||
};
|
||||
|
||||
services = {
|
||||
btrfs.autoScrub.enable = true;
|
||||
fwupd.enable = true;
|
||||
|
||||
openssh = {
|
||||
settings = {
|
||||
PasswordAuthentication = false;
|
||||
KbdInteractiveAuthentication = false;
|
||||
};
|
||||
extraConfig = ''
|
||||
PrintLastLog no
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
networking = {
|
||||
# I fart in your general direction!
|
||||
firewall.rejectPackets = true;
|
||||
nftables.enable = true;
|
||||
};
|
||||
|
||||
security = {
|
||||
polkit = {
|
||||
enable = true;
|
||||
# Not yet in stable as of 26.05.
|
||||
# enablePkexecWrapper = true;
|
||||
extraConfig = ''
|
||||
polkit.addRule(function (action, subject) {
|
||||
if (subject.user == "rei") {
|
||||
return polkit.Result.AUTH_SELF;
|
||||
}
|
||||
});
|
||||
'';
|
||||
};
|
||||
|
||||
sudo.extraConfig = ''
|
||||
Defaults lecture="never"
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue