/
flake.nix
133 lines (123 loc) · 5.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
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
125
126
127
128
129
130
131
132
133
{
description = "orb-software flake";
inputs = {
# Worlds largest repository of linux software
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Provides eachDefaultSystem and other utility functions
utils.url = "github:numtide/flake-utils";
# Replacement for rustup
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Replaces the need to have a git submodule.
seekSdk = {
url = "github:worldcoin/seek-thermal-sdk";
flake = false;
};
};
outputs = { self, nixpkgs, utils, fenix, seekSdk }:
# This helper function is used to more easily abstract
# over the host platform.
# See https://github.com/numtide/flake-utils#eachdefaultsystem--system---attrs
utils.lib.eachDefaultSystem (system:
let
p = {
# The platform that you are running nix on and building from
native = nixpkgs.legacyPackages.${system};
# The other platforms we support for cross compilation
arm-linux = nixpkgs.legacyPackages.aarch64-linux;
x86-linux = nixpkgs.legacyPackages.x86_64-linux;
arm-macos = nixpkgs.legacyPackages.aarch64-darwin;
x86-macos = nixpkgs.legacyPackages.x86_64-darwin;
};
# p.native.lib.asserts.assertOneOf "system" system ["aarch64-linux"];
seekSdkPath = seekSdk + "/Seek_Thermal_SDK_4.1.0.0";
# Gets the same rust toolchain that rustup would have used.
# Note: You don't *have* to do the build with `nix build`,
# you can still `cargo zigbuild`.
rustToolchain = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-+syqAd2kX8KVa8/U2gz3blIQTTsYYt3U63xBWaGOSc8=";
};
rustPlatform = p.native.makeRustPlatform {
inherit (rustToolchain) cargo rustc;
};
macFrameworks = with p.native.darwin.apple_sdk.frameworks; [
SystemConfiguration
AudioUnit
];
# Set PKG_CONFIG_PATH for the cross-compiled libraries
# rust's `pkg-config` build script will prioritize env vars
# suffixed with the target artchitecture.
makePkgConfigPath = p: p.lib.concatStringsSep ":" ([
"${p.libsodium.dev}/lib/pkgconfig"
"${p.openssl.dev}/lib/pkgconfig"
] ++ p.lib.lists.optionals p.stdenv.isLinux [
"${p.alsaLib.dev}/lib/pkgconfig"
]);
pkgConfigPath = {
native = makePkgConfigPath p.native;
arm-linux = makePkgConfigPath p.arm-linux;
x86-linux = makePkgConfigPath p.x86-linux;
arm-macos = makePkgConfigPath p.arm-macos;
x86-macos = makePkgConfigPath p.x86-macos;
};
in
# See https://nixos.wiki/wiki/Flakes#Output_schema
{
# Everything in here becomes your shell (nix develop)
devShells.default = p.native.mkShell.override
{
stdenv = p.native.clangStdenv;
}
{
# Nix makes the following list of dependencies available to the development
# environment.
buildInputs = (with p.native; [
# Needed for cargo zigbuild
zig
cargo-zigbuild
# Needed for packaging for orb-os
cargo-deb
# Used by various rust build scripts to find system libs
# Note that this is the unwrapped version of pkg-config. By default,
# nix wraps pkg-config with a script that replaces the PKG_CONFIG_PATH
# with the proper settings for cross compilation. We already set these
# env variables ourselves and don't want nix overwriting them, so we
# use the unwrapped version.
pkg-config-unwrapped
# Useful
cargo-deny
cargo-expand
cargo-binutils
protobuf
nixpkgs-fmt
# python stuff
python3
black
# This is missing on mac m1 nix, for some reason.
# see https://stackoverflow.com/a/69732679
libiconv
]) ++ [
rustToolchain
rustPlatform.bindgenHook # Configures bindgen to use nix clang
] ++ p.native.lib.lists.optionals p.native.stdenv.isDarwin [
macFrameworks
];
# The following sets up environment variables for the shell. These are used
# by the build.rs build scripts of the rust crates.
shellHook = ''
export SEEK_SDK_PATH="${seekSdkPath}";
export PKG_CONFIG_ALLOW_CROSS=1;
export PKG_CONFIG_PATH_aarch64_unknown_linux_gnu="${pkgConfigPath.arm-linux}";
export PKG_CONFIG_PATH_x86_64_unknown_linux_gnu="${pkgConfigPath.x86-linux}";
export PKG_CONFIG_PATH_aarch64_apple_darwin="${pkgConfigPath.arm-macos}";
export PKG_CONFIG_PATH_x86_64_apple_darwin="${pkgConfigPath.x86-macos}";
'';
};
# Lets you type `nix fmt` to format the flake.
formatter = p.native.nixpkgs-fmt;
}
);
}