19 Commits

Author SHA1 Message Date
ahtlon
a07bec0472 [scripts] only need to unlock once
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m18s
2025-01-24 18:42:31 +01:00
ahtlon
4a67683462 [disko] Bit of a hack but the storage partition now gets mounted after zroot using a file on the disk.
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m17s
2025-01-24 18:30:51 +01:00
ahtlon
fb222bc1a4 [disko] rm btrfs-laptop.nix 2025-01-24 15:08:24 +01:00
5c17164fd8 [testvm] integrate into hosts.nix
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m24s
2025-01-23 21:20:37 +01:00
a8bf6539e6 [run-vm] optional forward ports
Some checks failed
Check flake syntax / flake-check (push) Failing after 1m5s
currently only allows forwarding to port 80, i was to lazy to handle two
arguments in bash
2025-01-23 21:12:53 +01:00
a4063bf02b [testvm] add to nixosConfigurations again 2025-01-23 21:11:31 +01:00
74ebf042e7 [run-vm] mv to /scripts
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m11s
2025-01-23 21:00:30 +01:00
a7ae07eba3 [nix] rm machines/configuration.nix 2025-01-23 21:00:30 +01:00
baf77a1abd [nix] mv buildVM to host_builder 2025-01-23 21:00:30 +01:00
fa5c68b2a3 [vmBuilder] add writable store flag 2025-01-23 21:00:30 +01:00
2fb89082dd [nix] fix imports 2025-01-23 21:00:30 +01:00
0f3591d111 [nix] mv vm overwrites to host_builder 2025-01-23 21:00:30 +01:00
4eea2de7ec [nix] mv host_builer.nix host_builder.nix 2025-01-23 21:00:30 +01:00
03f9e9b9a2 [nix] create nixosConfigurations using malobeo.hosts 2025-01-23 21:00:30 +01:00
b349391de6 [nix] mv host declarations to hosts.nix, add util to host_builer.nix 2025-01-23 21:00:30 +01:00
a02b2c2bc4 [nix] generate hosts 2025-01-23 21:00:30 +01:00
dcc81ec929 [nix] init host_builder.nix 2025-01-23 21:00:30 +01:00
de774ac9b4 [fanny] nat microvm traffic
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m22s
2025-01-23 19:03:46 +01:00
c8f7358ac2 [nextcloud] add deck and polls
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m22s
2025-01-23 17:31:38 +01:00
11 changed files with 35 additions and 80 deletions

View File

@@ -72,6 +72,12 @@ 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 ];
}; };

View File

@@ -66,6 +66,10 @@
mac = "D0:E5:CA:F0:D7:E0"; mac = "D0:E5:CA:F0:D7:E0";
}; };
}; };
testvm = {
type = "host";
};
}; };
}; };
} }

View File

@@ -1,63 +0,0 @@
{ 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";
};
};
};
};
};
};
};
};
};
};
}

View File

@@ -187,6 +187,7 @@ in
postCreateHook = lib.mkIf cfg.encryption '' postCreateHook = lib.mkIf cfg.encryption ''
zfs set keylocation="prompt" zroot/encrypted; zfs set keylocation="prompt" zroot/encrypted;
''; '';
}; };
"encrypted/root" = { "encrypted/root" = {
type = "zfs_fs"; type = "zfs_fs";
@@ -244,13 +245,12 @@ 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="prompt" storage/encrypted; zfs set keylocation="file:///root/secret.key" 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
@@ -267,7 +267,7 @@ 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."/boot".neededForBoot = true;

View File

@@ -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) (pkgs.lib.mkForce [ forwardPorts = pkgs.lib.mkIf (!options.withNetworking && options.fwdPort != 0) (pkgs.lib.mkForce [
{ from = "host"; host.port = 8080; guest.port = 80; } { from = "host"; host.port = options.fwdPort; guest.port = 80; }
]); ]);
}; };
@@ -212,12 +212,13 @@ 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: (self.nixosConfigurations.${host}.extendModules { buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: fwdPort: (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") [

View File

@@ -30,9 +30,7 @@ in
loader.efi.canTouchEfiVariables = true; loader.efi.canTouchEfiVariables = true;
supportedFilesystems = [ "vfat" "zfs" ]; supportedFilesystems = [ "vfat" "zfs" ];
zfs = { zfs = {
forceImportAll = true;
requestEncryptionCredentials = true; requestEncryptionCredentials = true;
}; };
initrd = { initrd = {
availableKernelModules = cfg.ethernetDrivers; availableKernelModules = cfg.ethernetDrivers;

View File

@@ -46,7 +46,7 @@ with lib;
}; };
extraAppsEnable = true; extraAppsEnable = true;
extraApps = { extraApps = {
inherit (config.services.nextcloud.package.packages.apps) contacts calendar; inherit (config.services.nextcloud.package.packages.apps) contacts calendar deck polls;
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";

View File

@@ -24,7 +24,7 @@ in
malobeo.disks = { malobeo.disks = {
enable = true; enable = true;
encryption = false; encryption = true;
hostId = "83abc8cb"; hostId = "83abc8cb";
devNodes = "/dev/disk/by-path/"; devNodes = "/dev/disk/by-path/";
root = { root = {

View File

@@ -37,9 +37,11 @@ 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 ""

View File

@@ -6,6 +6,7 @@ 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
} }
@@ -22,6 +23,7 @@ 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
@@ -40,6 +42,15 @@ 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
@@ -53,4 +64,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).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 $FWD_PORT).config.microvm.declaredRunner"

View File

@@ -23,18 +23,14 @@ 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
echo echo
echo "Unlock the root disk on a remote host." echo "Unlock the root disk on a remote host."