Compare commits
29 Commits
a019b33fbf
...
issue31
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f4cb3787b | |||
| 4f9e66ba82 | |||
| 1f9d39b53d | |||
|
|
362d9cf488 | ||
|
|
e22c895cf7 | ||
|
|
a07bec0472 | ||
|
|
4a67683462 | ||
|
|
fb222bc1a4 | ||
| 5c17164fd8 | |||
| a8bf6539e6 | |||
| a4063bf02b | |||
| 74ebf042e7 | |||
| a7ae07eba3 | |||
| baf77a1abd | |||
| fa5c68b2a3 | |||
| 2fb89082dd | |||
| 0f3591d111 | |||
| 4eea2de7ec | |||
| 03f9e9b9a2 | |||
| b349391de6 | |||
| a02b2c2bc4 | |||
| dcc81ec929 | |||
| de774ac9b4 | |||
| c8f7358ac2 | |||
|
|
c51c1e8e92 | ||
|
|
a96b8f65c9 | ||
| 29d6bc02e0 | |||
|
|
c0cef1ff1e | ||
|
|
7099c92236 |
@@ -26,6 +26,7 @@ in
|
||||
|
||||
malobeo.disks = {
|
||||
enable = true;
|
||||
legacy = true;
|
||||
hostId = "a3c3102f";
|
||||
root = {
|
||||
disk0 = "disk/by-id/ata-HITACHI_HTS725016A9A364_110308PCKB04VNHX9XTJ";
|
||||
@@ -33,9 +34,7 @@ in
|
||||
};
|
||||
|
||||
malobeo.initssh = {
|
||||
enable = true;
|
||||
authorizedKeys = sshKeys.admins;
|
||||
ethernetDrivers = ["r8169"];
|
||||
enable = false;
|
||||
};
|
||||
|
||||
hardware.sane.enable = true; #scanner support
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
{ self
|
||||
, nixpkgs-unstable
|
||||
, nixpkgs
|
||||
, sops-nix
|
||||
, inputs
|
||||
, nixos-hardware
|
||||
, home-manager
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
nixosSystem = nixpkgs.lib.makeOverridable nixpkgs.lib.nixosSystem;
|
||||
nixosSystemUnstable = nixpkgs-unstable.lib.makeOverridable nixpkgs-unstable.lib.nixosSystem;
|
||||
|
||||
baseModules = [
|
||||
# make flake inputs accessiable in NixOS
|
||||
{ _module.args.inputs = inputs; }
|
||||
{
|
||||
imports = [
|
||||
({ pkgs, ... }: {
|
||||
nix = {
|
||||
extraOptions = ''
|
||||
experimental-features = nix-command flakes
|
||||
'';
|
||||
|
||||
settings = {
|
||||
substituters = [
|
||||
"https://cache.dynamicdiscord.de"
|
||||
"https://cache.nixos.org/"
|
||||
];
|
||||
trusted-public-keys = [
|
||||
"cache.dynamicdiscord.de:DKueZicqi2NhJJXz9MYgUbiyobMs10fTyHCgAUibRP4="
|
||||
];
|
||||
trusted-users = [ "root" "@wheel" ];
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
sops-nix.nixosModules.sops
|
||||
];
|
||||
}
|
||||
];
|
||||
defaultModules = baseModules;
|
||||
|
||||
makeMicroVM = hostName: ipv4Addr: macAddr: modules: [
|
||||
inputs.microvm.nixosModules.microvm
|
||||
{
|
||||
microvm = {
|
||||
hypervisor = "cloud-hypervisor";
|
||||
mem = 2560;
|
||||
shares = [
|
||||
{
|
||||
source = "/nix/store";
|
||||
mountPoint = "/nix/.ro-store";
|
||||
tag = "store";
|
||||
proto = "virtiofs";
|
||||
socket = "store.socket";
|
||||
}
|
||||
{
|
||||
source = "/var/lib/microvms/${hostName}/etc";
|
||||
mountPoint = "/etc";
|
||||
tag = "etc";
|
||||
proto = "virtiofs";
|
||||
socket = "etc.socket";
|
||||
}
|
||||
{
|
||||
source = "/var/lib/microvms/${hostName}/var";
|
||||
mountPoint = "/var";
|
||||
tag = "var";
|
||||
proto = "virtiofs";
|
||||
socket = "var.socket";
|
||||
}
|
||||
];
|
||||
|
||||
interfaces = [
|
||||
{
|
||||
type = "tap";
|
||||
id = "vm-${hostName}";
|
||||
mac = "${macAddr}";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
systemd.network.enable = true;
|
||||
|
||||
systemd.network.networks."20-lan" = {
|
||||
matchConfig.Type = "ether";
|
||||
networkConfig = {
|
||||
Address = [ "${ipv4Addr}/24" ];
|
||||
Gateway = "10.0.0.1";
|
||||
DNS = ["1.1.1.1"];
|
||||
DHCP = "no";
|
||||
};
|
||||
};
|
||||
}
|
||||
] ++ defaultModules ++ modules;
|
||||
|
||||
inputsMod = inputs // { malobeo = self; };
|
||||
in
|
||||
{
|
||||
louise = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
modules = defaultModules ++ [
|
||||
./louise/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
bakunin = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
modules = defaultModules ++ [
|
||||
./bakunin/configuration.nix
|
||||
inputs.disko.nixosModules.disko
|
||||
];
|
||||
};
|
||||
|
||||
lucia = nixosSystem {
|
||||
system = "aarch64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
modules = defaultModules ++ [
|
||||
./lucia/configuration.nix
|
||||
./lucia/hardware_configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
fanny = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputsMod;
|
||||
modules = defaultModules ++ [
|
||||
self.nixosModules.malobeo.vpn
|
||||
./fanny/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
durruti = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = makeMicroVM "durruti" "10.0.0.5" "52:DA:0D:F9:EF:F9" [
|
||||
./durruti/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
vpn = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = makeMicroVM "vpn" "10.0.0.10" "D0:E5:CA:F0:D7:E6" [
|
||||
self.nixosModules.malobeo.vpn
|
||||
./vpn/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
infradocs = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = makeMicroVM "infradocs" "10.0.0.11" "D0:E5:CA:F0:D7:E7" [
|
||||
self.nixosModules.malobeo.vpn
|
||||
./infradocs/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
uptimekuma = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = makeMicroVM "uptimekuma" "10.0.0.12" "D0:E5:CA:F0:D7:E8" [
|
||||
./uptimekuma/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
nextcloud = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = makeMicroVM "nextcloud" "10.0.0.13" "D0:E5:CA:F0:D7:E9" [
|
||||
./nextcloud/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
overwatch = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = makeMicroVM "overwatch" "10.0.0.14" "D0:E5:CA:F0:D7:E0" [
|
||||
./overwatch/configuration.nix
|
||||
];
|
||||
};
|
||||
|
||||
testvm = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs.inputs = inputs;
|
||||
specialArgs.self = self;
|
||||
modules = defaultModules ++ [ ./testvm ];
|
||||
};
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ in
|
||||
../modules/sshd.nix
|
||||
../modules/minimal_tools.nix
|
||||
../modules/autoupdate.nix
|
||||
inputs.self.nixosModules.malobeo.vpn
|
||||
inputs.self.nixosModules.malobeo.initssh
|
||||
inputs.self.nixosModules.malobeo.disko
|
||||
inputs.self.nixosModules.malobeo.microvm
|
||||
@@ -50,6 +51,7 @@ in
|
||||
disk0 = "disk/by-id/ata-SAMSUNG_MZ7LN256HCHP-000L7_S20HNAAH200381";
|
||||
};
|
||||
storage = {
|
||||
enable = true;
|
||||
disks = ["disk/by-id/wwn-0x50014ee265b53b60" "disk/by-id/wwn-0x50014ee2bb0a194a"];
|
||||
mirror = true;
|
||||
};
|
||||
@@ -71,6 +73,12 @@ in
|
||||
services.malobeo.microvm.deployHosts = [ "overwatch" "infradocs" "nextcloud" "durruti" ];
|
||||
|
||||
networking = {
|
||||
nat = {
|
||||
enable = true;
|
||||
externalInterface = "enp1s0";
|
||||
internalInterfaces = [ "microvm" ];
|
||||
};
|
||||
|
||||
firewall = {
|
||||
allowedTCPPorts = [ 80 ];
|
||||
};
|
||||
|
||||
75
machines/hosts.nix
Normal file
75
machines/hosts.nix
Normal file
@@ -0,0 +1,75 @@
|
||||
{ ... }:
|
||||
|
||||
{
|
||||
malobeo = {
|
||||
hosts = {
|
||||
louise = {
|
||||
type = "host";
|
||||
};
|
||||
|
||||
bakunin = {
|
||||
type = "host";
|
||||
};
|
||||
|
||||
fanny = {
|
||||
type = "host";
|
||||
};
|
||||
|
||||
lucia = {
|
||||
type = "rpi";
|
||||
};
|
||||
|
||||
durruti = {
|
||||
type = "microvm";
|
||||
network = {
|
||||
address = "10.0.0.5";
|
||||
mac = "52:DA:0D:F9:EF:F9";
|
||||
};
|
||||
};
|
||||
|
||||
vpn = {
|
||||
type = "microvm";
|
||||
network = {
|
||||
address = "10.0.0.10";
|
||||
mac = "D0:E5:CA:F0:D7:E6";
|
||||
};
|
||||
};
|
||||
|
||||
infradocs = {
|
||||
type = "microvm";
|
||||
network = {
|
||||
address = "10.0.0.11";
|
||||
mac = "D0:E5:CA:F0:D7:E7";
|
||||
};
|
||||
};
|
||||
|
||||
uptimekuma = {
|
||||
type = "microvm";
|
||||
network = {
|
||||
address = "10.0.0.12";
|
||||
mac = "D0:E5:CA:F0:D7:E8";
|
||||
};
|
||||
};
|
||||
|
||||
nextcloud = {
|
||||
type = "microvm";
|
||||
network = {
|
||||
address = "10.0.0.13";
|
||||
mac = "D0:E5:CA:F0:D7:E9";
|
||||
};
|
||||
};
|
||||
|
||||
overwatch = {
|
||||
type = "microvm";
|
||||
network = {
|
||||
address = "10.0.0.14";
|
||||
mac = "D0:E5:CA:F0:D7:E0";
|
||||
};
|
||||
};
|
||||
|
||||
testvm = {
|
||||
type = "host";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -9,7 +9,7 @@ with lib;
|
||||
};
|
||||
|
||||
imports = [
|
||||
self.nixosModules.malobeo.metrics
|
||||
inputs.malobeo.nixosModules.malobeo.metrics
|
||||
../durruti/documentation.nix
|
||||
../modules/malobeo_user.nix
|
||||
../modules/sshd.nix
|
||||
|
||||
@@ -6,6 +6,7 @@ in
|
||||
{
|
||||
imports =
|
||||
[ # Include the results of the hardware scan.
|
||||
./hardware_configuration.nix
|
||||
../modules/malobeo_user.nix
|
||||
];
|
||||
|
||||
|
||||
@@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -20,6 +20,11 @@ in
|
||||
default = true;
|
||||
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 {
|
||||
type = lib.types.str;
|
||||
default = "/dev/disk/by-id/";
|
||||
@@ -81,198 +86,220 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
networking.hostId = cfg.hostId;
|
||||
disko.devices = {
|
||||
disk = lib.mkMerge [
|
||||
{
|
||||
ssd0 = lib.mkIf (cfg.root.disk0 != "") {
|
||||
type = "disk";
|
||||
device = "/dev/${cfg.root.disk0}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
size = "1024M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
config = lib.mkMerge [
|
||||
(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;
|
||||
disko.devices = {
|
||||
disk = lib.mkMerge [
|
||||
{
|
||||
ssd0 = lib.mkIf (cfg.root.disk0 != "") {
|
||||
type = "disk";
|
||||
device = "/dev/${cfg.root.disk0}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = lib.mkIf (!cfg.legacy) {
|
||||
size = "1024M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
encryptedSwap = {
|
||||
size = cfg.root.swap;
|
||||
content = {
|
||||
type = "swap";
|
||||
randomEncryption = true;
|
||||
boot = lib.mkIf cfg.legacy {
|
||||
size = "1024M";
|
||||
type = "EF02";
|
||||
};
|
||||
};
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
encryptedSwap = {
|
||||
size = cfg.root.swap;
|
||||
content = {
|
||||
type = "swap";
|
||||
randomEncryption = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
ssd1 = lib.mkIf (cfg.root.disk1 != "") {
|
||||
type = "disk";
|
||||
device = "/dev/${cfg.root.disk1}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
(lib.mkIf cfg.storage.enable (
|
||||
lib.mkMerge (
|
||||
map (diskname: {
|
||||
"${diskname}" = {
|
||||
type = "disk";
|
||||
device = "/dev/${diskname}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "storage";
|
||||
};
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}) cfg.storage.disks
|
||||
)
|
||||
))
|
||||
];
|
||||
};
|
||||
ssd1 = lib.mkIf (cfg.root.disk1 != "") {
|
||||
type = "disk";
|
||||
device = "/dev/${cfg.root.disk1}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
(lib.mkIf cfg.storage.enable (
|
||||
lib.mkMerge (
|
||||
map (diskname: {
|
||||
"${diskname}" = {
|
||||
type = "disk";
|
||||
device = "/dev/${diskname}";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "storage";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}) cfg.storage.disks
|
||||
)
|
||||
))
|
||||
];
|
||||
|
||||
zpool = {
|
||||
zroot = {
|
||||
type = "zpool";
|
||||
mode = lib.mkIf cfg.root.mirror "mirror";
|
||||
# Workaround: cannot import 'zroot': I/O error in disko tests
|
||||
options.cachefile = "none";
|
||||
rootFsOptions = {
|
||||
mountpoint = "none";
|
||||
xattr = "sa"; # für microvm virtiofs mount
|
||||
acltype = "posixacl"; # für microvm virtiofs mount
|
||||
compression = "zstd";
|
||||
"com.sun:auto-snapshot" = "false";
|
||||
zpool = {
|
||||
zroot = {
|
||||
type = "zpool";
|
||||
mode = lib.mkIf cfg.root.mirror "mirror";
|
||||
# Workaround: cannot import 'zroot': I/O error in disko tests
|
||||
options.cachefile = "none";
|
||||
rootFsOptions = {
|
||||
mountpoint = "none";
|
||||
xattr = "sa"; # für microvm virtiofs mount
|
||||
acltype = "posixacl"; # für microvm virtiofs mount
|
||||
compression = "zstd";
|
||||
"com.sun:auto-snapshot" = "false";
|
||||
};
|
||||
|
||||
datasets = {
|
||||
encrypted = {
|
||||
type = "zfs_fs";
|
||||
options = {
|
||||
mountpoint = "none";
|
||||
encryption = lib.mkIf cfg.encryption "aes-256-gcm";
|
||||
keyformat = lib.mkIf cfg.encryption "passphrase";
|
||||
keylocation = lib.mkIf cfg.encryption "file:///tmp/secret.key";
|
||||
};
|
||||
# use this to read the key during boot
|
||||
postCreateHook = lib.mkIf cfg.encryption ''
|
||||
zfs set keylocation="prompt" zroot/encrypted;
|
||||
'';
|
||||
};
|
||||
"encrypted/root" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/var" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/var";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/etc" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/etc";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/home" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/home";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/nix" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/nix";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
reserved = {
|
||||
# for cow delete if pool is full
|
||||
options = {
|
||||
canmount = "off";
|
||||
mountpoint = "none";
|
||||
reservation = "${cfg.root.reservation}";
|
||||
};
|
||||
type = "zfs_fs";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
datasets = {
|
||||
encrypted = {
|
||||
type = "zfs_fs";
|
||||
options = {
|
||||
mountpoint = "none";
|
||||
encryption = lib.mkIf cfg.encryption "aes-256-gcm";
|
||||
keyformat = lib.mkIf cfg.encryption "passphrase";
|
||||
keylocation = lib.mkIf cfg.encryption "file:///tmp/secret.key";
|
||||
storage = lib.mkIf cfg.storage.enable {
|
||||
type = "zpool";
|
||||
mode = lib.mkIf (cfg.storage.mirror) "mirror";
|
||||
rootFsOptions = {
|
||||
mountpoint = "none";
|
||||
xattr = "sa"; # für microvm virtiofs mount
|
||||
acltype = "posixacl"; # für microvm virtiofs mount
|
||||
};
|
||||
datasets = {
|
||||
encrypted = {
|
||||
type = "zfs_fs";
|
||||
options = {
|
||||
mountpoint = "none";
|
||||
encryption = lib.mkIf cfg.encryption "aes-256-gcm";
|
||||
keyformat = lib.mkIf cfg.encryption "passphrase";
|
||||
keylocation = lib.mkIf cfg.encryption "file:///tmp/secret.key";
|
||||
};
|
||||
# use this to read the key during boot
|
||||
postCreateHook = lib.mkIf cfg.encryption ''
|
||||
zfs set keylocation="file:///root/secret.key" storage/encrypted;
|
||||
'';
|
||||
};
|
||||
# use this to read the key during boot
|
||||
postCreateHook = lib.mkIf cfg.encryption ''
|
||||
zfs set keylocation="prompt" zroot/encrypted;
|
||||
'';
|
||||
};
|
||||
"encrypted/root" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/var" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/var";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/etc" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/etc";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/home" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/home";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
"encrypted/nix" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/nix";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
reserved = {
|
||||
# for cow delete if pool is full
|
||||
options = {
|
||||
canmount = "off";
|
||||
mountpoint = "none";
|
||||
reservation = "${cfg.root.reservation}";
|
||||
"encrypted/data" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/data";
|
||||
};
|
||||
type = "zfs_fs";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
storage = lib.mkIf cfg.storage.enable {
|
||||
type = "zpool";
|
||||
mode = lib.mkIf (cfg.storage.mirror) "mirror";
|
||||
rootFsOptions = {
|
||||
mountpoint = "none";
|
||||
xattr = "sa"; # für microvm virtiofs mount
|
||||
acltype = "posixacl"; # für microvm virtiofs mount
|
||||
};
|
||||
datasets = {
|
||||
encrypted = {
|
||||
type = "zfs_fs";
|
||||
options = {
|
||||
mountpoint = "none";
|
||||
encryption = lib.mkIf cfg.encryption "aes-256-gcm";
|
||||
keyformat = lib.mkIf cfg.encryption "passphrase";
|
||||
keylocation = lib.mkIf cfg.encryption "file:///tmp/secret.key";
|
||||
reserved = {
|
||||
# for cow delete if pool is full
|
||||
options = {
|
||||
canmount = "off";
|
||||
mountpoint = "none";
|
||||
reservation = "${cfg.storage.reservation}";
|
||||
};
|
||||
type = "zfs_fs";
|
||||
};
|
||||
# use this to read the key during boot
|
||||
postCreateHook = lib.mkIf cfg.encryption ''
|
||||
zfs set keylocation="prompt" storage/encrypted;
|
||||
'';
|
||||
};
|
||||
"encrypted/data" = {
|
||||
type = "zfs_fs";
|
||||
mountpoint = "/data";
|
||||
options.mountpoint = "legacy";
|
||||
};
|
||||
reserved = {
|
||||
# for cow delete if pool is full
|
||||
options = {
|
||||
canmount = "off";
|
||||
mountpoint = "none";
|
||||
reservation = "${cfg.storage.reservation}";
|
||||
};
|
||||
type = "zfs_fs";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
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."/etc".neededForBoot = true;
|
||||
fileSystems."/boot".neededForBoot = true;
|
||||
fileSystems."/var".neededForBoot = true;
|
||||
fileSystems."/home".neededForBoot = true;
|
||||
fileSystems."/nix".neededForBoot = true;
|
||||
};
|
||||
fileSystems."/".neededForBoot = true;
|
||||
fileSystems."/etc".neededForBoot = true;
|
||||
fileSystems."/var".neededForBoot = true;
|
||||
fileSystems."/home".neededForBoot = true;
|
||||
fileSystems."/nix".neededForBoot = true;
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
243
machines/modules/host_builder.nix
Normal file
243
machines/modules/host_builder.nix
Normal file
@@ -0,0 +1,243 @@
|
||||
{ self
|
||||
, nixpkgs-unstable
|
||||
, nixpkgs
|
||||
, sops-nix
|
||||
, inputs
|
||||
, hosts
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages."x86_64-linux";
|
||||
in
|
||||
rec {
|
||||
nixosSystem = nixpkgs.lib.makeOverridable nixpkgs.lib.nixosSystem;
|
||||
nixosSystemUnstable = nixpkgs-unstable.lib.makeOverridable nixpkgs-unstable.lib.nixosSystem;
|
||||
|
||||
baseModules = [
|
||||
# make flake inputs accessiable in NixOS
|
||||
{ _module.args.inputs = inputs; }
|
||||
{
|
||||
imports = [
|
||||
({ pkgs, ... }: {
|
||||
nix = {
|
||||
extraOptions = ''
|
||||
experimental-features = nix-command flakes
|
||||
'';
|
||||
|
||||
settings = {
|
||||
substituters = [
|
||||
"https://cache.dynamicdiscord.de"
|
||||
"https://cache.nixos.org/"
|
||||
];
|
||||
trusted-public-keys = [
|
||||
"cache.dynamicdiscord.de:DKueZicqi2NhJJXz9MYgUbiyobMs10fTyHCgAUibRP4="
|
||||
];
|
||||
trusted-users = [ "root" "@wheel" ];
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
sops-nix.nixosModules.sops
|
||||
];
|
||||
}
|
||||
];
|
||||
defaultModules = baseModules;
|
||||
|
||||
makeMicroVM = hostName: ipv4Addr: macAddr: modules: [
|
||||
{
|
||||
microvm = {
|
||||
hypervisor = "cloud-hypervisor";
|
||||
mem = 2560;
|
||||
shares = [
|
||||
{
|
||||
source = "/nix/store";
|
||||
mountPoint = "/nix/.ro-store";
|
||||
tag = "store";
|
||||
proto = "virtiofs";
|
||||
socket = "store.socket";
|
||||
}
|
||||
{
|
||||
source = "/var/lib/microvms/${hostName}/etc";
|
||||
mountPoint = "/etc";
|
||||
tag = "etc";
|
||||
proto = "virtiofs";
|
||||
socket = "etc.socket";
|
||||
}
|
||||
{
|
||||
source = "/var/lib/microvms/${hostName}/var";
|
||||
mountPoint = "/var";
|
||||
tag = "var";
|
||||
proto = "virtiofs";
|
||||
socket = "var.socket";
|
||||
}
|
||||
];
|
||||
|
||||
interfaces = [
|
||||
{
|
||||
type = "tap";
|
||||
id = "vm-${hostName}";
|
||||
mac = "${macAddr}";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
systemd.network.enable = true;
|
||||
|
||||
systemd.network.networks."20-lan" = {
|
||||
matchConfig.Type = "ether";
|
||||
networkConfig = {
|
||||
Address = [ "${ipv4Addr}/24" ];
|
||||
Gateway = "10.0.0.1";
|
||||
DNS = ["1.1.1.1"];
|
||||
DHCP = "no";
|
||||
};
|
||||
};
|
||||
}
|
||||
] ++ defaultModules ++ modules;
|
||||
|
||||
inputsMod = inputs // { malobeo = self; };
|
||||
|
||||
|
||||
vmMicroVMOverwrites = hostname: options: {
|
||||
microvm = rec {
|
||||
mem = pkgs.lib.mkForce 4096;
|
||||
hypervisor = pkgs.lib.mkForce "qemu";
|
||||
socket = pkgs.lib.mkForce null;
|
||||
|
||||
|
||||
#needed for hosts that deploy imperative microvms (for example fanny)
|
||||
writableStoreOverlay = pkgs.lib.mkIf options.writableStore "/nix/.rw-store";
|
||||
volumes = pkgs.lib.mkIf options.writableStore [ {
|
||||
image = "nix-store-overlay.img";
|
||||
mountPoint = writableStoreOverlay;
|
||||
size = 2048;
|
||||
} ];
|
||||
|
||||
shares = pkgs.lib.mkForce (pkgs.lib.optionals (!options.writableStore) [
|
||||
{
|
||||
tag = "ro-store";
|
||||
source = "/nix/store";
|
||||
mountPoint = "/nix/.ro-store";
|
||||
}
|
||||
] ++ pkgs.lib.optionals (options.varPath != "") [
|
||||
{
|
||||
source = "${options.varPath}";
|
||||
securityModel = "mapped";
|
||||
mountPoint = "/var";
|
||||
tag = "var";
|
||||
}
|
||||
]);
|
||||
|
||||
interfaces = pkgs.lib.mkIf (!options.withNetworking) (pkgs.lib.mkForce [{
|
||||
type = "user";
|
||||
id = "eth0";
|
||||
mac = "02:23:de:ad:be:ef";
|
||||
}]);
|
||||
|
||||
#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 [
|
||||
{ from = "host"; host.port = options.fwdPort; guest.port = 80; }
|
||||
]);
|
||||
|
||||
};
|
||||
|
||||
fileSystems = {
|
||||
"/".fsType = pkgs.lib.mkForce "tmpfs";
|
||||
|
||||
# prometheus uses a memory mapped file which doesnt seem supported by 9p shares
|
||||
# therefore we mount a tmpfs inside the datadir
|
||||
"/var/lib/prometheus2/data" = pkgs.lib.mkIf (hostname == "overwatch" && options.varPath != "") (pkgs.lib.mkForce {
|
||||
fsType = pkgs.lib.mkForce "tmpfs";
|
||||
});
|
||||
};
|
||||
|
||||
boot.isContainer = pkgs.lib.mkForce false;
|
||||
services.timesyncd.enable = false;
|
||||
users.users.root.password = "";
|
||||
services.getty.helpLine = ''
|
||||
Log in as "root" with an empty password.
|
||||
Use "reboot" to shut qemu down.
|
||||
'';
|
||||
};
|
||||
|
||||
vmDiskoOverwrites = {
|
||||
boot.initrd = {
|
||||
secrets = pkgs.lib.mkForce {};
|
||||
network.ssh.enable = pkgs.lib.mkForce false;
|
||||
};
|
||||
|
||||
malobeo.disks.enable = pkgs.lib.mkForce false;
|
||||
networking.hostId = "a3c3101f";
|
||||
};
|
||||
|
||||
vmSopsOverwrites = host: {
|
||||
sops.defaultSopsFile = pkgs.lib.mkForce ../${host}/dummy.yaml;
|
||||
|
||||
environment.etc = {
|
||||
devHostKey = {
|
||||
source = ../secrets/devkey_ed25519;
|
||||
mode = "0600";
|
||||
};
|
||||
};
|
||||
|
||||
services.openssh.hostKeys = [{
|
||||
path = "/etc/devHostKey";
|
||||
type = "ed25519";
|
||||
}];
|
||||
};
|
||||
|
||||
vmNestedMicroVMOverwrites = host: sopsDummy: {
|
||||
|
||||
services.malobeo.microvm.deployHosts = pkgs.lib.mkForce [];
|
||||
microvm.vms =
|
||||
let
|
||||
# Map the values to each hostname to then generate an Attrset using listToAttrs
|
||||
mapperFunc = name: { inherit name; value = {
|
||||
specialArgs.inputs = inputsMod;
|
||||
specialArgs.self = self;
|
||||
config = {
|
||||
imports = (makeMicroVM "${name}"
|
||||
"${hosts.malobeo.hosts.${name}.network.address}"
|
||||
"${hosts.malobeo.hosts.${name}.network.mac}" [
|
||||
../${name}/configuration.nix
|
||||
(vmMicroVMOverwrites name {
|
||||
withNetworking = true;
|
||||
varPath = "";
|
||||
writableStore = false; })
|
||||
(if sopsDummy then (vmSopsOverwrites name) else {})
|
||||
]);
|
||||
};
|
||||
}; };
|
||||
in
|
||||
builtins.listToAttrs (map mapperFunc self.nixosConfigurations.${host}.config.services.malobeo.microvm.deployHosts);
|
||||
};
|
||||
|
||||
buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: fwdPort: (self.nixosConfigurations.${host}.extendModules {
|
||||
modules = [
|
||||
(vmMicroVMOverwrites host {
|
||||
withNetworking = networking;
|
||||
varPath = "${varPath}";
|
||||
writableStore = writableStore;
|
||||
fwdPort = fwdPort; })
|
||||
(if sopsDummy then (vmSopsOverwrites host) else {})
|
||||
(if disableDisko then vmDiskoOverwrites else {})
|
||||
] ++ pkgs.lib.optionals (hosts.malobeo.hosts.${host}.type != "microvm") [
|
||||
inputs.microvm.nixosModules.microvm
|
||||
] ++ pkgs.lib.optionals (self.nixosConfigurations.${host}.config ? services.malobeo.microvm.deployHosts) [
|
||||
(vmNestedMicroVMOverwrites host sopsDummy)
|
||||
];
|
||||
});
|
||||
|
||||
buildHost = hosts: (builtins.mapAttrs (host: settings: nixosSystem {
|
||||
system = if (settings.type == "rpi") then "aarch64-linux" else "x86_64-linux";
|
||||
specialArgs.inputs = inputsMod;
|
||||
specialArgs.self = self;
|
||||
modules = (if (settings.type != "microvm") then
|
||||
defaultModules ++ [ ../${host}/configuration.nix ]
|
||||
else
|
||||
makeMicroVM "${host}" "${settings.network.address}" "${settings.network.mac}" [
|
||||
inputs.microvm.nixosModules.microvm
|
||||
../${host}/configuration.nix
|
||||
]);
|
||||
}) hosts);
|
||||
}
|
||||
@@ -26,13 +26,8 @@ in
|
||||
|
||||
config = lib.mkIf (cfg.enable && config.malobeo.disks.encryption) {
|
||||
boot = {
|
||||
loader.systemd-boot.enable = true;
|
||||
loader.efi.canTouchEfiVariables = true;
|
||||
supportedFilesystems = [ "vfat" "zfs" ];
|
||||
zfs = {
|
||||
forceImportAll = true;
|
||||
requestEncryptionCredentials = true;
|
||||
|
||||
};
|
||||
initrd = {
|
||||
availableKernelModules = cfg.ethernetDrivers;
|
||||
|
||||
@@ -30,6 +30,13 @@
|
||||
publicKey = "TrJ4UAF//zXdaLwZudI78L+rTC36zEDodTDOWNS4Y1Y=";
|
||||
};
|
||||
|
||||
"hetzner" = {
|
||||
role = "client";
|
||||
address = [ "10.100.0.6/24" ];
|
||||
allowedIPs = [ "10.100.0.6/32" ];
|
||||
publicKey = "csRzgwtnzmSLeLkSwTwEOrdKq55UOxZacR5D3GopCTQ=";
|
||||
};
|
||||
|
||||
"fanny" = {
|
||||
role = "client";
|
||||
address = [ "10.100.0.101/24" ];
|
||||
|
||||
@@ -46,7 +46,7 @@ with lib;
|
||||
};
|
||||
extraAppsEnable = true;
|
||||
extraApps = {
|
||||
inherit (config.services.nextcloud.package.packages.apps) contacts calendar;
|
||||
inherit (config.services.nextcloud.package.packages.apps) contacts calendar deck polls;
|
||||
collectives = pkgs.fetchNextcloudApp {
|
||||
sha256 = "sha256-cj/8FhzxOACJaUEu0eG9r7iAQmnOG62yFHeyUICalFY=";
|
||||
url = "https://github.com/nextcloud/collectives/releases/download/v2.15.2/collectives-2.15.2.tar.gz";
|
||||
|
||||
@@ -24,7 +24,7 @@ in
|
||||
|
||||
malobeo.disks = {
|
||||
enable = true;
|
||||
encryption = false;
|
||||
encryption = true;
|
||||
hostId = "83abc8cb";
|
||||
devNodes = "/dev/disk/by-path/";
|
||||
root = {
|
||||
@@ -17,6 +17,7 @@ with lib;
|
||||
};
|
||||
|
||||
imports = [
|
||||
inputs.self.nixosModules.malobeo.vpn
|
||||
../modules/malobeo_user.nix
|
||||
../modules/sshd.nix
|
||||
../modules/minimal_tools.nix
|
||||
|
||||
153
outputs.nix
153
outputs.nix
@@ -15,86 +15,8 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
pkgs-unstable = nixpkgs-unstable.legacyPackages."${system}";
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
|
||||
vmMicroVMOverwrites = hostname: options: {
|
||||
microvm = {
|
||||
mem = pkgs.lib.mkForce 4096;
|
||||
hypervisor = pkgs.lib.mkForce "qemu";
|
||||
socket = pkgs.lib.mkForce null;
|
||||
shares = pkgs.lib.mkForce ([
|
||||
{
|
||||
tag = "ro-store";
|
||||
source = "/nix/store";
|
||||
mountPoint = "/nix/.ro-store";
|
||||
}
|
||||
] ++ pkgs.lib.optionals (options.varPath != "") [
|
||||
{
|
||||
source = "${options.varPath}";
|
||||
securityModel = "mapped";
|
||||
mountPoint = "/var";
|
||||
tag = "var";
|
||||
}
|
||||
]);
|
||||
interfaces = pkgs.lib.mkIf (!options.withNetworking) (pkgs.lib.mkForce [{
|
||||
type = "user";
|
||||
id = "eth0";
|
||||
mac = "02:23:de:ad:be:ef";
|
||||
}]);
|
||||
};
|
||||
|
||||
fileSystems = {
|
||||
"/".fsType = pkgs.lib.mkForce "tmpfs";
|
||||
|
||||
# prometheus uses a memory mapped file which doesnt seem supported by 9p shares
|
||||
# therefore we mount a tmpfs inside the datadir
|
||||
"/var/lib/prometheus2/data" = pkgs.lib.mkIf (hostname == "overwatch" && options.varPath != "") (pkgs.lib.mkForce {
|
||||
fsType = pkgs.lib.mkForce "tmpfs";
|
||||
});
|
||||
};
|
||||
|
||||
boot.isContainer = pkgs.lib.mkForce false;
|
||||
services.timesyncd.enable = false;
|
||||
users.users.root.password = "";
|
||||
services.getty.helpLine = ''
|
||||
Log in as "root" with an empty password.
|
||||
Use "reboot" to shut qemu down.
|
||||
'';
|
||||
};
|
||||
|
||||
vmDiskoOverwrites = {
|
||||
boot.initrd = {
|
||||
secrets = pkgs.lib.mkForce {};
|
||||
network.ssh.enable = pkgs.lib.mkForce false;
|
||||
};
|
||||
|
||||
malobeo.disks.enable = pkgs.lib.mkForce false;
|
||||
networking.hostId = "a3c3101f";
|
||||
};
|
||||
|
||||
vmSopsOverwrites = host: {
|
||||
sops.defaultSopsFile = pkgs.lib.mkForce ./machines/${host}/dummy.yaml;
|
||||
|
||||
environment.etc = {
|
||||
devHostKey = {
|
||||
source = ./machines/secrets/devkey_ed25519;
|
||||
mode = "0600";
|
||||
};
|
||||
};
|
||||
|
||||
services.openssh.hostKeys = [{
|
||||
path = "/etc/devHostKey";
|
||||
type = "ed25519";
|
||||
}];
|
||||
};
|
||||
|
||||
buildVM = host: networking: sopsDummy: disableDisko: varPath: (self.nixosConfigurations.${host}.extendModules {
|
||||
modules = [
|
||||
(vmMicroVMOverwrites host { withNetworking = networking; varPath = "${varPath}"; })
|
||||
(if sopsDummy then (vmSopsOverwrites host) else {})
|
||||
(if disableDisko then vmDiskoOverwrites else {})
|
||||
] ++ pkgs.lib.optionals (! self.nixosConfigurations.${host}.config ? microvm) [
|
||||
microvm.nixosModules.microvm
|
||||
];
|
||||
}).config.microvm.declaredRunner;
|
||||
hosts = import ./machines/hosts.nix ( inputs // { inherit inputs; self = self; });
|
||||
utils = import ./machines/modules/host_builder.nix ( inputs // { inherit inputs; self = self; hosts = hosts; });
|
||||
in
|
||||
{
|
||||
devShells.default =
|
||||
@@ -130,7 +52,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
scripts.run-vm = self.packages.${system}.run-vm;
|
||||
};
|
||||
|
||||
vmBuilder = buildVM;
|
||||
vmBuilder = utils.buildVM;
|
||||
|
||||
packages = {
|
||||
docs = pkgs.stdenv.mkDerivation {
|
||||
@@ -150,60 +72,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
'';
|
||||
};
|
||||
|
||||
run-vm = pkgs.writeShellScriptBin "run-vm" ''
|
||||
usage() {
|
||||
echo "Usage: run-vm <hostname> [--networking] [--dummy-secrets] [--no-disko]"
|
||||
echo "ATTENTION: This script must be run from the flakes root directory"
|
||||
echo "--networking setup interfaces. requires root and hostbridge enabled on the host"
|
||||
echo "--dummy-secrets run vm with dummy sops secrets"
|
||||
echo "--no-disko disable disko and initrd secrets. needed for real hosts 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"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# check at least one arg was given
|
||||
if [ "$#" -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
HOSTNAME=$1
|
||||
|
||||
# Optionale Argumente
|
||||
NETWORK=false
|
||||
DUMMY_SECRETS=false
|
||||
NO_DISKO=false
|
||||
VAR_PATH=""
|
||||
|
||||
# check argws
|
||||
shift
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--networking) NETWORK=true ;;
|
||||
--dummy-secrets) DUMMY_SECRETS=true ;;
|
||||
--no-disko) NO_DISKO=true ;;
|
||||
--var)
|
||||
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
||||
VAR_PATH="$2"
|
||||
shift
|
||||
else
|
||||
echo "Error: --var requires a non-empty string argument."
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
*) echo "Unknown argument: $1"; usage ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
echo "starting host $HOSTNAME"
|
||||
echo "enable networking: $NETWORK"
|
||||
echo "deploy dummy secrets: $DUMMY_SECRETS"
|
||||
echo "disable disko and initrd secrets: $NO_DISKO"
|
||||
if [ -n "$VAR_PATH" ]; then
|
||||
echo "sharing var directory: $VAR_PATH"
|
||||
fi
|
||||
|
||||
${pkgs.nix}/bin/nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\")"
|
||||
'';
|
||||
run-vm = pkgs.writeShellScriptBin "run-vm" (builtins.readFile ./scripts/run-vm.sh);
|
||||
};
|
||||
|
||||
apps = {
|
||||
@@ -229,11 +98,13 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
};
|
||||
};
|
||||
|
||||
})) // {
|
||||
nixosConfigurations = import ./machines/configuration.nix (inputs // {
|
||||
inherit inputs;
|
||||
self = self;
|
||||
});
|
||||
})) // (
|
||||
let
|
||||
hosts = import ./machines/hosts.nix ( inputs // { inherit inputs; self = self; });
|
||||
utils = import ./machines/modules/host_builder.nix ( inputs // { inherit inputs; self = self; hosts = hosts; });
|
||||
in
|
||||
{
|
||||
nixosConfigurations = utils.buildHost hosts.malobeo.hosts;
|
||||
|
||||
nixosModules.malobeo = {
|
||||
host.imports = [ ./machines/durruti/host_config.nix ];
|
||||
@@ -255,4 +126,4 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
nixpkgs.lib.mapAttrs getBuildEntry self.nixosConfigurations
|
||||
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -37,9 +37,11 @@ trap cleanup EXIT
|
||||
|
||||
# Create the directory where sshd expects to find the host keys
|
||||
install -d -m755 "$temp/etc/ssh/"
|
||||
install -d -m755 "$temp/root/"
|
||||
|
||||
diskKey=$(sops -d machines/$hostname/disk.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/initrd -t ed25519 -N ""
|
||||
|
||||
67
scripts/run-vm.sh
Normal file
67
scripts/run-vm.sh
Normal file
@@ -0,0 +1,67 @@
|
||||
usage() {
|
||||
echo "Usage: run-vm <hostname> [--networking] [--dummy-secrets] [--no-disko]"
|
||||
echo "ATTENTION: This script must be run from the flakes root directory"
|
||||
echo "--networking setup interfaces. requires root and hostbridge enabled on the host"
|
||||
echo "--dummy-secrets run vm with dummy sops secrets"
|
||||
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 "--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
|
||||
}
|
||||
|
||||
# check at least one arg was given
|
||||
if [ "$#" -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
HOSTNAME=$1
|
||||
|
||||
# Optionale Argumente
|
||||
NETWORK=false
|
||||
DUMMY_SECRETS=false
|
||||
NO_DISKO=false
|
||||
RW_STORE=false
|
||||
VAR_PATH=""
|
||||
FWD_PORT=0
|
||||
|
||||
# check argws
|
||||
shift
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--networking) NETWORK=true ;;
|
||||
--dummy-secrets) DUMMY_SECRETS=true ;;
|
||||
--no-disko) NO_DISKO=true ;;
|
||||
--writable-store) RW_STORE=true ;;
|
||||
--var)
|
||||
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
||||
VAR_PATH="$2"
|
||||
shift
|
||||
else
|
||||
echo "Error: --var requires a non-empty string argument."
|
||||
usage
|
||||
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 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
echo "starting host $HOSTNAME"
|
||||
echo "enable networking: $NETWORK"
|
||||
echo "deploy dummy secrets: $DUMMY_SECRETS"
|
||||
echo "disable disko and initrd secrets: $NO_DISKO"
|
||||
echo "use writable store: $RW_STORE"
|
||||
if [ -n "$VAR_PATH" ]; then
|
||||
echo "sharing var directory: $VAR_PATH"
|
||||
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"
|
||||
@@ -23,18 +23,14 @@ echo
|
||||
if [ $# = 1 ]
|
||||
then
|
||||
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
|
||||
|
||||
elif [ $# = 2 ]
|
||||
then
|
||||
diskkey=$(sops -d machines/$HOSTNAME/disk.key)
|
||||
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
|
||||
|
||||
|
||||
else
|
||||
echo
|
||||
echo "Unlock the root disk on a remote host."
|
||||
|
||||
Reference in New Issue
Block a user