156 lines
5.3 KiB
Nix
156 lines
5.3 KiB
Nix
{ config, pkgs, ... }:
|
|
|
|
let
|
|
impermanence = builtins.fetchTarball "https://github.com/nix-community/impermanence/archive/master.tar.gz";
|
|
in
|
|
{
|
|
imports =
|
|
[
|
|
"${impermanence}/nixos.nix"
|
|
./hardware-configuration.nix
|
|
];
|
|
|
|
networking.hostName = "zippy";
|
|
|
|
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
|
nix.settings.trusted-users = [ "root" "@wheel" ];
|
|
|
|
boot.initrd.kernelModules = [ "usb_storage" ];
|
|
boot.initrd.luks.devices."luksroot" = {
|
|
allowDiscards = true;
|
|
bypassWorkqueues = true;
|
|
keyFileSize = 4096;
|
|
keyFile = "/dev/sdb";
|
|
};
|
|
|
|
swapDevices = pkgs.lib.mkForce [ {
|
|
device = "/dev/disk/by-id/ata-KINGSTON_SKC600MS1024G_50026B7785AE0A92-part2";
|
|
randomEncryption.enable = true;
|
|
}];
|
|
|
|
fileSystems."/".options = ["compress=zstd" "noatime" ];
|
|
fileSystems."/nix".options = ["compress=zstd" "noatime" ];
|
|
fileSystems."/persist".options = ["compress=zstd" "noatime" ];
|
|
fileSystems."/persist".neededForBoot = true;
|
|
fileSystems."/var/log".options = ["compress=zstd" "noatime" ];
|
|
fileSystems."/var/log".neededForBoot = true;
|
|
|
|
# reset / at each boot
|
|
# Note `lib.mkBefore` is used instead of `lib.mkAfter` here.
|
|
boot.initrd.postDeviceCommands = pkgs.lib.mkBefore ''
|
|
mkdir -p /mnt
|
|
|
|
# We first mount the btrfs root to /mnt
|
|
# so we can manipulate btrfs subvolumes.
|
|
mount -o subvol=/ /dev/mapper/luksroot /mnt
|
|
|
|
# While we're tempted to just delete /root and create
|
|
# a new snapshot from /root-blank, /root is already
|
|
# populated at this point with a number of subvolumes,
|
|
# which makes `btrfs subvolume delete` fail.
|
|
# So, we remove them first.
|
|
#
|
|
# /root contains subvolumes:
|
|
# - /root/var/lib/portables
|
|
# - /root/var/lib/machines
|
|
#
|
|
# I suspect these are related to systemd-nspawn, but
|
|
# since I don't use it I'm not 100% sure.
|
|
# Anyhow, deleting these subvolumes hasn't resulted
|
|
# in any issues so far, except for fairly
|
|
# benign-looking errors from systemd-tmpfiles.
|
|
btrfs subvolume list -o /mnt/root |
|
|
cut -f9 -d' ' |
|
|
while read subvolume; do
|
|
echo "deleting /$subvolume subvolume..."
|
|
btrfs subvolume delete "/mnt/$subvolume"
|
|
done &&
|
|
echo "deleting /root subvolume..." &&
|
|
btrfs subvolume delete /mnt/root
|
|
|
|
echo "restoring blank /root subvolume..."
|
|
btrfs subvolume snapshot /mnt/root-blank /mnt/root
|
|
|
|
# Once we're done rolling back to a blank snapshot,
|
|
# we can unmount /mnt and continue on the boot process.
|
|
umount /mnt
|
|
'';
|
|
|
|
# configure impermanence
|
|
environment.persistence."/persist" = {
|
|
directories = [
|
|
"/etc/nixos"
|
|
];
|
|
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"
|
|
];
|
|
};
|
|
|
|
security.sudo = {
|
|
extraConfig = ''
|
|
# rollback results in sudo lectures after each reboot
|
|
Defaults lecture = never
|
|
'';
|
|
wheelNeedsPassword = false;
|
|
};
|
|
|
|
# Use the systemd-boot EFI boot loader.
|
|
boot.loader.systemd-boot.enable = true;
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
networking.networkmanager.enable = true;
|
|
|
|
time.timeZone = "Europe/Lisbon";
|
|
|
|
users.mutableUsers = false;
|
|
users.users.ppetru = {
|
|
isNormalUser = true;
|
|
extraGroups = [ "wheel" ];
|
|
|
|
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCdZ9dHN+DamoyRAIS8v7Ph85KyJ9zYdgwoqkp7F+smEJEdDKboHE5LA49IDQk4cgkR5xNEMtxANpJm+AXNAhQOPVl/w57vI/Z+TBtSvDoj8LuAvKjmmrPfok2iyD2IIlbctcw8ypn1revZwDb1rBFefpbbZdr5h+75tVqqmNebzxk6UQsfL++lU8HscWwYKzxrrom5aJL6wxNTfy7/Htkt4FHzoKAc5gcB2KM/q0s6NvZzX9WtdHHwAR1kib2EekssjDM9VLecX75Xhtbp+LrHOJKRnxbIanXos4UZUzaJctdNTcOYzEVLvV0BCYaktbI+uVvJcC0qo28bXbHdS3rTGRu8CsykFneJXnrrRIJw7mYWhJSTV9bf+6j/lnFNAurbiYmd4SzaTgbGjj2j38Gr/CTsyv8Rho7P3QUWbRRZnn4a7eVPtjGagqwIwS59YDxRcOy2Wdsw35ry/N2G802V7Cr3hUqeaAIev2adtn4FaG72C8enacYUeACPEhi7TYdsDzuuyt31W7AQa5Te4Uda20rTa0Y9N5Lw85uGB2ebbdYWlO2CqI/m+xNYcPkKqL7zZILz782jDw1sxWd/RUbEgJNrWjsKZ7ybiEMmhpw5vLiMGOeqQWIT6cBCNjocmW0ocU+FBLhhioyrvuZOyacoEZLoklatsL0DMkvvkbT0Ew== petru@paler.net" ];
|
|
};
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
vim
|
|
];
|
|
|
|
services.openssh = {
|
|
enable = true;
|
|
settings = {
|
|
PasswordAuthentication = false;
|
|
KbdInteractiveAuthentication = false;
|
|
};
|
|
extraConfig = ''
|
|
AllowTcpForwarding yes
|
|
X11Forwarding no
|
|
AllowAgentForwarding no
|
|
AllowStreamLocalForwarding no
|
|
AuthenticationMethods publickey
|
|
'';
|
|
};
|
|
|
|
networking.firewall = {
|
|
enable = false;
|
|
allowedTCPPorts = [ 22 ];
|
|
allowedUDPPorts = [ ];
|
|
};
|
|
|
|
# Copy the NixOS configuration file and link it from the resulting system
|
|
# (/run/current-system/configuration.nix). This is useful in case you
|
|
# accidentally delete configuration.nix.
|
|
system.copySystemConfiguration = true;
|
|
|
|
# This value determines the NixOS release from which the default
|
|
# settings for stateful data, like file locations and database versions
|
|
# on your system were taken. It's perfectly fine and recommended to leave
|
|
# 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).
|
|
system.stateVersion = "24.05"; # Did you read the comment?
|
|
}
|
|
|