Skip to content

Flakes support #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@ jobs:
name: pre-commit-hooks
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- run: nix-build
tests-flakes:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v13
with:
install_url: https://nixos-nix-install-tests.cachix.org/serve/lb41az54kzk6j12p81br4bczary7m145/install
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve'
extra_nix_config: |
experimental-features = nix-command flakes
- uses: cachix/cachix-action@v10
with:
name: pre-commit-hooks
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- run: nix flake check
- run: nix eval .#lib.x86_64-linux.run
41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
description = "Seamless integration of https://pre-commit.com git hooks with Nix.";

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
exposed = import ./nix { nixpkgs = nixpkgs; inherit system; gitignore-nix-src = null; isFlakes = true; };
in
{
packages = exposed.packages;

defaultPackage = exposed.packages.pre-commit;

checks = exposed.checks;

lib = { inherit (exposed) run; };
}
);
}
13 changes: 1 addition & 12 deletions modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ let
touch $out
[ $? -eq 0 ] && exit $exitcode
'';

# TODO: provide a default pin that the user may override
inherit (import (import ../nix/sources.nix)."gitignore.nix" { inherit lib; })
gitignoreSource
;
in
{
options =
Expand All @@ -180,7 +175,6 @@ in
''
The pre-commit package to use.
'';
default = pkgs.pre-commit;
defaultText =
literalExample ''
pkgs.pre-commit
Expand All @@ -190,16 +184,12 @@ in
tools =
mkOption {
type = types.lazyAttrsOf types.package;

description =
''
Tool set from which nix-pre-commit will pick binaries.

nix-pre-commit comes with its own set of packages for this purpose.
'';
# This default is for when the module is the entry point rather than
# /default.nix. /default.nix will override this for efficiency.
default = (import ../nix { inherit (pkgs) system; }).callPackage ../nix/tools.nix { };
defaultText =
literalExample ''nix-pre-commit-hooks-pkgs.callPackage tools-dot-nix { inherit (pkgs) system; }'';
};
Expand Down Expand Up @@ -247,15 +237,14 @@ in

rootSrc =
mkOption {
type = types.package;
type = types.path;
description =
''
The source of the project to be checked.

This is used in the derivation that performs the check.
'';
defaultText = literalExample ''gitignoreSource config.src'';
default = gitignoreSource config.src;
};

excludes =
Expand Down
17 changes: 9 additions & 8 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{ sources ? import ./sources.nix
, system ? builtins.currentSystem
, nixpkgs ? sources.nixpkgs
, gitignore-nix-src ? sources."gitignore.nix"
, isFlakes ? false
}:
let
overlay =
_: pkgs:
self: pkgs:
let
run = pkgs.callPackage ./run.nix { inherit tools; };
tools = pkgs.callPackage ./tools.nix { };
tools = pkgs.lib.filterAttrs (k: v: !(pkgs.lib.any (a: k == a) [ "override" "overrideDerivation" ])) (pkgs.callPackage ./tools.nix { });
run = pkgs.callPackage ./run.nix { inherit pkgs tools isFlakes gitignore-nix-src; };
in
{
inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter;
cabal-fmt = pkgs.haskell.lib.enableSeparateBinOutput pkgs.haskellPackages.cabal-fmt;
hindent = pkgs.haskell.lib.enableSeparateBinOutput pkgs.haskellPackages.hindent;
inherit tools;
inherit tools run;
# Flake style attributes
packages = {
inherit tools run;
inherit (pkgs.gitAndTools) pre-commit;
packages = tools // {
inherit (pkgs) pre-commit;
};
checks = tools // {
checks = self.packages // {
# A pre-commit-check for nix-pre-commit itself
pre-commit-check = run {
src = ../.;
Expand Down
14 changes: 9 additions & 5 deletions nix/run.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
builtinStuff@{ pkgs, tools, pre-commit, git, runCommand, writeText, writeScript, lib }:
builtinStuff@{ pkgs, tools, isFlakes, pre-commit, git, runCommand, writeText, writeScript, lib, gitignore-nix-src }:

{ src
, hooks ? { }
Expand All @@ -8,8 +8,6 @@ builtinStuff@{ pkgs, tools, pre-commit, git, runCommand, writeText, writeScript,
, default_stages ? [ ]
}:
let
sources = import ./sources.nix;

project =
lib.evalModules {
modules =
Expand All @@ -19,9 +17,15 @@ let
config =
{
_module.args.pkgs = pkgs;
inherit hooks excludes settings src default_stages;
_module.args.gitignore-nix-src = gitignore-nix-src;
inherit hooks excludes settings default_stages;
tools = builtinStuff.tools // tools;
};
package = pre-commit;
} // (if isFlakes
then { rootSrc = src; }
else {
rootSrc = (import gitignore-nix-src { inherit (pkgs) lib; }).gitignoreSource src;
});
}
];
};
Expand Down