From 925a52cf8f17b4bf8ea0285b8c15fbc9be3b3b67 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Thu, 7 Mar 2024 09:59:58 -0800 Subject: [PATCH] chore(hass): finalPackage attr --- modules/nixos/home-assistant.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/nixos/home-assistant.nix b/modules/nixos/home-assistant.nix index 7c63b82f..c9b2d4be 100644 --- a/modules/nixos/home-assistant.nix +++ b/modules/nixos/home-assistant.nix @@ -5,7 +5,7 @@ ... }: let cfg = config.services.home-assistant; - inherit (lib.modules) mkIf mkMerge mkBefore mkDefault; + inherit (lib.modules) mkIf mkMerge mkBefore mkDefault mkOptionDefault; inherit (lib.options) mkOption mkEnableOption; inherit (lib.lists) optional optionals elem unique; inherit (lib.strings) toLower; @@ -41,6 +41,10 @@ in { default = cfg.openFirewall; }; }; + finalPackage = mkOption { + type = types.path; + readOnly = true; + }; }; config = { @@ -180,6 +184,18 @@ in { "test_check_config" ]); }); + finalPackage = let + inherit (lib.strings) hasSuffix removeSuffix splitString; + inherit (lib.lists) head; + inherit (lib.attrsets) attrNames filterAttrs; + inherit (config.systemd.services.home-assistant.serviceConfig) ExecStart; + isHassDrv = drv: context: hasSuffix "-${cfg.package.name}.drv" drv && context.outputs or [ ] == [ "out" ]; + drvs = filterAttrs isHassDrv (builtins.getContext ExecStart); + isImpure = builtins ? currentSystem; + in mkIf cfg.enable (mkOptionDefault ( + if isImpure then import (head (attrNames drvs)) + else removeSuffix "/bin/hass" (head (splitString " " ExecStart)) + )); extraPackages = python3Packages: with python3Packages; mkMerge [ [ psycopg2