forked from prisma/prisma-engines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-vm.nix
98 lines (91 loc) · 2.59 KB
/
dev-vm.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{ pkgs, flakeInputs, system, self', ... }:
# Run qemu with a disk image containing prisma-engines repo, docker and all the
# packages to build and test engines.
#
# This is useful for testing engines with e.g. artificial memory or cpu limits.
#
# You can run it using:
#
# ```
# $ nix run .#dev-vm
# ```
#
# This will boot the VM and create a nixos.qcow2 VM image file, or reuse it if
# it is already there.
#
# You can pass extra arguments to the qemu command line, they will be forwarded
# (see --help for example). That lets you easily constrain the VM's resources
# (CPU, RAM, network, disk IO), among other things.
#
# The recommended way to interact with the vm is through SSH. It listens on
# 2222 on the host's localhost:
#
# ```
# $ ssh prisma@localhost -p 2222
# ```
#
# Both the username and password are "prisma".
#
# Links:
# - https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/qemu-vm.nix
let
evalConfig = import "${flakeInputs.nixpkgs}/nixos/lib/eval-config.nix";
prisma-engines = self'.packages.prisma-engines;
prisma-engines-inputs = prisma-engines.buildInputs ++ prisma-engines.nativeBuildInputs;
vmConfig = (evalConfig {
modules = [
{
system.stateVersion = "23.05";
virtualisation.docker.enable = true;
virtualisation.vmVariant.virtualisation = {
diskSize = 1024 * 8; # 8GB
forwardPorts = [
{
from = "host";
host.port = 2222;
guest.port = 22;
}
];
writableStore = true;
writableStoreUseTmpfs = false;
sharedDirectories.prisma-engines = {
source = "${prisma-engines.src}";
target = "/home/prisma/prisma-engines";
};
};
# Enable flakes in the host vm
nix = {
# package = pkgs.nixUnstable;
extraOptions = "experimental-features = nix-command flakes";
};
environment.systemPackages = with pkgs; [
tmux
git
coreutils
gnumake
] ++ prisma-engines-inputs;
services.openssh = {
listenAddresses = [{
addr = "0.0.0.0";
port = 22;
}];
enable = true;
settings.PasswordAuthentication = true;
};
users.users.prisma = {
isNormalUser = true;
extraGroups = [
"docker"
"wheel" # Enable ‘sudo’ for the user.
];
password = "prisma";
};
}
];
system = "x86_64-linux";
}
).config;
in
{
packages.dev-vm = vmConfig.system.build.vm;
}