huecli/flake.nix

177 lines
4.9 KiB
Nix
Raw Normal View History

2024-06-04 14:08:08 +00:00
{
2024-11-28 20:42:45 +00:00
description = "Set Philips Hue lights using MQTT";
2024-06-04 14:08:08 +00:00
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2024-11-28 20:42:45 +00:00
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";
2024-06-04 14:08:08 +00:00
inputs.nixpkgs.follows = "nixpkgs";
};
};
2024-11-28 20:42:45 +00:00
outputs =
2024-06-04 14:43:57 +00:00
{
2024-11-28 20:42:45 +00:00
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";
2024-06-04 14:43:57 +00:00
};
2024-11-28 20:42:45 +00:00
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 {
2024-06-15 09:43:36 +00:00
python = pkgs.python312;
2024-11-28 20:42:45 +00:00
};
# 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};
2024-11-28 22:23:52 +00:00
venv = pythonSet.mkVirtualEnv "huecli-env" workspace.deps.default;
2024-11-28 20:42:45 +00:00
in
{
2024-11-28 22:23:52 +00:00
default = pkgs.stdenv.mkDerivation {
2024-11-30 00:43:13 +00:00
pname = "huecli";
2024-11-30 00:36:05 +00:00
version = pythonSet.huecli.version;
2024-11-28 22:23:52 +00:00
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)
'';
};
2024-11-28 20:42:45 +00:00
}
);
2024-11-28 21:26:44 +00:00
overlays.default = final: prev: {
huecli = self.packages.${prev.system}.default;
};
2024-11-28 20:42:45 +00:00
# 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
2024-06-04 14:08:08 +00:00
'';
};
2024-11-28 20:42:45 +00:00
}
);
};
2024-06-04 14:08:08 +00:00
}