Use pyproject-based Nix flake build and fix install logic for pkgmgr
- Add pyproject.toml to define package-manager as a Python application
- Declare setuptools build backend (setuptools.build_meta) and wheel
- Expose CLI entrypoint via [project.scripts] as `pkgmgr = pkgmgr.cli:main`
- Define PyYAML as a base runtime dependency
- Update flake.nix to build pkgmgr via python311Packages.buildPythonApplication
- Use format = "pyproject" and src = ./. (current git checkout)
- Add setuptools and wheel to nativeBuildInputs for the backend
- Add pyyaml to propagatedBuildInputs to match pyproject dependencies
- Provide a devShell that includes the built pkgmgr, git, and Ansible
- Expose `nix run .#pkgmgr` and `nix run .#default` as flake apps
- Fix Makefile install target for Nix shells
- Treat install as a no-op when IN_NIX_SHELL is set (skip venv / pip)
- In non-Nix environments, create ~/.venvs/pkgmgr, install deps, and
wire automatic activation into shell rc files
- Keep Arch/Manjaro-specific aur_builder/yay setup behind pacman check
- Adjust PKGBUILD prepare() to correctly copy the full project tree
- Stop excluding the top-level src directory from rsync
- Still exclude .git, .github, pkg, and srcpkg
This unifies the installation workflow across Arch, Nix, and local venvs,
and ensures pkgmgr builds cleanly inside the Docker-based Nix devShell tests.
Reference: ChatGPT-assisted refactor & debugging session on 2025-12-07.
https://chatgpt.com/share/6935ee1f-6c0c-800f-bb32-434c4051bd1e
This commit is contained in:
137
flake.nix
137
flake.nix
@@ -13,118 +13,95 @@
|
||||
let
|
||||
systems = [ "x86_64-linux" "aarch64-linux" ];
|
||||
|
||||
# Helper to build an attribute set for all target systems
|
||||
forAllSystems = f:
|
||||
builtins.listToAttrs (map (system: {
|
||||
name = system;
|
||||
value = f system;
|
||||
}) systems);
|
||||
in {
|
||||
# Development shells: `nix develop .#default`
|
||||
devShells = forAllSystems (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
# Base Python interpreter
|
||||
python = pkgs.python311;
|
||||
|
||||
# Python environment with pip + PyYAML so `python -m pip` works
|
||||
pythonEnv = python.withPackages (ps: with ps; [
|
||||
pip
|
||||
pyyaml
|
||||
]);
|
||||
|
||||
# Be robust: use ansible-core if available, otherwise ansible
|
||||
ansiblePkg =
|
||||
if pkgs ? ansible-core then pkgs.ansible-core
|
||||
else pkgs.ansible;
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pythonEnv
|
||||
pkgs.git
|
||||
ansiblePkg
|
||||
];
|
||||
shellHook = ''
|
||||
echo "Entered pkgmgr development environment for ${system}";
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# Packages: `nix build .#pkgmgr` or `nix build .#default`
|
||||
in
|
||||
{
|
||||
##########################################################################
|
||||
# PACKAGES
|
||||
##########################################################################
|
||||
packages = forAllSystems (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
python = pkgs.python311;
|
||||
|
||||
# Runtime Python for pkgmgr (with pip + PyYAML)
|
||||
pythonEnv = python.withPackages (ps: with ps; [
|
||||
pip
|
||||
pyyaml
|
||||
]);
|
||||
|
||||
# Optional: include Ansible in the runtime closure
|
||||
ansiblePkg =
|
||||
if pkgs ? ansible-core then pkgs.ansible-core
|
||||
else pkgs.ansible;
|
||||
pyPkgs = pkgs.python311Packages;
|
||||
in
|
||||
rec {
|
||||
pkgmgr = pkgs.stdenv.mkDerivation {
|
||||
pkgmgr = pyPkgs.buildPythonApplication {
|
||||
pname = "package-manager";
|
||||
version = "0.1.1";
|
||||
|
||||
# Use the current repository as the source
|
||||
# Use the git repo as source
|
||||
src = ./.;
|
||||
|
||||
# No traditional configure/build steps
|
||||
dontConfigure = true;
|
||||
dontBuild = true;
|
||||
# Build using pyproject.toml
|
||||
format = "pyproject";
|
||||
|
||||
# Runtime dependencies: Python (with pip + PyYAML) + Ansible
|
||||
buildInputs = [
|
||||
pythonEnv
|
||||
ansiblePkg
|
||||
# Build backend requirements from [build-system]
|
||||
nativeBuildInputs = [
|
||||
pyPkgs.setuptools
|
||||
pyPkgs.wheel
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p "$out/bin" "$out/lib/package-manager"
|
||||
# Runtime dependencies (matches [project.dependencies])
|
||||
propagatedBuildInputs = [
|
||||
pyPkgs.pyyaml
|
||||
# Add more here if needed, e.g.:
|
||||
# pyPkgs.click
|
||||
# pyPkgs.rich
|
||||
];
|
||||
|
||||
# Copy the full project tree into the runtime closure
|
||||
cp -a . "$out/lib/package-manager/"
|
||||
doCheck = false;
|
||||
|
||||
# Wrapper that runs main.py from the copied tree,
|
||||
# using the pythonEnv interpreter.
|
||||
cat > "$out/bin/pkgmgr" << 'EOF'
|
||||
#!${pythonEnv}/bin/python3
|
||||
import os
|
||||
import runpy
|
||||
|
||||
if __name__ == "__main__":
|
||||
base_dir = os.path.join(os.path.dirname(__file__), "..", "lib", "package-manager")
|
||||
main_path = os.path.join(base_dir, "main.py")
|
||||
os.chdir(base_dir)
|
||||
runpy.run_path(main_path, run_name="__main__")
|
||||
EOF
|
||||
|
||||
chmod +x "$out/bin/pkgmgr"
|
||||
'';
|
||||
pythonImportsCheck = [ "pkgmgr" ];
|
||||
};
|
||||
|
||||
# Default package points to pkgmgr
|
||||
default = pkgmgr;
|
||||
}
|
||||
);
|
||||
|
||||
# Apps: `nix run .#pkgmgr` or `nix run .#default`
|
||||
##########################################################################
|
||||
# DEVELOPMENT SHELL
|
||||
##########################################################################
|
||||
devShells = forAllSystems (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
pkgmgrPkg = self.packages.${system}.pkgmgr;
|
||||
|
||||
ansiblePkg =
|
||||
if pkgs ? ansible-core then pkgs.ansible-core
|
||||
else pkgs.ansible;
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pkgmgrPkg
|
||||
pkgs.git
|
||||
ansiblePkg
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "Entered pkgmgr development shell for ${system}"
|
||||
echo "pkgmgr CLI is available via the flake build"
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
##########################################################################
|
||||
# nix run .#pkgmgr
|
||||
##########################################################################
|
||||
apps = forAllSystems (system:
|
||||
let
|
||||
pkgmgrPkg = self.packages.${system}.pkgmgr;
|
||||
in {
|
||||
in
|
||||
{
|
||||
pkgmgr = {
|
||||
type = "app";
|
||||
program = "${pkgmgrPkg}/bin/pkgmgr";
|
||||
};
|
||||
|
||||
default = self.apps.${system}.pkgmgr;
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user