Refactor pkgmgr self-install handling, add pip-enabled Python env to flake, and fix Nix/pip integration

- Rename requirements.txt to _requirements.txt to avoid unintended self-install via PythonInstaller.
- Update flake.nix to provide Python with pip in both devShell and runtime closure.
- Generate a wrapper for pkgmgr that uses the pip-enabled interpreter.
- Adjust NixFlakeInstaller to correctly handle old profile removal and install outputs.
- Update run_command to support string commands and allow_failure.
- Improve integration test by adding nix profile cleanup and debugging output.

Reference: https://chatgpt.com/share/69345df2-a960-800f-8395-92a7c3a6629f
This commit is contained in:
2025-12-06 17:47:46 +01:00
parent 96a0409dbb
commit f57ab0c2d1
5 changed files with 180 additions and 102 deletions

View File

@@ -1,7 +1,7 @@
{
description = "Nix flake for Kevin's package-manager tool";
nixConfig = {
nixConfig = {
extra-experimental-features = [ "nix-command" "flakes" ];
};
@@ -23,9 +23,16 @@
# Dev shells: nix develop .#default (on both architectures)
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs = nixpkgs.legacyPackages.${system};
# Base Python interpreter
python = pkgs.python311;
pypkgs = pkgs.python311Packages;
# Python env with pip + pyyaml available, so `python -m pip` works
pythonEnv = python.withPackages (ps: with ps; [
pip
pyyaml
]);
# Be robust: ansible-core if available, otherwise ansible.
ansiblePkg =
@@ -34,8 +41,7 @@
in {
default = pkgs.mkShell {
buildInputs = [
python
pypkgs.pyyaml
pythonEnv
pkgs.git
ansiblePkg
];
@@ -46,48 +52,59 @@
}
);
packages = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python311;
pypkgs = pkgs.python311Packages;
packages = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python311;
# Optional: ansible mit in den Closure nehmen
ansiblePkg =
if pkgs ? ansible-core then pkgs.ansible-core
else pkgs.ansible;
in
rec {
pkgmgr = pkgs.stdenv.mkDerivation {
pname = "package-manager";
version = "0.1.1";
# Runtime Python for pkgmgr (with pip + pyyaml)
pythonEnv = python.withPackages (ps: with ps; [
pip
pyyaml
]);
src = ./.;
# Optional: include Ansible in the runtime closure
ansiblePkg =
if pkgs ? ansible-core then pkgs.ansible-core
else pkgs.ansible;
in
rec {
pkgmgr = pkgs.stdenv.mkDerivation {
pname = "package-manager";
version = "0.1.1";
# Nix soll *kein* configure / build ausführen (also auch kein make)
dontConfigure = true;
dontBuild = true;
src = ./.;
# Wenn du Python/Ansible im Runtime-Closure haben willst:
buildInputs = [
python
pypkgs.pyyaml
ansiblePkg
];
# Nix should not run configure / build (no make)
dontConfigure = true;
dontBuild = true;
installPhase = ''
mkdir -p "$out/bin"
cp main.py "$out/bin/pkgmgr"
chmod +x "$out/bin/pkgmgr"
'';
};
# Runtime deps: Python (with pip) + Ansible
buildInputs = [
pythonEnv
ansiblePkg
];
# default package just points to pkgmgr
default = pkgmgr;
}
);
installPhase = ''
mkdir -p "$out/bin"
# Wrapper that always uses the pythonEnv interpreter, so
# sys.executable -m pip has a working pip.
cat > "$out/bin/pkgmgr" << EOF
#!${pythonEnv}/bin/python3
import runpy
if __name__ == "__main__":
runpy.run_module("main", run_name="__main__")
EOF
chmod +x "$out/bin/pkgmgr"
'';
};
# default package just points to pkgmgr
default = pkgmgr;
}
);
# Apps: nix run .#pkgmgr / .#default
apps = forAllSystems (system: