Rust template
All checks were successful
/ check (push) Successful in 5m12s

This commit is contained in:
Daniel Flanagan 2024-12-23 20:52:28 -06:00
parent f2ea15fa7c
commit b4bc4ce599
5 changed files with 124 additions and 76 deletions

View file

@ -1,81 +1,14 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
git-hooks,
nixpkgs,
}: let
inherit (self) outputs;
systems = ["aarch64-linux" "aarch64-darwin" "x86_64-darwin" "x86_64-linux"];
forSystems = nixpkgs.lib.genAttrs systems;
pkgsFor = system: (import nixpkgs {inherit system;}).extend outputs.overlays.default;
genPkgs = func: (forSystems (system: func (pkgsFor system)));
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.git-hooks.url = "github:cachix/git-hooks.nix";
inputs.git-hooks.inputs.nixpkgs.follows = "nixpkgs";
outputs = inputs: let
inherit (import nix/boilerplate.nix inputs) fullImport genPkgs;
in {
checks = genPkgs (pkgs: {
git-hooks = git-hooks.lib.${pkgs.system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
cargo-check.enable = true;
clippy = {
enable = true;
packageOverrides.cargo = pkgs.cargo;
packageOverrides.clippy = pkgs.rustPackages.clippy;
};
rustfmt = {
enable = true;
packageOverrides.rustfmt = pkgs.rustfmt;
};
};
};
});
packages = genPkgs (pkgs: {
my-package = pkgs.rustPlatform.buildRustPackage {
pname = "my-package";
version = "0.1.0";
/*
nativeBuildInputs = with pkgs; [
pkg-config
clang
];
buildInputs = with pkgs; [
];
*/
src = ./.;
hash = pkgs.lib.fakeHash;
cargoHash = "sha256-W7VQlMktGsRPQL9VGVmxYV6C5u2eJ48S7eTpOM+3n8U=";
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
};
default = outputs.packages.${pkgs.system}.my-package;
});
devShells = genPkgs (pkgs: {
default = pkgs.mkShell {
inherit (self.checks.${pkgs.system}.git-hooks) shellHook;
inputsFrom = [outputs.packages.${pkgs.system}.default];
packages = with pkgs; [
rustPackages.clippy
rust-analyzer
rustfmt
lldb
];
};
});
overlays = {
default = final: prev: {};
};
# overlays = import nix/overlays.nix;
checks = fullImport nix/checks.nix;
packages = fullImport nix/packages.nix;
devShells = fullImport nix/shells.nix;
formatter = genPkgs (p: p.alejandra);
};
}

View file

@ -0,0 +1,16 @@
inputs @ {
nixpkgs,
self,
...
}: let
forSelfOverlay =
if builtins.hasAttr "forSelf" self.overlays
then self.overlays.forSelf
else (_: p: p);
in rec {
systems = ["aarch64-linux" "x86_64-linux" "x86_64-darwin" "aarch64-darwin"];
forSystems = nixpkgs.lib.genAttrs systems;
pkgsFor = system: ((import nixpkgs {inherit system;}).extend forSelfOverlay);
genPkgs = func: (forSystems (system: func (pkgsFor system)));
call = imported: genPkgs (pkgs: imported (inputs // {inherit pkgs;}));
}

View file

@ -0,0 +1,25 @@
{
pkgs,
git-hooks,
...
}: {
git-hooks = git-hooks.lib.${pkgs.system}.run {
src = ./..;
hooks = {
alejandra.enable = true;
cargo-check.enable = true;
convco.enable = true;
cargo-test = {
enable = true;
name = "cargo-test";
entry = "cargo test";
# types = ["rust"];
# language = "rust";
pass_filenames = false;
stages = ["pre-commit"];
};
clippy.enable = true;
rustfmt.enable = true;
};
};
}

View file

@ -0,0 +1,52 @@
{pkgs, ...}: rec {
lyrs = pkgs.rustPlatform.buildRustPackage {
pname = "lyrs";
version = "0.1.0";
/*
nativeBuildInputs = with pkgs; [
pkg-config
clang
];
buildInputs = with pkgs; [
];
*/
src = ./..;
hash = pkgs.lib.fakeHash;
cargoHash = "sha256-XHCXOlG4sdr1A3lqIK/7bB3soms1jxMIdfsFABmHVog=";
};
pwatch = pkgs.writeShellScriptBin "pwatch" ''
dir="$(dirname "$(cargo locate-project --workspace --message-format plain)")"
pushd "$dir"
additional_watchexec_args=""
if [[ -f apps/$pkg/build.rs ]]; then
additional_watchexec_args="--watch apps/$pkg/build.rs"
fi
pkg="$1"; shift
cargo_subcmd="$1"; shift
cargo_subcmd_args="$@"; shift
argfile="apps/$pkg/.watchexec.argfile"
argfile_args=""
if [[ -f $argfile ]]; then
argfile_args="@$argfile"
fi
watchexec $argfile_args --stop-timeout 0s --restart \
--watch Cargo.toml \
--watch libs \
--watch apps/$pkg/src/ \
--watch apps/$pkg/Cargo.toml \
$additional_watchexec_args \
cargo "$cargo_subcmd" --package "$pkg" "$cargo_subcmd_args"
popd
'';
default = lyrs;
}

View file

@ -0,0 +1,22 @@
{
self,
pkgs,
...
}: let
inherit (pkgs) system;
in rec {
lyrs-dev = pkgs.mkShell {
inherit (self.checks.${system}.git-hooks) shellHook;
inputsFrom = [self.packages.${system}.lyrs];
packages = with pkgs; [
convco
rustPackages.clippy
typescript-language-server
rust-analyzer
rustfmt
nixd
lldb
];
};
default = lyrs-dev;
}