-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
150 lines (117 loc) · 4.86 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
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
outputs = { self, nixpkgs }:
let
flakePkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ self.overlays.default ];
};
currentVersion = builtins.readFile ./VERSION;
buildPackage = pname: luaPackages: with luaPackages;
buildLuaPackage rec {
name = "${pname}-${version}";
inherit pname;
version = "${currentVersion}-${self.shortRev or "dev"}";
src = ./.;
propagatedBuildInputs = [ lua lgi ];
buildInputs = [ busted luacov ldoc luacheck ];
buildPhase = ":";
installPhase = ''
mkdir -p "$out/share/lua/${lua.luaversion}"
cp -r src/${pname} "$out/share/lua/${lua.luaversion}/"
'';
doCheck = true; # more tests done using the flake checks
checkPhase = "luacheck src tests";
};
makeCheck = lua: luaPackages: flakePkgs.nixosTest {
name = luaPackages.dbus_proxy.name;
nodes.machine = { pkgs, lib, ... }: {
virtualisation.writableStore = true;
nix.settings.substituters = lib.mkForce [ ]; # no network
nixpkgs.overlays = [
self.overlays.default
(this: super: {
dbus_proxy_tests = pkgs.stdenv.mkDerivation {
name = "dbus_proxy_tests";
src = ./.;
buildPhase = ":";
installPhase = "mkdir -p $out/tests && cp -r tests/ $out/tests/";
doCheck = false;
};
dbus_proxy_app = lua.withPackages (ps: [
luaPackages.dbus_proxy
] ++ luaPackages.dbus_proxy.buildInputs);
})
];
environment.variables = {
LUA_DBUS_PROXY_TESTS_PATH = "${pkgs.dbus_proxy_tests}";
GI_TYPELIB_PATH = "${pkgs.lib.getLib pkgs.glib}/lib/girepository-1.0/";
};
users.users.test-user = {
isNormalUser = true;
shell = pkgs.bashInteractive;
password = "just-A-pass";
home = "/home/test-user";
packages = [ pkgs.dbus_proxy_app ];
};
};
testScript = ''
# To use DBus properly, login and execute the test suite.
# strategy taken from nixos/tests/login.nix
machine.wait_for_unit("multi-user.target")
machine.wait_until_tty_matches("1", "login: ")
machine.send_chars("test-user\n")
machine.wait_until_tty_matches("1", "login: test-user")
machine.wait_until_succeeds("pgrep login")
machine.wait_until_tty_matches("1", "Password: ")
machine.send_chars("just-A-pass\n")
machine.wait_until_succeeds("pgrep -u test-user bash")
machine.send_chars("busted $LUA_DBUS_PROXY_TESTS_PATH > output\n")
machine.wait_for_file("/home/test-user/output")
machine.send_chars("echo $? > result\n")
machine.wait_for_file("/home/test-user/result")
output = machine.succeed("cat /home/test-user/output")
result = machine.succeed("cat /home/test-user/result")
assert result == "0\n", "Test suite failed: {}".format(output)
print(output)
'';
};
in
{
packages.x86_64-linux = rec {
default = lua_dbus_proxy;
lua_dbus_proxy = buildPackage "dbus_proxy" flakePkgs.luaPackages;
lua52_dbus_proxy = buildPackage "dbus_proxy" flakePkgs.lua52Packages;
lua53_dbus_proxy = buildPackage "dbus_proxy" flakePkgs.lua53Packages;
luajit_dbus_proxy = buildPackage "dbus_proxy" flakePkgs.luajitPackages;
};
overlays.default = final: prev: with self.packages.x86_64-linux; {
# NOTE: lua = prev.lua.override { packageOverrides = this: other: {... }}
# Seems to be broken as it does not allow to combine different overlays.
luaPackages = prev.luaPackages // {
dbus_proxy = lua_dbus_proxy;
};
lua52Packages = prev.lua52Packages // {
dbus_proxy = lua52_dbus_proxy;
};
lua53Packages = prev.lua53Packages // {
dbus_proxy = lua53_dbus_proxy;
};
luajitPackages = prev.luajitPackages // {
dbus_proxy = luajit_dbus_proxy;
};
};
devShells.x86_64-linux.default = flakePkgs.mkShell {
LUA_PATH = "./src/?.lua;./src/?/init.lua";
buildInputs = (with self.packages.x86_64-linux.lua53_dbus_proxy; buildInputs ++ propagatedBuildInputs) ++ (with flakePkgs; [
nixpkgs-fmt
luarocks
]);
};
checks.x86_64-linux = {
lua52Check = with flakePkgs; makeCheck lua5_2 lua52Packages;
lua53Check = with flakePkgs; makeCheck lua5_3 lua53Packages;
luajitCheck = with flakePkgs; makeCheck luajit luajitPackages;
} // self.packages.x86_64-linux;
};
}