Allow mapping the current user's keys into the VM

This commit is contained in:
Manuel Thalmann 2024-05-11 01:26:54 +02:00
parent 3b27b8669f
commit 06efd25d98
2 changed files with 22 additions and 1 deletions

View file

@ -16,6 +16,7 @@
vmConfig = {
virtualisation = {
sharedHostKeys = true;
sharedUserKeys = true;
usb-redirect = true;
virt-viewer = true;
cores = 4;

View file

@ -36,6 +36,12 @@ in {
default = false;
};
sharedUserKeys = lib.mkOption {
type = lib.types.bool;
description = lib.mdDoc "Whether to load the current user's keys into every user's homer on the VM.";
default = false;
};
usb-redirect = lib.mkOption {
type = lib.types.bool;
description = lib.mdDoc "Whether to enable USB redirection to the VM.";
@ -137,7 +143,21 @@ in {
source = path;
target = path;
};
} // (lib.optionalAttrs vmVariant.virtualisation.sharedUserKeys (
lib.attrsets.concatMapAttrs (
name: user:
let
prefix = if vmVariant.virtualisation.runAsRoot
then "sudo -u#$SUDO_UID "
else "";
homeDir = "$(${prefix}bash -c 'echo $HOME')";
in {
"userKeys-${name}" = {
source = "${homeDir}/.ssh";
target = "/home/${name}/.ssh";
};
})
config.users.myUsers));
};
};