2021-04-07 00:17:50 +02:00
|
|
|
{
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
2023-06-26 18:32:36 +02:00
|
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
|
|
systems.url = "github:nix-systems/default";
|
|
|
|
|
|
|
|
# Dev tools
|
|
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
|
|
mission-control.url = "github:Platonic-Systems/mission-control";
|
|
|
|
flake-root.url = "github:srid/flake-root";
|
2021-04-07 00:17:50 +02:00
|
|
|
};
|
|
|
|
|
2023-06-26 18:32:36 +02:00
|
|
|
outputs = inputs:
|
|
|
|
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
|
|
|
systems = import inputs.systems;
|
|
|
|
imports = [
|
|
|
|
inputs.treefmt-nix.flakeModule
|
|
|
|
inputs.mission-control.flakeModule
|
|
|
|
inputs.flake-root.flakeModule
|
|
|
|
];
|
2023-07-23 16:07:10 +02:00
|
|
|
perSystem = { config, self', pkgs, lib, system, ... }:
|
2023-06-26 18:32:36 +02:00
|
|
|
|
2023-07-23 16:07:10 +02:00
|
|
|
let
|
|
|
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
|
|
|
nonRustDeps = [
|
|
|
|
pkgs.libiconv
|
2023-06-26 18:32:36 +02:00
|
|
|
];
|
2023-07-23 16:07:10 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# Rust package
|
|
|
|
packages.default =
|
|
|
|
pkgs.rustPlatform.buildRustPackage {
|
|
|
|
inherit (cargoToml.package) name version;
|
|
|
|
src = ./.;
|
|
|
|
cargoLock.lockFile = ./Cargo.lock;
|
|
|
|
};
|
2023-06-26 18:32:36 +02:00
|
|
|
|
2023-07-23 16:07:10 +02:00
|
|
|
# Rust dev environment
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
|
|
inputsFrom = [
|
|
|
|
config.treefmt.build.devShell
|
|
|
|
config.mission-control.devShell
|
|
|
|
config.flake-root.devShell
|
|
|
|
];
|
|
|
|
shellHook = ''
|
|
|
|
# For rust-analyzer 'hover' tooltips to work.
|
|
|
|
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
|
|
|
|
'';
|
|
|
|
buildInputs = nonRustDeps;
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
|
|
rustc
|
|
|
|
cargo
|
|
|
|
cargo-watch
|
|
|
|
rust-analyzer
|
|
|
|
];
|
2023-06-26 18:32:36 +02:00
|
|
|
};
|
|
|
|
|
2023-07-23 16:07:10 +02:00
|
|
|
# Add your auto-formatters here.
|
|
|
|
# cf. https://numtide.github.io/treefmt/
|
|
|
|
treefmt.config = {
|
|
|
|
projectRootFile = "flake.nix";
|
|
|
|
programs = {
|
|
|
|
nixpkgs-fmt.enable = true;
|
|
|
|
rustfmt.enable = true;
|
|
|
|
};
|
2023-06-26 18:32:36 +02:00
|
|
|
};
|
|
|
|
|
2023-07-23 16:07:10 +02:00
|
|
|
# Makefile'esque but in Nix. Add your dev scripts here.
|
|
|
|
# cf. https://github.com/Platonic-Systems/mission-control
|
|
|
|
mission-control.scripts = {
|
|
|
|
fmt = {
|
|
|
|
exec = config.treefmt.build.wrapper;
|
|
|
|
description = "Auto-format project tree";
|
|
|
|
};
|
2023-06-26 18:32:36 +02:00
|
|
|
|
2023-07-23 16:07:10 +02:00
|
|
|
run = {
|
|
|
|
exec = ''
|
|
|
|
cargo run "$@"
|
|
|
|
'';
|
|
|
|
description = "Run the project executable";
|
|
|
|
};
|
|
|
|
|
|
|
|
watch = {
|
|
|
|
exec = ''
|
|
|
|
set -x
|
|
|
|
cargo watch -x "run -- $*"
|
|
|
|
'';
|
|
|
|
description = "Watch for changes and run the project executable";
|
|
|
|
};
|
2023-06-26 18:32:36 +02:00
|
|
|
};
|
2022-05-08 23:00:33 +02:00
|
|
|
};
|
|
|
|
};
|
2021-04-07 00:17:50 +02:00
|
|
|
}
|