This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.nix
62 lines (52 loc) · 1.75 KB
/
actions.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
{
lib,
nixpkgs,
mkCommand,
}: let
contextFreeDrv = target: lib.unsafeDiscardStringContext target.drvPath;
build = currentSystem: target:
mkCommand currentSystem {
name = "build";
description = "build artifact";
command = ''
# ${target}
nix build ${contextFreeDrv target}
'';
targetDrv = target.drvPath;
proviso =
# bash
''
function proviso() {
local -n input=$1
local -n output=$2
local drvs
local -a uncached
# FIXME: merge upstream to avoid any need for runtime context
command nix build github:divnix/nix-uncached/v2.13.1
drvs=$(command jq -r '.targetDrv | select(. != "null")' <<< "''${input[@]}")
uncached_json=$(result/bin/nix-uncached $drvs)
mapfile -t uncached < <(command jq -r 'to_entries[]|select(.value != [])|.key' <<< "$uncached_json")
if [[ -n ''${uncached[*]} ]]; then
local list filtered
list=$(command jq -ncR '[inputs]' <<< "''${uncached[@]}")
filtered=$(command jq -c 'select([.targetDrv] | inside($p))' --argjson p "$list" <<< "''${input[@]}")
output=$(command jq -cs '. += $p' --argjson p "$output" <<< "$filtered")
fi
}
'';
};
run = currentSystem: target: let
programName =
target.meta.mainProgram
or (lib.getName target);
in
mkCommand currentSystem {
name = "run";
description = "run artifact";
# this is the exact sequence mentioned by the `nix run` docs
# and so should be compatible
command = ''
${target.program or "${target}/bin/${programName}"} "$@"
'';
};
in {inherit build run;}