forked from jacg/iced-test-drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
123 lines (107 loc) · 4.7 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
# The core functionality is provided here using flakes. Legacy support for
# `nix-shell` is provided by a wrapper in `shell.nix`.
{
description = "Rust development environment";
inputs = {
# Version pinning is managed in flake.lock. Upgrading can be done with
# something like
#
# nix flake lock --update-input nixpkgs
nixpkgs .url = "github:nixos/nixpkgs/nixos-22.05";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils .url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
# Option 1: try to support each default system
flake-utils.lib.eachDefaultSystem # NB Some packages in nixpkgs are not supported on some systems
# Option 2: try to support selected systems
# flake-utils.lib.eachSystem ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"]
(system:
let pkgs = import nixpkgs {
inherit system;
overlays = [
# ===== Specification of the rust toolchain to be used ====================
rust-overlay.overlays.default (final: prev:
let
# If you have a rust-toolchain file for rustup, set `choice =
# rust-tcfile` further down to get the customized toolchain
# derivation.
rust-tcfile = final.rust-bin.fromRustupToolchainFile ./rust-toolchain;
rust-latest = final.rust-bin.stable .latest ;
rust-beta = final.rust-bin.beta .latest ;
rust-nightly = final.rust-bin.nightly."2022-08-13";
rust-stable = final.rust-bin.stable ."1.63.0" ; # nix flake lock --update-input rust-overlay
rust-analyzer-preview-on = date:
final.rust-bin.nightly.${date}.default.override {
extensions = [ "rust-analyzer-preview" ];
};
in
rec {
# The version of the Rust system to be used in buildInputs.
# Set `choice` to `rust-<choice>` where `<choice>` is one of
# tcfile / latest / beta / nightly / stable
# (see names set above)
choice = rust-stable;
rust-tools = choice.default.override {
# extensions = [];
# targets = [ "wasm32-unknown-unknown" ];
};
rust-analyzer-preview = rust-analyzer-preview-on "2022-08-13";
rust-src = rust-stable.rust-src;
})
];
};
# X11 support
libPath = pkgs.lib.makeLibraryPath [
pkgs.libGL
pkgs.libxkbcommon
(linux pkgs.wayland)
pkgs.xorg.libX11
pkgs.xorg.libXcursor
pkgs.xorg.libXi
pkgs.xorg.libXrandr
pkgs.vulkan-loader
];
# ----- Conditional inclusion ----------------------------------------------------
nothing = pkgs.coreutils;
linux = drvn: if pkgs.stdenv.isLinux then drvn else nothing;
darwin = drvn: if pkgs.stdenv.isDarwin then drvn else nothing;
linuxList = list: if pkgs.stdenv.isLinux then list else [];
darwinList = list: if pkgs.stdenv.isDarwin then list else [];
darwinStr = str: if pkgs.stdenv.isDarwin then str else "";
# ----- Darwin-specific ----------------------------------------------------------
darwin-frameworks = pkgs.darwin.apple_sdk.frameworks;
in
{
devShell = pkgs.mkShell {
name = "my-rust-project";
buildInputs = [
pkgs.rust-tools
pkgs.rust-analyzer-preview
pkgs.cargo-nextest
pkgs.just
pkgs.cmake
pkgs.fontconfig
pkgs.pkg-config
];
packages = [
pkgs.lolcat
pkgs.exa
];
shellHook =
''
export PS1="rust devshell> "
alias foo='cowsay Foo'
alias bar='exa -l | lolcat'
alias baz='cowsay What is the difference between buildIntputs and packages? | lolcat'
'';
RUST_SRC_PATH = "${pkgs.rust-src}/lib/rustlib/src/rust/library";
LD_LIBRARY_PATH = libPath;
};
}
);
}