chore: update template
This commit is contained in:
parent
9af4e6c6c2
commit
ed51574014
5 changed files with 117 additions and 113 deletions
|
@ -1,6 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["Sridhar Ratnakumar <srid@srid.ca>"]
|
authors = ["Toby <toby@tobot.dev>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
# If you change the name here, you must also do it in flake.nix (and run `cargo generate-lockfile` afterwards)
|
|
||||||
name = "rust-nix-template"
|
name = "rust-nix-template"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
92
flake.lock
generated
92
flake.lock
generated
|
@ -1,64 +1,33 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"flake-parts": {
|
"fenix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1696343447,
|
"lastModified": 1714631076,
|
||||||
"narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=",
|
"narHash": "sha256-at4+1R9gx3CGvX0ZJo9GwDZyt3RzOft7qDCTsYHjI4M=",
|
||||||
"owner": "hercules-ci",
|
"owner": "nix-community",
|
||||||
"repo": "flake-parts",
|
"repo": "fenix",
|
||||||
"rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4",
|
"rev": "22a9eb3f20dd340d084cee4426f386a90b1351ca",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "hercules-ci",
|
"owner": "nix-community",
|
||||||
"repo": "flake-parts",
|
"repo": "fenix",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1704626572,
|
"lastModified": 1714635257,
|
||||||
"narHash": "sha256-VwRTEKzK4wSSv64G+g3RLF3t6yBHrhR2VK3kZ5UWisU=",
|
"narHash": "sha256-4cPymbty65RvF1DWQfc+Bc8B233A1BWxJnNULJKQ1EY=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "24fe8bb4f552ad3926274d29e083b79d84707da6",
|
"rev": "63c3a29ca82437c87573e4c6919b09a24ea61b0f",
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs-lib": {
|
|
||||||
"locked": {
|
|
||||||
"dir": "lib",
|
|
||||||
"lastModified": 1696019113,
|
|
||||||
"narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"dir": "lib",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixos-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1695644571,
|
|
||||||
"narHash": "sha256-asS9dCCdlt1lPq0DLwkVBbVoEKuEuz+Zi3DG7pR/RxA=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "6500b4580c2a1f3d0f980d32d285739d8e156d92",
|
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -70,37 +39,40 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts",
|
"fenix": "fenix",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"systems": "systems",
|
|
||||||
"treefmt-nix": "treefmt-nix"
|
"treefmt-nix": "treefmt-nix"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"rust-analyzer-src": {
|
||||||
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681028828,
|
"lastModified": 1714572655,
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
"narHash": "sha256-xjD8vmit0Nz1qaSSSpeXOK3saSvAZtOGHS2SHZE75Ek=",
|
||||||
"owner": "nix-systems",
|
"owner": "rust-lang",
|
||||||
"repo": "default",
|
"repo": "rust-analyzer",
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
"rev": "cfce2bb46da62950a8b70ddb0b2a12332da1b1e1",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nix-systems",
|
"owner": "rust-lang",
|
||||||
"repo": "default",
|
"ref": "nightly",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"treefmt-nix": {
|
"treefmt-nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1697388351,
|
"lastModified": 1714058656,
|
||||||
"narHash": "sha256-63N2eBpKaziIy4R44vjpUu8Nz5fCJY7okKrkixvDQmY=",
|
"narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "treefmt-nix",
|
"repo": "treefmt-nix",
|
||||||
"rev": "aae39f64f5ecbe89792d05eacea5cb241891292a",
|
"rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
124
flake.nix
124
flake.nix
|
@ -1,62 +1,84 @@
|
||||||
{
|
{
|
||||||
|
description = "A Nix-flake-based Rust development environment";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
||||||
systems.url = "github:nix-systems/default";
|
|
||||||
|
|
||||||
# Dev tools
|
treefmt-nix = {
|
||||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
url = "github:numtide/treefmt-nix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
|
||||||
|
fenix = {
|
||||||
|
url = "github:nix-community/fenix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs:
|
outputs =
|
||||||
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
{
|
||||||
systems = import inputs.systems;
|
self,
|
||||||
imports = [
|
nixpkgs,
|
||||||
inputs.treefmt-nix.flakeModule
|
treefmt-nix,
|
||||||
|
fenix,
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
supportedSystems = [
|
||||||
|
"x86_64-linux"
|
||||||
|
"aarch64-linux"
|
||||||
|
"x86_64-darwin"
|
||||||
|
"aarch64-darwin"
|
||||||
];
|
];
|
||||||
perSystem = { config, self', pkgs, lib, system, ... }:
|
forEachSupportedSystem =
|
||||||
let
|
f:
|
||||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
nixpkgs.lib.genAttrs supportedSystems (
|
||||||
nonRustDeps = [
|
system:
|
||||||
];
|
f (
|
||||||
rust-toolchain = pkgs.symlinkJoin {
|
let
|
||||||
name = "rust-toolchain";
|
pkgs = import nixpkgs { inherit system; };
|
||||||
paths = [ pkgs.rustc pkgs.cargo pkgs.rust-analyzer pkgs.rustPlatform.rustcSrc ];
|
fenix' = (import fenix { inherit system pkgs; });
|
||||||
};
|
toolchain = fenix'.complete.withComponents (
|
||||||
in
|
(builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.components
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit pkgs toolchain;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
formatter = forEachSupportedSystem (
|
||||||
|
{ pkgs, ... }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
|
||||||
|
);
|
||||||
|
devShells = forEachSupportedSystem (
|
||||||
|
{ pkgs, toolchain }:
|
||||||
{
|
{
|
||||||
# Rust package
|
default = pkgs.mkShell {
|
||||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
nativeBuildInputs = [ toolchain ];
|
||||||
inherit (cargoToml.package) name version;
|
buildInputs = [ toolchain ];
|
||||||
src = ./.;
|
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
# Rust dev environment
|
);
|
||||||
devShells.default = pkgs.mkShell {
|
packages = forEachSupportedSystem (
|
||||||
inputsFrom = [
|
{ pkgs, toolchain }:
|
||||||
config.treefmt.build.devShell
|
{
|
||||||
];
|
default = (
|
||||||
shellHook = ''
|
let
|
||||||
# For rust-analyzer 'hover' tooltips to work.
|
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
|
||||||
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
|
rustPlatform = pkgs.makeRustPlatform {
|
||||||
'';
|
cargo = toolchain;
|
||||||
buildInputs = nonRustDeps;
|
rustc = toolchain;
|
||||||
nativeBuildInputs = [
|
};
|
||||||
rust-toolchain
|
in
|
||||||
];
|
rustPlatform.buildRustPackage {
|
||||||
RUST_BACKTRACE = 1;
|
pname = manifest.name;
|
||||||
};
|
version = manifest.version;
|
||||||
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
# Add your auto-formatters here.
|
src = pkgs.lib.cleanSource ./.;
|
||||||
# cf. https://numtide.github.io/treefmt/
|
}
|
||||||
treefmt.config = {
|
);
|
||||||
projectRootFile = "flake.nix";
|
}
|
||||||
programs = {
|
);
|
||||||
nixpkgs-fmt.enable = true;
|
|
||||||
rustfmt.enable = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
3
rust-toolchain.toml
Normal file
3
rust-toolchain.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
components = ["rustfmt", "cargo", "rustc", "rust-src"]
|
8
treefmt.nix
Normal file
8
treefmt.nix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
projectRootFile = "flake.nix";
|
||||||
|
programs = {
|
||||||
|
nixfmt-rfc-style.enable = true;
|
||||||
|
rustfmt.enable = true;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue