nix-community.nixvim/tests/test-sources/modules/dependencies.nix
Matt Sturgeon 16879e3034
modules/dependencies: refactor all-examples test
Embed the original `path` as an attr in the literal expression, so that
we don't need to convert back from human readable paths in the test.
2025-04-13 18:23:06 +01:00

50 lines
1.2 KiB
Nix

{
override =
{ pkgs, ... }:
{
dependencies.git = {
enable = true;
package = pkgs.gitMinimal;
};
};
all =
{
lib,
pkgs,
options,
...
}:
{
dependencies = lib.mapAttrs (_: depOption: {
enable = lib.meta.availableOn pkgs.stdenv.hostPlatform depOption.package.default;
}) options.dependencies;
};
all-examples =
{
lib,
pkgs,
options,
...
}:
{
dependencies = lib.pipe options.dependencies [
# We use a literalExpression example, with an additional `path` attr.
# This means we don't have to convert human readable paths back to list-paths for this test.
(lib.filterAttrs (_: depOption: depOption.package ? example.path))
(lib.mapAttrs (
_: depOption:
let
packagePath = depOption.package.example.path;
packageName = lib.showAttrPath packagePath;
package = lib.attrByPath packagePath (throw "${packageName} not found in pkgs") pkgs;
in
{
enable = lib.meta.availableOn pkgs.stdenv.hostPlatform package;
inherit package;
}
))
];
};
}