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
| | # SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022-2025 Alyssa Ross <hi@alyssa.is>
# SPDX-FileCopyrightText: 2025 Yureka Lilian <yureka@cyberchaos.dev>
import ../lib/call-package.nix (
{ src, lib, stdenv, fetchCrate, fetchurl, runCommand, buildPackages
, meson, ninja, pkg-config, rustc
, llvmPackages, clippy, jq
, linuxHeaders
, libbpf
, buildSupport ? false
, appSupport ? true
, hostSupport ? false
, driverSupport ? false
}:
let
packageCache = [
(fetchCrate {
pname = "itoa";
version = "1.0.11";
unpack = false;
hash = "sha256-SfHxSHMzVFRQDVlhHxz0pLD3hvmsEfQxKnjkzyVmaVs=";
})
(fetchurl {
name = "miniserde-0.1.41.tar.gz";
url = "https://github.com/dtolnay/miniserde/archive/0.1.41.tar.gz";
hash = "sha256-2u3mIyslKzImtTJpK4M2nwN1PZJhJPa0ZxUDP/TaCAk=";
})
(fetchCrate {
pname = "proc-macro2";
version = "1.0.93";
unpack = false;
hash = "sha256-YJRqaOX50osNwcIbuKl+59AYqLMi+leDi6McyHjiLZk=";
})
(fetchCrate {
pname = "quote";
version = "1.0.38";
unpack = false;
hash = "sha256-Dk3Mqq+JUU9UbGk93BQPcp+VjCR5GKEzgMzMYHg5Gsw=";
})
(fetchCrate {
pname = "ryu";
version = "1.0.17";
unpack = false;
hash = "sha256-6GaXyRYBmoWIyZtfrDzq107AtLgZcHpoL9TSP6DOG6E=";
})
(fetchCrate {
pname = "syn";
version = "2.0.58";
unpack = false;
hash = "sha256-RM+5PzgHC+7jaz/vfU9aFvJ3UdlLGHtmalzF6bDTBoc=";
})
(fetchCrate {
pname = "unicode-ident";
version = "1.0.12";
unpack = false;
hash = "sha256-M1S5rD+uH/Z1XLbbU2g622YWNPZ1V5Qt6k+s6+wP7ks=";
})
];
in
stdenv.mkDerivation (finalAttrs: {
name = "spectrum-tools";
src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.intersection src (lib.fileset.unions ([
./meson.build
./meson.options
] ++ lib.optionals buildSupport [
./lseek.c
] ++ lib.optionals appSupport [
./xdg-desktop-portal-spectrum
] ++ lib.optionals hostSupport [
./lsvm.rs
./sd-notify-adapter.c
./start-vmm
./subprojects
] ++ lib.optionals driverSupport [
./xdp-forwarder
]));
};
sourceRoot = "source/tools";
depsBuildBuild = lib.optionals hostSupport [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ meson ninja ]
++ lib.optionals (appSupport || driverSupport) [ pkg-config ]
++ lib.optionals hostSupport [ rustc ]
++ lib.optionals driverSupport [ llvmPackages.clang-unwrapped ];
buildInputs = lib.optionals driverSupport [ libbpf linuxHeaders ];
postPatch = lib.optionals hostSupport (lib.concatMapStringsSep "\n" (crate: ''
mkdir -p subprojects/packagecache
ln -s ${crate} subprojects/packagecache/${crate.name}
'') packageCache);
mesonFlags = [
(lib.mesonBool "build" buildSupport)
(lib.mesonBool "app" appSupport)
(lib.mesonBool "host" hostSupport)
(lib.mesonBool "driver" driverSupport)
"-Dhostfsrootdir=/run/virtiofs/virtiofs0"
"-Dtests=false"
"-Dunwind=false"
"-Dwerror=true"
] ++ lib.optionals driverSupport [
"-Dlinux-headers=${linuxHeaders}"
];
passthru.tests = {
clang-tidy = finalAttrs.finalPackage.overrideAttrs (
{ name, src, nativeBuildInputs ? [], ... }:
{
name = "${name}-clang-tidy";
src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.union (lib.fileset.fromSource src) ../.clang-tidy;
};
# clang-tools needs to be before clang, otherwise it will not use
# the Nix include path correctly and fail to find headers
nativeBuildInputs = [ llvmPackages.clang-tools jq ] ++ nativeBuildInputs;
buildPhase = ''
jq -r '.[].file | select(endswith(".c"))' compile_commands.json |
xargs clang-tidy --warnings-as-errors='*'
touch $out
exit 0
'';
}
);
tests = finalAttrs.finalPackage.overrideAttrs (
{ name, mesonFlags ? [], ... }:
{
name = "${name}-tests";
mesonFlags = mesonFlags ++ [
"-Dunwind=true"
"-Dtests=true"
];
doCheck = true;
}
);
} // lib.optionalAttrs hostSupport {
clippy = finalAttrs.finalPackage.overrideAttrs (
{ name, nativeBuildInputs ? [], ... }:
{
name = "${name}-clippy";
nativeBuildInputs = nativeBuildInputs ++ [ clippy ];
dontBuild = true;
doCheck = true;
dontUseMesonCheck = true;
checkTarget = "clippy";
installPhase = ''touch $out && exit 0'';
}
);
};
meta = with lib; {
description = "First-party Spectrum programs";
license = licenses.eupl12;
maintainers = with maintainers; [ qyliss ];
platforms = platforms.linux;
};
})
) (_: {})
|