forked from nix-community/nh
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage.nix
More file actions
135 lines (124 loc) · 4.04 KB
/
Copy pathpackage.nix
File metadata and controls
135 lines (124 loc) · 4.04 KB
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
{
lib,
stdenv,
rustPlatform,
makeBinaryWrapper,
installShellFiles,
versionCheckHook,
sudo,
use-nom ? true,
nix-output-monitor ? null,
rev ? "dirty",
}:
assert use-nom -> nix-output-monitor != null;
let
runtimeDeps = lib.optionals use-nom [ nix-output-monitor ];
cargoToml = lib.importTOML ./Cargo.toml;
in
rustPlatform.buildRustPackage (finalAttrs: {
pname = "nh";
version = "${cargoToml.workspace.package.version}-${rev}";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) (
lib.fileset.unions [
./.cargo
./.config
./crates
./xtask
./Cargo.toml
./Cargo.lock
]
);
};
strictDeps = true;
nativeBuildInputs = [
installShellFiles
makeBinaryWrapper
];
cargoLock.lockFile = ./Cargo.lock;
postInstall =
lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
# Run both shell completion and manpage generation tasks. Unlike the
# fine-grained variants, the 'dist' command doesn't allow specifying the
# path but that's fine, because we can simply install them from the implicit
# output directories.
$out/bin/xtask dist
# The dist task above should've created
# 1. Shell completions in comp/
# 2. The NH manpage (nh.1) in man/
# Let's install those.
# The important thing to note here is that installShellCompletion cannot
# actually load *all* shell completions we generate with 'xtask dist'.
# Elvish, for example isn't supported. So we have to be very explicit
# about what we're installing, or this will fail.
installShellCompletion --cmd ${finalAttrs.meta.mainProgram} ./comp/*.{bash,fish,zsh,nu}
installManPage ./man/nh.1
''
+ ''
# Avoid populating PATH with an 'xtask' cmd
rm $out/bin/xtask
'';
postFixup = ''
wrapProgram $out/bin/nh \
--prefix PATH : ${lib.makeBinPath runtimeDeps}
'';
nativeInstallCheckInputs = [ versionCheckHook ];
doInstallCheck = false; # FIXME: --version includes 'dirty' and the hook doesn't let us change the assertion
versionCheckProgram = "${placeholder "out"}/bin/${finalAttrs.meta.mainProgram}";
versionCheckProgramArg = "--version";
# pkgs.sudo is not available on the Darwin platform, and thus breaks build
# if added to nativeCheckInputs. We must manually disable the tests that
# *require* it, because they will fail when sudo is missing.
nativeCheckInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ sudo ];
checkFlags = [
# These do not work in Nix's sandbox
"--skip"
"test_get_build_image_variants_expression"
"--skip"
"test_get_build_image_variants_file"
"--skip"
"test_get_build_image_variants_flake"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# Tests that require sudo in PATH (not available on Darwin)
"--skip"
"test_build_sudo_cmd_basic"
"--skip"
"test_build_sudo_cmd_with_preserve_vars"
"--skip"
"test_build_sudo_cmd_with_preserve_vars_disabled"
"--skip"
"test_build_sudo_cmd_with_set_vars"
"--skip"
"test_build_sudo_cmd_force_no_stdin"
"--skip"
"test_build_sudo_cmd_with_remove_vars"
"--skip"
"test_build_sudo_cmd_with_askpass"
"--skip"
"test_build_sudo_cmd_env_added_once"
"--skip"
"test_elevation_strategy_passwordless_resolves"
"--skip"
"test_build_sudo_cmd_with_nix_config_spaces"
];
# Besides the install check, we have a bunch of tests to run. Nextest is
# the fastest way of running those since it's significantly faster than
# `cargo test`, and has a nicer UI with CI-friendly characteristics.
useNextest = true;
cargoTestFlags = [ "--workspace" ];
env.NH_REV = rev;
meta = {
description = "Yet another nix cli helper";
homepage = "https://github.com/nix-community/nh";
license = lib.licenses.eupl12;
mainProgram = "nh";
maintainers = with lib.maintainers; [
drupol
faukah
NotAShelf
viperML
];
};
})