Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request hercules-ci#130 from hercules-ci/flakeModule
Browse files Browse the repository at this point in the history
Flake module
  • Loading branch information
domenkozar committed Nov 5, 2022
2 parents 3eb97d9 + 1ee64b8 commit b845485
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
HOST_XDG_DATA_DIRS="${XDG_DATA_DIRS:-}"
eval "$(lorri direnv)"
export XDG_DATA_DIRS="${XDG_DATA_DIRS}:${HOST_XDG_DATA_DIRS}"

# Use system PKI
unset SSL_CERT_FILE
Expand Down
70 changes: 70 additions & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
A module to import into flakes based on flake-parts.
Makes integration into a flake easy and tidy.
See https://flake.parts
*/

{ lib, self, flake-parts-lib, ... }:
let
inherit (lib)
mkOption
types
;
in
{
options = {
perSystem = flake-parts-lib.mkPerSystemOption ({ config, pkgs, ... }:
let cfg = config.pre-commit;
in
{
options = {
pre-commit = {
check.enable = mkOption {
description = lib.mdDoc ''
Whether to add a derivation to the flake `checks`.
It will perform the pre-commit checks in `nix flake check`.
You can disable this if one of your hooks do not run properly in
the Nix sandbox; for example because it needs network access.
'';
type = types.bool;
default = true;
};
pkgs = mkOption {
type = types.uniq (types.lazyAttrsOf (types.raw or types.unspecified));
description = lib.mdDoc ''
Nixpkgs to use in the pre-commit [`settings`](#opt-perSystem.pre-commit.settings).
'';
default = pkgs;
defaultText = lib.literalDocBook "<literal>pkgs</literal> (module argument)";
};
settings = mkOption {
type = types.submoduleWith {
modules = [ ./modules/all-modules.nix ];
specialArgs = { inherit (cfg) pkgs; };
};
default = { };
description = lib.mdDoc ''
The pre-commit-hooks.nix configuration.
'';
};
installationScript = mkOption {
type = types.str;
description = lib.mdDoc "A bash fragment that sets up [pre-commit](https://pre-commit.com/).";
default = cfg.settings.installationScript;
defaultText = lib.literalDocBook "bash statements";
readOnly = true;
};
};
};
config = {
checks = lib.optionalAttrs cfg.check.enable { pre-commit = cfg.settings.run; };
pre-commit.settings = { pkgs, ... }: {
rootSrc = self.outPath;
package = lib.mkDefault pkgs.pre-commit;
tools = import ./nix/call-tools.nix pkgs;
};
};
});
};
}
12 changes: 11 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@
"x86_64-linux"
];
in
flake-utils.lib.eachSystem defaultSystems (system:
{
flakeModule = ./flake-module.nix;

defaultTemplate = {
path = ./template;
description = ''
A template with flake-parts and nixpkgs-fmt.
'';
};
}
// flake-utils.lib.eachSystem defaultSystems (system:
let
exposed = import ./nix { nixpkgs = nixpkgs; inherit system; gitignore-nix-src = null; isFlakes = true; };
in
Expand Down
Loading

0 comments on commit b845485

Please sign in to comment.