diff options
author | Simon THOBY <git@nightmared.fr> | 2022-11-08 19:46:41 +0100 |
---|---|---|
committer | Simon THOBY <git@nightmared.fr> | 2022-11-08 22:07:58 +0100 |
commit | 92413e071b58db591eb838a1a0e37b7e6bb415c7 (patch) | |
tree | 500191c3b6c86bbbf3b88d1797d399639736278a /flake.nix | |
parent | d7c0d6721148a63a78666274cf57ae68ddfb2b01 (diff) |
add rules for building/developing with the nix package manager
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..861979e --- /dev/null +++ b/flake.nix @@ -0,0 +1,63 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixpkgs-mozilla = { url = "github:mozilla/nixpkgs-mozilla"; flake = false; }; + crate2nix = { url = "github:kolloch/crate2nix/master"; flake = false; }; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, nixpkgs-mozilla, crate2nix, utils } @ inputs : + let + rustOverlay = (final: prev: + let + rustChannel = prev.rustChannelOf { + channel = "1.65.0"; + sha256 = "DzNEaW724O8/B8844tt5AVHmSjSQ3cmzlU4BP90oRlY="; + }; + in + { + inherit rustChannel; + rustc = rustChannel.rust; + cargo = rustChannel.rust; + } + ); + rustDevOverlay = final: prev: { + # rust-analyzer needs core source + rustc-with-src = prev.rustc.override { extensions = [ "rust-src" ]; }; + }; + in + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import "${nixpkgs-mozilla}/rust-overlay.nix") rustOverlay rustDevOverlay ]; + }; + customBuildCrate = pkgs: pkgs.buildRustCrate.override { + defaultCrateOverrides = pkgs.defaultCrateOverrides // { + rustables = attrs: with pkgs; { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ clang linuxHeaders ]; + LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; + }; + }; + }; + cargoNix = import ./Cargo.nix { + inherit pkgs; + buildRustCrateForPkgs = customBuildCrate; + release = false; + }; + in { + defaultPackage = cargoNix.rootCrate.build; + packages = { + rustables = cargoNix.rootCrate.build; + }; + devShell = pkgs.mkShell { + name = "rustables"; + nativeBuildInputs = cargoNix.rootCrate.build.nativeBuildInputs; + BuildInputs = cargoNix.rootCrate.build.dependencies; + packages = with pkgs; [ rust-analyzer rustc-with-src ]; + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; + }; + } + ); +} |