Compare commits
11 Commits
issue31
...
eb7db0dc95
| Author | SHA1 | Date | |
|---|---|---|---|
| eb7db0dc95 | |||
| d91760f781 | |||
| 13db9eb4c9 | |||
| caa0a800a8 | |||
| f7130d1483 | |||
| e61f29055d | |||
| 883549f15c | |||
| 72c614d330 | |||
| 9794c81894 | |||
| 47eda81019 | |||
| 0a5359138a |
@@ -26,7 +26,6 @@ in
|
|||||||
|
|
||||||
malobeo.disks = {
|
malobeo.disks = {
|
||||||
enable = true;
|
enable = true;
|
||||||
legacy = true;
|
|
||||||
hostId = "a3c3102f";
|
hostId = "a3c3102f";
|
||||||
root = {
|
root = {
|
||||||
disk0 = "disk/by-id/ata-HITACHI_HTS725016A9A364_110308PCKB04VNHX9XTJ";
|
disk0 = "disk/by-id/ata-HITACHI_HTS725016A9A364_110308PCKB04VNHX9XTJ";
|
||||||
@@ -34,7 +33,9 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
malobeo.initssh = {
|
malobeo.initssh = {
|
||||||
enable = false;
|
enable = true;
|
||||||
|
authorizedKeys = sshKeys.admins;
|
||||||
|
ethernetDrivers = ["r8169"];
|
||||||
};
|
};
|
||||||
|
|
||||||
hardware.sane.enable = true; #scanner support
|
hardware.sane.enable = true; #scanner support
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ in
|
|||||||
disk0 = "disk/by-id/ata-SAMSUNG_MZ7LN256HCHP-000L7_S20HNAAH200381";
|
disk0 = "disk/by-id/ata-SAMSUNG_MZ7LN256HCHP-000L7_S20HNAAH200381";
|
||||||
};
|
};
|
||||||
storage = {
|
storage = {
|
||||||
enable = true;
|
|
||||||
disks = ["disk/by-id/wwn-0x50014ee265b53b60" "disk/by-id/wwn-0x50014ee2bb0a194a"];
|
disks = ["disk/by-id/wwn-0x50014ee265b53b60" "disk/by-id/wwn-0x50014ee2bb0a194a"];
|
||||||
mirror = true;
|
mirror = true;
|
||||||
};
|
};
|
||||||
@@ -73,12 +72,6 @@ in
|
|||||||
services.malobeo.microvm.deployHosts = [ "overwatch" "infradocs" "nextcloud" "durruti" ];
|
services.malobeo.microvm.deployHosts = [ "overwatch" "infradocs" "nextcloud" "durruti" ];
|
||||||
|
|
||||||
networking = {
|
networking = {
|
||||||
nat = {
|
|
||||||
enable = true;
|
|
||||||
externalInterface = "enp1s0";
|
|
||||||
internalInterfaces = [ "microvm" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
firewall = {
|
firewall = {
|
||||||
allowedTCPPorts = [ 80 ];
|
allowedTCPPorts = [ 80 ];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -66,10 +66,6 @@
|
|||||||
mac = "D0:E5:CA:F0:D7:E0";
|
mac = "D0:E5:CA:F0:D7:E0";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testvm = {
|
|
||||||
type = "host";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
63
machines/modules/disko/btrfs-laptop.nix
Normal file
63
machines/modules/disko/btrfs-laptop.nix
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
{ config, self, inputs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
inputs.disko.nixosModules.disko
|
||||||
|
];
|
||||||
|
|
||||||
|
# https://github.com/nix-community/disko/blob/master/example/luks-btrfs-subvolumes.nix
|
||||||
|
disko.devices = {
|
||||||
|
disk = {
|
||||||
|
main = {
|
||||||
|
type = "disk";
|
||||||
|
# When using disko-install, we will overwrite this value from the commandline
|
||||||
|
device = "/dev/disk/by-id/some-disk-id";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
ESP = {
|
||||||
|
size = "512M";
|
||||||
|
type = "EF00";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "vfat";
|
||||||
|
mountpoint = "/boot";
|
||||||
|
mountOptions = [ "umask=0077" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
luks = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "luks";
|
||||||
|
name = "crypted";
|
||||||
|
passwordFile = /tmp/secret.key; # Interactive
|
||||||
|
content = {
|
||||||
|
type = "btrfs";
|
||||||
|
extraArgs = [ "-f" ];
|
||||||
|
subvolumes = {
|
||||||
|
"/root" = {
|
||||||
|
mountpoint = "/";
|
||||||
|
mountOptions = [ "compress=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
"/home" = {
|
||||||
|
mountpoint = "/home";
|
||||||
|
mountOptions = [ "compress=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
"/nix" = {
|
||||||
|
mountpoint = "/nix";
|
||||||
|
mountOptions = [ "compress=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
"/swap" = {
|
||||||
|
mountpoint = "/.swapvol";
|
||||||
|
swap.swapfile.size = "20M";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -20,11 +20,6 @@ in
|
|||||||
default = true;
|
default = true;
|
||||||
description = "Allows encryption to be disabled for testing";
|
description = "Allows encryption to be disabled for testing";
|
||||||
};
|
};
|
||||||
legacy = lib.mkOption {
|
|
||||||
type = lib.types.bool;
|
|
||||||
default = false;
|
|
||||||
description = "Enable legacy boot (bios)";
|
|
||||||
};
|
|
||||||
devNodes = lib.mkOption {
|
devNodes = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "/dev/disk/by-id/";
|
default = "/dev/disk/by-id/";
|
||||||
@@ -86,25 +81,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkMerge [
|
config = lib.mkIf cfg.enable {
|
||||||
(lib.mkIf (cfg.enable && !cfg.legacy) {
|
|
||||||
boot = {
|
|
||||||
loader.systemd-boot.enable = true;
|
|
||||||
loader.efi.canTouchEfiVariables = true;
|
|
||||||
supportedFilesystems = [ "vfat" "zfs" ];
|
|
||||||
};
|
|
||||||
fileSystems."/boot".neededForBoot = true;
|
|
||||||
})
|
|
||||||
(lib.mkIf (cfg.enable && cfg.legacy) {
|
|
||||||
boot.loader.grub = {
|
|
||||||
enable = lib.mkForce true;
|
|
||||||
device = "/dev/${cfg.root.disk0}-part1";
|
|
||||||
efiSupport = false;
|
|
||||||
enableCryptodisk = cfg.encryption;
|
|
||||||
zfsSupport = true;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(lib.mkIf cfg.enable {
|
|
||||||
networking.hostId = cfg.hostId;
|
networking.hostId = cfg.hostId;
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = lib.mkMerge [
|
disk = lib.mkMerge [
|
||||||
@@ -115,7 +92,7 @@ in
|
|||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
ESP = lib.mkIf (!cfg.legacy) {
|
ESP = {
|
||||||
size = "1024M";
|
size = "1024M";
|
||||||
type = "EF00";
|
type = "EF00";
|
||||||
content = {
|
content = {
|
||||||
@@ -125,10 +102,6 @@ in
|
|||||||
mountOptions = [ "umask=0077" ];
|
mountOptions = [ "umask=0077" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
boot = lib.mkIf cfg.legacy {
|
|
||||||
size = "1024M";
|
|
||||||
type = "EF02";
|
|
||||||
};
|
|
||||||
encryptedSwap = {
|
encryptedSwap = {
|
||||||
size = cfg.root.swap;
|
size = cfg.root.swap;
|
||||||
content = {
|
content = {
|
||||||
@@ -271,12 +244,13 @@ in
|
|||||||
};
|
};
|
||||||
# use this to read the key during boot
|
# use this to read the key during boot
|
||||||
postCreateHook = lib.mkIf cfg.encryption ''
|
postCreateHook = lib.mkIf cfg.encryption ''
|
||||||
zfs set keylocation="file:///root/secret.key" storage/encrypted;
|
zfs set keylocation="prompt" storage/encrypted;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
"encrypted/data" = {
|
"encrypted/data" = {
|
||||||
type = "zfs_fs";
|
type = "zfs_fs";
|
||||||
mountpoint = "/data";
|
mountpoint = "/data";
|
||||||
|
options.mountpoint = "legacy";
|
||||||
};
|
};
|
||||||
reserved = {
|
reserved = {
|
||||||
# for cow delete if pool is full
|
# for cow delete if pool is full
|
||||||
@@ -293,13 +267,12 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
boot.zfs.devNodes = lib.mkDefault cfg.devNodes;
|
boot.zfs.devNodes = lib.mkDefault cfg.devNodes;
|
||||||
boot.zfs.extraPools = lib.mkIf cfg.storage.enable [ "storage" ];
|
|
||||||
|
|
||||||
fileSystems."/".neededForBoot = true;
|
fileSystems."/".neededForBoot = true;
|
||||||
fileSystems."/etc".neededForBoot = true;
|
fileSystems."/etc".neededForBoot = true;
|
||||||
|
fileSystems."/boot".neededForBoot = true;
|
||||||
fileSystems."/var".neededForBoot = true;
|
fileSystems."/var".neededForBoot = true;
|
||||||
fileSystems."/home".neededForBoot = true;
|
fileSystems."/home".neededForBoot = true;
|
||||||
fileSystems."/nix".neededForBoot = true;
|
fileSystems."/nix".neededForBoot = true;
|
||||||
})
|
};
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ rec {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
#if networking is disabled forward port 80 to still have access to webservices
|
#if networking is disabled forward port 80 to still have access to webservices
|
||||||
forwardPorts = pkgs.lib.mkIf (!options.withNetworking && options.fwdPort != 0) (pkgs.lib.mkForce [
|
forwardPorts = pkgs.lib.mkIf (!options.withNetworking) (pkgs.lib.mkForce [
|
||||||
{ from = "host"; host.port = options.fwdPort; guest.port = 80; }
|
{ from = "host"; host.port = 8080; guest.port = 80; }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -212,13 +212,12 @@ rec {
|
|||||||
builtins.listToAttrs (map mapperFunc self.nixosConfigurations.${host}.config.services.malobeo.microvm.deployHosts);
|
builtins.listToAttrs (map mapperFunc self.nixosConfigurations.${host}.config.services.malobeo.microvm.deployHosts);
|
||||||
};
|
};
|
||||||
|
|
||||||
buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: fwdPort: (self.nixosConfigurations.${host}.extendModules {
|
buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: (self.nixosConfigurations.${host}.extendModules {
|
||||||
modules = [
|
modules = [
|
||||||
(vmMicroVMOverwrites host {
|
(vmMicroVMOverwrites host {
|
||||||
withNetworking = networking;
|
withNetworking = networking;
|
||||||
varPath = "${varPath}";
|
varPath = "${varPath}";
|
||||||
writableStore = writableStore;
|
writableStore = writableStore; })
|
||||||
fwdPort = fwdPort; })
|
|
||||||
(if sopsDummy then (vmSopsOverwrites host) else {})
|
(if sopsDummy then (vmSopsOverwrites host) else {})
|
||||||
(if disableDisko then vmDiskoOverwrites else {})
|
(if disableDisko then vmDiskoOverwrites else {})
|
||||||
] ++ pkgs.lib.optionals (hosts.malobeo.hosts.${host}.type != "microvm") [
|
] ++ pkgs.lib.optionals (hosts.malobeo.hosts.${host}.type != "microvm") [
|
||||||
|
|||||||
@@ -26,8 +26,13 @@ in
|
|||||||
|
|
||||||
config = lib.mkIf (cfg.enable && config.malobeo.disks.encryption) {
|
config = lib.mkIf (cfg.enable && config.malobeo.disks.encryption) {
|
||||||
boot = {
|
boot = {
|
||||||
|
loader.systemd-boot.enable = true;
|
||||||
|
loader.efi.canTouchEfiVariables = true;
|
||||||
|
supportedFilesystems = [ "vfat" "zfs" ];
|
||||||
zfs = {
|
zfs = {
|
||||||
|
forceImportAll = true;
|
||||||
requestEncryptionCredentials = true;
|
requestEncryptionCredentials = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
initrd = {
|
initrd = {
|
||||||
availableKernelModules = cfg.ethernetDrivers;
|
availableKernelModules = cfg.ethernetDrivers;
|
||||||
|
|||||||
@@ -30,13 +30,6 @@
|
|||||||
publicKey = "TrJ4UAF//zXdaLwZudI78L+rTC36zEDodTDOWNS4Y1Y=";
|
publicKey = "TrJ4UAF//zXdaLwZudI78L+rTC36zEDodTDOWNS4Y1Y=";
|
||||||
};
|
};
|
||||||
|
|
||||||
"hetzner" = {
|
|
||||||
role = "client";
|
|
||||||
address = [ "10.100.0.6/24" ];
|
|
||||||
allowedIPs = [ "10.100.0.6/32" ];
|
|
||||||
publicKey = "csRzgwtnzmSLeLkSwTwEOrdKq55UOxZacR5D3GopCTQ=";
|
|
||||||
};
|
|
||||||
|
|
||||||
"fanny" = {
|
"fanny" = {
|
||||||
role = "client";
|
role = "client";
|
||||||
address = [ "10.100.0.101/24" ];
|
address = [ "10.100.0.101/24" ];
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ with lib;
|
|||||||
};
|
};
|
||||||
extraAppsEnable = true;
|
extraAppsEnable = true;
|
||||||
extraApps = {
|
extraApps = {
|
||||||
inherit (config.services.nextcloud.package.packages.apps) contacts calendar deck polls;
|
inherit (config.services.nextcloud.package.packages.apps) contacts calendar;
|
||||||
collectives = pkgs.fetchNextcloudApp {
|
collectives = pkgs.fetchNextcloudApp {
|
||||||
sha256 = "sha256-cj/8FhzxOACJaUEu0eG9r7iAQmnOG62yFHeyUICalFY=";
|
sha256 = "sha256-cj/8FhzxOACJaUEu0eG9r7iAQmnOG62yFHeyUICalFY=";
|
||||||
url = "https://github.com/nextcloud/collectives/releases/download/v2.15.2/collectives-2.15.2.tar.gz";
|
url = "https://github.com/nextcloud/collectives/releases/download/v2.15.2/collectives-2.15.2.tar.gz";
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ in
|
|||||||
|
|
||||||
malobeo.disks = {
|
malobeo.disks = {
|
||||||
enable = true;
|
enable = true;
|
||||||
encryption = true;
|
encryption = false;
|
||||||
hostId = "83abc8cb";
|
hostId = "83abc8cb";
|
||||||
devNodes = "/dev/disk/by-path/";
|
devNodes = "/dev/disk/by-path/";
|
||||||
root = {
|
root = {
|
||||||
@@ -37,11 +37,9 @@ trap cleanup EXIT
|
|||||||
|
|
||||||
# Create the directory where sshd expects to find the host keys
|
# Create the directory where sshd expects to find the host keys
|
||||||
install -d -m755 "$temp/etc/ssh/"
|
install -d -m755 "$temp/etc/ssh/"
|
||||||
install -d -m755 "$temp/root/"
|
|
||||||
|
|
||||||
diskKey=$(sops -d machines/$hostname/disk.key)
|
diskKey=$(sops -d machines/$hostname/disk.key)
|
||||||
echo "$diskKey" > /tmp/secret.key
|
echo "$diskKey" > /tmp/secret.key
|
||||||
echo "$diskKey" > $temp/root/secret.key
|
|
||||||
|
|
||||||
ssh-keygen -f $temp/etc/ssh/"$hostname" -t ed25519 -N ""
|
ssh-keygen -f $temp/etc/ssh/"$hostname" -t ed25519 -N ""
|
||||||
ssh-keygen -f $temp/etc/ssh/initrd -t ed25519 -N ""
|
ssh-keygen -f $temp/etc/ssh/initrd -t ed25519 -N ""
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ usage() {
|
|||||||
echo "--no-disko disable disko and initrd secrets. needed for real hosts like fanny"
|
echo "--no-disko disable disko and initrd secrets. needed for real hosts like fanny"
|
||||||
echo "--writable-store enables writable store. necessary for host with nested imperative microvms like fanny"
|
echo "--writable-store enables writable store. necessary for host with nested imperative microvms like fanny"
|
||||||
echo "--var path to directory that should be shared as /var. may require root otherwise some systemd units fail within vm. if dir is empty vm will populate"
|
echo "--var path to directory that should be shared as /var. may require root otherwise some systemd units fail within vm. if dir is empty vm will populate"
|
||||||
echo "--fwd-port forwards the given port to port 80 on vm"
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +22,6 @@ DUMMY_SECRETS=false
|
|||||||
NO_DISKO=false
|
NO_DISKO=false
|
||||||
RW_STORE=false
|
RW_STORE=false
|
||||||
VAR_PATH=""
|
VAR_PATH=""
|
||||||
FWD_PORT=0
|
|
||||||
|
|
||||||
# check argws
|
# check argws
|
||||||
shift
|
shift
|
||||||
@@ -42,15 +40,6 @@ while [[ "$#" -gt 0 ]]; do
|
|||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
--fwd-port)
|
|
||||||
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
|
||||||
FWD_PORT="$2"
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
echo "Error: --var requires a non-empty string argument."
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*) echo "Unknown argument: $1"; usage ;;
|
*) echo "Unknown argument: $1"; usage ;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
@@ -64,4 +53,4 @@ if [ -n "$VAR_PATH" ]; then
|
|||||||
echo "sharing var directory: $VAR_PATH"
|
echo "sharing var directory: $VAR_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\" $RW_STORE $FWD_PORT).config.microvm.declaredRunner"
|
nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\" $RW_STORE).config.microvm.declaredRunner"
|
||||||
|
|||||||
@@ -23,12 +23,16 @@ echo
|
|||||||
if [ $# = 1 ]
|
if [ $# = 1 ]
|
||||||
then
|
then
|
||||||
diskkey=$(sops -d machines/$HOSTNAME/disk.key)
|
diskkey=$(sops -d machines/$HOSTNAME/disk.key)
|
||||||
|
echo "$diskkey" | ssh $sshoptions root@$HOSTNAME-initrd "systemd-tty-ask-password-agent" #storage
|
||||||
|
|
||||||
echo "$diskkey" | ssh $sshoptions root@$HOSTNAME-initrd "systemd-tty-ask-password-agent" #root
|
echo "$diskkey" | ssh $sshoptions root@$HOSTNAME-initrd "systemd-tty-ask-password-agent" #root
|
||||||
|
|
||||||
elif [ $# = 2 ]
|
elif [ $# = 2 ]
|
||||||
then
|
then
|
||||||
diskkey=$(sops -d machines/$HOSTNAME/disk.key)
|
diskkey=$(sops -d machines/$HOSTNAME/disk.key)
|
||||||
IP=$2
|
IP=$2
|
||||||
|
echo "$diskkey" | ssh $sshoptions root@$IP "systemd-tty-ask-password-agent" #storage
|
||||||
|
|
||||||
echo "$diskkey" | ssh $sshoptions root@$IP "systemd-tty-ask-password-agent" #root
|
echo "$diskkey" | ssh $sshoptions root@$IP "systemd-tty-ask-password-agent" #root
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user