Skip to content

Commit

Permalink
feat: reify requests (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jul 29, 2022
1 parent 8aa25d6 commit 1c8f4b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lib/make.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ let
in
lib.mkRequest [ maybeLocatedRequest ];

# Apply specific transformations to the request's configData & extra
reifiedRequest = userRequest // {
configData = userRequest.apply userRequest.configData;
hook = userRequest.hook // {
extra =
if builtins.isFunction userRequest.hook.extra
then userRequest.hook.extra userRequest.configData
else userRequest.hook.extra;
};
};

# The defined interface between Nixago and an engine is that it takes exactly
# one parameter: an instance of the request module. The result should be a
# derivation which builds the desired configuration file.
configFile = userRequest.engine userRequest;
configFile = userRequest.engine reifiedRequest;

# TODO: Remove this once we convert everything over to the new framework
name = "temp";

# TODO: Simplify this once we convert everything over to the new framework
hookConfig = {
inherit (userRequest) output;
inherit (userRequest.hook) extra mode;
inherit (reifiedRequest) output;
inherit (reifiedRequest.hook) extra mode;
};

# Builds the shell hook for managing the generated file.
Expand Down
7 changes: 6 additions & 1 deletion modules/request.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
options = {
# TODO: Make this a list
extra = mkOption {
type = types.str;
type = types.either types.str (types.functionTo types.str);
description = "Shell code to run when the file is updated";
default = "";
};
Expand Down Expand Up @@ -50,6 +50,11 @@ in
description = "Additional options for controlling hook generation";
default = { };
};
apply = mkOption {
type = types.functionTo types.anything;
description = "Apply this transformation to `configData`";
default = x: x;
};
output = mkOption {
type = types.str;
description = "The relative path to link the generated file";
Expand Down

0 comments on commit 1c8f4b3

Please sign in to comment.