crate2nix reborn

This commit is contained in:
Sridhar Ratnakumar 2021-04-08 13:10:55 -04:00
parent 35d3898e6b
commit 9cb3d4d960
3 changed files with 38 additions and 37 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target /target
/result /result
/result-lib

View file

@ -48,22 +48,6 @@
"type": "github" "type": "github"
} }
}, },
"gitignore": {
"flake": false,
"locked": {
"lastModified": 1611672876,
"narHash": "sha256-qHu3uZ/o9jBHiA3MEKHJ06k7w4heOhA+4HCSIvflRxo=",
"owner": "hercules-ci",
"repo": "gitignore",
"rev": "211907489e9f198594c0eb0ca9256a1949c9d412",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1617636226, "lastModified": 1617636226,
@ -99,7 +83,6 @@
"inputs": { "inputs": {
"crate2nix": "crate2nix", "crate2nix": "crate2nix",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay", "rust-overlay": "rust-overlay",
"utils": "utils" "utils": "utils"

View file

@ -1,13 +1,12 @@
# This file is pretty general, and you can adapt it in your project replacing
# only `name` and `description` below.
{ {
description = "bouncy"; description = "...";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore";
flake=false;
};
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
crate2nix = { crate2nix = {
url = "github:balsoft/crate2nix/tools-nix-version-comparison"; url = "github:balsoft/crate2nix/tools-nix-version-comparison";
@ -19,17 +18,20 @@
}; };
}; };
outputs = { self, nixpkgs, utils, gitignore, rust-overlay, crate2nix, ... }: outputs = { self, nixpkgs, utils, rust-overlay, crate2nix, ... }:
utils.lib.eachDefaultSystem let
name = "bouncy";
in utils.lib.eachDefaultSystem
(system: (system:
let let
# Imports
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ overlays = [
rust-overlay.overlay rust-overlay.overlay
(self: super: { (self: super: {
# Because rust-overlay bundles multiple rust packages into one # Because rust-overlay bundles multiple rust packages into one
# derivation, specify that mega-bundle here, so that naersk # derivation, specify that mega-bundle here, so that crate2nix
# will use them automatically. # will use them automatically.
rustc = self.rust-bin.stable.latest.default; rustc = self.rust-bin.stable.latest.default;
cargo = self.rust-bin.stable.latest.default; cargo = self.rust-bin.stable.latest.default;
@ -38,32 +40,47 @@
}; };
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) inherit (import "${crate2nix}/tools.nix" { inherit pkgs; })
generatedCargoNix; generatedCargoNix;
inherit (import gitignore { inherit (pkgs) lib; }) gitignoreSource;
# Create the cargo2nix project
project = pkgs.callPackage (generatedCargoNix { project = pkgs.callPackage (generatedCargoNix {
name = "bouncy"; inherit name;
src = gitignoreSource ./.; src = ./.;
}) { }) {
# Individual crate overrides go here # Individual crate overrides go here
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50 # 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;
} // buildEnvVars;
};
};
# Configuration for the non-Rust dependencies
buildInputs = with pkgs; [ openssl.dev ];
nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig ];
buildEnvVars = {
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
}; };
in rec { in rec {
packages.bouncy = project.rootCrate.build; packages.${name} = project.rootCrate.build;
# `nix build` # `nix build`
defaultPackage = packages.bouncy; defaultPackage = packages.${name};
# `nix run` # `nix run`
apps.bouncy = utils.lib.mkApp { apps.${name} = utils.lib.mkApp {
name = "bouncy"; inherit name;
drv = packages.bouncy; drv = packages.${name};
}; };
defaultApp = apps.bouncy; defaultApp = apps.${name};
# `nix develop` # `nix develop`
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ rustc cargo ]; inherit buildInputs nativeBuildInputs;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}; } // buildEnvVars;
} }
); );
} }