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 plugin module for cleaning up external API interface
  • Loading branch information
jmgilman committed Jun 4, 2022
commit 5338e72a1010a202e0975b0871d6ae8c356c7258
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@
];
};
in
{
rec {
# Load lib functions
lib = (import ./lib { inherit pkgs lib; });
lib = (import ./lib { inherit pkgs lib plugins; });

# Load plugins
plugins = import ./plugins { inherit pkgs lib; };
Expand Down
4 changes: 1 addition & 3 deletions lib/all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
configuration derivations and shellHook is a concatenated version of all
configuration shellHooks.
*/
{ pkgs, lib }:
{ pkgs, lib, plugins }:
all:
with pkgs.lib;
let
plugins = import ../plugins { inherit pkgs lib; };

# Create separate sets of plugin calls and plugin options
filteredOpts = filterAttrs
(path: data: (
Expand Down
10 changes: 6 additions & 4 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{ pkgs, lib }:
{ pkgs, lib, plugins }:
{
eval = import ./eval.nix { inherit pkgs lib; };
eval = import ./eval.nix { inherit pkgs lib plugins; };

mkAll = import ./all.nix { inherit pkgs lib; };
make = import ./make.nix { inherit pkgs lib plugins; };

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

/* Combines the shellHook from multiple configurations into one.
*/
mkShellHook = configs:
builtins.concatStringsSep "\n" (pkgs.lib.catAttrs "shellHook" configs);

mkTemplate = import ./template.nix { inherit pkgs lib; };
mkTemplate = import ./template.nix { inherit pkgs lib plugins; };
}
2 changes: 1 addition & 1 deletion lib/eval.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Evaluates the given input files and configData and returns a derivation which
builds the result.
*/
{ pkgs, lib }:
{ pkgs, lib, plugins }:
{ inputFiles
, outputFile
, postBuild ? ""
Expand Down
19 changes: 19 additions & 0 deletions lib/make.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ pkgs, lib, plugins }:
{ name, config, type ? "", output ? "", mode ? "", options ? { } }:
with pkgs.lib;
let
plugin = plugins.${name};
options = ({ configData = config; }
// optionalAttrs (type != "") { inherit type; }
// optionalAttrs (output != "") { inherit output; }
// optionalAttrs (mode != "") { inherit mode; }
// optionalAttrs (options != { }) { inherit options; });

config = (evalModules {
modules = [
../modules/plugin.nix
options
];
}).config;
in
plugin config
2 changes: 1 addition & 1 deletion lib/template.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
underlying `cue eval` command. The function returns the evaluated config from
the module.
*/
{ pkgs, lib }:
{ pkgs, lib, plugins }:
{ configData
, files
, output
Expand Down
34 changes: 34 additions & 0 deletions modules/plugin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ config, lib, flakeLib, pkgs, ... }:
with pkgs.lib;
{
options = {
configData = mkOption {
type = types.attrs;
description = "The raw configuration data";
};
mode = mkOption {
type = types.str;
description = "The output mode to use";
default = "link";
};
name = mkOption {
type = types.str;
description = "The plugin to use";
};
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";
};
};
}