Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Sep 17, 2020
1 parent b840cb8 commit 8f97647
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 181 deletions.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let pkgs = import ./nix {}; in pkgs.packages
let pkgs = import ./nix { }; in pkgs.packages
4 changes: 2 additions & 2 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ in
mkOption {
type = types.listOf types.str;
description = "Haskell language extensions to enable";
default = [];
default = [ ];
};
};
nix-linter =
Expand All @@ -22,7 +22,7 @@ in
type = types.listOf types.str;
description =
"Available checks (See `nix-linter --help-for [CHECK]` for more details)";
default = [];
default = [ ];
};
};
};
Expand Down
221 changes: 110 additions & 111 deletions modules/pre-commit.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ config, lib, pkgs, ... }:

let

inherit (lib)
attrNames
concatStringsSep
Expand All @@ -21,122 +19,123 @@ let
hookType =
types.submodule (
{ config, name, ... }:
{
options =
{
enable =
mkOption {
type = types.bool;
description = "Whether to enable this pre-commit hook.";
default = false;
};
raw =
mkOption {
type = types.attrsOf types.unspecified;
description =
''
Raw fields of a pre-commit hook. This is mostly for internal use but
exposed in case you need to work around something.
{
options =
{
enable =
mkOption {
type = types.bool;
description = "Whether to enable this pre-commit hook.";
default = false;
};
raw =
mkOption {
type = types.attrsOf types.unspecified;
description =
''
Raw fields of a pre-commit hook. This is mostly for internal use but
exposed in case you need to work around something.
Default: taken from the other hook options.
'';
};
name =
mkOption {
type = types.str;
default = name;
defaultText = literalExample "internal name, same as id";
description =
''
The name of the hook - shown during hook execution.
'';
};
entry =
mkOption {
type = types.str;
description =
''
The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i.
'';
};
language =
mkOption {
type = types.str;
description =
''
The language of the hook - tells pre-commit how to install the hook.
'';
default = "system";
};
files =
mkOption {
type = types.str;
description =
''
The pattern of files to run on.
'';
default = "";
};
types =
mkOption {
type = types.listOf types.str;
description =
''
List of file types to run on. See Filtering files with types (https://pre-commit.com/#plugins).
'';
default = [ "file" ];
};
description =
mkOption {
type = types.str;
description =
''
Description of the hook. used for metadata purposes only.
'';
default = "";
};
excludes =
mkOption {
type = types.listOf types.str;
description =
''
Exclude files that were matched by these patterns.
'';
default = [];
};
pass_filenames =
mkOption {
type = types.bool;
description = "Whether to pass filenames as arguments to the entry point.";
default = true;
};
};
config =
{
raw =
{
inherit (config) name entry language files types pass_filenames;
id = name;
exclude = mergeExcludes config.excludes;
};
};
}
Default: taken from the other hook options.
'';
};
name =
mkOption {
type = types.str;
default = name;
defaultText = literalExample "internal name, same as id";
description =
''
The name of the hook - shown during hook execution.
'';
};
entry =
mkOption {
type = types.str;
description =
''
The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i.
'';
};
language =
mkOption {
type = types.str;
description =
''
The language of the hook - tells pre-commit how to install the hook.
'';
default = "system";
};
files =
mkOption {
type = types.str;
description =
''
The pattern of files to run on.
'';
default = "";
};
types =
mkOption {
type = types.listOf types.str;
description =
''
List of file types to run on. See Filtering files with types (https://pre-commit.com/#plugins).
'';
default = [ "file" ];
};
description =
mkOption {
type = types.str;
description =
''
Description of the hook. used for metadata purposes only.
'';
default = "";
};
excludes =
mkOption {
type = types.listOf types.str;
description =
''
Exclude files that were matched by these patterns.
'';
default = [ ];
};
pass_filenames =
mkOption {
type = types.bool;
description = "Whether to pass filenames as arguments to the entry point.";
default = true;
};
};
config =
{
raw =
{
inherit (config) name entry language files types pass_filenames;
id = name;
exclude = mergeExcludes config.excludes;
};
};
}
);

mergeExcludes =
excludes:
if excludes == [] then "^$" else "(${concatStringsSep "|" excludes})";
if excludes == [ ] then "^$" else "(${concatStringsSep "|" excludes})";

enabledHooks = filterAttrs (id: value: value.enable) cfg.hooks;
processedHooks =
mapAttrsToList (id: value: value.raw // { inherit id; }) enabledHooks;

configFile =
runCommand "pre-commit-config.json" {
buildInputs = [ pkgs.jq ];
passAsFile = [ "rawJSON" ];
rawJSON = builtins.toJSON cfg.rawConfig;
} ''
runCommand "pre-commit-config.json"
{
buildInputs = [ pkgs.jq ];
passAsFile = [ "rawJSON" ];
rawJSON = builtins.toJSON cfg.rawConfig;
} ''
{
echo '# DO NOT MODIFY';
echo '# This file was generated by nix-pre-commit-hooks';
Expand Down Expand Up @@ -200,7 +199,7 @@ in
'';
# 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 {};
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 All @@ -212,7 +211,7 @@ in
''
The hook definitions.
'';
default = {};
default = { };
};

run =
Expand Down Expand Up @@ -255,7 +254,7 @@ in
''
Exclude files that were matched by these patterns.
'';
default = [];
default = [ ];
};

rawConfig =
Expand Down Expand Up @@ -284,7 +283,7 @@ in
hooks = processedHooks;
}
];
} // lib.optionalAttrs (cfg.excludes != []) {
} // lib.optionalAttrs (cfg.excludes != [ ]) {
exclude = mergeExcludes cfg.excludes;
};

Expand Down
15 changes: 7 additions & 8 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{ sources ? import ./sources.nix
, system ? builtins.currentSystem
}:

let
overlay =
_: pkgs:
{
inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter;
cabal-fmt = pkgs.haskellPackages.cabal-fmt;
hindent = pkgs.haskellPackages.callCabal2nix "hindent" sources.hindent {};
packages = pkgs.callPackages ./packages.nix {};
};
{
inherit (pkgs) nixfmt niv ormolu nixpkgs-fmt nix-linter;
cabal-fmt = pkgs.haskellPackages.cabal-fmt;
hindent = pkgs.haskellPackages.callCabal2nix "hindent" sources.hindent { };
packages = pkgs.callPackages ./packages.nix { };
};
in
import sources.nixpkgs {
overlays = [ overlay ];
config = {};
config = { };
inherit system;
}
Loading

0 comments on commit 8f97647

Please sign in to comment.