Skip to content

Commit

Permalink
Switch to JSON for config (#59)
Browse files Browse the repository at this point in the history
* Switch to JSON for config

* rename options accordingly

* changelog
  • Loading branch information
srid authored Feb 22, 2024
1 parent b346fb3 commit dded78f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- #52: Add `is_foreground` option
- #54: Add `apiServer` option to control REST API server
- #56: Add `preHook` and `postHook` for running commands before and after launching process-compose respectively.
- Notable changes
- #58: Obviate IFD by switching to JSON config
- Fixes
- #19: Reintroduce the `shell` option so process-compose doesn't rely on user's global bash (which doesn't exist nixosTest runners).
- #22: `command` option is no longer wrapped in `writeShellApplication`.
Expand Down
4 changes: 2 additions & 2 deletions nix/process-compose/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ in
{
inherit name;
inherit (config) tui apiServer port preHook postHook;
configFile = config.outputs.settingsYaml;
configFile = config.outputs.settingsFile;
};
testPackage =
if
Expand All @@ -75,7 +75,7 @@ in
{
name = "${name}-test";
inherit (config) tui apiServer port preHook postHook;
configFile = config.outputs.settingsTestYaml;
configFile = config.outputs.settingsTestFile;
}
else null;
};
Expand Down
22 changes: 12 additions & 10 deletions nix/process-compose/settings/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ in
Which runs process-compose with the declared config.
'';
};
outputs.settingsYaml = mkOption {
outputs.settingsFile = mkOption {
type = types.attrsOf types.raw;
internal = true;
description = ''
The settings file that will be used to run the process-compose flake.
'';
};

outputs.settingsTestYaml = mkOption {
outputs.settingsTestFile = mkOption {
type = types.attrsOf types.raw;
internal = true;
};
Expand All @@ -106,16 +109,15 @@ in
# evaluate it again and to get rid of it.
in
lib.pipe attrs [ f f ];
toYAMLFile =
attrs:
pkgs.runCommand "${name}.yaml" { buildInputs = [ pkgs.yq-go ]; } ''
yq -oy -P '.' ${pkgs.writeTextFile { name = "process-compose-${name}.json"; text = (builtins.toJSON attrs); }} > $out
'';

toPCJson = attrs:
pkgs.writeTextFile {
name = "process-compose-${name}.json";
text = builtins.toJSON attrs;
};
in
{
settingsYaml = toYAMLFile (removeNullAndEmptyAttrs config.settings);
settingsTestYaml = toYAMLFile (removeNullAndEmptyAttrs
settingsFile = toPCJson (removeNullAndEmptyAttrs config.settings);
settingsTestFile = toPCJson (removeNullAndEmptyAttrs
(lib.updateManyAttrsByPath [
{
path = [ "processes" "test" ];
Expand Down

0 comments on commit dded78f

Please sign in to comment.