From 2ee343a22d6892e80795c704917731832710cd62 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Mon, 15 Jul 2019 13:31:44 -0400
Subject: [PATCH] Try to bring the Nix configuration into good shape

Not currently working
---
 autobahn.nix                       | 11 +++++++++++
 cryptography.nix                   | 11 +++++++++++
 default.nix                        | 13 ++-----------
 overlays.nix                       | 17 +++++++++++++++++
 secure-access-token-authorizer.nix |  2 +-
 tahoe-lafs.nix                     | 12 +++++++++---
 6 files changed, 51 insertions(+), 15 deletions(-)
 create mode 100644 autobahn.nix
 create mode 100644 cryptography.nix
 create mode 100644 overlays.nix

diff --git a/autobahn.nix b/autobahn.nix
new file mode 100644
index 0000000..5403cd5
--- /dev/null
+++ b/autobahn.nix
@@ -0,0 +1,11 @@
+{ fetchFromGitHub, autobahn }:
+autobahn.overrideAttrs (old: rec {
+  pname = "autobahn";
+  version = "19.7.1";
+  src = fetchFromGitHub {
+    owner = "crossbario";
+    repo = "autobahn-python";
+    rev = "v${version}";
+    sha256 = "1gl2m18s77hlpiglh44plv3k6b965n66ylnxbzgvzcdl9jf3l3q3";
+  };
+})
diff --git a/cryptography.nix b/cryptography.nix
new file mode 100644
index 0000000..dc61091
--- /dev/null
+++ b/cryptography.nix
@@ -0,0 +1,11 @@
+{ fetchFromGitHub, cryptography }:
+cryptography.overrideAttrs (old: rec {
+  pname = "cryptography";
+  version = "2.7";
+  src = fetchFromGitHub {
+    owner = "pyca";
+    repo = "cryptography";
+    rev = "2.7";
+    sha256 = "145byri5c3b8m6dbhwb6yxrv9jrr652l3z1w16mz205z8dz38qja";
+  };
+})
diff --git a/default.nix b/default.nix
index 0a9c3cf..5415160 100644
--- a/default.nix
+++ b/default.nix
@@ -1,14 +1,5 @@
 { pkgs ? import <nixpkgs> { } }:
 let
-  eliot = pkgs.pythonPackages.callPackage ./eliot.nix { };
-
-  # tahoe-lafs in nixpkgs is packaged as an application!  so we have to
-  # re-package it ourselves as a library.
-  tahoe-lafs = pkgs.pythonPackages.callPackage ./tahoe-lafs.nix {
-    inherit eliot;
-  };
-
+  newpkgs = import pkgs.path { overlays = [ import ./overlays.nix ]; };
 in
-  pkgs.pythonPackages.callPackage ./secure-access-token-authorizer.nix {
-    inherit tahoe-lafs;
-  }
+  pkgs.pythonPackages.callPackage ./secure-access-token-authorizer.nix { }
diff --git a/overlays.nix b/overlays.nix
new file mode 100644
index 0000000..12280b9
--- /dev/null
+++ b/overlays.nix
@@ -0,0 +1,17 @@
+self: super: {
+  python = super.python.override {
+    packageOverrides = python-self: python-super: {
+      # new tahoe-lafs dependency
+      eliot = pkgs.pythonPackages.callPackage ./eliot.nix { };
+      # new autobahn requires a newer cryptography
+      cryptography = pkgs.pythonPackages.callPackage ./cryptography.nix { };
+      # new tahoe-lafs depends on a very recent autobahn for better
+      # websocket testing features.
+      autobahn = pkgs.pythonPackages.callPackage ./autobahn.nix { };
+
+      # tahoe-lafs in nixpkgs is packaged as an application!  so we have to
+      # re-package it ourselves as a library.
+      tahoe-lafs = pkgs.pythonPackages.callPackage ./tahoe-lafs.nix { };
+    };
+  };
+}
diff --git a/secure-access-token-authorizer.nix b/secure-access-token-authorizer.nix
index 65de5cd..e3dda5a 100644
--- a/secure-access-token-authorizer.nix
+++ b/secure-access-token-authorizer.nix
@@ -1,4 +1,4 @@
-{ buildPythonPackage, sphinx, circleci-cli, pythonPackages, tahoe-lafs }:
+{ buildPythonPackage, sphinx, circleci-cli, pythonPackages }:
 buildPythonPackage rec {
   version = "0.0";
   name = "secure-access-token-authorizer-${version}";
diff --git a/tahoe-lafs.nix b/tahoe-lafs.nix
index da0f4e6..f5a1ff6 100644
--- a/tahoe-lafs.nix
+++ b/tahoe-lafs.nix
@@ -1,8 +1,14 @@
-{ nettools, pythonPackages, buildPythonPackage, eliot }:
+{ fetchFromGitHub, nettools, pythonPackages, buildPythonPackage, eliot, autobahn }:
 buildPythonPackage rec {
   version = "1.14.0.dev";
   name = "tahoe-lafs-${version}";
-  src = ~/Work/python/tahoe-lafs;
+  src = fetchFromGitHub {
+    owner = "tahoe-lafs";
+    repo = "tahoe-lafs";
+    # HEAD of integration/storage-economics branch as of July 15th 2019.
+    rev = "48bd16a8d9109910122cc2e2c85eb4f378390135";
+    sha256 = "0i8k7zb4381vbblriciz1m33va0mxld6nrhpwvjqr9jk335b1a9q";
+  };
 
   postPatch = ''
     sed -i "src/allmydata/util/iputil.py" \
@@ -21,7 +27,7 @@ buildPythonPackage rec {
 
 
   propagatedBuildInputs = with pythonPackages; [
-    twisted foolscap nevow simplejson zfec pycryptopp darcsver
+    twisted autobahn foolscap nevow simplejson zfec pycryptopp darcsver
     setuptoolsTrial setuptoolsDarcs pycrypto pyasn1 zope_interface
     service-identity pyyaml magic-wormhole treq appdirs
 
-- 
GitLab