Missing attribute on config.services

I was referring to nixos wiki for home-assistant, and came with the following config. I need to allow my hass server to be accessible on the port its configured on.

{ config, pkgs, ... }:
{
  services.home-assistant = {
    enable = true;
    openFirewall = true;
    package = pkgs.unstable.home-assistant;
    extraComponents = [
      "apple_tv"
      "met"
      "lastfm_scrobbler"
      "hacs"
      "divoom_pixoo"
      "isal"
    ];
    config = {
      default_config = { };
      http = {
        trusted_proxies = [
          "::1"
          "127.0.0.1"
        ];
        use_x_forwarded_for = true;
      };
      "automation ui" = "!include automations.yaml";
      "scene ui" = "!include scenes.yaml";
      "script ui" = "!include scripts.yaml";
      recorder.db_url = "postgresql://@/hass";
    };
    extraPackages = ps: with ps; [ psycopg2 ];
  };

  services.postgresql = {
    enable = true;
    ensureDatabases = [ "hass" ];
    ensureUsers = [{
      name = "hass";
      ensureDBOwnership = true;
    }];
  };

  networking.firewall.allowedTCPPorts = [
    config.services.home-assistant.config.http.server_port
    1883
  ];
  systemd.tmpfiles.rules = [
    "f ${config.services.home-assistant.configDir}/automations.yaml 0755 hass hass"
  ];

  services.mosquitto = {
    enable = true;
    listeners = [
      {
        acl = [ "pattern readwrite #" ];
        omitPasswordAuth = true;
        settings.allow_anonymous = true;
      }
    ];
  };

}

Upon running home-manager switch --flake .#username@hostname I get the following error

error: attribute 'home-assistant' missing
       at /nix/store/i0f9rldmf3vx4pxc3qjgiawwm5w3bp72-source/home-manager/homelab/hass.nix:42:5:
           41|   networking.firewall.allowedTCPPorts = [
           42|     config.services.home-assistant.config.http.server_port
             |     ^
           43|     1883

I am pretty new to nixos configuration so any help would be amazing.

note that I am using the starter configs for organizing my nix configs from here nix-starter-configs/standard at main · Misterio77/nix-starter-configs · GitHub

I have imports configured ofc. Here is a tree output of my home-manager config (home.nix, imports homelab, where i have hass imported into default.nix)

home-manager/
├── homelab
│   ├── default.nix
│   └── hass.nix
├── home.nix

Sorry you got roped into a bad template. Use this instead. Also this is NixOS config not HM: flake-migration/nixos.md at d9e00d26de6fbf4aaf2ced29ea95542c3a795525 · eclairevoyant/flake-migration · GitHub

Besides that, just use services.home-assistant.openFirewall = true;, you don’t need to add ports manually. I don’t bother with the wikis generally.

Okay so I had to switch from path-based to a flake based config. Makes sense. But now I am not sure if I am supposed to get rid of the template?

What about this line? Also failing with the same error.

Home-manager doesn’t have a home-assistant module; home-assistant is a system service, running it as your user makes little sense.

You’ll need to do this with NixOS.

1 Like