mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 16:51:40 -05:00
Merge pull request #93 from nix-community/pythonversion
Fix semver pythonVersion checks
This commit is contained in:
commit
efe279fd31
6 changed files with 167 additions and 8 deletions
|
@ -180,7 +180,7 @@ let
|
|||
# Get dependencies and filter out depending on interpreter version
|
||||
getDeps = depAttr:
|
||||
let
|
||||
compat = isCompatible py.pythonVersion;
|
||||
compat = isCompatible (poetryLib.getPythonVersion py);
|
||||
deps = pyProject.tool.poetry.${depAttr} or {};
|
||||
depAttrs = builtins.map (d: lib.toLower d) (builtins.attrNames deps);
|
||||
in
|
||||
|
|
10
lib.nix
10
lib.nix
|
@ -11,6 +11,15 @@ let
|
|||
# Do some canonicalisation of module names
|
||||
moduleName = name: lib.toLower (lib.replaceStrings [ "_" "." ] [ "-" "-" ] name);
|
||||
|
||||
# Get a full semver pythonVersion from a python derivation
|
||||
getPythonVersion = python: let
|
||||
pyVer = lib.splitVersion python.pythonVersion ++ [ "0" ];
|
||||
ver = lib.splitVersion python.version;
|
||||
major = l: lib.elemAt l 0;
|
||||
minor = l: lib.elemAt l 1;
|
||||
joinVersion = v: lib.concatStringsSep "." v;
|
||||
in joinVersion (if major pyVer == major ver && minor pyVer == minor ver then ver else pyVer);
|
||||
|
||||
# Compare a semver expression with a version
|
||||
isCompatible = version:
|
||||
let
|
||||
|
@ -145,5 +154,6 @@ in
|
|||
satisfiesSemver
|
||||
cleanPythonSources
|
||||
moduleName
|
||||
getPythonVersion
|
||||
;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ pythonPackages.callPackage (
|
|||
);
|
||||
|
||||
propagatedBuildInputs = let
|
||||
compat = isCompatible python.pythonVersion;
|
||||
compat = isCompatible (poetryLib.getPythonVersion python);
|
||||
deps = lib.filterAttrs (n: v: v) (
|
||||
lib.mapAttrs (
|
||||
n: v:
|
||||
|
@ -132,7 +132,7 @@ pythonPackages.callPackage (
|
|||
builtins.map (n: pythonPackages.${moduleName n}) depAttrs;
|
||||
|
||||
meta = {
|
||||
broken = ! isCompatible python.pythonVersion python-versions;
|
||||
broken = ! isCompatible (poetryLib.getPythonVersion python) python-versions;
|
||||
license = [];
|
||||
inherit (python.meta) platforms;
|
||||
};
|
||||
|
|
14
nix/sources.json
Normal file
14
nix/sources.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"nixpkgs": {
|
||||
"branch": "nixos-unstable",
|
||||
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
|
||||
"homepage": "https://github.com/NixOS/nixpkgs",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs-channels",
|
||||
"rev": "7c399a4ee080f33cc500a3fda33af6fccfd617bd",
|
||||
"sha256": "0vqljvz5yrc8i3nj3d5xiiv475yydscckfc9z0hpran9q2rh4md1",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/NixOS/nixpkgs-channels/archive/7c399a4ee080f33cc500a3fda33af6fccfd617bd.tar.gz",
|
||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||
}
|
||||
}
|
134
nix/sources.nix
Normal file
134
nix/sources.nix
Normal file
|
@ -0,0 +1,134 @@
|
|||
# This file has been generated by Niv.
|
||||
|
||||
let
|
||||
|
||||
#
|
||||
# The fetchers. fetch_<type> fetches specs of type <type>.
|
||||
#
|
||||
|
||||
fetch_file = pkgs: spec:
|
||||
if spec.builtin or true then
|
||||
builtins_fetchurl { inherit (spec) url sha256; }
|
||||
else
|
||||
pkgs.fetchurl { inherit (spec) url sha256; };
|
||||
|
||||
fetch_tarball = pkgs: spec:
|
||||
if spec.builtin or true then
|
||||
builtins_fetchTarball { inherit (spec) url sha256; }
|
||||
else
|
||||
pkgs.fetchzip { inherit (spec) url sha256; };
|
||||
|
||||
fetch_git = spec:
|
||||
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
|
||||
|
||||
fetch_builtin-tarball = spec:
|
||||
builtins.trace
|
||||
''
|
||||
WARNING:
|
||||
The niv type "builtin-tarball" will soon be deprecated. You should
|
||||
instead use `builtin = true`.
|
||||
|
||||
$ niv modify <package> -a type=tarball -a builtin=true
|
||||
''
|
||||
builtins_fetchTarball { inherit (spec) url sha256; };
|
||||
|
||||
fetch_builtin-url = spec:
|
||||
builtins.trace
|
||||
''
|
||||
WARNING:
|
||||
The niv type "builtin-url" will soon be deprecated. You should
|
||||
instead use `builtin = true`.
|
||||
|
||||
$ niv modify <package> -a type=file -a builtin=true
|
||||
''
|
||||
(builtins_fetchurl { inherit (spec) url sha256; });
|
||||
|
||||
#
|
||||
# Various helpers
|
||||
#
|
||||
|
||||
# The set of packages used when specs are fetched using non-builtins.
|
||||
mkPkgs = sources:
|
||||
let
|
||||
sourcesNixpkgs =
|
||||
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
|
||||
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
||||
in
|
||||
if builtins.hasAttr "nixpkgs" sources
|
||||
then sourcesNixpkgs
|
||||
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
||||
import <nixpkgs> {}
|
||||
else
|
||||
abort
|
||||
''
|
||||
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||
add a package called "nixpkgs" to your sources.json.
|
||||
'';
|
||||
|
||||
# The actual fetching function.
|
||||
fetch = pkgs: name: spec:
|
||||
|
||||
if ! builtins.hasAttr "type" spec then
|
||||
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
||||
else if spec.type == "file" then fetch_file pkgs spec
|
||||
else if spec.type == "tarball" then fetch_tarball pkgs spec
|
||||
else if spec.type == "git" then fetch_git spec
|
||||
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
|
||||
else if spec.type == "builtin-url" then fetch_builtin-url spec
|
||||
else
|
||||
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
|
||||
|
||||
# Ports of functions for older nix versions
|
||||
|
||||
# a Nix version of mapAttrs if the built-in doesn't exist
|
||||
mapAttrs = builtins.mapAttrs or (
|
||||
f: set: with builtins;
|
||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
|
||||
);
|
||||
|
||||
# fetchTarball version that is compatible between all the versions of Nix
|
||||
builtins_fetchTarball = { url, sha256 }@attrs:
|
||||
let
|
||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchTarball { inherit url; }
|
||||
else
|
||||
fetchTarball attrs;
|
||||
|
||||
# fetchurl version that is compatible between all the versions of Nix
|
||||
builtins_fetchurl = { url, sha256 }@attrs:
|
||||
let
|
||||
inherit (builtins) lessThan nixVersion fetchurl;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchurl { inherit url; }
|
||||
else
|
||||
fetchurl attrs;
|
||||
|
||||
# Create the final "sources" from the config
|
||||
mkSources = config:
|
||||
mapAttrs (
|
||||
name: spec:
|
||||
if builtins.hasAttr "outPath" spec
|
||||
then abort
|
||||
"The values in sources.json should not have an 'outPath' attribute"
|
||||
else
|
||||
spec // { outPath = fetch config.pkgs name spec; }
|
||||
) config.sources;
|
||||
|
||||
# The "config" used by the fetchers
|
||||
mkConfig =
|
||||
{ sourcesFile ? ./sources.json
|
||||
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
|
||||
, pkgs ? mkPkgs sources
|
||||
}: rec {
|
||||
# The sources, i.e. the attribute set of spec name to spec
|
||||
inherit sources;
|
||||
|
||||
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
|
||||
inherit pkgs;
|
||||
};
|
||||
in
|
||||
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
11
shell.nix
11
shell.nix
|
@ -1,11 +1,11 @@
|
|||
{ pkgs ? import (fetchTarball { url = "channel:nixpkgs-unstable"; }) {
|
||||
let
|
||||
sources = import ./nix/sources.nix;
|
||||
pkgs = import sources.nixpkgs {
|
||||
overlays = [
|
||||
(import ./overlay.nix)
|
||||
];
|
||||
}
|
||||
}:
|
||||
let
|
||||
tools = pkgs.callPackage ./tools {};
|
||||
};
|
||||
tools = pkgs.callPackage ./tools { };
|
||||
in
|
||||
pkgs.mkShell {
|
||||
buildInputs = [
|
||||
|
@ -13,5 +13,6 @@ pkgs.mkShell {
|
|||
tools.release
|
||||
pkgs.nixpkgs-fmt
|
||||
pkgs.poetry
|
||||
pkgs.niv
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue