-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
79 lines (74 loc) · 2.33 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks.url = "github:jmgilman/pre-commit-hooks.nix/hadolint";
};
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }:
flake-utils.lib.eachDefaultSystem (system:
let
# Inherit system packages
pkgs = import nixpkgs {
inherit system;
};
# Configure home-manager overrides
hm = pkgs.lib.generators.toPretty { } {
programs.zsh = {
envExtra = ''
# Custom functions
cmt() {
git commit -m "$1: $2"
}
'';
};
};
# Create a wrapper for enforcing conventional commit messages
checkCommit = pkgs.writeShellScriptBin "checkCommit" ''
cog verify "$(cat $1)"
'';
in
{
# Add custom pre-commit checks
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
commit-check = {
enable = true;
name = "Check commit message";
entry = "checkCommit";
language = "system";
stages = [ "commit-msg" ];
};
hadolint.enable = true;
nixpkgs-fmt.enable = true;
prettier.enable = true;
};
};
};
# Configure development environment
devShell = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check);
shellHook = ''
${self.checks.${system}.pre-commit-check.shellHook}
# Push local home-manager config to filesystem
cat << 'EOT' > /tmp/local.nix
{ config, pkgs, ... }:
${hm}
EOT
# If something has changed, replace the config and call switch
if ! cmp --silent -- /tmp/local.nix ~/.config/devcontainer/extra/local.nix; then
cp /tmp/local.nix ~/.config/devcontainer/extra/local.nix
home-manager switch --flake ~/.config/devcontainer#vscode
fi
'';
packages = [
checkCommit
pkgs.cocogitto
pkgs.hadolint
pkgs.nixpkgs-fmt
];
};
}
);
}