Skip to content

Commit dade3a7

Browse files
authored
Use flake-parts (#149)
* Add flake-parts input * Use `flake-parts` `mkFlake` * Add git-hooks-nix input * Enable alejandra pre-commit hook * Add pre-commit shellHook * Use pre-commit hook in `nix fmt` * Enable nil hook * Remove `nil` from home packages * Enable statix hook * Fix statix issue * Remove `statix` from home packages * Expose pre-commit packages in dev shell
1 parent d67bdee commit dade3a7

4 files changed

Lines changed: 153 additions & 66 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22

33
.direnv
4+
/.pre-commit-config.yaml

‎flake.lock‎

Lines changed: 71 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
url = "path:./flake.systems.nix";
99
flake = false;
1010
};
11-
flake-utils = {
12-
url = "github:numtide/flake-utils";
13-
inputs.systems.follows = "systems";
11+
flake-parts = {
12+
url = "github:hercules-ci/flake-parts";
13+
inputs.nixpkgs-lib.follows = "nixpkgs";
1414
};
1515
agenix = {
1616
url = "github:ryantm/agenix";
@@ -23,6 +23,10 @@
2323
url = "github:nix-community/home-manager";
2424
inputs.nixpkgs.follows = "nixpkgs";
2525
};
26+
git-hooks-nix = {
27+
url = "github:cachix/git-hooks.nix";
28+
inputs.nixpkgs.follows = "nixpkgs";
29+
};
2630

2731
# Linux
2832
disko = {
@@ -37,6 +41,7 @@
3741
zx-dev = {
3842
url = "github:stackptr/zx.dev";
3943
inputs.nixpkgs.follows = "nixpkgs";
44+
inputs.flake-parts.follows = "flake-parts";
4045
};
4146

4247
# macOS
@@ -58,66 +63,90 @@
5863
mac-app-util = {
5964
url = "github:hraban/mac-app-util";
6065
inputs.nixpkgs.follows = "nixpkgs";
61-
inputs.flake-utils.follows = "flake-utils";
6266
inputs.systems.follows = "systems";
6367
};
6468
};
6569

66-
outputs = inputs @ {
67-
nixpkgs,
68-
flake-utils,
69-
agenix,
70-
...
71-
}: let
72-
inherit (import ./lib/hosts.nix inputs) mkNixosHost mkDarwinHost;
73-
in
74-
{
75-
nixosConfigurations = {
76-
zeta = mkNixosHost {
77-
hostname = "zeta";
78-
system = "aarch64-linux";
79-
username = "mu";
80-
};
81-
glyph = mkNixosHost {
82-
hostname = "glyph";
83-
system = "x86_64-linux";
84-
username = "mu";
70+
outputs = inputs @ {flake-parts, ...}:
71+
flake-parts.lib.mkFlake {inherit inputs;} ({
72+
config,
73+
withSystem,
74+
moduleWithSystem,
75+
...
76+
}: {
77+
imports = [
78+
inputs.git-hooks-nix.flakeModule
79+
];
80+
81+
flake = let
82+
inherit (import ./lib/hosts.nix inputs) mkNixosHost mkDarwinHost;
83+
in {
84+
nixosConfigurations = {
85+
zeta = mkNixosHost {
86+
hostname = "zeta";
87+
system = "aarch64-linux";
88+
username = "mu";
89+
};
90+
glyph = mkNixosHost {
91+
hostname = "glyph";
92+
system = "x86_64-linux";
93+
username = "mu";
94+
};
95+
spore = mkNixosHost {
96+
hostname = "spore";
97+
system = "x86_64-linux";
98+
username = "mu";
99+
};
85100
};
86-
spore = mkNixosHost {
87-
hostname = "spore";
88-
system = "x86_64-linux";
89-
username = "mu";
101+
102+
darwinConfigurations = {
103+
Rhizome = mkDarwinHost {
104+
hostname = "Rhizome";
105+
username = "corey";
106+
};
90107
};
91-
};
92108

93-
darwinConfigurations = {
94-
Rhizome = mkDarwinHost {
95-
hostname = "Rhizome";
96-
username = "corey";
109+
nixConfig = {
110+
experimental-features = ["nix-command" "flakes"];
111+
extra-substituters = [
112+
"https://stackptr.cachix.org"
113+
];
114+
extra-trusted-public-keys = [
115+
"stackptr.cachix.org-1:5e2q7OxdRdAtvRmHTeogpgJKzQhbvFqNMmCMw71opZA="
116+
];
97117
};
98118
};
99-
}
100-
// flake-utils.lib.eachDefaultSystem (
101-
system: let
102-
pkgs = nixpkgs.legacyPackages.${system};
103-
agenixPkg = agenix.packages.${system}.default;
104-
in {
119+
120+
systems = import inputs.systems;
121+
perSystem = {
122+
pkgs,
123+
inputs',
124+
config,
125+
...
126+
}: {
105127
devShells = {
106128
default = pkgs.mkShell {
107-
packages = [agenixPkg pkgs.cachix pkgs.just];
129+
packages =
130+
[
131+
inputs'.agenix.packages.default
132+
pkgs.cachix
133+
pkgs.just
134+
]
135+
++ config.pre-commit.settings.enabledPackages;
136+
inherit (config.pre-commit) shellHook;
108137
};
109138
};
110-
formatter = pkgs.alejandra;
111-
}
112-
);
113-
114-
nixConfig = {
115-
experimental-features = ["nix-command" "flakes"];
116-
extra-substituters = [
117-
"https://stackptr.cachix.org"
118-
];
119-
extra-trusted-public-keys = [
120-
"stackptr.cachix.org-1:5e2q7OxdRdAtvRmHTeogpgJKzQhbvFqNMmCMw71opZA="
121-
];
122-
};
139+
formatter = let
140+
inherit (config.pre-commit.settings) package configFile;
141+
in
142+
pkgs.writeShellScriptBin "pre-commit-run" ''
143+
${pkgs.lib.getExe package} run --all-files --config ${configFile}
144+
'';
145+
pre-commit.settings.hooks = {
146+
alejandra.enable = true;
147+
nil.enable = true;
148+
statix.enable = true;
149+
};
150+
};
151+
});
123152
}

‎home/default.nix‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
nixSpecific = [
2828
comma
2929
manix
30-
nil
3130
nix-du
3231
nix-tree
3332
nix-your-shell
34-
statix
3533
];
3634
tuiApps = [
3735
claude-code

0 commit comments

Comments
 (0)