-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
124 lines (104 loc) · 3.72 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
124
{
description = "nu_plugin_bash_env";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
bash-env-json = {
url = "github:tesujimath/bash-env-json/main";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, rust-overlay, flake-utils, bash-env-json, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
inherit (pkgs) lib rust-bin stdenvNoCC writeShellScriptBin;
flakePkgs = {
bash-env-json = bash-env-json.packages.${system}.default;
};
bash-env-module-with-bash-env-json = stdenvNoCC.mkDerivation
{
name = "bash-env.nu-with-bash-env-json";
src = ./bash-env.nu;
dontUnpack = true;
preferLocalBuild = true;
allowSubstitutes = false;
buildPhase = ''
runHook preBuild
mkdir -p "$out"
substitute "$src" "$out/bash-env.nu" --replace-fail ${lib.escapeShellArg "bash-env-json"} ${lib.escapeShellArg "${flakePkgs.bash-env-json}/bin/bash-env-json"}
runHook postBuild
'';
};
# cargo-nightly based on https://github.com/oxalica/rust-overlay/issues/82
nightly = rust-bin.selectLatestNightlyWith (t: t.default);
cargo-nightly = writeShellScriptBin "cargo-nightly" ''
export RUSTC="${nightly}/bin/rustc";
exec "${nightly}/bin/cargo" "$@"
'';
nu_plugin_bash_env =
let
inherit (builtins) fromTOML readFile;
inherit (pkgs) lib makeWrapper rustPlatform;
cargoConfig = fromTOML (readFile ./Cargo.toml);
in
rustPlatform.buildRustPackage
{
pname = "nu_plugin_bash_env";
version = cargoConfig.package.version;
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
meta = with lib; {
description = "A Bash environment plugin for Nushell";
homepage = "https://github.com/tesujimath/nu_plugin_bash_env";
license = licenses.mit;
maintainers = [ maintainers.tailhook ];
};
buildInputs = [
makeWrapper
flakePkgs.bash-env-json
];
preBuild = ''
export NIX_BASH_ENV_JSON=${flakePkgs.bash-env-json}/bin/bash-env-json
'';
postFixup = ''
wrapProgram $out/bin/nu_plugin_bash_env --set NU_PLUGIN_BASH_ENV_JSON ${flakePkgs.bash-env-json}/bin/bash-env-json
'';
};
in
{
devShells.default =
let
inherit (pkgs)
mkShell
bashInteractive
jq
cargo-modules
cargo-udeps
rust-bin;
in
mkShell {
nativeBuildInputs = [
bashInteractive
jq
cargo-modules
cargo-nightly
cargo-udeps
rust-bin.stable.latest.default
];
};
packages = {
default = bash-env-module-with-bash-env-json;
module = bash-env-module-with-bash-env-json;
plugin = nu_plugin_bash_env;
};
}
);
}