forked from BrianHicks/nix-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
103 lines (92 loc) · 2.42 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
{
inputs = {
# Required when installing `nix-script` without Flakes. See `default.nix`.
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
{
self,
flake-utils,
naersk,
nixpkgs,
...
}:
{
overlay =
final: prev:
let
naerskLib = naersk.lib."${final.system}";
nixScript = naerskLib.buildPackage rec {
name = "nix-script";
version = "3.0.0";
root = ./.;
nativeBuildInputs = [ prev.clippy ];
preBuild = ''
# Make sure the version of the packages and the Nix derivations match.
grep -q -e 'version = "${version}"' ${name}/Cargo.toml || \
(echo "Nix Flake version mismatch ${version}!" && exit 1)
'';
doCheck = true;
checkPhase = ''
cargo clippy -- --deny warnings
'';
};
nixScriptBash = prev.writeShellScriptBin "nix-script-bash" ''
exec ${nixScript}/bin/nix-script \
--build-command 'cp $SRC $OUT' \
--interpreter bash \
"$@"
'';
nixScriptAll = prev.symlinkJoin {
name = "nix-script-all";
paths = [
nixScript
nixScriptBash
];
};
in
{
nix-script = nixScriptAll;
};
}
// flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
in
{
packages = {
nix-script = pkgs.nix-script;
};
defaultPackage = pkgs.nix-script;
devShell = pkgs.mkShell {
NIX_PKGS = nixpkgs;
packages =
with pkgs;
[
# Rust.
cargo
clippy
rustc
rustfmt
rust-analyzer
# External Cargo commands.
cargo-audit
cargo-edit
cargo-udeps
]
++ (lib.optionals stdenv.isDarwin [ libiconv ]);
};
}
);
}