Nixos-shell: Difference between revisions
mNo edit summary |
m →Graphical session: replace nameless {{file}} template with <syntaxhighlight lang=nix> |
||
| (10 intermediate revisions by 3 users not shown) | |||
| Line 21: | Line 21: | ||
settings.title = "My Wiki"; | settings.title = "My Wiki"; | ||
}; | }; | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
| Line 31: | Line 31: | ||
After the VM is successfully booted, DokuWiki will be available on http://localhost:8080 | After the VM is successfully booted, DokuWiki will be available on http://localhost:8080 | ||
=== Reference local nixpkgs folder === | |||
Using the <code>-I nixpkgs</code> parameter, you could choose to use a local ''nixpkgs'' repository, for example to test unfinished packages or modules:<syntaxhighlight lang="console"> | |||
$ nixos-shell -I nixpkgs=/home/myuser/projects/nixpkgs myvm.nix | |||
</syntaxhighlight> | |||
=== Graphical session === | |||
Following snippet will spawn a QEMU session with a graphical screen running GNOME, configured to auto login the user <code>nixos</code>: | |||
<syntaxhighlight lang=nix> | |||
{ ... }: { | |||
virtualisation.memorySize = 8096; | |||
virtualisation.cores = 8; | |||
virtualisation.graphics = true; | |||
services.displayManager.gdm.enable = true; | |||
services.desktopManager.gnome.enable = true; | |||
services.displayManager.autoLogin = { | |||
enable = true; | |||
user = "nixos"; | |||
}; | |||
users.users.nixos = { | |||
isNormalUser = true; | |||
initialPassword = "nixos"; | |||
}; | |||
}; | |||
</syntaxhighlight> | |||
If you want auto screen resize support and clipboard-sharing between host and guest to work, append the following lines to your guest config: | |||
<syntaxhighlight lang=nix> | |||
{ ... }: { | |||
[...] | |||
nixpkgs.overlays = [ | |||
(final: prev: { | |||
qemu = prev.qemu.overrideAttrs (old: { | |||
configureFlags = old.configureFlags ++ ["--enable-gtk-clipboard"]; | |||
}); | |||
qemu_kvm = prev.qemu_kvm.overrideAttrs (old: { | |||
configureFlags = old.configureFlags ++ ["--enable-gtk-clipboard"]; | |||
}); | |||
}) | |||
]; | |||
virtualisation.qemu.options = [ | |||
"-device virtio-vga-gl" | |||
"-display gtk,gl=on" | |||
"-chardev qemu-vdagent,id=vdagent,name=vdagent,clipboard=on" | |||
"-device virtio-serial" | |||
"-device virtserialport,chardev=vdagent,name=com.redhat.spice.0" | |||
]; | |||
services.spice-vdagentd.enable = true; | |||
systemd.user.services.spice-vdagent = { | |||
description = "spice-vdagent user daemon"; | |||
after = [ "spice-vdagentd.service" "graphical-session.target" ]; | |||
requires = [ "graphical-session.target" ]; | |||
wantedBy = [ "graphical-session.target" ]; | |||
serviceConfig = { | |||
ExecStart = "${pkgs.spice-vdagent}/bin/spice-vdagent -x"; | |||
}; | |||
unitConfig = { | |||
ConditionPathExists = "/run/spice-vdagentd/spice-vdagent-sock"; | |||
}; | |||
}; | |||
}; | |||
</syntaxhighlight> | |||
=== Mounting host directories === | === Mounting host directories === | ||
| Line 37: | Line 107: | ||
{{file|myvm.nix|nix|<nowiki> | {{file|myvm.nix|nix|<nowiki> | ||
{ | { ... }: { | ||
nixos-shell.mounts.extraMounts = { | nixos-shell.mounts.extraMounts = { | ||
"/var/lib/nextcloud/store-apps/calendar" = { | "/var/lib/nextcloud/store-apps/calendar" = { | ||
| Line 88: | Line 158: | ||
The configuration of the virtual machine is inside the file <code>myvm.nix</code> in the same directory. The virtual machine will use the nixpkgs source defined in the flake inputs. | The configuration of the virtual machine is inside the file <code>myvm.nix</code> in the same directory. The virtual machine will use the nixpkgs source defined in the flake inputs. | ||
[[Category:Container]] | |||