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: fix bug causing config file not to be written (including http.server_port) #82480

Closed
wants to merge 2 commits into from

Conversation

matt-snider
Copy link
Contributor

@matt-snider matt-snider commented Mar 13, 2020

Motivation for this change

This fixes #82076 by ensuring that the configuration.yaml file is always (over)written. I think this approach simplifies things a bit, and to me aligns more with what I would assume "default config" means. I'm not sure it's the right way though, since it changes the behaviour of applyDefaultConfig.

It would be great to get some feedback on a few points in particular:

  • Would is be better to set defaultConfig to a subset of the contents of the default configuration.yaml file plus the port and timezone? For now I just have frontend in there. This might be less of a breaking change but it would mean keeping up to date when home-assistant changes that file. For reference, this is what that file looks like:
    # Configure a default setup of Home Assistant (frontend, api, etc)
    default_config:
    
    # Uncomment this if you are using SSL/TLS, running in Docker container, etc.
    # http:
    #   base_url: example.duckdns.org:8123
    
    # Text to speech
    tts:
      - platform: google_translate
    
    # These files all start off empty
    group: !include groups.yaml
    automation: !include automations.yaml
    script: !include scripts.yaml
    scene: !include scenes.yaml
    
  • Tests: I've never written nixos tests before, so I don't know if this is the right approach, or whether this kind of test is necessary. Either way, it was useful to debug the problem.

NOTE: some of the home-assistant tests seem to be failing currently, but this appears to be caused by #82441

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.

…viour

If the `config` option is not set, the `port` option has no effect. This
is caused by the condition `cfg.config != null` not passing, resulting
in the default `configuration.yaml` file not being overwritten.

If `time.timeZone` isn't set, it also appears to cause home-assistant to
error out.

Another issue is that the `defaultConfig` doesn't currently set `frontend`
which means in the minimal setup with just `port` set, we still won't be able
to reach the frontend.
@stale
Copy link

stale bot commented Sep 27, 2020

Hello, I'm a bot and I thank you in the name of the community for your contributions.

Nixpkgs is a busy repository, and unfortunately sometimes PRs get left behind for too long. Nevertheless, we'd like to help committers reach the PRs that are still important. This PR has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

If this is still important to you and you'd like to remove the stale label, we ask that you leave a comment. Your comment can be as simple as "still important to me". But there's a bit more you can do:

If you received an approval by an unprivileged maintainer and you are just waiting for a merge, you can @ mention someone with merge permissions and ask them to help. You might be able to find someone relevant by using Git blame on the relevant files, or via GitHub's web interface. You can see if someone's a member of the nixpkgs-committers team, by hovering with the mouse over their username on the web interface, or by searching them directly on the list.

If your PR wasn't reviewed at all, it might help to find someone who's perhaps a user of the package or module you are changing, or alternatively, ask once more for a review by the maintainer of the package/module this is about. If you don't know any, you can use Git blame on the relevant files, or GitHub's web interface to find someone who touched the relevant files in the past.

If your PR has had reviews and nevertheless got stale, make sure you've responded to all of the reviewer's requests / questions. Usually when PR authors show responsibility and dedication, reviewers (privileged or not) show dedication as well. If you've pushed a change, it's possible the reviewer wasn't notified about your push via email, so you can always officially request them for a review, or just @ mention them and say you've addressed their comments.

Lastly, you can always ask for help at our Discourse Forum, or more specifically, at this thread or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 27, 2020
@matt-snider
Copy link
Contributor Author

@colemickens or @dotlambda does this change make sense to either of you?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 27, 2020
@colemickens
Copy link
Member

I'm not sure I'm familiar enough, or having enough time, to review this well. cc: @Mic92 even though I think they've seen it.

@aanderse
Copy link
Member

ping @colemickens @dotlambda @Mic92 @peterhoeg

I'm sure @matt-snider would appreciate a review very much so. Is anyone able to sacrifice some time and help out with this? ❤️

@@ -225,7 +228,7 @@ in {
systemd.services.home-assistant = {
description = "Home Assistant";
after = [ "network.target" ];
preStart = optionalString (cfg.config != null) (if cfg.configWritable then ''
Copy link
Member

Choose a reason for hiding this comment

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

So the actual bug fix is this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but I believe frontend missing was also causing issues. It's been quite a while though and it's not that fresh anymore. I'll have to spend some time going through and running it in various situations.

Comment on lines +20 to +28
hassMinimal = mkHass {};

hassTimeZone = mkHass {
machineAttrs = { time.timeZone = "UTC"; };
};

hassNoDefault = mkHass {
hassAttrs = { applyDefaultConfig = false; };
};
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are going to need all those tests. They don't test much but still needs to be maintained and they are expensive to evaluate. It would be fine if they only would generate the configuration but they spawn actual VMs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @Mic92 thanks for the feedback. This was my feeling as well, but I wasn't sure how to do unit tests in Nix. Perhaps I just missed some examples or documentation. Is there anything you could point me to that might help?

@aanderse
Copy link
Member

Thank you @Mic92!

@matt-snider matt-snider mentioned this pull request Jan 16, 2021
10 tasks
@mweinelt mweinelt added this to To do in Home Assistant via automation May 4, 2021
@stale
Copy link

stale bot commented Jun 22, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 22, 2021
@aanderse
Copy link
Member

@matt-snider what do you need to push this through to the finish line?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 23, 2021
@matt-snider
Copy link
Contributor Author

@aanderse Thanks for following up! I think the main suggestion from @Mic92 was to remove the tests. Otherwise, from his comment "So the actual bug fix is this line?", I interpret that a more minimal change would be preferable. That's understandable, since it probably would have allowed this to be more easily approved.

Perhaps we should just close this PR, since it's over a year old, and I haven't run it with newer versions of home assistant. It doesn't seem to affect many people, judging by activity on this PR and the original issue.

@aanderse
Copy link
Member

Sorry things didn't go super smooth.

@matt-snider
Copy link
Contributor Author

@aanderse Not at all. I should have been more proactive with this one.

Thank you for all the work you and many others do on Nix. It really is an incredible project! I'd like to help out more but you know... time management :-/

Home Assistant automation moved this from Incoming to Done Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

home-assistant port doesn't do anything unless config is set
4 participants