93 lines
1.7 KiB
Nix
93 lines
1.7 KiB
Nix
{
|
|
checkSystem,
|
|
lib,
|
|
checkPkgs,
|
|
...
|
|
}:
|
|
let
|
|
petCats =
|
|
{
|
|
lib,
|
|
pkgs,
|
|
cats,
|
|
}:
|
|
pkgs.writeShellScript "pet-cats" (
|
|
lib.concatStringsSep "\n" (
|
|
map (
|
|
cat:
|
|
if cat == "niko" then
|
|
builtins.warn "niko is not a cat!!!" ""
|
|
else
|
|
"${pkgs.coreutils}/bin/printf 'cat %s has been petted!' ${lib.escapeShellArg cat}"
|
|
) (lib.unique (lib.sort (a: b: a < b) cats))
|
|
)
|
|
);
|
|
catsModule =
|
|
{ lib, ... }:
|
|
{
|
|
config.outputKinds = [
|
|
(_: {
|
|
options = with lib; {
|
|
cats = mkOption {
|
|
type = with types; listOf str;
|
|
description = "a list of cats to pet";
|
|
};
|
|
};
|
|
outputs =
|
|
{
|
|
lib,
|
|
hasSystem,
|
|
config,
|
|
system,
|
|
pkgs,
|
|
...
|
|
}:
|
|
lib.optionalAttrs hasSystem {
|
|
apps.${system}.catPetters = {
|
|
type = "app";
|
|
program = petCats {
|
|
cats = config.cats;
|
|
inherit lib pkgs;
|
|
};
|
|
};
|
|
};
|
|
})
|
|
];
|
|
};
|
|
in
|
|
{
|
|
outputs = [ catsModule ];
|
|
modules = [
|
|
(_: {
|
|
config = {
|
|
cats = [ "orange" ];
|
|
};
|
|
})
|
|
(_: {
|
|
config = {
|
|
cats = [ "pink" ];
|
|
};
|
|
})
|
|
(_: {
|
|
config = {
|
|
cats = [ "niko" ]; # uh oh
|
|
};
|
|
})
|
|
];
|
|
fails = false;
|
|
expectedOutput = {
|
|
|
|
apps.${checkSystem}.catPetters = {
|
|
type = "app";
|
|
program = petCats {
|
|
cats = [
|
|
"orange"
|
|
"pink"
|
|
"niko"
|
|
];
|
|
inherit lib;
|
|
pkgs = checkPkgs;
|
|
};
|
|
};
|
|
};
|
|
}
|