-
Notifications
You must be signed in to change notification settings - Fork 0
/
simula.nix
203 lines (181 loc) · 6.8 KB
/
simula.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# ▄▀▀ ▀ █▄░▄█ █░█ █░░ ▄▀▄ ▐▌░▐▌ █▀▀▄ █▄░█ ▀ █░█ ▄▀▄ ▄▀▀ ▄▀ ▄▀▄ █▄░█ █▀ ▀ ▄▀▀░
# ░▀▄ █ █░█░█ █░█ █░▄ █▀█ ░▀▄▀░ █▐█▀ █░▀█ █ ▄▀▄ █░█ ░▀▄ █░ █░█ █░▀█ █▀ █ █░▀▌
# ▀▀░ ▀ ▀░░░▀ ░▀░ ▀▀▀ ▀░▀ ░░▀░░ ▀░▀▀ ▀░░▀ ▀ ▀░▀ ░▀░ ▀▀░ ░▀ ░▀░ ▀░░▀ ▀░ ▀ ▀▀▀░
# NixOS settings for the upcoming Simula One (https://simulavr.com)
{ config, pkgs, lib, ... }:
let
# Fetch Simula source code from GitHub
simulaSrc = pkgs.fetchFromGitHub {
owner = "SimulaVR";
repo = "Simula";
rev = "7497ada3e415299c88cefed9e58ffec8a654362e";
sha256 = "04kqlgs740784642fbbypfyv3wa3ddqd9d764wadhjr36mf2rqi6";
fetchSubmodules = true;
};
# Build the Simula package
simula = pkgs.callPackage "${simulaSrc}/Simula.nix" {
onNixOS = true;
devBuild = false;
profileBuild = false;
externalSrc = simulaSrc;
};
in
{
# Provides necessary packages for interacting with Simula launch script
environment.systemPackages = with pkgs; [
simula
xorg.xrandr
read-edid
];
# Ensures that tracking devices can set their own priority
security.wrappers = {
simula-monado-service = {
source = "${simula}/bin/simula-monado-service";
capabilities = "cap_sys_nice+ep";
owner = "simula";
group = "users";
};
};
# Add the 'simula' user and grant appropriate permissions
nix.settings.trusted-users = [ "root" "simula" ];
users.extraUsers.simula = {
isNormalUser = true;
home = "/home/simula";
extraGroups = [ "wheel" "networkmanager" "video" "tty" ];
};
# Include udev rules for Simula tracking devices (just the Xvisio XR50 for now)
services.udev.extraRules = ''
# XVISIO SEERSENSE XR50 RULES
SUBSYSTEM=="usb", ATTR{idVendor}=="040e", MODE="0666", GROUP="plugdev"
'';
# Provides optical transforms for Simula One optics
environment.etc."simula/simula_monado_config.json".text = ''
{
"display_distortion": {
"left_eye": {
"half_fov": 0.9,
"display_size_mm_x": 51.7752,
"display_size_mm_y": 51.7752,
"params_red": {
"k1": 0.022474564980657766,
"k3": 6.426774232E-6,
"k5": 1.557249471935154E-8,
"k7": 3.456308599003131E-11,
"k9": -3.9098738307993384E-15
},
"params_green": {
"k1": 0.022474564980657766,
"k3": 7.140860258225189E-6,
"k5": 1.557249471935154E-8,
"k7": 3.456308599003131E-11,
"k9": -3.9098738307993384E-15
},
"params_blue": {
"k1": 0.022474564980657766,
"k3": 7.934289176E-6,
"k5": 1.557249471935154E-8,
"k7": 3.456308599003131E-11,
"k9": -3.9098738307993384E-15
}
},
"right_eye": {
"half_fov": 0.9,
"display_size_mm_x": 51.7752,
"display_size_mm_y": 51.7752,
"params_red": {
"k1": 0.022474564980657766,
"k3": 6.426774232E-6,
"k5": 1.557249471935154E-8,
"k7": 3.456308599003131E-11,
"k9": -3.9098738307993384E-15
},
"params_green": {
"k1": 0.022474564980657766,
"k3": 7.140860258225189E-6,
"k5": 1.557249471935154E-8,
"k7": 3.456308599003131E-11,
"k9": -3.9098738307993384E-15
},
"params_blue": {
"k1": 0.022474564980657766,
"k3": 7.934289176E-6,
"k5": 1.557249471935154E-8,
"k7": 3.456308599003131E-11,
"k9": -3.9098738307993384E-15
}
}
}
}
'';
# Launch monado + Simula's VR window manager on boot
services.xserver = {
enable = true;
autorun = true;
displayManager.lightdm.enable = false;
displayManager.startx.enable = false;
displayManager.autoLogin.enable = true;
displayManager.autoLogin.user = "simula";
displayManager.defaultSession = "simula-session";
desktopManager.session = [
{
name = "simula-session";
start = ''
#!${pkgs.bash}/bin/bash
# Set up logging
exec >~/.xsession-errors 2>&1
cd ~
echo "Checking for Simula One VR displays..."
checkForDisplays() {
local found_displays=()
local exit_code=0
# Load up the `found_displays` array with any detected displays
for output in /sys/class/drm/*/status; do
if grep -q "^connected$" "$output"; then
display_name="''${output%/status}"
display_name="''${display_name#/sys/class/drm/}"
found_displays+=("$display_name")
edid_file="''${output%status}edid"
if [ -f "$edid_file" ]; then
edid_model=$(${pkgs.read-edid}/bin/parse-edid < "$edid_file" 2> /dev/null | sed -n 's/.*VendorName *"\(.*\)".*/\1/p')
if [ -n "$edid_model" ]; then
found_displays+=("$edid_model")
fi
fi
fi
done
if [ $# -eq 0 ]; then
echo "Found displays:"
for display in "''${found_displays[@]}"; do
echo " - $display"
done
return 0
fi
if [[ " ''${found_displays[*]} " == *" $1 "* ]]; then
echo "$1 display found."
else
echo "ERROR: $1 monitor not connected or found."
exit_code=1
fi
return $exit_code
}
# List available displays, and check if Simula's VR displays are detected
checkForDisplays
checkForDisplays "SVR"
echo "Setting xrandr modes for Simula One displays..."
${pkgs.xorg.xrandr}/bin/xrandr --newmode 1280x720_60.00 74.48 1280 1336 1472 1664 720 721 724 746 -HSync +Vsync
${pkgs.xorg.xrandr}/bin/xrandr --addmode DVI-I-1-1 1280x720_60.00
${pkgs.xorg.xrandr}/bin/xrandr --output DVI-I-1-1 --mode 1280x720_60.00
${pkgs.xorg.xrandr}/bin/xrandr --output DP-2 --off
${pkgs.xorg.xrandr}/bin/xrandr --output DP-1 --off
echo "Launching Monado..."
rm /run/user/$(id -u)/monado_comp_ipc || true
XRT_NO_STDIN=1 ${simula}/bin/simula-monado-service &
echo "Waiting for Monado to be ready..."
until [ -e /run/user/$(id -u)/monado_comp_ipc ]; do sleep 0.1; done
echo "Launching Simula..."
exec ${simula}/bin/simula
'';
}
];
};
}