nix fmt .

This commit is contained in:
Motiejus Jakštys 2023-04-03 16:50:52 +03:00
parent 03629e8561
commit aadf1c170b
6 changed files with 313 additions and 256 deletions

View File

@ -1,6 +1,9 @@
{ config, pkgs, lib, ... }:
let
{
config,
pkgs,
lib,
...
}: let
gitea_uidgid = 995;
tailscale_subnet = {
@ -16,7 +19,7 @@ let
ssh_pubkeys = {
motiejus = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+qpaaD+FCYPcUU1ONbw/ff5j0xXu5DNvp/4qZH/vOYwG13uDdfI5ISYPs8zNaVcFuEDgNxWorVPwDw4p6+1JwRLlhO4J/5tE1w8Gt6C7y76LRWnp0rCdva5vL3xMozxYIWVOAiN131eyirV2FdOaqTwPy4ouNMmBFbibLQwBna89tbFMG/jwR7Cxt1I6UiYOuCXIocI5YUbXlsXoK9gr5yBRoTjl2OfH2itGYHz9xQCswvatmqrnteubAbkb6IUFYz184rnlVntuZLwzM99ezcG4v8/485gWkotTkOgQIrGNKgOA7UNKpQNbrwdPAMugqfSTo6g8fEvy0Q+6OXdxw5X7en2TJE+BLVaXp4pVMdOAzKF0nnssn64sRhsrUtFIjNGmOWBOR2gGokaJcM6x9R72qxucuG5054pSibs32BkPEg6Qzp+Bh77C3vUmC94YLVg6pazHhLroYSP1xQjfOvXyLxXB1s9rwJcO+s4kqmInft2weyhfaFE0Bjcoc+1/dKuQYfPCPSB//4zvktxTXud80zwWzMy91Q4ucRrHTBz3PrhO8ys74aSGnKOiG3ccD3HbaT0Ff4qmtIwHcAjrnNlINAcH/A2mpi0/2xA7T8WpFnvgtkQbcMF0kEKGnNS5ULZXP/LC8BlLXxwPdqTzvKikkTb661j4PhJhinhVwnQ==";
vno1_root = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMiWb7yeSeuFCMZWarKJD6ZSxIlpEHbU++MfpOIy/2kh";
};
};
backup_paths = {
var_lib = {
@ -32,7 +35,7 @@ let
var_log = {
mountpoint = "/var/log";
zfs_name = "rpool/nixos/var/log";
paths = [ "/var/log/.snapshot-latest/caddy/" ];
paths = ["/var/log/.snapshot-latest/caddy/"];
patterns = [
"+ /var/log/.snapshot-latest/caddy/access-jakstys.lt.log-*.zst"
"- *"
@ -44,8 +47,11 @@ let
turn_cert_dir = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/turn.jakstys.lt";
# functions
mountLatest = ({mountpoint, zfs_name}:
''
mountLatest = (
{
mountpoint,
zfs_name,
}: ''
set -euo pipefail
${pkgs.util-linux}/bin/umount ${mountpoint}/.snapshot-latest &>/dev/null || :
mkdir -p ${mountpoint}/.snapshot-latest
@ -53,29 +59,31 @@ let
''
);
umountLatest = ({mountpoint, ...}:
''set -euo pipefail
umountLatest = (
{mountpoint, ...}: '' set -euo pipefail
${pkgs.util-linux}/bin/umount ${mountpoint}/.snapshot-latest
''
);
in {
imports =
[
imports = [
./hardware-configuration.nix
./zfs.nix
];
nixpkgs.overlays = [ (self: super: {
nixpkgs.overlays = [
(self: super: {
systemd = super.systemd.overrideAttrs (old: {
patches = (old.patches or []) ++ [
patches =
(old.patches or [])
++ [
(super.fetchpatch {
url = "https://github.com/systemd/systemd/commit/e7f64b896201da4a11da158c35865604cf02062f.patch";
sha256 = "sha256-AvBkrD9n5ux1o167yKg1eJK8C300vBS/ks3Gbvy5vjw=";
})
];
});
} ) ];
})
];
boot.initrd.network = {
enable = true;
@ -83,7 +91,7 @@ in {
enable = true;
port = 22;
authorizedKeys = builtins.attrValues ssh_pubkeys;
hostKeys = [ "/etc/secrets/initrd/ssh_host_ed25519_key" ];
hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"];
};
};
@ -111,9 +119,9 @@ in {
motiejus = {
isNormalUser = true;
extraGroups = [ "wheel" ];
extraGroups = ["wheel"];
uid = 1000;
openssh.authorizedKeys.keys = [ ssh_pubkeys.motiejus ];
openssh.authorizedKeys.keys = [ssh_pubkeys.motiejus];
};
};
@ -170,7 +178,7 @@ in {
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHtYsaht57g2sp6UmLHqsCK+fHjiiZ0rmGceFmFt88pY";
};
"hel1-a.servers.jakst" = {
extraHostNames = ["hel1-a.jakstys.lt" "git.jakstys.lt" "vpn.jakstys.lt" "jakstys.lt" "www.jakstys.lt" ];
extraHostNames = ["hel1-a.jakstys.lt" "git.jakstys.lt" "vpn.jakstys.lt" "jakstys.lt" "www.jakstys.lt"];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF6Wd2lKrpP2Gqul10obMo2dc1xKaaLv0I4FAnfIaFKu";
};
"mtwork.motiejus.jakst" = {
@ -220,20 +228,25 @@ in {
autosnap = true;
autoprune = true;
};
datasets = lib.mapAttrs' (name: value: {
datasets =
lib.mapAttrs' (name: value: {
name = value.zfs_name;
value = { use_template = ["prod"]; };
}) backup_paths;
extraArgs = [ "--verbose" ];
value = {use_template = ["prod"];};
})
backup_paths;
extraArgs = ["--verbose"];
};
borgbackup.jobs = lib.mapAttrs' (name: value:
let
snapshot = { mountpoint = value.mountpoint; zfs_name = value.zfs_name; };
borgbackup.jobs = lib.mapAttrs' (name: value: let
snapshot = {
mountpoint = value.mountpoint;
zfs_name = value.zfs_name;
};
rwpath = value.mountpoint + "/.snapshot-latest";
in {
name = name;
value = {
value =
{
doInit = true;
repo = "zh2769@zh2769.rsync.net:hel1-a.servers.jakst";
encryption = {
@ -244,7 +257,7 @@ in {
extraArgs = "--remote-path=borg1";
compression = "auto,lzma";
startAt = value.backup_at;
readWritePaths = [ rwpath ];
readWritePaths = [rwpath];
preHook = mountLatest snapshot;
postHook = umountLatest snapshot;
prune.keep = {
@ -253,12 +266,12 @@ in {
weekly = 4;
monthly = 3;
};
} // lib.optionalAttrs (value ? patterns) {
}
// lib.optionalAttrs (value ? patterns) {
patterns = value.patterns;
};
}) backup_paths;
headscale = {
enable = true;
serverUrl = "https://vpn.jakstys.lt";
@ -273,7 +286,7 @@ in {
"fd7a:115c:a1e0:59b0::/64"
];
dns_config = {
nameservers = [ "1.1.1.1" "8.8.4.4" ];
nameservers = ["1.1.1.1" "8.8.4.4"];
magic_dns = true;
base_domain = "jakst";
};
@ -404,7 +417,7 @@ in {
enable_registration = false;
report_stats = true;
signing_key_path = "/run/matrix-synapse/jakstys.lt.signing.key";
extraConfigFiles = [ "/run/matrix-synapse/secrets.yaml" ];
extraConfigFiles = ["/run/matrix-synapse/secrets.yaml"];
log_config = pkgs.writeText "log.config" ''
version: 1
formatters:
@ -442,11 +455,31 @@ in {
federation_rc_concurrent = 3;
allow_profile_lookup_over_federation = false;
thumbnail_sizes = [
{ width = 32; height = 32; method = "crop"; }
{ width = 96; height = 96; method = "crop"; }
{ width = 320; height = 240; method = "scale"; }
{ width = 640; height = 480; method = "scale"; }
{ width = 800; height = 600; method = "scale"; }
{
width = 32;
height = 32;
method = "crop";
}
{
width = 96;
height = 96;
method = "crop";
}
{
width = 320;
height = 240;
method = "scale";
}
{
width = 640;
height = 480;
method = "scale";
}
{
width = 800;
height = 600;
method = "scale";
}
];
user_directory = {
enabled = true;
@ -469,7 +502,7 @@ in {
postfix = {
enable = true;
enableSmtp = true;
networks = [ "127.0.0.1/8" "[::ffff:127.0.0.0]/104" "[::1]/128" tailscale_subnet.cidr ];
networks = ["127.0.0.1/8" "[::ffff:127.0.0.0]/104" "[::1]/128" tailscale_subnet.cidr];
hostname = "${config.networking.hostName}.${config.networking.domain}";
relayHost = "smtp.sendgrid.net";
relayPort = 587;
@ -551,23 +584,30 @@ in {
semantic-checks: on
'';
};
};
networking = {
hostName = "hel1-a";
domain = "jakstys.lt";
firewall = let
coturn = with config.services.coturn; [ { from = min-port; to = max-port; } ];
coturn = with config.services.coturn; [
{
from = min-port;
to = max-port;
}
];
in {
allowedTCPPorts = [
53
80 443
3478 5349 5350 # coturn
80
443
3478
5349
5350 # coturn
];
allowedUDPPorts = [
53 443
53
443
41641
];
allowedUDPPortRanges = coturn;
@ -602,7 +642,8 @@ in {
"d /run/matrix-synapse 0700 matrix-synapse matrix-synapse -"
];
systemd.services = {
systemd.services =
{
"make-snapshot-dirs" = let
vals = builtins.attrValues backup_paths;
mountpoints = builtins.catAttrs "mountpoint" vals;
@ -646,7 +687,7 @@ in {
EOF
'';
in {
serviceConfig.ExecStartPre = [ "" secretsScript ];
serviceConfig.ExecStartPre = ["" secretsScript];
serviceConfig.LoadCredential = [
"jakstys.lt.signing.key:/var/src/secrets/synapse/jakstys.lt.signing.key"
"registration_shared_secret:/var/src/secrets/synapse/registration_shared_secret"
@ -700,14 +741,14 @@ in {
zfs-scrub.unitConfig.OnFailure = "unit-status-mail@zfs-scrub.service";
nixos-upgrade.unitConfig.OnFailure = "unit-status-mail@nixos-upgrade.service";
} // lib.mapAttrs' (name: value: {
}
// lib.mapAttrs' (name: value: {
name = "borgbackup-job-${name}";
value = {
unitConfig.OnFailure = "unit-status-mail@borgbackup-job-${name}.service";
};
}) backup_paths;
})
backup_paths;
systemd.paths = {
cert-watcher = {
@ -722,4 +763,3 @@ in {
# Do not change
system.stateVersion = "22.11";
}

View File

@ -9,10 +9,15 @@
deploy-rs.inputs.utils.follows = "flake-utils";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, deploy-rs, flake-utils }: {
outputs = {
self,
nixpkgs,
deploy-rs,
flake-utils,
}:
{
nixosConfigurations.hel1-a = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
@ -36,15 +41,15 @@
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
}
// flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells.default = with pkgs; mkShell {
// flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
in {
devShells.default = with pkgs;
mkShell {
name = "rules_nixpkgs_shell";
packages = [ bash ];
packages = [bash];
};
formatter = pkgs.alejandra;
});
}

View File

@ -1,43 +1,51 @@
# Do not modify this file! It was generated by nixos-generate-config
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:
{
imports =
[ (modulesPath + "/profiles/qemu-guest.nix") ];
boot.initrd.availableKernelModules = [ "ata_piix" "virtio_pci" "virtio_scsi" "xhci_pci" "sd_mod" "sr_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
config,
lib,
pkgs,
modulesPath,
...
}: {
imports = [(modulesPath + "/profiles/qemu-guest.nix")];
boot.initrd.availableKernelModules = ["ata_piix" "virtio_pci" "virtio_scsi" "xhci_pci" "sd_mod" "sr_mod"];
boot.initrd.kernelModules = [];
boot.kernelModules = [];
boot.extraModulePackages = [];
fileSystems."/" =
{ device = "rpool/nixos/root";
fsType = "zfs"; options = [ "zfsutil" "X-mount.mkdir" ];
fileSystems."/" = {
device = "rpool/nixos/root";
fsType = "zfs";
options = ["zfsutil" "X-mount.mkdir"];
};
fileSystems."/home" =
{ device = "rpool/nixos/home";
fsType = "zfs"; options = [ "zfsutil" "X-mount.mkdir" ];
fileSystems."/home" = {
device = "rpool/nixos/home";
fsType = "zfs";
options = ["zfsutil" "X-mount.mkdir"];
};
fileSystems."/var/lib" =
{ device = "rpool/nixos/var/lib";
fsType = "zfs"; options = [ "zfsutil" "X-mount.mkdir" ];
fileSystems."/var/lib" = {
device = "rpool/nixos/var/lib";
fsType = "zfs";
options = ["zfsutil" "X-mount.mkdir"];
};
fileSystems."/var/log" =
{ device = "rpool/nixos/var/log";
fsType = "zfs"; options = [ "zfsutil" "X-mount.mkdir" ];
fileSystems."/var/log" = {
device = "rpool/nixos/var/log";
fsType = "zfs";
options = ["zfsutil" "X-mount.mkdir"];
};
fileSystems."/boot" =
{ device = "bpool/nixos/root";
fsType = "zfs"; options = [ "zfsutil" "X-mount.mkdir" ];
fileSystems."/boot" = {
device = "bpool/nixos/root";
fsType = "zfs";
options = ["zfsutil" "X-mount.mkdir"];
};
fileSystems."/boot/efis/scsi-0QEMU_QEMU_HARDDISK_9233346-part1" =
{ device = "/dev/disk/by-uuid/B6D7-D52E";
fileSystems."/boot/efis/scsi-0QEMU_QEMU_HARDDISK_9233346-part1" = {
device = "/dev/disk/by-uuid/B6D7-D52E";
fsType = "vfat";
};
@ -47,7 +55,7 @@
# options = [ "bind" ];
# };
swapDevices = [ { device = "/dev/disk/by-uuid/03ebe703-aa24-4ee5-a7c3-f8614ee779b0"; } ];
swapDevices = [{device = "/dev/disk/by-uuid/03ebe703-aa24-4ee5-a7c3-f8614ee779b0";}];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's

View File

@ -15,11 +15,12 @@ let
};
}
];
in {
hel1a = pkgs.krops.writeDeploy "deploy-hel1a" {
source = source;
target = lib.mkTarget "motiejus@hel1-a.jakstys.lt" // {
target =
lib.mkTarget "motiejus@hel1-a.jakstys.lt"
// {
sudo = true;
};
};

View File

@ -3,4 +3,4 @@ let
spec = lock.nodes.nixpkgs.locked;
nixpkgs = fetchTarball "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
in
import nixpkgs
import nixpkgs

61
zfs.nix
View File

@ -1,34 +1,37 @@
{ config, pkgs, ... }:
{ boot.supportedFilesystems = [ "zfs" ];
{
config,
pkgs,
...
}: {
boot.supportedFilesystems = ["zfs"];
networking.hostId = "cd1a441c";
boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
boot.loader.efi.efiSysMountPoint = "/boot/efi";
boot.loader.efi.canTouchEfiVariables = false;
boot.loader.generationsDir.copyKernels = true;
boot.loader.grub.efiInstallAsRemovable = true;
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.copyKernels = true;
boot.loader.grub.efiSupport = true;
boot.loader.grub.zfsSupport = true;
#boot.loader.grub.extraPrepareConfig = ''
# mkdir -p /boot/efis
# for i in /boot/efis/*; do mount $i ; done
#
# mkdir -p /boot/efi
# mount /boot/efi
#'';
#boot.loader.grub.extraInstallCommands = ''
#ESP_MIRROR=$(mktemp -d)
#cp -r /boot/efi/EFI $ESP_MIRROR
#for i in /boot/efis/*; do
# cp -r $ESP_MIRROR/EFI $i
#done
#rm -rf $ESP_MIRROR
#'';
boot.loader.grub.devices = [
boot.loader.efi.efiSysMountPoint = "/boot/efi";
boot.loader.efi.canTouchEfiVariables = false;
boot.loader.generationsDir.copyKernels = true;
boot.loader.grub.efiInstallAsRemovable = true;
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.copyKernels = true;
boot.loader.grub.efiSupport = true;
boot.loader.grub.zfsSupport = true;
#boot.loader.grub.extraPrepareConfig = ''
# mkdir -p /boot/efis
# for i in /boot/efis/*; do mount $i ; done
#
# mkdir -p /boot/efi
# mount /boot/efi
#'';
#boot.loader.grub.extraInstallCommands = ''
#ESP_MIRROR=$(mktemp -d)
#cp -r /boot/efi/EFI $ESP_MIRROR
#for i in /boot/efis/*; do
# cp -r $ESP_MIRROR/EFI $i
#done
#rm -rf $ESP_MIRROR
#'';
boot.loader.grub.devices = [
"/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_9233346"
];
users.users.root.initialHashedPassword = "$6$oXLEcliXQJloPkrW$Or3O2tLdpLMs4s4gyn2hJlvMjm0S7zLlFlQCOx.S3fdLKxyFjQFaLhPZXJPluZ7iYrB65JSdT0ESluFwgJwLi.";
users.users.root.initialHashedPassword = "$6$oXLEcliXQJloPkrW$Or3O2tLdpLMs4s4gyn2hJlvMjm0S7zLlFlQCOx.S3fdLKxyFjQFaLhPZXJPluZ7iYrB65JSdT0ESluFwgJwLi.";
}