generated from SKalt/rust-nix-project-template
/
flake.nix
100 lines (91 loc) · 3.41 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
{
description = "A language server to help write conventional commits.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils"; # TODO: pin
rust-overlay = {
url = "github:oxalica/rust-overlay"; # TODO: pin
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = { flake-utils, nixpkgs, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [(import rust-overlay)];
pkgs = (import nixpkgs) {
inherit system overlays;
};
rust_toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
base_info = (builtins.fromTOML (builtins.readFile ./pkg/base/Cargo.toml));
# pro_info = (builtins.fromTOML (builtins.readFile ./pkg/pro/Cargo.toml));
in {
# TODO: figure out how to build or cross-compile
packages = {
# For `nix build` & `nix run`:
# TODO: base, pro, default
base = pkgs.rustPlatform.buildRustPackage
{
# https://nixos.org/manual/nixpkgs/stable/#compiling-rust-applications-with-cargo
inherit cargoDeps;
cargoLock = { # TODO: see if this is needed
lockFile = ./Cargo.lock;
};
pname = "cconvention"; # overrides actual info in pkg/base/Cargo.toml
version = base_info.package.version;
src = ./.;
# > One caveat is that Cargo.lock cannot be patched in the patchPhase because it runs after the dependencies have already been fetched.
# > Note that setting cargoLock.lockFile or cargoLock.lockFileContents doesn’t add a Cargo.lock to your src, and a Cargo.lock is still required to build a rust package.
# > -- https://nixos.org/manual/nixpkgs/stable/#importing-a-cargo.lock-file
# postPatch = ''
# ln -s ${./Cargo.lock} Cargo.lock
# '';
nativeBuildInputs = [rust_toolchain];
};
};
# For `nix develop`:
devShell = pkgs.mkShell {
# see https://github.com/NixOS/nixpkgs/issues/52447
# see https://hoverbear.org/blog/rust-bindgen-in-nix/
# see https://slightknack.dev/blog/nix-os-bindgen/
# https://nixos.wiki/wiki/Rust#Installation_via_rustup
nativeBuildInputs = [rust_toolchain];
buildInputs = with pkgs;
[
# rust tools
cargo-bloat
rust-analyzer-unwrapped
cargo-cross
zig # temp
cargo-zigbuild
llvmPackages_16.bintools
# nix support
nixpkgs-fmt
nil
# for recording demos
vhs
ttyd
ffmpeg
libfaketime
git
bashInteractive
# JS/TS development
nodejs_18
nodejs_18.pkgs.pnpm
# demo editors
helix
vim
neovim
# other
lychee
shellcheck
];
};
# Environment variables
RUST_SRC_PATH = "${rust_toolchain}/lib/rustlib/src/rust/library";
}
);
}