-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
123 lines (113 loc) · 3.44 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
{
description = "Flox example environments";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flox.url = "github:flox/flox/refs/tags/v1.3.5";
outputs =
{
self,
flake-utils,
nixpkgs,
flox,
} @ inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
lib = nixpkgs.lib;
pkgs = nixpkgs.legacyPackages.${system};
mkFloxEnvPkg = name: {
path ? "${inputs.self}/${name}",
packages ? with pkgs; [
coreutils
flox.packages."${system}".default
],
}: pkgs.writeShellScriptBin "test-${name}" ''
set -eo pipefail
export FLOX_DISABLE_METRICS=true
export FLOX_ENVS_TESTING=1
export PATH="${lib.makeBinPath packages}:$PATH"
export LANG=
export LC_COLLATE="C"
export LC_CTYPE="C"
export LC_MESSAGES="C"
export LC_MONETARY="C"
export LC_NUMERIC="C"
export LC_TIME="C"
export LC_ALL=
# copy self/nb into temp dir
export TESTDIR="$(mktemp -d --suffix floxenvs-${name}-example)"
cp -R ${path}/* $TESTDIR
cp -R ${path}/.flox* $TESTDIR
if [ -f ${path}/.env ]; then
cp -R ${path}/.env $TESTDIR
fi
chown -R $(whoami) $TESTDIR/.flox*
chmod -R +w $TESTDIR/.flox*
# switch to root for the test
cd $TESTDIR
echo "👉 Running tests in $TESTDIR"
start_services=""
if [ "$1" == "true" ]; then
start_services=" --start-services"
fi
# run tests
if [ ! -f test.sh ]; then
echo "Error: No test.sh script found"
exit 1
fi
echo "👉 Running ${name} test..."
flox activate$start_services -- ${pkgs.bashInteractive}/bin/bash test.sh
ret=$?
if [ $ret -ne 0 ]; then
echo "Error: Tests failed"
exit $ret
fi
'';
mkFloxEnvApp = path: let
name = builtins.baseNameOf path;
script = mkFloxEnvPkg name {};
in {
name = "test-${name}";
value = {
type = "app";
program = "${script}/bin/test-${name}";
};
};
manifestPath = ".flox/env/manifest.toml";
allEnvironments =
builtins.map
(x:
let
xs = builtins.toString x;
len = (builtins.stringLength xs) - (builtins.stringLength manifestPath);
in
builtins.substring 0 len xs
)
(
builtins.filter
(x: lib.hasSuffix manifestPath (builtins.toString x))
(lib.filesystem.listFilesRecursive ./.)
);
environmentsWithTest =
builtins.filter
(x: builtins.pathExists "${x}/test.sh")
allEnvironments;
in
{
packages = builtins.listToAttrs (
builtins.map
(path: rec {
name = builtins.baseNameOf path;
value = mkFloxEnvPkg name {};
})
environmentsWithTest
);
apps = builtins.listToAttrs (
builtins.map mkFloxEnvApp environmentsWithTest
);
devShells.default = pkgs.mkShell {
packages = [];
};
}
);
}