Skip to content

Commit 183c5aa

Browse files
committed
wip
1 parent 9d28618 commit 183c5aa

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

default.nix

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
let
2-
flake = (import
3-
(
4-
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
5-
fetchTarball {
6-
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
7-
sha256 = lock.nodes.flake-compat.locked.narHash;
8-
}
9-
)
10-
{ src = ./.; }
11-
).defaultNix;
2+
flake =
3+
(import
4+
(
5+
let
6+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
7+
in
8+
fetchTarball {
9+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.flake-compat.locked.narHash;
11+
}
12+
)
13+
{ src = ./.; }).defaultNix;
1214
in
13-
flake.lib.${builtins.currentSystem} // flake.packages.${builtins.currentSystem}
15+
flake.lib.${builtins.currentSystem} // flake.legacyPackages.${builtins.currentSystem}

dev/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
description = "A very basic flake";
2+
description = "An internal test flake for git-hooks.nix";
33

44
inputs = {
55
git-hooks.url = "path:..";

flake.nix

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@
4040
'';
4141
};
4242

43-
legacyPackages = self.packages;
44-
4543
# The set of tools exposed by git-hooks.
46-
# Each entry is guaranteed to be a derivation, but broken packages are not filtered out.
47-
# `nix flake check` will likely not work.
44+
# We use legacyPackages because not all tools are derivations that evaluate.
45+
legacyPackages = forAllSystems ({ pkgs, exposed, ... }: exposed.tools // {
46+
pre-commit = pkgs.pre-commit;
47+
});
48+
49+
# WARN: use `legacyPackages` instead to get error messages for deprecated packages
50+
#
51+
# Each entry is guaranteed to be a derivation that evaluates.
52+
# TODO: this should be deprecated as it exposes a subset of nixpkgs, which is incompatbile with the packages output.
4853
packages = forAllSystems ({ exposed, ... }: exposed.packages // {
4954
default = exposed.packages.pre-commit;
5055
});
@@ -59,6 +64,7 @@
5964

6065
lib = forAllSystems ({ exposed, ... }: { inherit (exposed) run; });
6166

67+
# TODO: remove and expose a `lib` function is needed
6268
exposed = forAllSystems ({ exposed, ... }: exposed);
6369
};
6470
}

nix/call-tools.nix

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
pkgs:
22
pkgs.lib.flip builtins.removeAttrs [ "override" "overrideDerivation" ] (
33
pkgs.callPackage ./tools.nix {
4-
placeholder = name: {
5-
# Allows checking without forcing evaluation
6-
meta.isPlaceholder = true;
4+
placeholder =
5+
name:
6+
let
7+
errorMsg = ''
8+
git-hooks: the package `${name}` is not available in your nixpkgs revision.
9+
'';
10+
in
11+
{
12+
# Allows checking without forcing evaluation
13+
meta.isPlaceholder = true;
714

8-
# Throw when the package is actually used
9-
outPath = throw ''
10-
git-hooks: the package `${name} is not available in your nixpkgs revision.
11-
'';
12-
13-
type = "derivation";
14-
name = name + "placeholder";
15-
};
15+
type = "derivation";
16+
name = name + "-placeholder";
17+
outPath = throw errorMsg;
18+
drvPath = throw errorMsg;
19+
};
1620
}
1721
)

nix/default.nix

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ let
1919
;
2020
};
2121

22+
removeInvalidPackage = removeInvalidPackageWith { };
23+
removeInvalidPackageQuiet = removeInvalidPackageWith { warn = false; };
24+
2225
# Filter out broken and placeholder packages.
23-
filterPackageForCheck =
26+
removeInvalidPackageWith =
27+
{ warn ? true
28+
,
29+
}:
2430
name: package:
2531
let
2632
isPlaceholder = package.meta.isPlaceholder or false;
@@ -46,19 +52,18 @@ let
4652
""; # Not used
4753

4854
in
49-
lib.warnIf (!result) message result;
55+
if warn then lib.warnIfNot result message result else result;
5056
in
5157
{
5258
inherit tools run;
5359

5460
# Flake-style attributes
55-
# Do not remove: these are exposed in the flake.
56-
# Each should also be a valid derivation.
57-
packages = tools // {
61+
# Each should strictly be a valid derivation that evaluates.
62+
packages = (lib.filterAttrs removeInvalidPackageQuiet tools) // {
5863
inherit (pkgs) pre-commit;
5964
};
6065

61-
checks = (lib.filterAttrs filterPackageForCheck tools) // {
66+
checks = (lib.filterAttrs removeInvalidPackage tools) // {
6267
# A pre-commit-check for nix-pre-commit itself
6368
pre-commit-check = run {
6469
src = ../.;
@@ -87,7 +92,7 @@ let
8792
f n h.package;
8893

8994
allEntryPoints = lib.pipe allHooks [
90-
(lib.filterAttrs (getPackage filterPackageForCheck))
95+
(lib.filterAttrs (getPackage (removeInvalidPackageQuiet)))
9196
(lib.mapAttrsToList getEntry)
9297
];
9398
in

0 commit comments

Comments
 (0)