Skip to content

Commit f9c547a

Browse files
committed
very temp
1 parent 3603c71 commit f9c547a

File tree

9 files changed

+189
-16
lines changed

9 files changed

+189
-16
lines changed

flake.lock

+10-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
impermanence.url = "github:nix-community/impermanence";
5757
microvm = {
5858
inputs.nixpkgs.follows = "nixpkgs";
59-
url = "path:/home/flafy/repos/astro/microvm.nix";
59+
url = "github:FlafyDev/microvm.nix/flafy-main";
6060
};
6161
mobile-nixos = {
6262
flake = false;

hosts/ope/modules/test.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
import io
3+
import select
4+
from subprocess import Popen, PIPE
5+
from sys import argv
6+
7+
8+
def kill_when_found(process, needle, size=io.DEFAULT_BUFFER_SIZE):
9+
if isinstance(needle, str):
10+
needle = needle.encode()
11+
assert isinstance(needle, bytes)
12+
13+
streams = [process.stdout, process.stderr]
14+
poll = select.poll()
15+
for stream in streams:
16+
if stream:
17+
poll.register(stream, select.POLLIN)
18+
19+
output_buffers = {stream: b"" for stream in streams if stream}
20+
21+
while process.poll() is None:
22+
events = poll.poll(100)
23+
if not events:
24+
continue
25+
26+
for fd, _ in events:
27+
for stream in streams:
28+
if stream and stream.fileno() == fd:
29+
output = stream.read1(size)
30+
sys.stdout.buffer.write(output)
31+
sys.stdout.buffer.flush()
32+
output_buffers[stream] += output
33+
34+
if needle in output_buffers[stream]:
35+
process.kill()
36+
return process.poll()
37+
38+
if len(output_buffers[stream]) >= len(needle):
39+
output_buffers[stream] = output_buffers[stream][
40+
-len(needle):
41+
]
42+
43+
return process.poll()
44+
45+
46+
if __name__ == "__main__":
47+
if len(argv) <= 3:
48+
print(
49+
"""
50+
Usage: Pass in at least 2 arguments. The first argument is the search string;
51+
the remaining arguments form the command to be executed (and watched over).
52+
"""
53+
)
54+
sys.exit(0)
55+
else:
56+
process = Popen(argv[2:], stdout=PIPE, stderr=PIPE)
57+
retcode = kill_when_found(process, argv[1])
58+
sys.exit(retcode)

hosts/ope/modules/vm0.nix

+108-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
{utils, ...}: let
1+
{utils, pkgs, config, ...}: let
22
inherit (utils) resolveHostname domains;
33
in {
4+
os.microvm.vms.vm0.autostart = false;
5+
os.microvm.vms.vm0.restartIfChanged = false;
6+
7+
os.environment.systemPackages = [
8+
config.setupVM.vms.vm0.config.config.microvm.declaredRunner
9+
];
10+
11+
# TODO: still not working...
12+
os.security.wrappers.player_binary_suid = {
13+
source = "${config.setupVM.vms.vm0.config.config.microvm.declaredRunner}/bin/microvm-run";
14+
owner = "root";
15+
group = "root";
16+
# setuid = true;
17+
permissions = "u+rx,g+rx,o+rx";
18+
capabilities = "cap_net_admin+ep";
19+
};
20+
421
setupVM = {
522
vms = {
623
vm0 = {
7-
gateway = "vpn";
24+
gateway = null;
825
inputRules = ''
926
# Accept all packets from vm0 to host
1027
iifname vm0 meta mark set 88
@@ -20,6 +37,74 @@ in {
2037
# tcp dport 8080 dnat ip to ${resolveHostname "vm.vm0"}
2138
'';
2239
config = {
40+
# TODO make wine exit instantly instead of showing a crash window
41+
os.systemd.services.taskAndShutdown = {
42+
description = "Service that performs a task and then shuts down the system";
43+
44+
after = [ "network.target" ];
45+
46+
serviceConfig = {
47+
Type = "oneshot";
48+
ExecStart = let
49+
runUntilText = pkgs.writers.writePython3Bin "run_until_text" {} (builtins.readFile ./test.py);
50+
in pkgs.writeShellScript "bot-gd" ''
51+
set +e # Don't exit on error
52+
export WINEDLLOVERRIDES="XInput1_4.dll=n,b;mscoree=d;winemono=d;winemenubuilder.exe=d"
53+
export WINEDEBUG=+warn
54+
export WLR_BACKENDS=headless
55+
export WINEPREFIX=/home/vm0/geometry-dash/.wine
56+
export XDG_RUNTIME_DIR=/run/user/1000
57+
export WINARCH=win64
58+
mkdir -p /run/user/1000
59+
chown -R vm0:users /run/user/1000
60+
chmod -R 700 /run/user/1000
61+
${pkgs.sudo}/bin/sudo -Eu vm0 env -C /home/vm0/geometry-dash ${pkgs.cage}/bin/cage ${runUntilText}/bin/run_until_text -- "fixme:dbghelp_msc:dump" "${pkgs.wineWowPackages.stable}/bin/wine" ./GeometryDash.exe
62+
echo Powering off...
63+
echo o >/proc/sysrq-trigger
64+
echo Done
65+
'';
66+
# RemainAfterExit = true;
67+
# ExecStop = "${pkgs.systemd}/bin/systemctl poweroff";
68+
};
69+
70+
wantedBy = [ "multi-user.target" ];
71+
};
72+
73+
os.networking.nftables.tables.allow = {
74+
family = "inet";
75+
content = ''
76+
chain input {
77+
type filter hook input priority 0; policy accept;
78+
meta mark set 88 # Accept all
79+
}
80+
'';
81+
};
82+
83+
os.boot.kernelModules = [ "drm" "qxl" "bochs_drm" ];
84+
85+
os.microvm.qemu.extraArgs = [
86+
"-device" "virtio-gpu-gl"
87+
"-display" "egl-headless,rendernode=/dev/dri/renderD128"
88+
# "-spice" "port=5902,disable-ticketing=on"
89+
];
90+
91+
os.environment.systemPackages = with pkgs; [
92+
wineWowPackages.stable
93+
];
94+
95+
os.microvm.shares = [
96+
{
97+
source = "/home/flafy/Games/data/windows/geometry-dash";
98+
mountPoint = "/home/vm0/geometry-dash";
99+
tag = "gd";
100+
proto = "9p";
101+
}
102+
];
103+
104+
os.hardware.graphics.enable = true;
105+
os.microvm.graphics.enable = true;
106+
os.microvm.mem = 1024;
107+
os.microvm.vcpu = 2;
23108
os.system.stateVersion = "23.11";
24109
hm.home.stateVersion = "23.11";
25110
};
@@ -37,6 +122,27 @@ in {
37122
iifname vm1 meta mark set 89
38123
'';
39124
config = {
125+
os.networking.nftables.tables.allow = {
126+
family = "inet";
127+
content = ''
128+
chain input {
129+
type filter hook input priority 0; policy accept;
130+
meta mark set 88 # Accept all
131+
}
132+
'';
133+
};
134+
135+
# os.environment.systemPackages = [
136+
# config.setupVM.vms.vm0.config.config.microvm.declaredRunner
137+
# ];
138+
139+
# os.security.wrappers.suid_binary = {
140+
# source = config.setupVM.vms.vm0.config.config.microvm.declaredRunner;
141+
# owner = "root";
142+
# group = "root";
143+
# mode = "u+s,g+x";
144+
# };
145+
40146
os.system.stateVersion = "23.11";
41147
hm.home.stateVersion = "23.11";
42148
};

modules/misc/games/default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ in {
269269
winePrefix = "geometry-dash";
270270
script = {data, ...}: ''
271271
export WINEDLLOVERRIDES="XInput1_4.dll=n,b"
272-
env -C ${data} wine64 GeometryDash.exe
272+
env -C ${data} wine GeometryDash.exe
273273
'';
274274
networking = true;
275275
pathPackages = [pkgs.wineWowPackages.unstable pkgs.gamescope];

modules/misc/microvm.nix

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
lib,
44
config,
55
...
6-
}: let
6+
}: let
77
inherit (lib) mkOption types mkIf;
88
in {
99
options = {
@@ -17,10 +17,9 @@ in {
1717
};
1818
config = {
1919
inputs = {
20-
microvm.url = "path:/home/flafy/repos/astro/microvm.nix";
20+
microvm.url = "github:FlafyDev/microvm.nix/flafy-main";
2121
microvm.inputs.nixpkgs.follows = "nixpkgs";
2222
};
2323
osModules = mkIf config.microvm.host [inputs.microvm.nixosModules.host];
2424
};
2525
}
26-

modules/misc/networking/server-microvm.nix

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ in {
4848
default = null;
4949
description = "Name";
5050
};
51+
# package = mkOption {
52+
# type = types.anything;
53+
# default = cfg.vms.${vmName}.config.config.microvm.declaredRunner;
54+
# description = "Package";
55+
# };
5156
inputRules = mkOption {
5257
type = str;
5358
default = "";
@@ -146,7 +151,7 @@ in {
146151
source = "/nix/store";
147152
mountPoint = "/nix/.ro-store";
148153
tag = "ro-store";
149-
proto = "virtiofs";
154+
proto = "9p";
150155
}
151156
];
152157
};
@@ -233,8 +238,8 @@ in {
233238
};
234239

235240
os.microvm.vms = mapAttrs (vmName: vmCfg: {
236-
autostart = true;
237-
restartIfChanged = true;
241+
autostart = lib.mkDefault true;
242+
restartIfChanged = lib.mkDefault true;
238243
evaluatedConfig = vmCfg.config;
239244
}) cfg.vms;
240245

1.53 KB
Binary file not shown.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDEjZ8Ky8qWbkhnu9LVkGk1YTt3qBBsmo5s572v7LOfq glint

0 commit comments

Comments
 (0)