{ description = "Set Philips Hue lights using MQTT"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; pyproject-nix = { url = "github:pyproject-nix/pyproject.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; uv2nix = { url = "github:pyproject-nix/uv2nix"; inputs.pyproject-nix.follows = "pyproject-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; pyproject-build-systems = { url = "github:pyproject-nix/build-system-pkgs"; inputs.pyproject-nix.follows = "pyproject-nix"; inputs.uv2nix.follows = "uv2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, uv2nix, pyproject-nix, pyproject-build-systems, ... }: let inherit (nixpkgs) lib; forAllSystems = lib.genAttrs lib.systems.flakeExposed; workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; }; overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; }; editableOverlay = workspace.mkEditablePyprojectOverlay { root = "$REPO_ROOT"; }; # Python sets grouped per system pythonSets = forAllSystems ( system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) stdenv; # Base Python package set from pyproject.nix baseSet = pkgs.callPackage pyproject-nix.build.packages { python = pkgs.python312; }; # An overlay of build fixups & test additions pyprojectOverrides = ( final: prev: { huecli = prev.huecli.overrideAttrs (old: { # Add tests to passthru.tests # # These attribute are used in Flake checks. passthru = old.passthru // { tests = (old.tests or { }) // { # Run mypy checks mypy = let venv = final.mkVirtualEnv "huecli-typing-env" { huecli = [ "typing" ]; }; in stdenv.mkDerivation { name = "${final.huecli.name}-mypy"; inherit (final.huecli) src; nativeBuildInputs = [ venv ]; dontConfigure = true; dontInstall = true; buildPhase = '' mkdir $out mypy --strict huecli --junit-xml $out/junit.xml ''; }; }; }; }); } ); in baseSet.overrideScope ( lib.composeManyExtensions [ pyproject-build-systems.overlays.default overlay pyprojectOverrides ] ) ); in { checks = forAllSystems ( system: let pythonSet = pythonSets.${system}; in # Inherit tests from passthru.tests into flake checks pythonSet.huecli.passthru.tests ); packages = forAllSystems ( system: let pkgs = nixpkgs.legacyPackages.${system}; pythonSet = pythonSets.${system}; venv = pythonSet.mkVirtualEnv "huecli-env" workspace.deps.default; in { default = pkgs.stdenv.mkDerivation { pname = "huecli"; # TODO: Fix this, get version from pyproject version = "0.1.7"; dontConfigure = true; dontUnpack = true; dontBuild = true; buildInputs = [ venv ]; nativeBuildInputs = [ pkgs.installShellFiles ]; postInstall = '' mkdir -p $out/bin ln -s ${venv}/bin/huecli $out/bin/huecli installShellCompletion --cmd huecli \ --bash <($out/bin/huecli --show-completion bash) \ --zsh <($out/bin/huecli --show-completion zsh) \ --fish <($out/bin/huecli --show-completion fish) ''; }; } ); overlays.default = final: prev: { huecli = self.packages.${prev.system}.default; }; # Use an editable Python set for development. devShells = forAllSystems ( system: let pkgs = nixpkgs.legacyPackages.${system}; editablePythonSet = pythonSets.${system}.overrideScope editableOverlay; venv = editablePythonSet.mkVirtualEnv "huecli-dev-env" { huecli = [ "dev" ]; }; in { default = pkgs.mkShell { packages = [ venv pkgs.uv ]; shellHook = '' unset PYTHONPATH export REPO_ROOT=$(git rev-parse --show-toplevel) export UV_NO_SYNC=1 ''; }; } ); }; }