Compare commits
No commits in common. "7d9b2d18187647060cd1b204d916ca0317739707" and "96b2edfb41eb6eed674c32e4576c432720b26959" have entirely different histories.
7d9b2d1818
...
96b2edfb41
134
flake.nix
134
flake.nix
|
@ -11,23 +11,14 @@
|
|||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
# Advisory db from rust-sec
|
||||
advisory-db = {
|
||||
url = "github:RustSec/advisory-db";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
description = "Rust Toolchain and Utility Flake";
|
||||
|
||||
outputs = { self, nixpkgs, utils, ... }@inputs:
|
||||
with builtins;
|
||||
let
|
||||
sources = fromJSON (readFile ./sources/sources.json);
|
||||
rustPackageNames = attrValues sources;
|
||||
# Build the rust packages we'll be using
|
||||
in (utils.lib.eachDefaultSystem (system: {
|
||||
(utils.lib.eachDefaultSystem (system: {
|
||||
packages = let
|
||||
sources = builtins.fromJSON (builtins.readFile ./sources/sources.json);
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import inputs.rust-overlay) ];
|
||||
|
@ -39,127 +30,10 @@
|
|||
rustc = rust;
|
||||
cargo = rust;
|
||||
};
|
||||
in mapAttrs (name: source:
|
||||
in builtins.mapAttrs (name: source:
|
||||
naersk-lib.buildPackage {
|
||||
pname = source.pname;
|
||||
src = pkgs.fetchCrate source;
|
||||
}) sources;
|
||||
})) //
|
||||
# Now provide our builder functions
|
||||
{
|
||||
# Build a rust flake with a single crate
|
||||
single = { src, crateName, sharedDeps ? (system: [ ])
|
||||
, sharedNativeDeps ? (system: [ ]) }:
|
||||
utils.lib.eachDefaultsystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ (import inputs.rust-overlay) ];
|
||||
};
|
||||
rust = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = [ "llvm-tools-preview" ];
|
||||
};
|
||||
naersk-lib = inputs.naersk.lib."${system}".override {
|
||||
rustc = rust;
|
||||
cargo = rust;
|
||||
};
|
||||
devBase = with pkgs;
|
||||
[
|
||||
# Build tools
|
||||
openssl
|
||||
pkg-config
|
||||
rust-analyzer
|
||||
cmake
|
||||
gnuplot
|
||||
# git tooling
|
||||
gitFull
|
||||
pre-commit
|
||||
git-lfs
|
||||
git-cliff
|
||||
# Formatters
|
||||
nixfmt
|
||||
python311Packages.mdformat
|
||||
] ++ map (x: self.packages.${system}.${x}) rustPackageNames;
|
||||
in rec {
|
||||
# Main binary
|
||||
packages.${crateName} = naersk-lib.buildPackage {
|
||||
pname = "${crateName}";
|
||||
buildInputs = sharedDeps system;
|
||||
nativeBuildInputs = sharedNativeDeps system;
|
||||
root = src;
|
||||
};
|
||||
# binary + tests
|
||||
packages.tests.${crateName} = naersk-lib.buildPackage {
|
||||
pname = "${crateName}";
|
||||
buildInputs = sharedDeps system;
|
||||
nativeBuildInputs = sharedNativeDeps system;
|
||||
root = src;
|
||||
doCheck = true;
|
||||
};
|
||||
# Docs
|
||||
packages.docs.${crateName} = naersk-lib.buildPackage {
|
||||
pname = "${crateName}";
|
||||
buildInputs = sharedDeps system;
|
||||
nativeBuildInputs = sharedNativeDeps system;
|
||||
root = src;
|
||||
dontBuild = true;
|
||||
doDoc = true;
|
||||
doDocFail = true;
|
||||
};
|
||||
|
||||
# Set the default package to the main binary
|
||||
defaultPackage = packages.${crateName};
|
||||
|
||||
# CI tasks
|
||||
packages.lints = {
|
||||
# lint formatting
|
||||
format.${crateName} = with import nixpkgs { inherit system; };
|
||||
stdenv.mkDerivation {
|
||||
name = "format lint";
|
||||
src = src;
|
||||
nativeBuildInputs = with pkgs;
|
||||
[ rust-bin.stable.latest.default ]
|
||||
++ (sharedNativeDeps system);
|
||||
buildInputs = sharedDeps system;
|
||||
buildPhase = "cargo fmt -- --check";
|
||||
installPhase = "mkdir -p $out; echo 'done'";
|
||||
};
|
||||
# audit against stored advisory db
|
||||
audit.${crateName} = with import nixpkgs { inherit system; };
|
||||
stdenv.mkDerivation {
|
||||
name = "audit lint";
|
||||
src = src;
|
||||
nativeBuildInputs = with pkgs;
|
||||
[ rust-bin.stable.latest.default cargo-audit ]
|
||||
++ (sharedNativeDeps system);
|
||||
buildInputs = sharedDeps system;
|
||||
buildPhase = ''
|
||||
export HOME=$TMP
|
||||
mkdir -p ~/.cargo
|
||||
cp -r ${advisory-db} ~/.cargo/advisory-db
|
||||
cargo audit -n
|
||||
'';
|
||||
installPhase = "mkdir -p $out; echo 'done'";
|
||||
};
|
||||
# Clippy
|
||||
clippy.${crateName} = naersk-lib.buildPackage {
|
||||
pname = "${crateName}";
|
||||
root = src;
|
||||
buildInputs = sharedDeps system;
|
||||
nativeBuildInputs = sharedNativeDeps system;
|
||||
cargoTestCommands = (old: [ "cargo $cargo_options clippy" ]);
|
||||
doCheck = true;
|
||||
dontBuild = true;
|
||||
};
|
||||
};
|
||||
|
||||
# Development environments
|
||||
devShell = pkgs.mkShell {
|
||||
inputsFrom = builtins.attrValues packages.${system};
|
||||
buildInputs = [ rust ] ++ devBase ++ (sharedDeps system)
|
||||
++ (sharedNativeDeps system);
|
||||
};
|
||||
|
||||
});
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
[package]
|
||||
name = "test-crate"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -1,25 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1683777345,
|
||||
"narHash": "sha256-V2p/A4RpEGqEZussOnHYMU6XglxBJGCODdzoyvcwig8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "635a306fc8ede2e34cb3dd0d6d0a5d49362150ed",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
inputs = { rust = { url = ./..; }; };
|
||||
description = "Simple Test Package";
|
||||
|
||||
outputs = { self, nixpkgs, rust }:
|
||||
rust.single {
|
||||
name = "test-crate";
|
||||
src = ./.;
|
||||
};
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Reference in New Issue