-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
64 lines (62 loc) · 2.25 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
inputs = {
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
{
systems,
treefmt-nix,
nixpkgs,
...
}:
let
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./dev/treefmt.nix);
inherit (nixpkgs) lib;
overrides_by_version = import ./collected.nix;
# find the latest version of the override that is older than the current version
# or if no version is older than the requestd one, find the first one.
version_match =
name: version:
let
versions_available = lib.attrsets.attrNames (overrides_by_version.${name} or { });
sorted_versions_available = lib.lists.sort lib.versionOlder versions_available;
older_versions = lib.lists.filter (
v: ((v == version) || (lib.versionOlder v version))
) sorted_versions_available;
in
if builtins.length older_versions == 0 then
(
if builtins.length sorted_versions_available == 0 then
throw ("No versions available for " + name)
else
builtins.elemAt sorted_versions_available 0 # what happens if sorted_versions_available is empty?
)
else
lib.lists.last older_versions;
helpers = import ./helpers.nix { pkgs = nixpkgs.legacyPackages.x86_64-linux; };
in
{
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
overrides =
nixpkgs_pkgs: final: prev:
(lib.attrsets.mapAttrs (
#todo: how do they get packages?
name: available_versions:
let
matched_version = version_match name prev.${name}.version;
in
prev.${name}.overridePythonAttrs (
available_versions.${builtins.trace (name + " matched to " + matched_version) matched_version} {
inherit final prev helpers;
pkgs = nixpkgs_pkgs;
}
)
) overrides_by_version);
devShell.x86_64-linux =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
pkgs.mkShell { buildInputs = [ pkgs.pre-commit ]; };
};
}