2021-04-08 19:10:55 +02:00
|
|
|
# This file is pretty general, and you can adapt it in your project replacing
|
|
|
|
# only `name` and `description` below.
|
|
|
|
|
2021-04-07 00:17:50 +02:00
|
|
|
{
|
2021-04-10 18:10:57 +02:00
|
|
|
description = "My awesome Rust project";
|
2021-04-07 00:17:50 +02:00
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
2021-04-08 01:07:41 +02:00
|
|
|
utils.url = "github:numtide/flake-utils";
|
2021-04-08 06:06:28 +02:00
|
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
2021-04-08 04:39:02 +02:00
|
|
|
crate2nix = {
|
2021-04-08 19:14:11 +02:00
|
|
|
url = "github:kolloch/crate2nix";
|
2021-04-08 04:39:02 +02:00
|
|
|
flake = false;
|
|
|
|
};
|
2021-04-07 05:25:05 +02:00
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
};
|
2021-04-07 00:17:50 +02:00
|
|
|
};
|
|
|
|
|
2021-04-08 19:10:55 +02:00
|
|
|
outputs = { self, nixpkgs, utils, rust-overlay, crate2nix, ... }:
|
2021-04-09 03:27:32 +02:00
|
|
|
let
|
2021-04-08 19:10:55 +02:00
|
|
|
name = "bouncy";
|
2021-04-09 03:27:32 +02:00
|
|
|
in
|
|
|
|
utils.lib.eachDefaultSystem
|
2021-04-07 05:42:32 +02:00
|
|
|
(system:
|
2021-04-09 03:27:32 +02:00
|
|
|
let
|
2021-04-08 19:10:55 +02:00
|
|
|
# Imports
|
2021-04-09 03:27:32 +02:00
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [
|
2021-04-08 06:06:28 +02:00
|
|
|
rust-overlay.overlay
|
|
|
|
(self: super: {
|
|
|
|
# Because rust-overlay bundles multiple rust packages into one
|
2021-04-08 19:10:55 +02:00
|
|
|
# derivation, specify that mega-bundle here, so that crate2nix
|
2021-04-08 06:06:28 +02:00
|
|
|
# will use them automatically.
|
|
|
|
rustc = self.rust-bin.stable.latest.default;
|
|
|
|
cargo = self.rust-bin.stable.latest.default;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
2021-04-08 04:39:02 +02:00
|
|
|
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; })
|
|
|
|
generatedCargoNix;
|
2021-04-08 19:10:55 +02:00
|
|
|
|
|
|
|
# Create the cargo2nix project
|
2021-04-09 03:27:32 +02:00
|
|
|
project = pkgs.callPackage
|
|
|
|
(generatedCargoNix {
|
|
|
|
inherit name;
|
|
|
|
src = ./.;
|
|
|
|
})
|
|
|
|
{
|
|
|
|
# Individual crate overrides go here
|
|
|
|
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50
|
|
|
|
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
|
|
|
|
# The himalaya crate itself is overriden here. Typically we
|
|
|
|
# configure non-Rust dependencies (see below) here.
|
|
|
|
${name} = oldAttrs: {
|
|
|
|
inherit buildInputs nativeBuildInputs;
|
2021-04-10 05:31:48 +02:00
|
|
|
};
|
2021-04-09 03:27:32 +02:00
|
|
|
};
|
2021-04-08 19:10:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# Configuration for the non-Rust dependencies
|
|
|
|
buildInputs = with pkgs; [ openssl.dev ];
|
2021-04-09 03:27:32 +02:00
|
|
|
nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig nixpkgs-fmt ];
|
|
|
|
in
|
|
|
|
rec {
|
2021-04-08 19:10:55 +02:00
|
|
|
packages.${name} = project.rootCrate.build;
|
2021-04-08 04:39:02 +02:00
|
|
|
|
2021-04-08 01:07:41 +02:00
|
|
|
# `nix build`
|
2021-04-08 19:10:55 +02:00
|
|
|
defaultPackage = packages.${name};
|
2021-04-08 01:07:41 +02:00
|
|
|
|
|
|
|
# `nix run`
|
2021-04-08 19:10:55 +02:00
|
|
|
apps.${name} = utils.lib.mkApp {
|
|
|
|
inherit name;
|
|
|
|
drv = packages.${name};
|
2021-04-08 01:07:41 +02:00
|
|
|
};
|
2021-04-08 19:10:55 +02:00
|
|
|
defaultApp = apps.${name};
|
2021-04-08 01:07:41 +02:00
|
|
|
|
|
|
|
# `nix develop`
|
2021-04-09 03:27:32 +02:00
|
|
|
devShell = pkgs.mkShell
|
|
|
|
{
|
|
|
|
inherit buildInputs nativeBuildInputs;
|
|
|
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
2021-04-10 05:31:48 +02:00
|
|
|
};
|
2021-04-07 00:17:50 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|