-
Notifications
You must be signed in to change notification settings - Fork 17
/
default.nix
80 lines (68 loc) · 2.39 KB
/
default.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
{ craneLib
, lib
, stdenv
, darwin
, installShellFiles
, makeWrapper
, nix
, openssl
, pkg-config
, plugins ? [ ]
# Allowing running the tests without the "recursive-nix" feature to allow
# building the package without having a recursive-nix-enabled Nix.
, enableRecursiveNixTests ? false
, target ? stdenv.targetPlatform.rust.cargoShortTarget
}:
let
commonArgs = {
src = lib.cleanSourceWith rec {
src = craneLib.path ./.;
filter = path: type:
let pathWithoutPrefix = lib.removePrefix (toString src) path; in
lib.hasPrefix "/docs/" pathWithoutPrefix ||
lib.hasPrefix "/example/" pathWithoutPrefix ||
lib.hasPrefix "/src/" pathWithoutPrefix ||
craneLib.filterCargoSources path type;
};
# build dependencies
nativeBuildInputs = [
pkg-config
installShellFiles
] ++ lib.optionals (plugins != [ ]) [
makeWrapper
];
# runtime dependencies
buildInputs = [
openssl
] ++ lib.optionals stdenv.isDarwin [
darwin.Security
];
# Absolute path to the `nix` binary, used in `build.rs`
RAGENIX_NIX_BIN_PATH = lib.getExe nix;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "--target ${target}";
cargoTestExtraArgs = lib.optionalString (!enableRecursiveNixTests) "--no-default-features";
requiredSystemFeatures = lib.optionals enableRecursiveNixTests [ "recursive-nix" ];
postInstall = ''
set -euo pipefail
# Provide a symlink from `agenix` to `ragenix` for compat
ln -sr "$out/bin/ragenix" "$out/bin/agenix"
# Stdout of build.rs
buildOut=$(grep -m 1 -Rl 'RAGENIX_COMPLETIONS_BASH=/' target/ | head -n 1)
printf "found build script output at %s\n" "$buildOut"
set +u # required due to `installShellCompletion`'s implementation
installShellCompletion --bash "$(grep -oP 'RAGENIX_COMPLETIONS_BASH=\K.+' "$buildOut")"
installShellCompletion --zsh "$(grep -oP 'RAGENIX_COMPLETIONS_ZSH=\K.+' "$buildOut")"
installShellCompletion --fish "$(grep -oP 'RAGENIX_COMPLETIONS_FISH=\K.+' "$buildOut")"
installManPage docs/ragenix.1
'';
# Make the plugins available in ragenix' PATH
postFixup = lib.optionalString (plugins != [ ]) ''
wrapProgram "$out/bin/ragenix" --suffix PATH : ${lib.strings.makeBinPath plugins}
'';
passthru.cargoArtifacts = cargoArtifacts;
})