Skip to content

Commit

Permalink
flake.nix: expose library as an overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
t184256 committed May 18, 2023
1 parent 0081cb9 commit f0acee7
Showing 1 changed file with 52 additions and 33 deletions.
85 changes: 52 additions & 33 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,77 @@
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python3Packages = pkgs.python311Packages; # force 3.11+
pylama = python3Packages.pylama.overridePythonAttrs (_: {
# https://github.com/klen/pylama/issues/232
patches = [
(pkgs.fetchpatch {
url = "https://github.com/klen/pylama/pull/233.patch";
hash = "sha256-jaVG/vuhkPiHEL+28Pf1VuClBVlFtlzDohT0mZasL04=";
})
];
});
pytest-asyncio =
python3Packages.pytest-asyncio.overridePythonAttrs rec {
pname = "pytest-asyncio";
version = "0.21.0"; # first one with typing
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "sha256-Kziklq71b1aw6HVX7DE+EeGrknb8OGP2p74PHQ5BXhs=";
};
};
deps = pyPackages: with pyPackages; [
sqlalchemy aiosqlite
];
tools = pkgs: pyPackages: (with pyPackages; [
tools = pyPackages: (with pyPackages; [
pytest pytestCheckHook
coverage pytest-cov
mypy pytest-mypy
pylama pyflakes pycodestyle pydocstyle mccabe pylint
(pylama' pyPackages)
pyflakes pycodestyle pydocstyle mccabe pylint
eradicate
pytest-asyncio
(pytest-asyncio' pyPackages)
]);

asyncdbview = python3Packages.buildPythonPackage {
pname = "asyncdbview";
version = "0.0.1";
src = ./.;
format = "pyproject";
propagatedBuildInputs = deps python3Packages;
nativeBuildInputs = [ python3Packages.setuptools ];
checkInputs = tools pkgs python3Packages;
pylama' = pyPackages:
pyPackages.pylama.overridePythonAttrs (_: {
# https://github.com/klen/pylama/issues/232
patches = [
(pkgs.fetchpatch {
url = "https://github.com/klen/pylama/pull/233.patch";
hash = "sha256-jaVG/vuhkPiHEL+28Pf1VuClBVlFtlzDohT0mZasL04=";
})
];
});
pytest-asyncio' = pyPackages:
pyPackages.pytest-asyncio.overridePythonAttrs rec {
pname = "pytest-asyncio";
version = "0.21.0"; # first one with typing
src = pyPackages.fetchPypi {
inherit pname version;
sha256 = "sha256-Kziklq71b1aw6HVX7DE+EeGrknb8OGP2p74PHQ5BXhs=";
};
};

asyncdbview-package = {python3Packages}:
python3Packages.buildPythonPackage {
pname = "asyncdbview";
version = "0.0.1";
src = ./.;
format = "pyproject";
propagatedBuildInputs = deps python3Packages;
nativeBuildInputs = [ python3Packages.setuptools ];
checkInputs = tools python3Packages;
};
asyncdbview-pyextension = pyFinal: pyPrev: {
asyncdbview = pkgs.callPackage asyncdbview-package {
python3Packages = pyFinal;
};
};

overlay = final: prev: {
pythonPackagesExtensions =
prev.pythonPackagesExtensions ++ [ asyncdbview-pyextension ];
};
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };

defaultPython3Packages = pkgs.python311Packages; # 3.11+
asyncdbview = pkgs.callPackage asyncdbview-package {
python3Packages = defaultPython3Packages;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [(python3Packages.python.withPackages deps)];
nativeBuildInputs = tools pkgs python3Packages;
buildInputs = [(defaultPython3Packages.python.withPackages deps)];
nativeBuildInputs = tools defaultPython3Packages;
shellHook = ''
export PYTHONASYNCIODEBUG=1 PYTHONWARNINGS=error
'';
};
packages.asyncdbview = asyncdbview;
packages.default = asyncdbview;
overlays.default = overlay;
}
);
}

0 comments on commit f0acee7

Please sign in to comment.