forked from cid-chan/peerix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
139 lines (118 loc) · 4.06 KB
/
Copy pathflake.nix
File metadata and controls
139 lines (118 loc) · 4.06 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
description = "Peer2Peer Nix-Binary-Cache";
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }: {
nixosModules.peerix = { pkgs, ... }: {
nixpkgs.overlays = [ (import ./overlay.nix { inherit self; }) ];
imports = [ ./module.nix ];
};
overlay = import ./overlay.nix { inherit self; };
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python3;
# Iroh P2P library (binary wheel from PyPI)
iroh = python.pkgs.buildPythonPackage rec {
pname = "iroh";
version = "0.35.0";
format = "wheel";
src = pkgs.fetchurl {
url = "https://files.pythonhosted.org/packages/a6/01/afba5b09b5c7dbde2beee05a4e73656de4e3469f930524c15f17b96590f9/iroh-0.35.0-py3-none-manylinux_2_28_x86_64.whl";
sha256 = "0im8rilciffg4bznm7pqrnam057a77rnjwfrij2g5bzidih7nrcl";
};
# Binary wheel, no build deps needed
pythonImportsCheck = [ "iroh" ];
};
# Core packages for peerix (lan/ipfs modes)
corePackages = with python.pkgs; [
trio
httpx
hypercorn
starlette
psutil
];
# Iroh mode packages
irohPackages = with python.pkgs; [
iroh
uvicorn
];
in {
packages = rec {
# Python environment with all dependencies (for running with -m)
peerix-python = python.withPackages (ps: corePackages);
peerix-unwrapped = python.pkgs.buildPythonApplication {
pname = "peerix";
version = builtins.replaceStrings [ " " "\n" ] [ "" "" ] (builtins.readFile ./VERSION);
src = ./.;
pyproject = true;
doCheck = false;
build-system = [ python.pkgs.setuptools ];
dependencies = corePackages ++ irohPackages;
propagatedBuildInputs = with pkgs; [
nix
nix-serve
];
meta = {
description = "Peer-to-peer Nix binary cache";
longDescription = ''
Peerix enables sharing Nix store paths between machines.
Modes:
- ipfs: IPFS-based P2P with content-addressed storage (default)
- lan: UDP broadcast for local network discovery
'';
};
};
peerix = let
gitCommit = self.shortRev or "dirty";
in pkgs.symlinkJoin {
name = "peerix";
paths = [
(pkgs.writeShellScriptBin "peerix" ''
PATH=${pkgs.nix}/bin:${pkgs.nix-serve}:$PATH
export PEERIX_COMMIT="${gitCommit}"
exec ${peerix-unwrapped}/bin/peerix "$@"
'')
(pkgs.writeShellScriptBin "peerix-tracker" ''
export PEERIX_COMMIT="${gitCommit}"
exec ${peerix-unwrapped}/bin/peerix-tracker "$@"
'')
(pkgs.writeShellScriptBin "peerix-iroh" ''
PATH=${pkgs.nix}/bin:${pkgs.nix-serve}:$PATH
export PEERIX_COMMIT="${gitCommit}"
exec ${peerix-unwrapped}/bin/peerix-iroh "$@"
'')
];
};
default = peerix;
};
defaultPackage = self.packages.${system}.peerix;
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
nix-serve
niv
(python.withPackages (ps: corePackages ++ irohPackages ++ (with ps; [
# Dev dependencies
pytest
pytest-asyncio
black
mypy
])))
];
shellHook = ''
echo "Peerix development shell"
echo ""
echo "Run peerix: python -m peerix --mode ipfs"
echo "Run iroh mode: python -m peerix.iroh_app --tracker http://sophronesis.dev:12305"
echo ""
'';
};
defaultApp = { type = "app"; program = "${self.packages.${system}.peerix}/bin/peerix"; };
});
}