mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2024-12-14 11:47:31 +00:00
commit
60c4f3b26e
4 changed files with 102 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
|||
nativeBuildInputs = [
|
||||
pkgs.nixpkgs-fmt
|
||||
pkgs.pre-commit
|
||||
pkgs.hci
|
||||
];
|
||||
shellHook = ''
|
||||
${config.pre-commit.installationScript}
|
||||
|
@ -30,5 +31,10 @@
|
|||
# for repl exploration / debug
|
||||
config.config = config;
|
||||
options.mySystem = lib.mkOption { default = config.allSystems.${builtins.currentSystem}; };
|
||||
config.effects = withSystem "x86_64-linux" ({ config, pkgs, hci-effects, ... }: {
|
||||
tests = {
|
||||
template = pkgs.callPackage ./tests/template.nix { inherit hci-effects; };
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
15
dev/tests/README.md
Normal file
15
dev/tests/README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
# Running the tests
|
||||
|
||||
These tests can be run locally with the `hci effect run` command. This gives
|
||||
the tests access to a proper nix daemon and the network.
|
||||
|
||||
Designed for convenient deployments, it needs some information from git. You
|
||||
may use `--no-token` to disable this functionality if you're getting errors, or
|
||||
if you're asked to log in.
|
||||
|
||||
Example:
|
||||
|
||||
```console
|
||||
hci effect run --no-token default.effects.tests.template
|
||||
```
|
37
dev/tests/template.nix
Normal file
37
dev/tests/template.nix
Normal file
|
@ -0,0 +1,37 @@
|
|||
{ hci-effects, nix, git, path }:
|
||||
|
||||
hci-effects.mkEffect {
|
||||
inputs = [ nix git ];
|
||||
effectScript = ''
|
||||
ann() { # announce
|
||||
printf '\n\e[34;1m%s\e[0m\n' "$*"
|
||||
}
|
||||
mkdir -p ~/.config/nix
|
||||
echo 'experimental-features = nix-command flakes' >>~/.config/nix/nix.conf
|
||||
mkdir clean
|
||||
cd clean
|
||||
|
||||
ann nix flake init...
|
||||
nix -v flake init -t ${../..}
|
||||
|
||||
ann pointing to local sources...
|
||||
sed -i flake.nix -e 's^nixpkgs.url = ".*";^nixpkgs.url = "${path}"; flake-parts.url = "${../..}";^'
|
||||
# head flake.nix
|
||||
grep -F ${path} flake.nix >/dev/null
|
||||
|
||||
ann nix flake lock...
|
||||
nix flake lock
|
||||
|
||||
ann nix flake show...
|
||||
nix -v flake show
|
||||
|
||||
ann nix build...
|
||||
nix build .
|
||||
|
||||
ann checking result...
|
||||
readlink ./result | grep hello
|
||||
|
||||
echo
|
||||
printf '\n\e[32;1m%s\e[0m\n' 'All good!'
|
||||
'';
|
||||
}
|
|
@ -1,21 +1,55 @@
|
|||
{ config, lib, flake-parts-lib, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
filterAttrs
|
||||
mapAttrs
|
||||
mkOption
|
||||
optionalAttrs
|
||||
types
|
||||
;
|
||||
inherit (flake-parts-lib)
|
||||
mkTransposedPerSystemModule
|
||||
mkSubmoduleOptions
|
||||
mkPerSystemOption
|
||||
;
|
||||
in
|
||||
mkTransposedPerSystemModule {
|
||||
name = "formatter";
|
||||
option = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = null;
|
||||
description = ''
|
||||
A package used by [`nix fmt`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-fmt.html).
|
||||
'';
|
||||
{
|
||||
options = {
|
||||
flake = mkSubmoduleOptions {
|
||||
formatter = mkOption {
|
||||
type = types.lazyAttrsOf types.package;
|
||||
default = { };
|
||||
description = ''
|
||||
An attribute set of per system a package used by [`nix fmt`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-fmt.html).
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = mkPerSystemOption ({ config, ... }: {
|
||||
_file = ./formatter.nix;
|
||||
options = {
|
||||
formatter = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = null;
|
||||
description = ''
|
||||
A package used by [`nix fmt`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-fmt.html).
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
config = {
|
||||
flake.formatter =
|
||||
mapAttrs
|
||||
(k: v: v.formatter)
|
||||
(filterAttrs
|
||||
(k: v: v.formatter != null)
|
||||
config.allSystems
|
||||
);
|
||||
|
||||
perInput = system: flake:
|
||||
optionalAttrs (flake?formatter.${system}) {
|
||||
formatter = flake.formatter.${system};
|
||||
};
|
||||
|
||||
};
|
||||
file = ./formatter.nix;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue