-
Notifications
You must be signed in to change notification settings - Fork 0
/
nixb
executable file
·84 lines (74 loc) · 2.08 KB
/
nixb
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
#!/usr/bin/env bash
set -euo pipefail
# `nix build` wrapper script utilizing remote builders
flags=()
builders_config="${NIX_BUILDERS_CONFIG:-${HOME}/config/nix-builders.nix}"
if [ -f "${builders_config}" ]; then
builders_string="$(nix-instantiate --eval --json -E '
let
mkBuilder = let
nullOr = e: v: if v == null then e else v;
dash = v: if v == null then "-" else toString v;
dashList = v: if (v == null || v == []) then "-" else builtins.concatStringsSep "," v;
in
{ hostName
, system ? null
, systems ? null
, sshUser ? null
, sshKey ? null
, maxJobs ? null
, speedFactor ? null
, mandatoryFeatures ? null
, supportedFeatures ? null
, publicHostKey ? null
}:
assert (hostName != null && hostName != "");
builtins.concatStringsSep " " [
(if sshUser != null then "${sshUser}@${hostName}" else hostName)
(nullOr (dashList systems) system)
(dash sshKey)
(toString (nullOr 1 maxJobs))
(toString (nullOr 1 speedFactor))
(dashList ((nullOr [] supportedFeatures) ++ (nullOr [] mandatoryFeatures)))
(dashList mandatoryFeatures)
(dash publicHostKey)
];
builders = import '"$(realpath -- "${builders_config}")"';
in
builtins.concatStringsSep "; " (map mkBuilder builders)
' | jq -r '.')"
flags+=(
--builders "${builders_string}"
--builders-use-substitutes
)
fi
current_system="$(nix-instantiate --eval -E --json 'builtins.currentSystem' | jq -r '.')"
target_system="${current_system}"
orig_argv=( "${@}" )
while [ -n "${1:-}" ]; do
arg="${1}"
case "${arg}" in
--expr)
# Skip processing tons of text
shift
;;
--system)
shift
target_system="${1}"
;;
--store)
shift
store_path="${1}"
if ! [ "${store_path}" = "/nix/store" ] && [ "$(uname -s)" = "Darwin" ]; then
# error: building using a diverted store is not supported on this platform
flags+=(--max-jobs 0)
fi
;;
esac
shift
done
set -- "${orig_argv[@]}"
if ! [ "${current_system}" = "${target_system}" ]; then
flags+=(--max-jobs 0)
fi
nix "${flags[@]}" "${@}"