From 08ffb1865a639ae00ddb135bb61e05a6e464886a Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Thu, 7 Sep 2023 00:00:34 +0200 Subject: [PATCH] machine/serverle: switch to disko config --- README.md | 2 - machines/serverle/configuration.nix | 6 ++- machines/serverle/disko-config.nix | 74 +++++++++++++++++++++++++++++ machines/serverle/disks.nix | 29 ----------- machines/serverle/syncthing.nix | 22 ++++----- modules/services/backup/default.nix | 4 +- 6 files changed, 92 insertions(+), 45 deletions(-) create mode 100644 machines/serverle/disko-config.nix delete mode 100644 machines/serverle/disks.nix diff --git a/README.md b/README.md index 56857fb..3744f8a 100644 --- a/README.md +++ b/README.md @@ -131,8 +131,6 @@ used flakes: root@ ``` - - ## Inspired by - [Nix config by Mic92](https://github.com/Mic92/dotfiles) diff --git a/machines/serverle/configuration.nix b/machines/serverle/configuration.nix index 1e9aa13..a209203 100644 --- a/machines/serverle/configuration.nix +++ b/machines/serverle/configuration.nix @@ -2,13 +2,17 @@ { imports = [ ./hardware-configuration.nix - ./disks.nix ./network.nix ./services.nix ./syncthing.nix ./system.nix ./wifi.nix ]; + + disko.devices = import ./disko-config.nix { + disks = [ "/dev/disk/by-id/usb-Seagate_Expansion_2HC015KJ-0:0" ]; + }; + networking.hostName = "serverle"; sops = { diff --git a/machines/serverle/disko-config.nix b/machines/serverle/disko-config.nix new file mode 100644 index 0000000..6a73236 --- /dev/null +++ b/machines/serverle/disko-config.nix @@ -0,0 +1,74 @@ +{ disks ? [ "/dev/sda" ], ... }: +{ + disk = { + vdb = { + type = "disk"; + device = builtins.head disks; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for grub MBR + }; + ESP = { + size = "512M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ + "defaults" + ]; + }; + }; + luks = { + size = "100%"; + content = { + type = "luks"; + name = "encrypted"; + extraOpenArgs = [ "--allow-discards" ]; + passwordFile = "/tmp/disk.key"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + }; + }; + }; + }; + }; + }; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + root = { + size = "50G"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + data = { + size = "350G"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/data"; + }; + }; + swap = { + size = "4G"; + content = { + type = "swap"; + randomEncryption = true; + resumeDevice = true; + }; + }; + }; + }; + }; +} diff --git a/machines/serverle/disks.nix b/machines/serverle/disks.nix deleted file mode 100644 index 8fa7566..0000000 --- a/machines/serverle/disks.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - boot.initrd.luks.devices."luks-drive" = { - name = "luks-drive"; - device = "/dev/disk/by-partlabel/Crypt"; - preLVM = true; - allowDiscards = true; - }; - - fileSystems."/" = { - device = "/dev/disk/by-label/serverle-root"; - fsType = "ext4"; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-label/serverle-bo"; - fsType = "vfat"; - }; - - fileSystems."/srv" = { - device = "/dev/disk/by-label/serverle-srv"; - fsType = "ext4"; - }; - - swapDevices = [{ - device = "/dev/disk/by-label/serverle-swap"; - }]; -} diff --git a/machines/serverle/syncthing.nix b/machines/serverle/syncthing.nix index be38a04..755fb1b 100644 --- a/machines/serverle/syncthing.nix +++ b/machines/serverle/syncthing.nix @@ -5,12 +5,12 @@ # make sure folders exist writable systemd.tmpfiles.rules = [ - "d /srv/data/ 0755 syncthing syncthing" - "d /srv/data/computer 0755 syncthing syncthing" - "d /srv/data/phone 0755 syncthing syncthing" - "d /srv/data/music 0755 syncthing syncthing" - "d /srv/data/photos 0755 syncthing syncthing" - "d /srv/data/tmp/aria2 0755 syncthing syncthing" + "d /data/ 0755 syncthing syncthing" + "d /data/computer 0755 syncthing syncthing" + "d /data/phone 0755 syncthing syncthing" + "d /data/music 0755 syncthing syncthing" + "d /data/photos 0755 syncthing syncthing" + "d /data/tmp/aria2 0755 syncthing syncthing" ]; services.syncthing = { @@ -37,7 +37,7 @@ folders = { "Computer" = { id = "djdxo-1akub"; - path = "/srv/data/computer"; + path = "/data/computer"; devices = [ "thinkman" "birdman" @@ -46,7 +46,7 @@ }; "Phone" = { id = "4hds7-gpypp"; - path = "/srv/data/phone"; + path = "/data/phone"; devices = [ "thinkman" "birdman" @@ -55,7 +55,7 @@ }; "Music" = { id = "mphdq-n6q7y"; - path = "/srv/data/music"; + path = "/data/music"; watch = false; devices = [ "thinkman" @@ -65,7 +65,7 @@ }; "Pictures" = { id = "cujyo-yiabu"; - path = "/srv/data/photos"; + path = "/data/photos"; watch = false; devices = [ "thinkman" @@ -74,7 +74,7 @@ }; "Aria2" = { id = "jjnzq-pgzua"; - path = "/srv/data/tmp/aria2"; + path = "/data/tmp/aria2"; devices = [ "thinkman" ]; diff --git a/modules/services/backup/default.nix b/modules/services/backup/default.nix index 3deccf5..954b8c2 100644 --- a/modules/services/backup/default.nix +++ b/modules/services/backup/default.nix @@ -101,8 +101,8 @@ in "/var/run" "/var/tmp" - "/srv/data/tmp" - "/srv/data/todo" + "/data/tmp" + "/data/todo" "/home/*/.cache" "/home/*/.gvfs"