nix-actions/default.nix

143 lines
2.8 KiB
Nix
Raw Normal View History

2024-12-26 20:51:08 +01:00
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
2024-11-11 16:29:36 +01:00
{
sources ? import ./npins,
pkgs ? import sources.nixpkgs { },
}:
let
inherit (pkgs) lib mkShell;
inherit (pkgs.lib.fileset) gitTracked toSource;
2024-11-11 16:29:36 +01:00
git-checks = (import sources.git-hooks).run {
src = ./.;
hooks = {
statix = {
enable = true;
stages = [ "pre-push" ];
settings.ignore = [ "npins" ];
};
deadnix = {
enable = true;
stages = [ "pre-push" ];
};
nixfmt-rfc-style = {
enable = true;
stages = [ "pre-push" ];
};
2024-12-26 20:51:08 +01:00
reuse = {
enable = true;
stages = [ "pre-push" ];
package = pkgs.reuse;
};
2024-12-30 12:16:00 +01:00
actions-validator = workflows.gitHook { stages = [ "pre-push" ]; };
2024-11-11 16:29:36 +01:00
commitizen.enable = true;
};
};
2024-12-26 20:51:08 +01:00
reuse = (import sources.nix-reuse { inherit pkgs; }).install {
defaultCopyright = "Tom Hubrecht <tom.hubrecht@dgnum.eu>";
defaultLicense = "EUPL-1.2";
downloadLicenses = true;
generatedPaths = [
".envrc"
".gitignore"
"shell.nix"
];
annotations = [
# npins generated files
{
path = "**/npins/*";
license = "EUPL-1.2";
copyright = "The [npins](https://github.com/andir/npins) contributors";
}
];
};
2024-11-11 16:29:36 +01:00
in
{
devShell = mkShell {
name = "nix-actions.dev";
2024-12-26 20:51:08 +01:00
packages = git-checks.enabledPackages;
shellHook = builtins.concatStringsSep "\n" [
git-checks.shellHook
reuse.shellHook
];
2024-11-11 16:29:36 +01:00
};
install =
{ src, ... }@config:
2024-11-11 16:29:36 +01:00
let
project = lib.evalModules {
modules = [
./modules
{
config = (removeAttrs config [ "src" ]) // {
2024-11-11 16:29:36 +01:00
_module.args.pkgs = pkgs;
rootSrc = toSource {
root = src;
fileset = gitTracked src;
};
2024-11-11 16:29:36 +01:00
};
}
];
};
in
{
shellHook = project.config.installationScript;
2024-12-30 12:16:00 +01:00
gitHook = recursiveUpdate {
enable = true;
name = "Actions validator";
entry = getExe pkgs.action-validator;
files = "\\.${project.config.platform}/workflows/.*\\.ya?ml";
};
2024-11-11 16:29:36 +01:00
};
2024-11-19 15:56:20 +01:00
lib = rec {
expr = repr: "\${{ ${repr} }}";
secret = name: expr "secrets.${name}";
};
2024-11-19 15:56:46 +01:00
steps =
{
__functor =
self:
{
name,
url,
defaultVersion,
}:
self
// {
${name} =
{
__version ? defaultVersion,
...
}@args:
{
uses = "${url}@${__version}";
"with" = builtins.removeAttrs args [ "__version" ];
};
};
}
{
name = "checkout";
defaultVersion = "v3";
url = "actions/checkout";
};
2024-11-11 16:29:36 +01:00
}