2025-12-05 15:57:45 +01:00
|
|
|
{
|
|
|
|
|
description = "Nix flake for Kevin's package-manager tool";
|
|
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
nixConfig = {
|
2025-12-05 20:20:33 +01:00
|
|
|
extra-experimental-features = [ "nix-command" "flakes" ];
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-05 15:57:45 +01:00
|
|
|
inputs = {
|
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs }:
|
|
|
|
|
let
|
2025-12-05 19:32:42 +01:00
|
|
|
systems = [ "x86_64-linux" "aarch64-linux" ];
|
|
|
|
|
|
|
|
|
|
# Small helper: build an attrset for all systems
|
|
|
|
|
forAllSystems = f:
|
|
|
|
|
builtins.listToAttrs (map (system: {
|
|
|
|
|
name = system;
|
|
|
|
|
value = f system;
|
|
|
|
|
}) systems);
|
2025-12-05 15:57:45 +01:00
|
|
|
in {
|
2025-12-05 19:32:42 +01:00
|
|
|
# Dev shells: nix develop .#default (on both architectures)
|
|
|
|
|
devShells = forAllSystems (system:
|
|
|
|
|
let
|
2025-12-06 17:47:46 +01:00
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
|
|
|
|
|
|
# Base Python interpreter
|
2025-12-05 19:32:42 +01:00
|
|
|
python = pkgs.python311;
|
2025-12-06 17:47:46 +01:00
|
|
|
|
|
|
|
|
# Python env with pip + pyyaml available, so `python -m pip` works
|
|
|
|
|
pythonEnv = python.withPackages (ps: with ps; [
|
|
|
|
|
pip
|
|
|
|
|
pyyaml
|
|
|
|
|
]);
|
2025-12-05 19:32:42 +01:00
|
|
|
|
|
|
|
|
# Be robust: ansible-core if available, otherwise ansible.
|
|
|
|
|
ansiblePkg =
|
|
|
|
|
if pkgs ? ansible-core then pkgs.ansible-core
|
|
|
|
|
else pkgs.ansible;
|
|
|
|
|
in {
|
|
|
|
|
default = pkgs.mkShell {
|
|
|
|
|
buildInputs = [
|
2025-12-06 17:47:46 +01:00
|
|
|
pythonEnv
|
2025-12-05 19:32:42 +01:00
|
|
|
pkgs.git
|
|
|
|
|
ansiblePkg
|
|
|
|
|
];
|
|
|
|
|
shellHook = ''
|
|
|
|
|
echo "Entered pkgmgr development environment for ${system}";
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
packages = forAllSystems (system:
|
|
|
|
|
let
|
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
|
python = pkgs.python311;
|
2025-12-05 22:47:13 +01:00
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
# Runtime Python for pkgmgr (with pip + pyyaml)
|
|
|
|
|
pythonEnv = python.withPackages (ps: with ps; [
|
|
|
|
|
pip
|
|
|
|
|
pyyaml
|
|
|
|
|
]);
|
2025-12-05 19:32:42 +01:00
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
# 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";
|
|
|
|
|
|
|
|
|
|
src = ./.;
|
2025-12-05 20:00:47 +01:00
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
# Nix should not run configure / build (no make)
|
|
|
|
|
dontConfigure = true;
|
|
|
|
|
dontBuild = true;
|
|
|
|
|
|
|
|
|
|
# Runtime deps: Python (with pip) + Ansible
|
|
|
|
|
buildInputs = [
|
|
|
|
|
pythonEnv
|
|
|
|
|
ansiblePkg
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-12-05 15:57:45 +01:00
|
|
|
|
2025-12-05 19:32:42 +01:00
|
|
|
# Apps: nix run .#pkgmgr / .#default
|
|
|
|
|
apps = forAllSystems (system:
|
|
|
|
|
let
|
|
|
|
|
pkgmgrPkg = self.packages.${system}.pkgmgr;
|
|
|
|
|
in {
|
|
|
|
|
pkgmgr = {
|
|
|
|
|
type = "app";
|
|
|
|
|
program = "${pkgmgrPkg}/bin/pkgmgr";
|
|
|
|
|
};
|
|
|
|
|
default = self.apps.${system}.pkgmgr;
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-12-05 15:57:45 +01:00
|
|
|
};
|
|
|
|
|
}
|