First useful solution

This commit is contained in:
Mikhail Klementev 2018-06-30 19:42:31 +00:00
parent 4cd7319752
commit 2fef367e45
6 changed files with 21 additions and 4 deletions

5
.gitignore vendored
View File

@ -1 +1,4 @@
bin bin/*
!bin/.keep
qemu/qcow2/*
!qemu/qcow2/.keep

12
appvm.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
if [[ "$1" == "build" && "$2" != "" ]]; then
NIX_PATH=$NIX_PATH:. nix-build '<nixpkgs/nixos>' -A config.system.build.vm -I nixos-config=nix/${2}.nix || exit 1
NIX_SYSTEM=$(realpath result/system)
mkdir -p bin
sed "s;NIX_SYSTEM_PLACEHOLDER;${NIX_SYSTEM};" qemu/qemu.template > bin/appvm.${2}
sed -i "s;NAME_PLACEHOLDER;${2};" bin/appvm.${2}
chmod +x bin/appvm.${2}
unlink result
else
echo "Usage: $0 build APPLICATION"
fi

View File

@ -2,7 +2,7 @@
{ {
imports = [ imports = [
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
<base.nix> <nix/base.nix>
]; ];
environment.systemPackages = [ pkgs.tdesktop ]; environment.systemPackages = [ pkgs.tdesktop ];

0
qemu/qcow2/.keep Normal file
View File

View File

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
NIX_DISK_IMAGE=$(readlink -f ${NIX_DISK_IMAGE:-./tdesktop.qcow2}) NAME=NAME_PLACEHOLDER
NIX_DISK_IMAGE=$(readlink -f ${NIX_DISK_IMAGE:-./${NAME}.qcow2})
if ! test -e "$NIX_DISK_IMAGE"; then if ! test -e "$NIX_DISK_IMAGE"; then
qemu-img create -f qcow2 "$NIX_DISK_IMAGE" 512M || exit 1 qemu-img create -f qcow2 "$NIX_DISK_IMAGE" 512M || exit 1
@ -19,7 +21,7 @@ NIX_SYSTEM="NIX_SYSTEM_PLACEHOLDER"
# Start QEMU. # Start QEMU.
qemu-system-x86_64 -enable-kvm \ qemu-system-x86_64 -enable-kvm \
-name tdesktop \ -name NAME_PLACEHOLDER \
-m 1024 \ -m 1024 \
-smp 1 \ -smp 1 \
-device virtio-rng-pci \ -device virtio-rng-pci \