server: switch to bcachefs

This commit is contained in:
chayleaf 2023-11-25 02:37:10 +07:00
parent dcbef373c4
commit 9bd6cce282
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
3 changed files with 56 additions and 21 deletions

View file

@ -5,12 +5,14 @@
, ... }: , ... }:
let let
encUuid = "15945050-df48-418b-b736-827749b9262a"; uuids.enc = "15945050-df48-418b-b736-827749b9262a";
encPart = "/dev/disk/by-uuid/${encUuid}"; uuids.oldroot = "de454394-8cc1-4267-b62b-1e25062f7cf4";
rootUuid = "de454394-8cc1-4267-b62b-1e25062f7cf4"; uuids.boot = "0603-5955";
rootPart = "/dev/disk/by-uuid/${rootUuid}"; uuids.bch0 = "9f10b9ac-3102-4816-8f2c-e0526c2aa65b";
bootUuid = "0603-5955"; uuids.bch1 = "4ffed814-057c-4f9f-9a12-9d8ac6331e62";
bootPart = "/dev/disk/by-uuid/${bootUuid}"; uuids.bch2 = "e761df86-35ce-4586-9349-2d646fcb1b2a";
uuids.bch = "088a3d70-b54c-4437-8e01-feda6bfb7236";
parts = builtins.mapAttrs (k: v: "/dev/disk/by-uuid/${v}") uuids;
in in
{ {
@ -28,8 +30,43 @@ in
]; ];
networking.useDHCP = true; networking.useDHCP = true;
/*
# as expected, systemd initrd and networking didn't work well, and i really cba to debug it
networking.useDHCP = false;
networking.useNetworkd = true;
systemd.network = {
enable = true;
links."10-mac" = {
matchConfig.OriginalName = "e*";
linkConfig = {
MACAddressPolicy = "none";
MACAddress = router-config.router-settings.serverMac;
};
};
networks."10-dhcp" = {
DHCP = "yes";
name = "e*";
};
};*/
boot.initrd = { boot.initrd = {
/*systemd = {
enable = true;
network = {
enable = true;
links."10-mac" = {
matchConfig.OriginalName = "e*";
linkConfig = {
MACAddressPolicy = "none";
MACAddress = router-config.router-settings.serverInitrdMac;
};
};
networks."10-dhcp" = {
DHCP = "yes";
name = "e*";
};
};
};*/
preLVMCommands = lib.mkOrder 499 '' preLVMCommands = lib.mkOrder 499 ''
ip link set eth0 address ${router-config.router-settings.serverInitrdMac} || true ip link set eth0 address ${router-config.router-settings.serverInitrdMac} || true
''; '';
@ -48,8 +85,8 @@ in
]; ];
# shell = "/bin/cryptsetup-askpass"; # shell = "/bin/cryptsetup-askpass";
}; };
luks.devices."cryptroot" = { luks.devices.cryptroot = {
device = encPart; device = parts.enc;
# idk whether this is needed but it works # idk whether this is needed but it works
preLVM = true; preLVM = true;
# see https://asalor.blogspot.de/2011/08/trim-dm-crypt-problems.html before enabling # see https://asalor.blogspot.de/2011/08/trim-dm-crypt-problems.html before enabling
@ -57,27 +94,27 @@ in
# improve SSD performance # improve SSD performance
bypassWorkqueues = true; bypassWorkqueues = true;
}; };
luks.devices.bch0 = { device = parts.bch0; preLVM = true; allowDiscards = true; bypassWorkqueues = true; };
luks.devices.bch1 = { device = parts.bch1; preLVM = true; allowDiscards = true; bypassWorkqueues = true; };
luks.devices.bch2 = { device = parts.bch2; preLVM = true; allowDiscards = true; bypassWorkqueues = true; };
}; };
boot.supportedFilesystems = [ "bcachefs" ]; boot.supportedFilesystems = [ "bcachefs" ];
fileSystems = let fileSystems = let
device = rootPart;
fsType = "btrfs";
neededForBoot = true; neededForBoot = true;
compress = "compress=zstd";
discard = "discard=async";
in { in {
"/" = { device = "none"; fsType = "tmpfs"; inherit neededForBoot; "/" = { device = "none"; fsType = "tmpfs"; inherit neededForBoot;
options = [ "defaults" "size=2G" "mode=755" ]; }; options = [ "defaults" "size=2G" "mode=755" ]; };
# TODO: switch to bcachefs?
# I wanna do it some day, but maybe starting with the next disk I get for this server
"/persist" = "/persist" =
{ inherit device fsType neededForBoot; { device = "UUID=${uuids.bch}"; fsType = "bcachefs"; inherit neededForBoot;
options = [ discard compress "subvol=@" ]; }; options = [ "errors=ro" ]; };
"/swap" = { inherit device fsType neededForBoot; #"/persist" =
options = [ discard "subvol=@swap" "noatime" ]; }; # { device = parts.oldroot; fsType = "btrfs"; inherit neededForBoot;
"/boot" = { device = bootPart; fsType = "vfat"; inherit neededForBoot; }; # options = [ "discard=async" "compress=zstd" "subvol=@" ]; };
"/swap" = { device = parts.oldroot; fsType = "btrfs"; inherit neededForBoot;
options = [ "discard=async" "subvol=@swap" "noatime" ]; };
"/boot" = { device = parts.boot; fsType = "vfat"; inherit neededForBoot; };
}; };
swapDevices = [ { device = "/swap/swapfile"; } ]; swapDevices = [ { device = "/swap/swapfile"; } ];

View file

@ -32,7 +32,6 @@ in {
{ directory = /var/www; } { directory = /var/www; }
{ directory = /secrets; mode = "0755"; } { directory = /secrets; mode = "0755"; }
]; ];
networking.useDHCP = true;
networking.firewall = { networking.firewall = {
enable = true; enable = true;
allowedTCPPorts = lib.mkMerge [ allowedTCPPorts = lib.mkMerge [

View file

@ -166,7 +166,6 @@ in {
nix.distributedBuilds = true; nix.distributedBuilds = true;
# limit CI CPU usage to 30% # limit CI CPU usage to 30%
# systemd.services.nix-daemon.serviceConfig.CPUQuota = "240%"; # systemd.services.nix-daemon.serviceConfig.CPUQuota = "240%";
# TODO: check if LimitNICE should be used instead
systemd.services.nix-daemon.serviceConfig.Nice = "19"; systemd.services.nix-daemon.serviceConfig.Nice = "19";
nix.daemonCPUSchedPolicy = "idle"; nix.daemonCPUSchedPolicy = "idle";
nix.daemonIOSchedClass = "idle"; nix.daemonIOSchedClass = "idle";