forked from DavHau/nix-pypi-fetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
94 lines (84 loc) · 2.98 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
description = "Convenient pypi fetcher for nix. Knows urls and hashes of all packages";
inputs = rec {
mach-nix.url = "mach-nix";
nixpkgs.url = "nixpkgs/nixos-unstable";
mach-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inp:
with builtins;
with inp.nixpkgs.lib;
let
systems = ["x86_64-linux"];
self = {
lib.formatVersion = toInt (readFile ./FORMAT_VERSION);
}
// foldl' (a: b: recursiveUpdate a b) {} ( map ( system:
let
pkgs = inp.nixpkgs.legacyPackages."${system}";
pyEnv = inp.mach-nix.lib."${system}".mkPython {
requirements = ''
requests
bounded-pool-executor
'';
ignoreDataOutdated = true;
python = "python39";
};
deps = [
pyEnv
pkgs.git
pkgs.nixFlakes
];
defaultVars = {
PYTHONPATH = "${./updater}";
};
fixedVars = {};
# defaultVars are only set if they are not already set
# fixedVars are always set
exports = ''
${concatStringsSep "\n" (mapAttrsToList (n: v: "export ${n}=\"${v}\"") fixedVars)}
${concatStringsSep "\n" (mapAttrsToList (n: v: "export ${n}=\"\${${n}:-${v}}\"") defaultVars)}
'';
in {
# devShell to load all dependencies and environment variables
devShell."${system}" = pkgs.mkShell {
buildInputs = deps;
shellHook = exports;
};
# apps to update the database
# All apps assume that the current directory is a git checkout of this project
apps."${system}" = rec {
# update the pypi index
update-urls.type = "app";
update-urls.program = toString (pkgs.writeScript "update-wheel" ''
#!/usr/bin/env bash
${exports}
export WORKERS=10
export EMAIL=$(git config --get user.email)
${pyEnv}/bin/python ${./updater}/crawl_urls.py ./pypi
'');
# job including git commit for executing in CI system
job-urls.type = "app";
job-urls.program = toString (pkgs.writeScript "job-urls" ''
#!/usr/bin/env bash
set -e
set -x
${update-urls.program}
# commit to git
echo $(date +%s) > UNIX_TIMESTAMP
git add pypi UNIX_TIMESTAMP
git pull origin $(git rev-parse --abbrev-ref HEAD)
git commit -m "$(date) - update sdist + wheel"
'');
};
# This python interpreter can be used for debugging in IDEs
# It will set all env variables during startup
packages."${system}".pythonWithVariables = pkgs.writeScriptBin "python3" ''
#!/usr/bin/env bash
${exports}
${pyEnv}/bin/python $@
'';
}) systems);
in
self;
}