Skip to content

Commit

Permalink
Add flake to have the toolchain anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 11, 2024
1 parent 53f65b9 commit 33f9ff0
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 1 deletion.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/target
/Cargo.lock
*coverage*
.direnv
106 changes: 106 additions & 0 deletions flake.lock

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

75 changes: 75 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
inputs = {
flake-utils = { url = "github:numtide/flake-utils"; };
nixpkgs = { url = "github:NixOS/nixpkgs/nixos-unstable"; };
rust-overlay =
{
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs =
{ self, nixpkgs, flake-utils, rust-overlay, crane }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src = craneLib.cleanCargoSource (craneLib.path ./.);

buildInputs = with pkgs; [ pkgs.stdenv.cc.cc ];
nativeBuildInputs = with pkgs; [
rustToolchain
clang
mold
curl
]
++ lib.optionals pkgs.stdenv.isLinux [ autoPatchelfHook ]
++ lib.optionals pkgs.stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
SystemConfiguration
Security
]);
commonArgs = {
pname = "ktls";
version = "latest";
strictDeps = true;
dontStrip = true;
# workaround for https://github.com/NixOS/nixpkgs/issues/166205
env = with pkgs; lib.optionalAttrs stdenv.cc.isClang {
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};
inherit src buildInputs nativeBuildInputs;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
bin = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
});
in
with pkgs;
{
packages = {
inherit bin;
default = bin;
};
devShells.default = mkShell {
inputsFrom = [ bin ];
packages = with pkgs; [ just nixpkgs-fmt ];
};
}
);
}
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "stable"
components = ["llvm-tools", "clippy", "rust-src"]

0 comments on commit 33f9ff0

Please sign in to comment.