nix: add flake

This commit is contained in:
Jake Hillion 2024-04-29 21:20:48 +01:00
parent 3ebb457d5a
commit 3c6091106f
2 changed files with 35 additions and 0 deletions

View File

@ -1,2 +1,3 @@
README.md README.md
Cargo.toml Cargo.toml
flake.nix

34
flake.nix Normal file
View File

@ -0,0 +1,34 @@
{
description = "A flake for building ${REPO_NAME}.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, treefmt-nix, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.$${system};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
treefmtEval = treefmt-nix.lib.evalModule pkgs (pkgs: {
projectRootFile = "flake.nix";
programs.rustfmt.enable = true;
programs.nixfmt.enable = true;
});
in {
packages.default = pkgs.rustPlatform.buildRustPackage {
inherit (cargoToml.package) name version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
};
formatter = treefmtEval.config.build.wrapper;
});
}