huecli/flake.nix
2024-06-04 16:09:05 +02:00

70 lines
2.3 KiB
Nix

{
description = "Application packaged using poetry2nix";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
pkgs = nixpkgs.legacyPackages.${system};
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication defaultPoetryOverrides;
pypkgs-build-requirements = {
paho-mqtt = [ "hatch-vcs" ];
};
p2n-overrides = defaultPoetryOverrides.extend (final: prev:
builtins.mapAttrs
(package: build-requirements:
(builtins.getAttr package prev).overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg prev else pkg) build-requirements);
})
)
pypkgs-build-requirements
);
in
{
packages = {
huecli = mkPoetryApplication {
projectDir = ./.;
overrides = p2n-overrides;
nativeBuildInputs = [ pkgs.installShellFiles ];
postInstall = ''
installShellCompletion --cmd huecli \
--bash <($out/bin/huecli --install-completion bash) \
--zsh <($out/bin/huecli --install-completion zsh) \
--fish <($out/bin/huecli --install-completion fish)
'';
};
default = self.packages.${system}.huecli;
};
# Shell for app dependencies.
#
# nix develop
#
# Use this shell for developing your app.
devShells.default = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.huecli ];
packages = [
pkgs.ruff
];
};
# Shell for poetry.
#
# nix develop .#poetry
#
# Use this shell for changes to pyproject.toml and poetry.lock.
devShells.poetry = pkgs.mkShell {
packages = [ pkgs.poetry ];
};
});
}