Skip to content

Commit

Permalink
feat: adds postBuild argument and formats justfile after generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed May 27, 2022
1 parent 3a82171 commit aa68983
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/eval.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Evaluates the given input files and data and returns a derivation which builds the result.
*/
{ pkgs, lib }:
{ inputFiles, outputFile, data ? { }, cue ? pkgs.cue, ... }@args:
{ inputFiles, outputFile, postBuild ? "", data ? { }, cue ? pkgs.cue, ... }@args:
with pkgs.lib;
let
json = optionalString (data != { }) (builtins.toJSON data);

defaultFlags = {
outfile = "$out";
};
extraFlags = removeAttrs args [ "inputFiles" "outputFile" "data" "cue" ];
extraFlags = removeAttrs args [ "inputFiles" "outputFile" "postBuild" "data" "cue" ];

allFlags = defaultFlags // extraFlags;
allInputs = inputFiles ++ optionals (json != "") [ "json: $jsonPath" ];
Expand All @@ -29,6 +29,7 @@ let
''
echo "nixago: Rendering output..."
${cueEvalCmd}
${postBuild}
'';
in
result
4 changes: 2 additions & 2 deletions lib/template.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
the module.
*/
{ pkgs, lib }:
{ data, files, output, shellHookExtra ? "", flags ? { } }:
{ data, files, output, postBuild ? "", shellHookExtra ? "", flags ? { } }:
with pkgs.lib;
let
result = evalModules {
modules = [
../modules/template.nix
{
inherit data files output shellHookExtra;
inherit data files output postBuild shellHookExtra;
}
];
specialArgs = ({ inherit pkgs; flakeLib = lib; } // flags);
Expand Down
6 changes: 6 additions & 0 deletions modules/template.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ in
inputFiles = config.files;
outputFile = config.output;
data = config.data;
postBuild = config.postBuild;
} // flags);
};
data = mkOption {
Expand All @@ -60,6 +61,11 @@ in
type = types.str;
description = "The name of the file to generate";
};
postBuild = mkOption {
type = types.str;
description = "Commands to run after the configuration is built";
default = "";
};
shellHook = mkOption {
type = types.str;
description = "Shell hook for linking generated configuration file";
Expand Down
3 changes: 3 additions & 0 deletions plugins/just/make.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ let
data = { data = config; };
files = [ ./template.cue ];
output = ".justfile";
postBuild = ''
${pkgs.just}/bin/just --unstable --fmt -f $out
'';
flags = {
expression = "rendered";
out = "text";
Expand Down
2 changes: 1 addition & 1 deletion tests/just/expected.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var := "value"

task1:
echo "Doing the thing"
@doThing

0 comments on commit aa68983

Please sign in to comment.