Skip to content

Commit 2eb2917

Browse files
committed
flakes support
1 parent 8537f4e commit 2eb2917

File tree

6 files changed

+98
-24
lines changed

6 files changed

+98
-24
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,21 @@ jobs:
1616
name: pre-commit-hooks
1717
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
1818
- run: nix-build
19+
tests-flakes:
20+
strategy:
21+
matrix:
22+
os: [ubuntu-latest, macos-latest]
23+
runs-on: ${{ matrix.os }}
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: cachix/install-nix-action@v13
27+
with:
28+
install_url: https://nixos-nix-install-tests.cachix.org/serve/lb41az54kzk6j12p81br4bczary7m145/install
29+
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve'
30+
extra_nix_config: |
31+
experimental-features = nix-command flakes
32+
- uses: cachix/cachix-action@v10
33+
with:
34+
name: pre-commit-hooks
35+
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
36+
- run: nix flake check

flake.lock

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

flake.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
description = "Seamless integration of https://pre-commit.com git hooks with Nix.";
3+
4+
inputs.flake-utils.url = "github:numtide/flake-utils";
5+
6+
outputs = { self, nixpkgs, flake-utils }:
7+
flake-utils.lib.eachDefaultSystem (system:
8+
let
9+
exposed = import ./nix { nixpkgs = nixpkgs; inherit system; gitignore-nix-src = null; isFlakes = true; };
10+
in
11+
{
12+
packages = exposed.packages;
13+
14+
defaultPackage = exposed.packages.pre-commit;
15+
16+
checks = exposed.checks;
17+
18+
lib = { inherit (exposed) run; };
19+
}
20+
);
21+
}

modules/pre-commit.nix

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ let
163163
touch $out
164164
[ $? -eq 0 ] && exit $exitcode
165165
'';
166-
167-
# TODO: provide a default pin that the user may override
168-
inherit (import (import ../nix/sources.nix)."gitignore.nix" { inherit lib; })
169-
gitignoreSource
170-
;
171166
in
172167
{
173168
options =
@@ -180,7 +175,6 @@ in
180175
''
181176
The pre-commit package to use.
182177
'';
183-
default = pkgs.pre-commit;
184178
defaultText =
185179
literalExample ''
186180
pkgs.pre-commit
@@ -190,16 +184,12 @@ in
190184
tools =
191185
mkOption {
192186
type = types.lazyAttrsOf types.package;
193-
194187
description =
195188
''
196189
Tool set from which nix-pre-commit will pick binaries.
197190
198191
nix-pre-commit comes with its own set of packages for this purpose.
199192
'';
200-
# This default is for when the module is the entry point rather than
201-
# /default.nix. /default.nix will override this for efficiency.
202-
default = (import ../nix { inherit (pkgs) system; }).callPackage ../nix/tools.nix { };
203193
defaultText =
204194
literalExample ''nix-pre-commit-hooks-pkgs.callPackage tools-dot-nix { inherit (pkgs) system; }'';
205195
};
@@ -247,15 +237,14 @@ in
247237

248238
rootSrc =
249239
mkOption {
250-
type = types.package;
240+
type = types.path;
251241
description =
252242
''
253243
The source of the project to be checked.
254244
255245
This is used in the derivation that performs the check.
256246
'';
257247
defaultText = literalExample ''gitignoreSource config.src'';
258-
default = gitignoreSource config.src;
259248
};
260249

261250
excludes =

nix/default.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
{ sources ? import ./sources.nix
22
, system ? builtins.currentSystem
33
, nixpkgs ? sources.nixpkgs
4+
, gitignore-nix-src ? sources."gitignore.nix"
5+
, isFlakes ? false
46
}:
57
let
68
overlay =
7-
_: pkgs:
9+
self: pkgs:
810
let
9-
run = pkgs.callPackage ./run.nix { inherit tools; };
10-
tools = pkgs.callPackage ./tools.nix { };
11+
tools = pkgs.lib.filterAttrs (k: v: !(pkgs.lib.any (a: k == a) [ "override" "overrideDerivation" ])) (pkgs.callPackage ./tools.nix { });
12+
run = pkgs.callPackage ./run.nix { inherit pkgs tools isFlakes gitignore-nix-src; };
1113
in
1214
{
1315
inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter;
1416
cabal-fmt = pkgs.haskell.lib.enableSeparateBinOutput pkgs.haskellPackages.cabal-fmt;
1517
hindent = pkgs.haskell.lib.enableSeparateBinOutput pkgs.haskellPackages.hindent;
1618
inherit tools;
1719
# Flake style attributes
18-
packages = {
19-
inherit tools run;
20-
inherit (pkgs.gitAndTools) pre-commit;
20+
packages = tools // {
21+
inherit (pkgs) pre-commit;
2122
};
22-
checks = tools // {
23+
checks = self.packages // {
2324
# A pre-commit-check for nix-pre-commit itself
2425
pre-commit-check = run {
2526
src = ../.;

nix/run.nix

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
builtinStuff@{ pkgs, tools, pre-commit, git, runCommand, writeText, writeScript, lib }:
1+
builtinStuff@{ pkgs, tools, isFlakes, pre-commit, git, runCommand, writeText, writeScript, lib, gitignore-nix-src }:
22

33
{ src
44
, hooks ? { }
@@ -8,8 +8,6 @@ builtinStuff@{ pkgs, tools, pre-commit, git, runCommand, writeText, writeScript,
88
, default_stages ? [ ]
99
}:
1010
let
11-
sources = import ./sources.nix;
12-
1311
project =
1412
lib.evalModules {
1513
modules =
@@ -19,9 +17,15 @@ let
1917
config =
2018
{
2119
_module.args.pkgs = pkgs;
22-
inherit hooks excludes settings src default_stages;
20+
_module.args.gitignore-nix-src = gitignore-nix-src;
21+
inherit hooks excludes settings default_stages;
2322
tools = builtinStuff.tools // tools;
24-
};
23+
package = pre-commit;
24+
} // (if isFlakes
25+
then { rootSrc = src; }
26+
else {
27+
rootSrc = (import gitignore-nix-src { inherit (pkgs) lib; }).gitignoreSource src;
28+
});
2529
}
2630
];
2731
};

0 commit comments

Comments
 (0)