wip
This commit is contained in:
14
modules/nixos/aarch64-vm.nix
Normal file
14
modules/nixos/aarch64-vm.nix
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
aarch64-vm.enable = lib.mkEnableOption "aarch64 virtualisation support";
|
||||
};
|
||||
|
||||
config = lib.mkIf config.aarch64-vm.enable {
|
||||
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
|
||||
};
|
||||
}
|
||||
61
modules/nixos/seed-ssh.nix
Normal file
61
modules/nixos/seed-ssh.nix
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
seed-ssh = {
|
||||
enable = lib.mkEnableOption "SSH key injection from seed ISO";
|
||||
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "user to install authorized_keys for";
|
||||
};
|
||||
|
||||
label = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "SEEDCONFIG";
|
||||
description = "volume label of the seed ISO";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.seed-ssh.enable {
|
||||
systemd.services.seed-ssh = {
|
||||
description = "Install SSH authorized_keys from seed ISO";
|
||||
after = [ "local-fs.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart =
|
||||
let
|
||||
cfg = config.seed-ssh;
|
||||
inherit (cfg) user;
|
||||
inherit (config.users.users.${user}) home;
|
||||
in
|
||||
pkgs.writeShellScript "seed-ssh" ''
|
||||
DEVICE="/dev/disk/by-label/${cfg.label}"
|
||||
if [ ! -e "$DEVICE" ]; then
|
||||
echo "seed ISO not found, skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
MOUNT=$(mktemp -d)
|
||||
mount -o ro "$DEVICE" "$MOUNT"
|
||||
|
||||
mkdir -p "${home}/.ssh"
|
||||
cp "$MOUNT/authorized_keys" "${home}/.ssh/authorized_keys"
|
||||
chmod 700 "${home}/.ssh"
|
||||
chmod 600 "${home}/.ssh/authorized_keys"
|
||||
chown -R ${user}:${user} "${home}/.ssh"
|
||||
|
||||
umount "$MOUNT"
|
||||
rmdir "$MOUNT"
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
62
modules/nixos/vm-guest.nix
Normal file
62
modules/nixos/vm-guest.nix
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
||||
options = {
|
||||
vm-guest = {
|
||||
enable = lib.mkEnableOption "VM guest configuration";
|
||||
headless = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "run without display, serial console only";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.vm-guest.enable {
|
||||
services.qemuGuest.enable = true;
|
||||
services.spice-vdagentd.enable = lib.mkIf (!config.vm-guest.headless) true;
|
||||
|
||||
boot.kernelParams = lib.mkIf config.vm-guest.headless [ "console=ttyS0,115200" ];
|
||||
|
||||
# 9p for host file mounting
|
||||
boot.initrd.availableKernelModules = [
|
||||
"9p"
|
||||
"9pnet_virtio"
|
||||
];
|
||||
boot.kernelModules = [
|
||||
"9p"
|
||||
"9pnet_virtio"
|
||||
];
|
||||
|
||||
# ssh with agent forwarding for git and hot-mount
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
ports = [ 22 ];
|
||||
settings = {
|
||||
PasswordAuthentication = false;
|
||||
PermitRootLogin = "no";
|
||||
AllowAgentForwarding = true;
|
||||
StreamLocalBindUnlink = "yes";
|
||||
};
|
||||
};
|
||||
|
||||
networking = {
|
||||
useDHCP = true;
|
||||
firewall.allowedTCPPorts = [ 22 ];
|
||||
};
|
||||
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
curl
|
||||
wget
|
||||
htop
|
||||
sshfs
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user