Skip to content

Commit 732d0b9

Browse files
committed
chore: add flake template
1 parent acad383 commit 732d0b9

File tree

6 files changed

+267
-0
lines changed

6 files changed

+267
-0
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
/.direnv
3+
/result

flake.lock

+162
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
description = "dpc's basic flake template";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
crane.url = "github:ipetkov/crane";
8+
crane.inputs.nixpkgs.follows = "nixpkgs";
9+
fenix = {
10+
url = "github:nix-community/fenix";
11+
inputs.nixpkgs.follows = "nixpkgs";
12+
};
13+
};
14+
15+
outputs = { self, nixpkgs, flake-utils, crane, fenix }:
16+
flake-utils.lib.eachDefaultSystem (system:
17+
let
18+
pkgs = import nixpkgs {
19+
inherit system;
20+
};
21+
lib = pkgs.lib;
22+
fenixChannel = fenix.packages.${system}.stable;
23+
fenixToolchain = (fenixChannel.withComponents [
24+
"rustc"
25+
"cargo"
26+
"clippy"
27+
"rust-analysis"
28+
"rust-src"
29+
"rustfmt"
30+
]);
31+
craneLib = crane.lib.${system}.overrideToolchain fenixToolchain;
32+
33+
commonArgs = {
34+
src = craneLib.cleanCargoSource ./.;
35+
36+
buildInputs = with pkgs; [
37+
];
38+
39+
nativeBuildInputs = with pkgs; [
40+
];
41+
};
42+
in
43+
{
44+
packages.default = craneLib.buildPackage ({ } // commonArgs);
45+
46+
devShells = {
47+
default = pkgs.mkShell {
48+
49+
buildInputs = with pkgs; [ ] ++ commonArgs.buildInputs;
50+
nativeBuildInputs = with pkgs; [
51+
fenix.packages.${system}.rust-analyzer
52+
fenixToolchain
53+
cargo-udeps
54+
55+
# This is required to prevent a mangled bash shell in nix develop
56+
# see: https://discourse.nixos.org/t/interactive-bash-with-nix-develop-flake/15486
57+
(hiPrio pkgs.bashInteractive)
58+
59+
# Nix
60+
pkgs.nixpkgs-fmt
61+
pkgs.shellcheck
62+
pkgs.rnix-lsp
63+
pkgs.nodePackages.bash-language-server
64+
65+
] ++ commonArgs.nativeBuildInputs;
66+
shellHook = ''
67+
dot_git="$(git rev-parse --git-common-dir)"
68+
if [[ ! -d "$dot_git/hooks" ]]; then mkdir "$dot_git/hooks"; fi
69+
for hook in misc/git-hooks/* ; do ln -sf "$(pwd)/$hook" "$dot_git/hooks/" ; done
70+
${pkgs.git}/bin/git config commit.template $(pwd)/misc/git-hooks/commit-template.txt
71+
'';
72+
};
73+
};
74+
}
75+
);
76+
}

misc/git-hooks/commit-template.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
# Explain *why* this change is being made width limit ->|

misc/git-hooks/pre-commit

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
# Revert `git stash` on exit
6+
function revert_git_stash {
7+
>&2 echo "Unstashing uncommited changes..."
8+
git stash pop -q
9+
}
10+
11+
set +e
12+
git diff-files --quiet
13+
is_unclean=$?
14+
set -e
15+
16+
# Stash pending changes and revert them when script ends
17+
if [ $is_unclean -ne 0 ]; then
18+
>&2 echo "Stashing uncommited changes..."
19+
git stash -q --keep-index
20+
trap revert_git_stash EXIT
21+
fi
22+
23+
# TODO: add checks below

0 commit comments

Comments
 (0)