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

nixos/home-assistant: allow arbitrary yaml functions #89337

Merged
merged 1 commit into from Jun 3, 2020

Conversation

mweinelt
Copy link
Member

@mweinelt mweinelt commented Jun 2, 2020

Motivation for this change

I'm trying to load additional themes without specifying them by hand:

{
  services.home-assistant.config.frontend = {
    themes = "!include_dir_merge_named themes";
  };
}

Without this patch the resulting config would quote the function call:

frontend:
  themes = '!include_dir_merge_named themes'

This prevents the function calls execution. The same workaround has been in place for the !secret function, let's now extend it to arbitrary functions.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Mic92 @dotlambda

Comment on lines 14 to 15
# Hack to support secrets, that are encoded as custom yaml objects,
# https://www.home-assistant.io/docs/configuration/secrets/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Hack to support secrets, that are encoded as custom yaml objects,
# https://www.home-assistant.io/docs/configuration/secrets/
# Hack to support custom yaml objects,
# i.e. secrets: https://www.home-assistant.io/docs/configuration/secrets/

@@ -13,7 +13,7 @@ let
${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
# Hack to support secrets, that are encoded as custom yaml objects,
# https://www.home-assistant.io/docs/configuration/secrets/
sed -i -e "s/'\!secret \(.*\)'/\!secret \1/" $out
sed -i -e "s/'\!\([^[:space:]]\+\) \(.*\)'/\!\1 \2/" $out
Copy link
Member

@Mic92 Mic92 Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should allow to escape \! at the beginning of a string:

Suggested change
sed -i -e "s/'\!\([^[:space:]]\+\) \(.*\)'/\!\1 \2/" $out
sed -i -e "s/'\!\(([a-z_]\+\) \(.*\)'/\!\1 \2/;s/^\!\!/\!/;" $out

untested, but hopefully comprehensible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that as if you want a literal exclamation mark at the beginning of your string use "!!something" => "!something". Is that correct?

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, probably didn't properly update the nixpkgs checkout when testing.

@mweinelt mweinelt force-pushed the hass-yaml-fun branch 3 times, most recently from 5a39308 to 1e135e4 Compare June 2, 2020 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants