nix: add Nix flake

Add the Nix flake machinery for developing using Nix tooling.

This requires that the following are added:
- Cargo.lock
- rust-toolchain

To ensure that versions are pinned.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2024-03-13 14:32:14 +00:00
parent b4ca7f31db
commit a37a40ee5e
7 changed files with 1689 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
use flake
-1
View File
@@ -1,7 +1,6 @@
target
.vscode
tags
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
Generated
+1306
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -7,3 +7,4 @@ members = [
"test",
]
resolver = "2"
package.version = "0.18.0"
Generated
+175
View File
@@ -0,0 +1,175 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1710178103,
"narHash": "sha256-Zg8JWAjMWHXtpUI7/nUC8iq3jKONLNSGQSBno5Rho8A=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "61f79bd5454eb6999417bea4701aa101c0897410",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1710003968,
"narHash": "sha256-g8+K+mLiNG5uch35Oy9oDQBAmGSkCcqrd0Jjme7xiG0=",
"owner": "ipetkov",
"repo": "crane",
"rev": "10484f86201bb94bd61ecc5335b1496794fedb78",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": "nixpkgs",
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1710310970,
"narHash": "sha256-YREcSnbDH7Es6MDvhmzPBBF3exEg2EP4sd3QCiPyWyI=",
"owner": "nix-community",
"repo": "fenix",
"rev": "df74cae97f59a868ad355af6a703e7845d0ae648",
"type": "github"
},
"original": {
"id": "fenix",
"type": "indirect"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1709961763,
"narHash": "sha256-6H95HGJHhEZtyYA3rIQpvamMKAGoa8Yh2rFV29QnuGw=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "3030f185ba6a4bf4f18b87f345f104e6a6961f34",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1710307192,
"narHash": "sha256-KZMc4hMS21gfneaMGZpdpMWsCFQdtiS0X9lGHIxERW0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7e972d239d09f5b7db6a43658d7888f4aa9eea1d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1710248332,
"narHash": "sha256-5Ozfx1xSscOrdCQoTLvcJHTtxgQ15YrXpjqce4vdzkQ=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "a2e274142f35d21fd28d28655f4af8e8531ab649",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1710295923,
"narHash": "sha256-B7wIarZOh5nNnj4GTOOYcxAwVGTO8y0dRSOzd6PtYE8=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "a30facbf72f29e5c930f394f637559f46a855e8b",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
+205
View File
@@ -0,0 +1,205 @@
{
description = "Improved types and functionality for using Git in Radicle";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
flake-utils.url = "github:numtide/flake-utils";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
nixConfig = {
keepOutputs = true;
};
outputs = {
self,
nixpkgs,
crane,
fenix,
flake-utils,
advisory-db,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pname = "radicle-git";
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
inherit (pkgs) lib;
rustToolChain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolChain;
srcFilters = path: type:
# Allow data/git-platinum.tgz
(lib.hasSuffix "\.tgz" path)
||
# Default filter from crane (allow .rs files)
(craneLib.filterCargoSources path type);
src = lib.cleanSourceWith {
src = ./.;
filter = srcFilters;
};
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit pname;
inherit src;
strictDeps = true;
buildInputs =
[
pkgs.git
# Add additional build inputs here
]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts =
craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
radicle-git-ext = craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./radicle-git-ext/Cargo.toml;});
doCheck = false;
inherit cargoArtifacts;
});
radicle-std-ext = craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./radicle-std-ext/Cargo.toml;});
doCheck = false;
inherit cargoArtifacts;
});
radicle-surf = craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./radicle-surf/Cargo.toml;});
inherit cargoArtifacts;
doCheck = false;
});
# Test crates
radicle-git-ext-test = craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./radicle-git-ext/t/Cargo.toml;});
inherit cargoArtifacts;
doCheck = false;
});
radicle-surf-test = craneLib.buildPackage (commonArgs
// {
inherit (craneLib.crateNameFromCargoToml {cargoToml = ./radicle-surf/t/Cargo.toml;});
inherit cargoArtifacts;
doCheck = false;
});
in {
# Formatter
formatter = pkgs.alejandra;
# Set of checks that are run: `nix flake check`
checks = {
# Build the crate as part of `nix flake check` for convenience
inherit radicle-git-ext;
inherit radicle-surf;
inherit radicle-git-ext-test;
inherit radicle-surf-test;
# Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
doc = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts;
});
# Check formatting
fmt = craneLib.cargoFmt {
inherit pname;
inherit src;
};
# Audit dependencies
audit = craneLib.cargoAudit {
inherit src advisory-db;
};
# Audit licenses
deny = craneLib.cargoDeny {
inherit pname;
inherit src;
};
# Run tests with cargo-nextest
nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
nativeBuildInputs = [
# git is required so the sandbox can access it.
pkgs.git
];
# Ensure dev is used since we rely on env variables being
# set in tests.
buildPhase = ''
export CARGO_PROFILE=dev;
'';
});
};
packages = {
inherit radicle-git-ext;
inherit radicle-surf;
inherit radicle-git-ext-test;
inherit radicle-surf-test;
};
devShells.default = craneLib.devShell {
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = [
pkgs.cargo-deny
pkgs.cargo-nextest
pkgs.cargo-watch
pkgs.ripgrep
pkgs.rust-analyzer
];
};
});
}
+1
View File
@@ -0,0 +1 @@
1.76