Skip to content

Commit 21c2b45

Browse files
committed
feat(flake.nix): rewrite with naersk
https://github.com/nix-community/naersk
1 parent e1760de commit 21c2b45

File tree

3 files changed

+83
-14
lines changed

3 files changed

+83
-14
lines changed

Diff for: flake.lock

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flake.nix

+40-13
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,57 @@
1818
};
1919
};
2020

21+
outputs = {
22+
self,
23+
nixpkgs,
24+
utils,
25+
naersk,
26+
rust-overlay,
27+
...
28+
}:
2129
utils.lib.eachDefaultSystem (system:
2230
let
23-
pkgs = import nixpkgs { inherit system; };
31+
overlays = [ (import rust-overlay) ];
32+
33+
pkgs = (import nixpkgs) {
34+
inherit system overlays;
35+
};
36+
37+
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
38+
39+
naersk' = pkgs.callPackage naersk {
40+
cargo = toolchain;
41+
rustc = toolchain;
42+
clippy = toolchain;
43+
};
2444

2545
nativeBuildInputs = with pkgs; [
2646
pkg-config
2747
];
2848

49+
darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
50+
pkgs.darwin.apple_sdk.frameworks.Security
51+
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
52+
];
53+
2954
buildInputs = with pkgs; [
3055
openssl
3156
dbus
3257
sqlite
33-
] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]);
34-
58+
] ++ darwinBuildInputs;
3559

36-
package = with pkgs; rustPlatform.buildRustPackage rec {
60+
package = naersk'.buildPackage rec {
3761
pname = "leetcode-cli";
3862
version = "git";
63+
3964
src = ./.;
65+
doCheck = true; # run `cargo test` on build
4066

4167
inherit buildInputs nativeBuildInputs;
4268

43-
# a nightly compiler is required unless we use this cheat code.
44-
RUSTC_BOOTSTRAP = 0;
69+
buildNoDefaultFeatures = true;
4570

46-
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
47-
CFG_RELEASE_CHANNEL = "stable";
71+
buildFeatures = "git";
4872

4973
meta = with pkgs.lib; {
5074
description = "Leet your code in command-line.";
@@ -53,6 +77,13 @@
5377
maintainers = with maintainers; [ congee ];
5478
mainProgram = "leetcode";
5579
};
80+
81+
# Env vars
82+
# a nightly compiler is required unless we use this cheat code.
83+
RUSTC_BOOTSTRAP = 0;
84+
85+
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
86+
CFG_RELEASE_CHANNEL = "stable";
5687
};
5788
in
5889
{
@@ -64,11 +95,7 @@
6495
inherit nativeBuildInputs;
6596

6697
buildInputs = buildInputs ++ [
67-
rustc
68-
cargo
69-
rustfmt
70-
clippy
71-
rust-analyzer
98+
toolchain
7299
cargo-edit
73100
cargo-bloat
74101
cargo-audit

Diff for: rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
2-
channel = "nightly"
2+
channel = "stable"
33
components = [
44
"rustc",
55
"cargo",

0 commit comments

Comments
 (0)