-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathflake.nix
108 lines (96 loc) · 3.07 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
# SPDX-FileCopyrightText: 2024-2025 Akira Komamura
# SPDX-License-Identifier: Unlicense
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
treefmt-nix.url = "github:numtide/treefmt-nix";
rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";
};
# Add settings for your binary cache.
# nixConfig = {
# extra-substituters = [
# ];
# extra-trusted-public-keys = [
# ];
# };
outputs =
inputs@{ nixpkgs, flake-parts, ... }:
let
# For details on these options, See
# https://github.com/oxalica/rust-overlay?tab=readme-ov-file#cheat-sheet-common-usage-of-rust-bin
#
# Channel of the Rust toolchain (stable or beta).
rustChannel = "stable";
# Version (latest or specific date/semantic version)
rustVersion = "latest";
# Profile (default or minimal)
rustProfile = "default";
in
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem =
{
config,
system,
pkgs,
lib,
craneLib,
commonArgs,
...
}:
{
_module.args = {
pkgs = import nixpkgs {
inherit system;
overlays = [ inputs.rust-overlay.overlays.default ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (
pkgs: pkgs.rust-bin.${rustChannel}.${rustVersion}.${rustProfile}
);
commonArgs = {
# Depending on your code base, you may have to customize the
# source filtering to include non-standard files during the build.
# See
# https://crane.dev/source-filtering.html?highlight=source#source-filtering
src = craneLib.cleanCargoSource (craneLib.path ./.);
# nativeBuildInputs = with pkgs; [
# pkg-config
# ];
# buildInputs = with pkgs; [
# openssl
# ];
};
};
# Build the executable package.
packages.default = craneLib.buildPackage (
commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
}
);
devShells.default = craneLib.devShell {
packages =
(commonArgs.nativeBuildInputs or [ ])
++ (commonArgs.buildInputs or [ ])
++ [ pkgs.rust-analyzer-unwrapped ];
RUST_SRC_PATH = "${
pkgs.rust-bin.${rustChannel}.${rustVersion}.rust-src
}/lib/rustlib/src/rust/library";
};
treefmt = {
projectRootFile = "Cargo.toml";
programs = {
actionlint.enable = true;
nixfmt.enable = true;
rustfmt.enable = true;
};
};
};
};
}