-
Notifications
You must be signed in to change notification settings - Fork 12
/
shell.nix
111 lines (99 loc) · 3.83 KB
/
shell.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
# fullAndroid implies withAndroid
{ fullAndroid ? false, withAndroid ? fullAndroid, withIos ? false, withEmbedded ? true }:
/*
based on
https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/9
*/
let
rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
pkgs = import <nixpkgs> { overlays = [ rust_overlay ]; config.android_sdk.accept_license = true; config.allowUnfree = true; };
lib = pkgs.lib;
rustVersion = "1.76.0";
rust = pkgs.rust-bin.stable.${rustVersion}.default.override {
extensions = [
"rust-src" # for rust-analyzer
];
targets = []
++ lib.optionals withEmbedded ["thumbv7em-none-eabihf"]
++ lib.optionals withAndroid ["x86_64-linux-android" "aarch64-linux-android"]
++ lib.optionals fullAndroid ["i686-linux-android" "armv7-linux-androideabi"]
++ lib.optionals withIos [ "aarch64-apple-ios-sim" "x86_64-apple-ios" "aarch64-apple-ios" ];
};
# hal is still using miniscript v9.0.1 which doesn't compile on >= 1.71
halRustPlatform = pkgs.makeRustPlatform {
cargo = pkgs.rust-bin.stable."1.70.0".minimal;
rustc = pkgs.rust-bin.stable."1.70.0".minimal;
};
hal = halRustPlatform.buildRustPackage rec {
pname = "hal";
version = "0.9.3";
src = pkgs.fetchFromGitHub {
owner = "stevenroose";
repo = pname;
rev = "v${version}";
hash = "sha256-QOp7YM/R8mhDVbSaABGjRqqqHW288UYWHxezz5dUAwU=";
};
cargoHash = "sha256-/+ld3zfyCpylEPUoGoOCBHiski2lle8QW+/zoW/PgmM=";
meta = with pkgs.lib; {
description = "the Bitcoin companion";
homepage = "https://github.com/stevenroose/hal";
license = licenses.unlicense;
maintainers = [];
};
};
android = lib.optionals withAndroid {
buildToolsVersion = "30.0.3";
cmakeVersion = "3.6.4111459";
};
androidShellHook = ''
# Add cmake to the path.
cmake_root="$(echo "$ANDROID_SDK_ROOT/cmake/${android.cmakeVersion}"*/)"
export PATH="$cmake_root/bin:$PATH"
# Write out local.properties for Android Studio.
cat <<EOF > ./sdk/libportal-android/local.properties
# This file was automatically generated by nix-shell.
sdk.dir=$ANDROID_SDK_ROOT
ndk.dir=$ANDROID_NDK_ROOT
cmake.dir=$cmake_root
EOF
'';
androidComposition = lib.optionals withAndroid pkgs.androidenv.composeAndroidPackages {
buildToolsVersions = [ android.buildToolsVersion ];
platformVersions = [ "33" ];
includeNDK = true;
ndkVersion = "23.1.7779620";
cmakeVersions = [ android.cmakeVersion ];
};
in
pkgs.mkShell rec {
buildInputs = [
pkgs.cmake
pkgs.SDL2
pkgs.fltk
pkgs.pango
pkgs.rust-analyzer
pkgs.pkg-config
pkgs.libusb
rust
]
++ lib.optionals withEmbedded (with pkgs; [ probe-rs gcc-arm-embedded qemu gdb openocd hal clang ])
++ lib.optionals withAndroid (with pkgs; [ cargo-ndk jdk ]);
RUST_BACKTRACE = 1;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
CC_thumbv7em_none_eabihf = lib.optionals withEmbedded "${pkgs.gcc-arm-embedded}/bin/arm-none-eabi-gcc";
ANDROID_SDK_ROOT = lib.optionals withAndroid "${androidComposition.androidsdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = lib.optionals withAndroid "${ANDROID_SDK_ROOT}/ndk-bundle";
# Ensures that we don't have to use a FHS env by using the nix store's aapt2.
GRADLE_OPTS = lib.optionals withAndroid "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${android.buildToolsVersion}/aapt2";
shellHook = ''
RED='\033[1;31m'
NC='\033[0m'
printf "$RED Warning: the shell.nix file is deprecated, please migrate to the flake$NC\n"
${
lib.optionalString withAndroid androidShellHook
}
${
lib.optionalString pkgs.stdenv.isDarwin ''export PATH="/usr/bin:$PATH"''
}
'';
}