Skip to content

Commit

Permalink
fix flake.nix (#170)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ryoppippi authored Oct 12, 2024
1 parent 541a06d commit 2a65d99
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.DS_Store
.idea
.direnv/
/result
54 changes: 48 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 57 additions & 23 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
{
description = "Leet your code in command-line.";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.utils.url = "github:numtide/flake-utils";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, utils, ... }:
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
utils,
naersk,
rust-overlay,
...
}:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
overlays = [ (import rust-overlay) ];

pkgs = (import nixpkgs) {
inherit system overlays;
};

toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

naersk' = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
clippy = toolchain;
};

nativeBuildInputs = with pkgs; [
pkg-config
];

darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];

buildInputs = with pkgs; [
openssl
dbus
sqlite
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
] ++ darwinBuildInputs;


package = with pkgs; rustPlatform.buildRustPackage rec {
package = naersk'.buildPackage rec {
pname = "leetcode-cli";
version = "0.4.3";
src = fetchCrate {
inherit pname version;
sha256 = "sha256-y5zh93WPWSMDXqYangqrxav+sC0b0zpFIp6ZIew6KMo=";
};
cargoSha256 = "sha256-VktDiLsU+GOsa6ba9JJZGEPTavSKp+aSZm2dfhPEqMs=";
version = "git";

src = ./.;
doCheck = true; # run `cargo test` on build

inherit buildInputs nativeBuildInputs;

# a nightly compiler is required unless we use this cheat code.
RUSTC_BOOTSTRAP = 0;
buildNoDefaultFeatures = true;

# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
CFG_RELEASE_CHANNEL = "stable";
buildFeatures = "git";

meta = with pkgs.lib; {
description = "Leet your code in command-line.";
Expand All @@ -44,9 +75,16 @@
maintainers = with maintainers; [ congee ];
mainProgram = "leetcode";
};

# Env vars
# a nightly compiler is required unless we use this cheat code.
RUSTC_BOOTSTRAP = 0;

# CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable";
CFG_RELEASE_CHANNEL = "stable";
};
in
{
{
defaultPackage = package;
overlay = final: prev: { leetcode-cli = package; };

Expand All @@ -55,11 +93,7 @@
inherit nativeBuildInputs;

buildInputs = buildInputs ++ [
rustc
cargo
rustfmt
clippy
rust-analyzer
toolchain
cargo-edit
cargo-bloat
cargo-audit
Expand Down
10 changes: 10 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[toolchain]
channel = "stable"
components = [
"rustc",
"cargo",
"rustfmt",
"clippy",
"rust-analyzer",
]
profile = "minimal"

0 comments on commit 2a65d99

Please sign in to comment.