-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
88 lines (79 loc) · 2.12 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
{
description = "nix-rust-template";
nixConfig.bash-prompt = "[nix]λ ";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
naersk = {
url = "github:nmattia/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, flake-utils, naersk, nixpkgs, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [
rust-overlay.overlay
naersk.overlay
];
pkgs = import nixpkgs {
inherit system overlays;
};
rust = pkgs.rust-bin.stable.latest.default;
naersk-lib = pkgs.naersk.override {
cargo = pkgs.rust-bin.nightly.latest.cargo;
rustc = rust;
};
rust-dev = rust.override {
extensions = [
"clippy-preview"
"rust-src"
"rustc-dev"
"rustfmt-preview"
];
};
in rec {
# `nix build`
packages.nix-rust-template = naersk-lib.buildPackage {
pname = "nix-rust-template";
root = ./.;
};
defaultPackage = packages.nix-rust-template;
# `nix run` or `nix run .#app`
apps.app = flake-utils.lib.mkApp {
drv = packages.nix-rust-template;
};
defaultApp = apps.app;
# `nix run .#watch`
apps.watch = flake-utils.lib.mkApp {
drv = pkgs.writeShellApplication {
name = "watch";
runtimeInputs = [
pkgs.cargo-watch
pkgs.gcc
rust
];
text = ''
cargo-watch -w "./src/" -x "run"
'';
};
};
# `nix develop`
devShell = pkgs.mkShell {
buildInputs = [
pkgs.cargo-edit
pkgs.cargo-watch
pkgs.rust-analyzer
];
nativeBuildInputs = [ rust-dev ];
};
}
);
}