huecli/flake.nix
2024-06-04 16:46:37 +02:00

63 lines
2.1 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 }:
{
overlays.default = final: prev: {
huecli = self.packages.${prev.system}.default;
};
}
//
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 --show-completion bash) \
--zsh <($out/bin/huecli --show-completion zsh) \
--fish <($out/bin/huecli --show-completion fish)
'';
};
default = self.packages.${system}.huecli;
};
devShells.default = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.huecli ];
packages = [
pkgs.ruff
pkgs.poetry
];
};
});
}