nixos/common.nix

515 lines
12 KiB
Nix
Raw Normal View History

2023-01-15 18:56:16 +01:00
{ config, pkgs, ... }:
let
impermanence = builtins.fetchTarball "https://github.com/nix-community/impermanence/archive/master.tar.gz";
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/master.tar.gz";
in
{
#
# stuff shared between home machines
#
# get impermanence & home manager working
imports = [
# manage persistent files
"${impermanence}/nixos.nix"
# home manager for per user config
"${home-manager}/nixos"
];
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
2023-06-09 18:26:35 +02:00
# on your system were taken. It's perfectly fine and recommended to leave
2023-01-15 18:56:16 +01:00
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
2023-06-09 18:26:35 +02:00
system.stateVersion = "23.05"; # Did you read the comment?
# use the latest kernel
boot.kernelPackages = pkgs.linuxPackages_latest;
2023-01-15 18:56:16 +01:00
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
2023-06-02 23:53:02 +02:00
# use a high resolution
boot.loader.systemd-boot.consoleMode = "max";
# we want to be able to do a memtest
boot.loader.systemd-boot.memtest86.enable = true;
2023-06-02 23:53:02 +02:00
# use systemd early
boot.initrd.systemd.enable = true;
# setup the console stuff early
console.earlySetup = true;
2023-01-15 18:56:16 +01:00
# keep some stuff persistent
environment.persistence."/nix/persistent" = {
directories = [
2023-01-16 19:54:58 +01:00
# systemd timers
{ directory = "/var/lib/systemd/timers"; user = "root"; group = "root"; mode = "u=rwx,g=rx,o=rx"; }
2023-01-15 18:56:16 +01:00
2023-01-16 19:54:58 +01:00
# clamav database
{ directory = "/var/lib/clamav"; user = "clamav"; group = "clamav"; mode = "u=rwx,g=rx,o=rx"; }
2023-01-15 18:56:16 +01:00
];
};
2023-06-10 17:33:43 +02:00
# ensure we scrub the btrfs sometimes
services.btrfs.autoScrub = {
enable = true;
interval = "weekly";
};
2023-01-15 22:48:29 +01:00
# allow all firmware
hardware.enableAllFirmware = true;
2023-10-21 21:48:11 +02:00
# use systemd-networkd
2023-09-17 15:57:39 +02:00
networking.useDHCP = false;
2023-10-21 21:48:11 +02:00
systemd.network = {
enable = true;
networks."10-wan" = {
networkConfig = {
# start a DHCP Client for IPv4 Addressing/Routing
DHCP = "ipv4";
# accept Router Advertisements for Stateless IPv6 Autoconfiguraton (SLAAC)
IPv6AcceptRA = true;
};
# make routing on this interface a dependency for network-online.target
linkConfig.RequiredForOnline = "routable";
};
};
2023-09-17 15:57:39 +02:00
2023-02-04 16:31:22 +01:00
# ensure firewall is up, allow ssh and http in
2023-01-15 22:48:29 +01:00
networking.firewall.enable = true;
2023-06-10 17:42:28 +02:00
networking.firewall.allowedTCPPorts = [ 22 ];
2023-06-09 18:26:35 +02:00
networking.firewall.logRefusedConnections = false;
2023-01-15 18:56:16 +01:00
2023-06-09 18:26:35 +02:00
# OpenSSH daemon config
services.openssh = {
# enable with public key only auth
2023-05-02 19:32:11 +02:00
enable = true;
2023-06-09 18:26:35 +02:00
settings.PasswordAuthentication = false;
settings.KbdInteractiveAuthentication = false;
# only ed25519 keys, make them persistent
hostKeys = [{
path = "/nix/persistent/ssh_host_ed25519_key";
type = "ed25519";
}];
2023-05-02 19:32:11 +02:00
};
2023-06-09 18:26:35 +02:00
# guard the ssh service
services.sshguard.enable = true;
2023-01-15 18:56:16 +01:00
# Set your time zone.
time.timeZone = "Europe/Berlin";
# default locale is English US
i18n.defaultLocale = "en_US.UTF-8";
# use German stuff for sorting/date/....
i18n.extraLocaleSettings = {
LC_ADDRESS = "de_DE.UTF-8";
LC_IDENTIFICATION = "de_DE.UTF-8";
LC_MEASUREMENT = "de_DE.UTF-8";
LC_MONETARY = "de_DE.UTF-8";
LC_NAME = "de_DE.UTF-8";
LC_NUMERIC = "de_DE.UTF-8";
LC_PAPER = "de_DE.UTF-8";
LC_TELEPHONE = "de_DE.UTF-8";
LC_TIME = "de_DE.UTF-8";
};
2023-09-02 17:06:15 +02:00
# allow to have all locales
i18n.supportedLocales = [ "all" ];
2023-01-15 18:56:16 +01:00
# ensure we see the journal on TTY12
services.journald.console = "/dev/tty12";
2023-01-15 21:44:28 +01:00
# keep power consumption and heat in check
powerManagement.enable = true;
powerManagement.cpuFreqGovernor = "powersave";
services.thermald.enable = true;
2023-01-15 18:56:16 +01:00
# allow firmware updates
services.fwupd.enable = true;
2023-10-21 21:31:26 +02:00
# EurKey layout everywhere
2023-10-21 21:25:14 +02:00
services.xserver.layout = "eu";
2023-10-21 21:31:26 +02:00
console.useXkbConfig = true;
2023-01-15 18:56:16 +01:00
2023-10-21 21:25:14 +02:00
# enable the KDE Plasma Desktop Environment
services.xserver.desktopManager.plasma5.enable = true;
2023-01-15 18:56:16 +01:00
2023-10-21 21:25:14 +02:00
# greetd console display manager
services.greetd = {
2023-01-15 18:56:16 +01:00
enable = true;
2023-10-21 21:25:14 +02:00
settings = {
default_session = {
command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd '${pkgs.plasma-workspace}/libexec/plasma-dbus-run-session-if-needed ${pkgs.plasma-workspace}/bin/startplasma-wayland'";
};
};
2023-01-15 18:56:16 +01:00
};
2023-05-20 22:37:33 +02:00
# enable sound with PipeWire
2023-01-15 18:56:16 +01:00
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
jack.enable = true;
2023-05-20 22:37:33 +02:00
pulse.enable = true;
2023-01-15 18:56:16 +01:00
};
# allow realtime
security.rtkit.enable = true;
# package manager config
nix = {
# auto optimize the store
settings.auto-optimise-store = true;
# cleanup the store from time to time
gc = {
automatic = true;
dates = "daily";
options = "--delete-older-than 7d";
};
# avoid that nix hogs all CPUs
settings = {
max-jobs = 1;
cores = 4;
};
2023-05-20 16:18:12 +02:00
# https://github.com/nix-community/nix-direnv
extraOptions = ''
keep-outputs = true
keep-derivations = true
'';
2023-01-15 18:56:16 +01:00
};
# avoid suspend ever to be triggered
systemd.targets.sleep.enable = false;
systemd.targets.suspend.enable = false;
systemd.targets.hibernate.enable = false;
systemd.targets.hybrid-sleep.enable = false;
# let home manager install stuff to /etc/profiles
home-manager.useUserPackages = true;
# use global pkgs
home-manager.useGlobalPkgs = true;
# Allow unfree packages
nixpkgs.config.allowUnfree = true;
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
2023-06-10 19:09:58 +02:00
ark
2023-01-15 18:56:16 +01:00
aspellDicts.de
aspellDicts.en
borgbackup
2023-03-23 20:50:35 +01:00
btop
calibre
2023-10-21 18:15:29 +02:00
chromium
2023-01-15 18:56:16 +01:00
clamav
2023-06-10 19:09:58 +02:00
clinfo
2023-09-16 16:54:02 +02:00
config.boot.kernelPackages.perf
2023-07-28 17:11:20 +02:00
efibootmgr
emacs
falkon
2023-10-15 17:18:18 +02:00
fdupes
ffmpeg
2023-10-15 17:18:18 +02:00
file
filelight
gimp
2023-01-15 18:56:16 +01:00
gitFull
2023-06-10 19:09:58 +02:00
glxinfo
go
2023-07-28 17:29:07 +02:00
gptfdisk
heaptrack
hotspot
hugo
2023-01-15 18:56:16 +01:00
hunspellDicts.de_DE
hunspellDicts.en_US
2023-10-15 17:18:18 +02:00
inetutils
kate
kcachegrind
kcalc
keychain
kmail
kompare
2023-10-15 17:08:01 +02:00
konsole
konversation
krita
libjxl
libreoffice
2023-06-10 19:09:58 +02:00
libva-utils
2023-01-15 18:56:16 +01:00
lsof
mc
neochat
nixos-install-tools
nmap
2023-09-16 17:08:34 +02:00
nvme-cli
okteta
okular
2023-08-06 19:41:42 +02:00
p7zip
2023-07-28 17:29:07 +02:00
parted
2023-10-15 17:18:18 +02:00
pciutils
pulseaudio
qmk
tcl
texlive.combined.scheme-small
tigervnc
tk
tokodon
2023-06-10 17:02:24 +02:00
unrar
unzip
usbutils
valgrind
vlc
vscodium
2023-06-10 19:09:58 +02:00
vulkan-tools
wayland-utils
2023-01-15 18:56:16 +01:00
zsh
zsh-powerlevel10k
];
2023-10-22 17:56:24 +02:00
# run browsers in a sandbox
2023-10-21 18:15:29 +02:00
programs.firejail = {
enable = true;
2023-10-21 19:22:49 +02:00
2023-10-21 18:15:29 +02:00
wrappedBinaries = {
chromium = {
executable = "${pkgs.lib.getBin pkgs.chromium}/bin/chromium";
profile = "${pkgs.firejail}/etc/firejail/chromium.profile";
};
2023-10-21 19:22:49 +02:00
2023-10-22 19:50:05 +02:00
falkon = {
executable = "${pkgs.lib.getBin pkgs.falkon}/bin/falkon";
profile = "${pkgs.firejail}/etc/firejail/falkon.profile";
};
2023-10-21 18:15:29 +02:00
firefox = {
executable = "${pkgs.lib.getBin pkgs.firefox}/bin/firefox";
profile = "${pkgs.firejail}/etc/firejail/firefox.profile";
};
2023-10-21 18:08:29 +02:00
};
};
2023-10-21 19:22:49 +02:00
2023-10-21 18:15:29 +02:00
# chromium needs programs.firefox.enable here and systemPackages entry to have icon and work
2023-10-15 16:27:54 +02:00
programs.chromium.enable = true;
2023-10-21 19:22:49 +02:00
2023-10-21 18:15:29 +02:00
# firefox needs programs.firefox.enable here but no systemPackages entry to have icon and work
2023-10-15 16:27:54 +02:00
programs.firefox.enable = true;
# Flatpak to sandbox Steam, Bottles and Co.
#
# flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
2023-10-22 17:56:24 +02:00
# flatpak install --user flathub org.signal.Signal
# flatpak install --user flathub com.usebottles.bottles
# flatpak install --user flathub com.valvesoftware.Steam
#
services.flatpak.enable = true;
2023-01-15 18:56:16 +01:00
# allow keyboard configure tools to work
2023-05-20 23:22:25 +02:00
hardware.keyboard.qmk.enable = true;
2023-01-15 18:56:16 +01:00
# add ~/bin to PATH
environment.homeBinInPath = true;
# more fonts for all users
fonts = {
# more fonts
2023-07-29 16:11:55 +02:00
packages = with pkgs; [
2023-01-15 18:56:16 +01:00
# needed for powerlevel10k zsh stuff
meslo-lgs-nf
2023-02-04 20:11:00 +01:00
# unicode capable font
noto-fonts
noto-fonts-extra
noto-fonts-emoji
2023-07-02 10:48:55 +02:00
2023-07-25 21:16:46 +02:00
# nice mono spaced fonts
fira-code
iosevka-bin
2023-07-02 10:48:55 +02:00
victor-mono
2023-01-15 18:56:16 +01:00
];
# tune fontconfig
fontconfig = {
# better default fonts
defaultFonts = {
monospace = ["Iosevka"];
};
};
};
# OpenGL
hardware.opengl.enable = true;
2023-05-20 23:22:25 +02:00
hardware.opengl.driSupport = true;
2023-01-15 18:56:16 +01:00
hardware.opengl.driSupport32Bit = true;
# virus scanner, we only want the updater running
2023-01-16 20:04:16 +01:00
services.clamav.updater.enable = true;
2023-01-15 18:56:16 +01:00
2023-02-06 20:20:40 +01:00
# try to ensure we can use our network LaserJet
2023-01-15 18:56:16 +01:00
services.printing.enable = true;
services.printing.drivers = [ pkgs.hplip ];
# let's get SSD status
services.smartd.enable = true;
# dconf is needed for gtk, see https://nixos.wiki/wiki/KDE
programs.dconf.enable = true;
2023-01-15 18:56:16 +01:00
# ensure cron and Co. can send mails
2023-10-15 15:33:41 +02:00
programs.msmtp = {
enable = true;
setSendmail = true;
accounts = {
default = {
auth = true;
tls = true;
from = "noreply@home.local";
host = "babylon2k.com";
port = "587";
user = builtins.readFile "/data/nixos/mailuser.secret";
password = builtins.readFile "/data/nixos/mailpassword.secret";
};
};
defaults = {
aliases = "/etc/aliases";
};
};
2023-01-15 18:56:16 +01:00
environment.etc = {
"aliases" = {
text = ''
root: christoph@cullmann.io
'';
mode = "0644";
};
};
# use ZSH per default with a proper config
2023-01-15 18:56:16 +01:00
users.defaultUserShell = pkgs.zsh;
programs.zsh = {
# zsh wanted
enable = true;
# some env vars I want in all of my shells
shellInit = ''
export MOZ_ENABLE_WAYLAND=1
export POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true
export XDG_DATA_DIRS=$XDG_DATA_DIRS:/usr/share:/var/lib/flatpak/exports/share:$HOME/.local/share/flatpak/exports/share
'';
2023-01-15 18:56:16 +01:00
# great prompt
promptInit = ''
source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
if [ -f ~/.p10k.zsh ]; then
source ~/.p10k.zsh;
fi
'';
2023-01-15 18:56:16 +01:00
# aliases
shellAliases = {
ll = "ls -l";
# system build/update/cleanup
update = "sudo nixos-rebuild switch";
upgrade = "sudo nixos-rebuild switch --upgrade";
gc = "sudo nix-collect-garbage --delete-older-than 7d";
verify = "sudo nix --extra-experimental-features nix-command store verify --all";
optimize = "sudo nix --extra-experimental-features nix-command store optimise";
# ssh around in the local network
kuro = "ssh kuro.fritz.box";
kuroroot = "ssh root@kuro.fritz.box";
mini = "ssh mini.fritz.box";
miniroot = "ssh root@mini.fritz.box";
neko = "ssh neko.fritz.box";
nekoroot = "ssh root@neko.fritz.box";
};
};
2023-05-20 22:37:33 +02:00
# enable VirtualBox for the main user
2023-01-15 18:56:16 +01:00
virtualisation.virtualbox.host.enable = true;
users.extraGroups.vboxusers.members = [ "cullmann" ];
2023-01-16 00:03:51 +01:00
# configure sudo
security.sudo.execWheelOnly = true;
security.sudo.extraConfig = ''
Defaults lecture = never
'';
2023-01-15 18:56:16 +01:00
###
### per user configuration below
###
# all users and passwords are defined here
users.mutableUsers = false;
#
# administrator
#
users.users.root = {
# init password
2023-06-09 18:26:35 +02:00
hashedPassword = builtins.readFile "/data/nixos/password.secret";
2023-01-15 18:56:16 +01:00
# use same keys as my main user
openssh.authorizedKeys.keys = pkgs.lib.splitString "\n" (builtins.readFile "/home/cullmann/.ssh/authorized_keys");
};
home-manager.users.root = { pkgs, ... }: {
# initial version
home.stateVersion = "22.11";
# generate the shell config
programs.zsh.enable = true;
2023-01-15 18:56:16 +01:00
};
#
# my main user
#
users.users.cullmann = {
# hard code UID for stability over machines
uid = 1000;
# normal user
isNormalUser = true;
# it's me :P
description = "Christoph Cullmann";
# allow sudo for my main user
extraGroups = [ "wheel" ];
# init password
2023-06-09 18:26:35 +02:00
hashedPassword = builtins.readFile "/data/nixos/password.secret";
2023-01-15 18:56:16 +01:00
};
home-manager.users.cullmann = { pkgs, ... }: {
# initial version
home.stateVersion = "22.11";
# generate the shell config
programs.zsh.enable = true;
2023-01-15 18:56:16 +01:00
# enable keychain
programs.keychain = {
enable = true;
keys = [ "id_ed25519" ];
};
# https://github.com/nix-community/nix-direnv
programs.direnv.enable = true;
programs.direnv.nix-direnv.enable = true;
2023-01-15 18:56:16 +01:00
};
}