-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
174 lines (151 loc) · 5.39 KB
/
flake.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
{
description = "Hyprland's IPC bindings for Go";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
{ self, nixpkgs, ... }:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in
{
checks = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
in
{
testVm =
let
user = "alice";
uid = 1000;
home = "/home/${user}";
# Testing related file paths
covHtml = "${home}/hyprland-go.html";
covOut = "${home}/hyprland-go.out";
glxinfoOut = "${home}/glxinfo.out";
testFinished = "${home}/test-finished";
testLog = "${home}/test.log";
in
pkgs.testers.runNixOSTest {
name = "hyprland-go";
nodes.machine =
{
config,
pkgs,
lib,
...
}:
{
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
programs.hyprland.enable = true;
users.users.${user} = {
inherit home uid;
isNormalUser = true;
};
environment.systemPackages = with pkgs; [
glxinfo # grab information about GPU
gnome-themes-extra # used in SetCursor() test
go
kitty
];
services.getty.autologinUser = user;
virtualisation.qemu = {
options = [
"-smp 2"
"-m 4G"
"-vga none"
"-device virtio-gpu-pci"
# Works only in Wayland, may be slightly faster
# "-device virtio-gpu-rutabaga,gfxstream-vulkan=on,cross-domain=on,hostmem=2G"
];
};
# Start hyprland at login
programs.bash.loginShellInit =
# bash
let
testScript =
pkgs.writeShellScript "hyprland-go-test"
# bash
''
set -euo pipefail
trap 'echo $? > ${testFinished}' EXIT
glxinfo -B > ${glxinfoOut} || true
cd ${./.}
export NIX_CI=1
go test -bench=. -coverprofile ${covOut} -v ./... > ${testLog} 2>&1
go tool cover -html=${covOut} -o ${covHtml}
'';
hyprlandConf =
pkgs.writeText "hyprland.conf"
# hyprlang
''
bind = SUPER, Q, exec, kitty # Bind() test need at least one bind
exec-once = kitty sh -c ${testScript}
animations {
# slow, and nobody is looking anyway
enabled = false
}
decoration {
# slow, and nobody is looking anyway
blur {
enabled = false
}
}
cursor {
# improve cursor in VM
no_hardware_cursors = true
}
'';
in
# bash
''
if [ "$(tty)" = "/dev/tty1" ]; then
Hyprland --config ${hyprlandConf}
fi
'';
};
testScript = # python
''
start_all()
machine.wait_for_unit("multi-user.target")
machine.wait_for_file("${testFinished}")
print(machine.succeed("cat ${glxinfoOut} || true"))
print(machine.succeed("cat ${testLog}"))
print(machine.succeed("exit $(cat ${testFinished})"))
machine.copy_from_vm("${covOut}")
machine.copy_from_vm("${covHtml}")
'';
};
}
);
packages = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
in
rec {
default = hyprland-go;
hyprland-go = pkgs.buildGoModule {
pname = "hyprland-go";
version = self.shortRev or "dirty";
src = ./.;
subPackages = [
"examples/events"
"examples/hyprctl"
"examples/hyprtabs"
];
vendorHash = null;
};
}
);
};
}