Skip to content

Commit 2a65d99

Browse files
authored
fix flake.nix (#170)
* fix(flake.nix): add `SystemConfiguration` for Darwin * style(flake.nix): fix inputs style * feat(flake.nix): add naersk as an input * feat(flake.nix): rust-overlay * feat(rust-toolchain.toml): define toolchaines * feat(flake.nix): rewrite with naersk https://github.com/nix-community/naersk * style(flake.nix): make it one line * chore(flake.lock): update * chore(gitignore): ignore nix result directory
1 parent 541a06d commit 2a65d99

File tree

4 files changed

+116
-29
lines changed

4 files changed

+116
-29
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.DS_Store
44
.idea
55
.direnv/
6+
/result

Diff for: flake.lock

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

Diff for: flake.nix

+57-23
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,72 @@
11
{
22
description = "Leet your code in command-line.";
33

4-
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5-
inputs.utils.url = "github:numtide/flake-utils";
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
utils.url = "github:numtide/flake-utils";
67

7-
outputs = { self, nixpkgs, utils, ... }:
8+
naersk = {
9+
url = "github:nix-community/naersk";
10+
inputs.nixpkgs.follows = "nixpkgs";
11+
};
12+
13+
rust-overlay = {
14+
url = "github:oxalica/rust-overlay";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
17+
};
18+
19+
outputs = {
20+
self,
21+
nixpkgs,
22+
utils,
23+
naersk,
24+
rust-overlay,
25+
...
26+
}:
827
utils.lib.eachDefaultSystem (system:
928
let
10-
pkgs = import nixpkgs { inherit system; };
29+
overlays = [ (import rust-overlay) ];
30+
31+
pkgs = (import nixpkgs) {
32+
inherit system overlays;
33+
};
34+
35+
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
36+
37+
naersk' = pkgs.callPackage naersk {
38+
cargo = toolchain;
39+
rustc = toolchain;
40+
clippy = toolchain;
41+
};
1142

1243
nativeBuildInputs = with pkgs; [
1344
pkg-config
1445
];
1546

47+
darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
48+
pkgs.darwin.apple_sdk.frameworks.Security
49+
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
50+
];
51+
1652
buildInputs = with pkgs; [
1753
openssl
1854
dbus
1955
sqlite
20-
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
56+
] ++ darwinBuildInputs;
2157

22-
23-
package = with pkgs; rustPlatform.buildRustPackage rec {
58+
package = naersk'.buildPackage rec {
2459
pname = "leetcode-cli";
25-
version = "0.4.3";
26-
src = fetchCrate {
27-
inherit pname version;
28-
sha256 = "sha256-y5zh93WPWSMDXqYangqrxav+sC0b0zpFIp6ZIew6KMo=";
29-
};
30-
cargoSha256 = "sha256-VktDiLsU+GOsa6ba9JJZGEPTavSKp+aSZm2dfhPEqMs=";
60+
version = "git";
61+
62+
src = ./.;
63+
doCheck = true; # run `cargo test` on build
3164

3265
inherit buildInputs nativeBuildInputs;
3366

34-
# a nightly compiler is required unless we use this cheat code.
35-
RUSTC_BOOTSTRAP = 0;
67+
buildNoDefaultFeatures = true;
3668

37-
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
38-
CFG_RELEASE_CHANNEL = "stable";
69+
buildFeatures = "git";
3970

4071
meta = with pkgs.lib; {
4172
description = "Leet your code in command-line.";
@@ -44,9 +75,16 @@
4475
maintainers = with maintainers; [ congee ];
4576
mainProgram = "leetcode";
4677
};
78+
79+
# Env vars
80+
# a nightly compiler is required unless we use this cheat code.
81+
RUSTC_BOOTSTRAP = 0;
82+
83+
# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
84+
CFG_RELEASE_CHANNEL = "stable";
4785
};
4886
in
49-
{
87+
{
5088
defaultPackage = package;
5189
overlay = final: prev: { leetcode-cli = package; };
5290

@@ -55,11 +93,7 @@
5593
inherit nativeBuildInputs;
5694

5795
buildInputs = buildInputs ++ [
58-
rustc
59-
cargo
60-
rustfmt
61-
clippy
62-
rust-analyzer
96+
toolchain
6397
cargo-edit
6498
cargo-bloat
6599
cargo-audit

Diff for: rust-toolchain.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = [
4+
"rustc",
5+
"cargo",
6+
"rustfmt",
7+
"clippy",
8+
"rust-analyzer",
9+
]
10+
profile = "minimal"

0 commit comments

Comments
 (0)