Files
pkgmgr/flake.nix
Kevin Veen-Birkenbach 0f74907f82 flake.nix: switch to generic python3 and remove side-effects from pkgmgr package root
- Replace hardcoded python311 references with generic python3 to avoid minor
  version pinning and ensure consistent interpreter selection across systems.
- Use python.pkgs instead of python311Packages in the build pipeline.
- Update devShell to use python3.withPackages, including pip and pyyaml.
- Add Python version echo in shellHook for improved debugging.
- Remove cli re-export from src/pkgmgr/__init__.py to eliminate heavy
  side-effects during import and prevent premature config loading in tests.
2025-12-11 10:30:19 +01:00

127 lines
3.4 KiB
Nix

{
description = "Nix flake for Kevin's package-manager tool";
nixConfig = {
extra-experimental-features = [ "nix-command" "flakes" ];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = f:
builtins.listToAttrs (map (system: {
name = system;
value = f system;
}) systems);
in
{
##########################################################################
# PACKAGES
##########################################################################
packages = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Single source of truth: "python3" from this nixpkgs revision
python = pkgs.python3;
pyPkgs = python.pkgs;
in
rec {
pkgmgr = pyPkgs.buildPythonApplication {
pname = "package-manager";
version = "0.9.1";
# Use the git repo as source
src = ./.;
# Build using pyproject.toml
format = "pyproject";
# Build backend requirements from [build-system]
nativeBuildInputs = [
pyPkgs.setuptools
pyPkgs.wheel
];
# Runtime dependencies (matches [project.dependencies] in pyproject.toml)
propagatedBuildInputs = [
pyPkgs.pyyaml
pyPkgs.pip
];
doCheck = false;
pythonImportsCheck = [ "pkgmgr" ];
};
default = pkgmgr;
}
);
##########################################################################
# DEVELOPMENT SHELL
##########################################################################
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
ansiblePkg =
if pkgs ? ansible-core then pkgs.ansible-core
else pkgs.ansible;
python = pkgs.python3;
pythonWithDeps = python.withPackages (ps: [
ps.pip
ps.pyyaml
]);
in
{
default = pkgs.mkShell {
buildInputs = [
pythonWithDeps
pkgs.git
ansiblePkg
];
shellHook = ''
# Ensure src/ layout is importable:
# pkgmgr lives in ./src/pkgmgr
export PYTHONPATH="$PWD/src:${PYTHONPATH:-}"
# Also add repo root in case tools/tests rely on it
export PYTHONPATH="$PWD:$PYTHONPATH"
echo "Entered pkgmgr development shell for ${system}"
echo "Python used in this shell:"
python --version
echo "pkgmgr CLI (from source) is available via:"
echo " python -m pkgmgr.cli --help"
'';
};
}
);
##########################################################################
# nix run .#pkgmgr
##########################################################################
apps = forAllSystems (system:
let
pkgmgrPkg = self.packages.${system}.pkgmgr;
in
{
pkgmgr = {
type = "app";
program = "${pkgmgrPkg}/bin/pkgmgr";
};
default = self.apps.${system}.pkgmgr;
}
);
};
}