-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm-interactive.nix
65 lines (59 loc) · 1.71 KB
/
vm-interactive.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ config, lib, pkgs, ... }:
{
imports = [
./vm-base.nix
./module
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
];
assertions = [ {
assertion = config.virtualisation.diskImage != null;
message = "must use disk image";
} ];
# enable all options
services.styx.enable = true;
# let styx handle everything
nix.settings.styx-ondemand = [ ".*" ];
# use shared nixpkgs
nix.nixPath = [ "nixpkgs=/tmp/nixpkgs" ];
# just console
virtualisation.graphics = false;
# provide nixpkgs and this dir for convenience
virtualisation.sharedDirectories = {
nixpkgs = { source = toString <nixpkgs>; target = "/tmp/nixpkgs"; };
styxsrc = { source = toString ./.; target = "/tmp/styxsrc"; };
};
# set fstype of root fs
virtualisation.fileSystems."/".fsType = lib.mkForce (builtins.getEnv "VMFSTYPE");
# ensure btrfs enabled
system.requiredKernelConfig = with config.lib.kernelConfig; [ (isEnabled "BTRFS_FS") ];
# more convenience
environment.shellAliases = {
l = "less";
ll = "ls -l";
g = "grep";
};
environment.variables = {
TMPDIR = "/tmp"; # tmpfs is too small to build stuff
};
environment.systemPackages = with pkgs; [
file
jq
psmisc
vim
];
# hack to transfer console size
systemd.services."serial-getty@".serviceConfig.ExecStartPost =
let fixconsole = pkgs.writeShellScript "fixconsole" ''
#!${pkgs.runtimeShell}
tty=/dev/$1
for o in $(</proc/cmdline); do
case $o in
styx.consolesize=*)
set -- $(IFS=:=; echo $o)
${pkgs.coreutils}/bin/stty -F $tty rows $2 cols $3
echo -ne '\e[?7h' > $tty
;;
esac
done
''; in "-${fixconsole} %i";
}