Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: standardizes the plugin interface #10

Merged
merged 14 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: adds module interfaces for cleaning up internal API
  • Loading branch information
jmgilman committed Jun 5, 2022
commit a000443c7d9f13f1ef0598ffe9ba813df4080e1b
3 changes: 3 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{ pkgs, lib, plugins }:
{
inherit (import ../modules { inherit pkgs; })
mkConfigResult mkEvalRequest mkPluginRequest;

eval = import ./eval.nix { inherit pkgs lib plugins; };

genConfig = import ./generate.nix { inherit pkgs lib plugins; };
Expand Down
14 changes: 14 additions & 0 deletions modules/config_result.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ config, lib, ... }:
with lib;
{
options = {
file = mkOption {
type = types.package;
description = "The derivation for generating the configuration file";
};
shellHook = mkOption {
type = types.str;
description = "The shell hook for managing the generated file";
};
};
}
38 changes: 38 additions & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ pkgs }:
with pkgs.lib;
{
mkConfigResult = { file, shellHook }:
evalModules ({
modules = [
../modules/config.nix
{
inherit file shellHook;
}
];
}).config;
mkEvalRequest = { pluginRequest, files, flags ? [ ], postBuild ? "", shellHookExtra ? "" }:
evalModules ({
modules = [
../modules/eval_request.nix
{
inherit name configData;
}
(optionalAttrs (flags != [ ]) { inherit flags; })
(optionalAttrs (postBuild != "") { inherit postBuild; })
(optionalAttrs (shellHookExtra != "") { inherit shellHookExtra; })
];
}).config;
mkPluginRequest = { name, configData, mode ? "", options ? { }, output ? "", type ? "" }:
evalModules ({
modules = [
../modules/plugin_request.nix
{
inherit name configData;
}
(optionalAttrs (mode != "") { inherit mode; })
(optionalAttrs (options != { }) { inherit options; })
(optionalAttrs (output != "") { inherit output; })
(optionalAttrs (type != "") { inherit type; })
];
}).config;
}
29 changes: 29 additions & 0 deletions modules/eval_request.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ config, lib, ... }:
with lib;
{
options = {
pluginRequest = mkOption {
type = types.submodule (import ./plugin_request.nix);
description = "The embedded plugin request";
};
files = mkOption {
type = types.listOf types.str;
description = "A list of input files to evaluate";
};
flags = mkOption {
type = types.attrs;
description = "An optional list of flags to pass to cue eval";
default = [ ];
};
postBuild = mkOption {
type = types.str;
description = "Shell code to run after executing cue eval";
default = "";
};
shellHookExtra = mkOption {
type = types.str;
description = "Shell code to run after configuration file is updated";
default = "";
};
};
}
34 changes: 34 additions & 0 deletions modules/plugin_request.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ config, lib, ... }:
with lib;
{
options = {
name = mkOption {
type = types.str;
description = "The plugin to use";
};
configData = mkOption {
type = types.anything;
description = "The raw configuration data";
};
mode = mkOption {
type = types.str;
description = "The output mode to use";
default = "link";
};
options = mkOption {
type = types.attrs;
description = "Additional options to pass to the plugin";
default = { };
};
output = mkOption {
type = types.str;
description = "The output path of the generated configuration file";
default = "";
};
type = mkOption {
type = types.str;
description = "The type of configuration to generate";
default = "default";
};
};
}