From 10773e19177826368aa54d599a65265f77f4f1d4 Mon Sep 17 00:00:00 2001
From: "William A. Kennington III" <william@wkennington.com>
Date: Fri, 9 May 2014 23:20:13 -0500
Subject: [PATCH 1/4] notbit: Bump to git-faf0930

---
 pkgs/applications/networking/notbit/default.nix | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pkgs/applications/networking/notbit/default.nix b/pkgs/applications/networking/notbit/default.nix
index db900f9ff256..8a7d7d3aedcf 100644
--- a/pkgs/applications/networking/notbit/default.nix
+++ b/pkgs/applications/networking/notbit/default.nix
@@ -1,12 +1,12 @@
 { stdenv, fetchgit, autoconf, automake, pkgconfig, openssl }:
 
 stdenv.mkDerivation rec {
-  name = "notbit-0.2-28-g06f9160";
+  name = "notbit-git-faf0930";
 
   src = fetchgit {
-    url = "git://git.busydoingnothing.co.uk/notbit";
-    rev = "06f916081836de12f8e57a9f50c95d4d1b51627f";
-    sha256 = "d5c38eea1d9ca213bfbea5c88350478a5088b5532e939de9680d72e60aa65288";
+    url = "git://github.com/bpeel/notbit";
+    rev = "faf09304bf723e75f3d98cca93cf45236ee9d6b6";
+    sha256 = "b229f87c4c5e901bfd8b13dffe31157126d98ed02118fff6553e8b58eb9ed030";
   };
 
   buildInputs = [ autoconf automake pkgconfig openssl ];

From 8915390baba34222e61af7e9172dd141fa8f653a Mon Sep 17 00:00:00 2001
From: "William A. Kennington III" <william@wkennington.com>
Date: Tue, 13 May 2014 20:19:27 -0500
Subject: [PATCH 2/4] notbit: Use the correct default port

---
 nixos/modules/services/networking/notbit.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nixos/modules/services/networking/notbit.nix b/nixos/modules/services/networking/notbit.nix
index b97435042395..63a332893461 100644
--- a/nixos/modules/services/networking/notbit.nix
+++ b/nixos/modules/services/networking/notbit.nix
@@ -35,7 +35,7 @@ with lib;
 
       port = mkOption {
         type = types.uniq types.int;
-        default = 8443;
+        default = 8444;
         description = "The port which the daemon listens for other bitmessage clients";
       };
 

From 042273e528b5e5837984f56f435053b8c5382770 Mon Sep 17 00:00:00 2001
From: "William A. Kennington III" <william@wkennington.com>
Date: Tue, 13 May 2014 20:19:57 -0500
Subject: [PATCH 3/4] notbit: Don't include unecessary notbit binaries in the
 environment

---
 nixos/modules/services/networking/notbit.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nixos/modules/services/networking/notbit.nix b/nixos/modules/services/networking/notbit.nix
index 63a332893461..b6a2b7897caa 100644
--- a/nixos/modules/services/networking/notbit.nix
+++ b/nixos/modules/services/networking/notbit.nix
@@ -53,7 +53,7 @@ with lib;
 
   config = mkIf cfg.enable {
 
-    environment.systemPackages = [ pkgs.notbit sendmail ];
+    environment.systemPackages = [ sendmail ];
 
     systemd.services.notbit = {
       description = "Notbit daemon";

From 08467c14deffcf33e0a1861c2dd50f7ebfd98852 Mon Sep 17 00:00:00 2001
From: "William A. Kennington III" <william@wkennington.com>
Date: Tue, 13 May 2014 20:20:19 -0500
Subject: [PATCH 4/4] notbit: Add additional options to the daemon

---
 nixos/modules/services/networking/notbit.nix | 39 +++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/nixos/modules/services/networking/notbit.nix b/nixos/modules/services/networking/notbit.nix
index b6a2b7897caa..3e8c956f191e 100644
--- a/nixos/modules/services/networking/notbit.nix
+++ b/nixos/modules/services/networking/notbit.nix
@@ -1,5 +1,6 @@
 { config, lib, pkgs, ... }:
 
+with pkgs.lib;
 let
   cfg = config.services.notbit;
   varDir = "/var/lib/notbit";
@@ -14,6 +15,10 @@ let
         --set XDG_RUNTIME_DIR ${varDir}
     '';
   };
+  opts = "${optionalString cfg.allowPrivateAddresses "-L"} ${optionalString cfg.noBootstrap "-b"} ${optionalString cfg.specifiedPeersOnly "-e"}";
+  peers = concatStringsSep " " (map (str: "-P \"${str}\"") cfg.peers);
+  listen = if cfg.listenAddress == [] then "-p ${toString cfg.port}" else
+    concatStringsSep " " (map (addr: "-a \"${addr}:${toString cfg.port}\"") cfg.listenAddress);
 in
 
 with lib;
@@ -45,6 +50,38 @@ with lib;
         description = "Set the nice level for the notbit daemon";
       };
 
+      listenAddress = mkOption {
+        type = types.listOf types.str;
+        default = [ ];
+        example = [ "localhost" "myhostname" ];
+        description = "The addresses which notbit will use to listen for incoming connections. These addresses are advertised to connecting clients.";
+      };
+
+      peers = mkOption {
+        type = types.listOf types.str;
+        default = [ ];
+        example = [ "bitmessage.org:8877" ];
+        description = "The initial set of peers notbit will connect to.";
+      };
+
+      specifiedPeersOnly = mkOption {
+        type = types.uniq types.bool;
+        default = false;
+        description = "If true, notbit will only connect to peers specified by the peers option.";
+      };
+
+      allowPrivateAddresses = mkOption {
+        type = types.uniq types.bool;
+        default = false;
+        description = "If true, notbit will allow connections to to RFC 1918 addresses.";
+      };
+
+      noBootstrap = mkOption {
+        type = types.uniq types.bool;
+        default = false;
+        description = "If true, notbit will not bootstrap an initial peerlist from bitmessage.org servers";
+      };
+
     };
 
   };
@@ -70,7 +107,7 @@ with lib;
 
       serviceConfig = {
         Type = "forking";
-        ExecStart = "${pkgs.notbit}/bin/notbit -d -p ${toString cfg.port}";
+        ExecStart = "${pkgs.notbit}/bin/notbit -d ${listen} ${peers} ${opts}";
         User = "notbit";
         Group = "notbit";
         UMask = "0077";