2020-10-03 19:11:50 +00:00
|
|
|
{
|
2021-03-26 15:17:44 +00:00
|
|
|
dataOutdated ? false,
|
2020-10-13 08:46:06 +00:00
|
|
|
pkgs ? import (import ./mach_nix/nix/nixpkgs-src.nix) { config = {}; overlays = []; },
|
2021-03-29 05:48:40 +00:00
|
|
|
pypiData ? builtins.fetchTarball {
|
|
|
|
name = "pypi-deps-db-src";
|
|
|
|
url = "https://github.com/DavHau/pypi-deps-db/tarball/${pypiDataRev}";
|
|
|
|
sha256 = "${pypiDataSha256}";
|
|
|
|
},
|
2020-11-25 08:27:46 +00:00
|
|
|
pypiDataRev ? ((import ./mach_nix/nix/flake-inputs.nix) "pypi-deps-db").rev,
|
|
|
|
pypiDataSha256 ? ((import ./mach_nix/nix/flake-inputs.nix) "pypi-deps-db").sha256,
|
2020-10-13 17:26:58 +00:00
|
|
|
python ? "python3",
|
2020-10-03 19:11:50 +00:00
|
|
|
...
|
|
|
|
}:
|
2020-10-13 08:46:06 +00:00
|
|
|
|
2020-09-13 06:53:23 +00:00
|
|
|
with builtins;
|
2020-10-13 08:46:06 +00:00
|
|
|
with pkgs.lib;
|
|
|
|
|
2020-04-22 09:28:58 +00:00
|
|
|
let
|
2020-10-13 09:46:04 +00:00
|
|
|
l = import ./mach_nix/nix/lib.nix { inherit pkgs; lib = pkgs.lib; };
|
|
|
|
|
2020-10-13 17:26:58 +00:00
|
|
|
python_machnix = import ./mach_nix/nix/python.nix { inherit pkgs; };
|
2020-10-11 10:47:12 +00:00
|
|
|
|
2020-10-13 08:46:06 +00:00
|
|
|
pypiFetcher = (import ./mach_nix/nix/deps-db-and-fetcher.nix {
|
|
|
|
inherit pkgs;
|
2021-03-29 05:48:40 +00:00
|
|
|
deps_db_src = pypiData;
|
2020-10-13 08:46:06 +00:00
|
|
|
}).pypi_fetcher;
|
2020-10-11 10:47:12 +00:00
|
|
|
|
2020-10-13 08:46:06 +00:00
|
|
|
withDot = mkPython: import ./mach_nix/nix/withDot.nix { inherit mkPython pypiFetcher; };
|
2020-10-11 10:47:40 +00:00
|
|
|
|
2021-03-26 15:17:44 +00:00
|
|
|
throwOnOutdatedData = args:
|
|
|
|
if dataOutdated && ! (args.ignoreDataOutdated or false) then
|
|
|
|
throw ''
|
|
|
|
The pypiDataRev seems to be older than the nixpkgs which is currently used.
|
|
|
|
Because of this, mach-nix might lack dependency information for some python packages in nixpkgs.
|
|
|
|
This can degrade the quality of the generated environment or result in failing builds.
|
|
|
|
It is recommended to pass a newer pypiDataRev to mach-nix during import.
|
|
|
|
For flakes users: Update the `pypi-deps-db` input of mach-nix.
|
|
|
|
You can ignore this error by passing 'ignoreDataOutdated = true' to mk* or build* functions
|
|
|
|
''
|
|
|
|
else args;
|
|
|
|
|
|
|
|
__buildPython = func: args: _buildPython func (throwOnOutdatedData args);
|
2020-10-13 09:46:04 +00:00
|
|
|
|
2020-10-13 12:50:13 +00:00
|
|
|
_buildPython = func: args:
|
2020-10-13 09:46:04 +00:00
|
|
|
if args ? extra_pkgs || args ? pkgsExtra then
|
|
|
|
throw "'extra_pkgs'/'pkgsExtra' cannot be passed to ${func}. Please pass it to a mkPython call."
|
2020-10-11 10:47:40 +00:00
|
|
|
else if isString args || isPath args || pkgs.lib.isDerivation args then
|
2021-03-29 05:48:40 +00:00
|
|
|
(import ./mach_nix/nix/buildPythonPackage.nix { inherit pkgs pypiData; })
|
2020-10-13 17:26:58 +00:00
|
|
|
python func { src = args; }
|
2020-10-11 10:47:40 +00:00
|
|
|
else
|
2021-03-29 05:48:40 +00:00
|
|
|
(import ./mach_nix/nix/buildPythonPackage.nix { inherit pkgs pypiData; })
|
2020-10-13 17:26:58 +00:00
|
|
|
python func (l.throwOnDeprecatedArgs func args);
|
2020-07-03 11:03:10 +00:00
|
|
|
|
2021-03-26 15:17:44 +00:00
|
|
|
__mkPython = caller: args: _mkPython caller (throwOnOutdatedData args);
|
2020-10-13 12:50:13 +00:00
|
|
|
|
2020-05-19 09:46:48 +00:00
|
|
|
# (High level API) generates a python environment with minimal user effort
|
2020-10-13 12:50:13 +00:00
|
|
|
_mkPython = caller: args:
|
|
|
|
if builtins.isList args then
|
2021-03-29 05:48:40 +00:00
|
|
|
(import ./mach_nix/nix/mkPython.nix { inherit pkgs pypiData; })
|
2020-11-25 07:09:40 +00:00
|
|
|
python { packagesExtra = args; }
|
2020-10-11 04:22:43 +00:00
|
|
|
else
|
2021-03-29 05:48:40 +00:00
|
|
|
(import ./mach_nix/nix/mkPython.nix { inherit pkgs pypiData; })
|
2020-10-13 17:26:58 +00:00
|
|
|
python (l.throwOnDeprecatedArgs caller args);
|
2020-10-11 17:17:54 +00:00
|
|
|
|
2020-10-11 10:47:12 +00:00
|
|
|
in
|
|
|
|
rec {
|
|
|
|
# the mach-nix cmdline tool derivation
|
2020-10-13 17:26:58 +00:00
|
|
|
mach-nix = python_machnix.pkgs.buildPythonPackage rec {
|
2020-10-11 10:47:12 +00:00
|
|
|
pname = "mach-nix";
|
|
|
|
version = builtins.readFile ./mach_nix/VERSION;
|
|
|
|
name = "${pname}-${version}";
|
|
|
|
src = ./.;
|
2021-03-12 05:37:07 +00:00
|
|
|
propagatedBuildInputs = pythonDeps;
|
2020-10-13 17:26:58 +00:00
|
|
|
checkInputs = [ python_machnix.pkgs.pytest ];
|
2020-10-12 06:31:46 +00:00
|
|
|
checkPhase = "pytest";
|
2020-10-11 10:47:12 +00:00
|
|
|
};
|
|
|
|
|
2021-03-12 05:37:07 +00:00
|
|
|
pythonDeps = (builtins.attrValues (import ./mach_nix/nix/python-deps.nix {
|
|
|
|
python = python_machnix;
|
|
|
|
fetchurl = pkgs.fetchurl;
|
|
|
|
}));
|
|
|
|
|
2020-10-11 10:47:12 +00:00
|
|
|
# the main functions
|
2020-10-13 12:50:13 +00:00
|
|
|
mkPython = args: __mkPython "mkPython" args;
|
|
|
|
mkPythonShell = args: (__mkPython "mkPythonShell" args).env;
|
|
|
|
mkDockerImage = args: (__mkPython "mkDockerImage" args).dockerImage;
|
|
|
|
mkOverlay = args: (__mkPython "mkOverlay" args).overlay;
|
|
|
|
mkNixpkgs = args: (__mkPython "mkNixpkgs" args).nixpkgs;
|
|
|
|
mkPythonOverrides = args: (__mkPython "mkPythonOverrides" args).pythonOverrides;
|
2020-10-11 10:47:12 +00:00
|
|
|
|
|
|
|
# equivalent to buildPythonPackage of nixpkgs
|
|
|
|
buildPythonPackage = __buildPython "buildPythonPackage";
|
|
|
|
|
|
|
|
# equivalent to buildPythonApplication of nixpkgs
|
|
|
|
buildPythonApplication = __buildPython "buildPythonApplication";
|
|
|
|
|
|
|
|
# provide pypi fetcher to user
|
|
|
|
fetchPypiSdist = pypiFetcher.fetchPypiSdist;
|
|
|
|
fetchPypiWheel = pypiFetcher.fetchPypiWheel;
|
|
|
|
|
|
|
|
# expose dot interface for flakes cmdline
|
2020-11-25 07:09:40 +00:00
|
|
|
"with" = pythonWith;
|
2020-10-13 12:50:13 +00:00
|
|
|
pythonWith = (withDot (__mkPython "'.pythonWith'")).pythonWith;
|
|
|
|
shellWith = (withDot (__mkPython "'.shellWith'")).shellWith;
|
|
|
|
dockerImageWith = (withDot (__mkPython "'.dockerImageWith'")).dockerImageWith;
|
2020-10-11 10:47:12 +00:00
|
|
|
|
|
|
|
# expose mach-nix' nixpkgs
|
|
|
|
# those are equivalent to the pkgs passed by the user
|
|
|
|
nixpkgs = pkgs;
|
|
|
|
|
2020-10-11 17:17:54 +00:00
|
|
|
# expose R packages
|
|
|
|
rPackages = pkgs.rPackages;
|
|
|
|
|
2020-10-11 10:47:12 +00:00
|
|
|
# this might beuseful for someone
|
2020-10-13 12:41:25 +00:00
|
|
|
inherit (l) mergeOverrides;
|
2020-04-24 10:35:42 +00:00
|
|
|
}
|