unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob d5832b19df78e25aef537ab4ddd148ed5c614f9c 57802 bytes (raw)
name: gnu/packages/tor.scm 	 # note: path name is non-authoritative(*)

   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
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2016, 2017, 2018, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2016, 2017 Nikita <nikita@n0.is>
;;; Copyright © 2017–2021 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2017, 2018, 2019, 2021 Eric Bavier <bavier@posteo.net>
;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Vincent Legoll <vincent.legoll@gmail.com>
;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
;;; Copyright © 2020, 2021 André Batista <nandre@riseup.net>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages tor)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix store)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system cargo)
  #:use-module (guix build-system go)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system python)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages assembly)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages cups)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages golang)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages gnuzilla)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages image)
  #:use-module (gnu packages kerberos)
  #:use-module (gnu packages libcanberra)
  #:use-module (gnu packages libevent)
  #:use-module (gnu packages libffi)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages node)
  #:use-module (gnu packages nss)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-crypto)
  #:use-module (gnu packages python-web)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages qt)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages rsync) ; for httpse
  #:use-module (gnu packages rust)
  #:use-module (gnu packages rust-apps)
  #:use-module (gnu packages sqlite)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages video)
  #:use-module (gnu packages vim) ; for xxd
  #:use-module (gnu packages w3m)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages xiph)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages xml) ; for httpse
  #:use-module (ice-9 match)
  #:use-module ((srfi srfi-1) #:hide (zip)))

(define-public tor
  (package
    (name "tor")
    (version "0.4.5.8")
    (source (origin
             (method url-fetch)
             (uri (string-append "https://dist.torproject.org/tor-"
                                 version ".tar.gz"))
             (sha256
              (base32
               "09z22gc01yh5zms7i31md6qpr0ir8i5fzrrz06qfpp5wx28x1pjp"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags
       (list "--enable-lzma"
             "--enable-zstd")
       #:phases
       (modify-phases %standard-phases
         (add-before 'check 'skip-practracker
           ;; This is a style linter.  It doesn't get to throw fatal errors.
           (lambda _
             (setenv "TOR_DISABLE_PRACTRACKER" "set")
             #t)))))
    (native-inputs
     `(("pkg-config" ,pkg-config)
       ("python" ,python)))             ; for tests
    (inputs
     `(("libevent" ,libevent)
       ("libseccomp" ,libseccomp)
       ("openssl" ,openssl)
       ("xz" ,xz)
       ("zlib" ,zlib)
       ("zstd" ,zstd "lib")))
    (home-page "https://www.torproject.org/")
    (synopsis "Anonymous network router to improve privacy on the Internet")
    (description
     "Tor protects you by bouncing your communications around a distributed
network of relays run by volunteers all around the world: it prevents
somebody watching your Internet connection from learning what sites you
visit, and it prevents the sites you visit from learning your physical
location.  Tor works with many of your existing applications, including
web browsers, instant messaging clients, remote login, and other
applications based on the TCP protocol.

This package is the full featured @code{tor} which is needed for running
relays, bridges or directory authorities. If you just want to access the Tor
network or to setup an onion service you may install @code{tor-client}
instead.")
    (license license:bsd-3)))

(define-public tor-client
  (package
    (inherit tor)
    (name "tor-client")
    (arguments
     (substitute-keyword-arguments (package-arguments tor)
       ((#:configure-flags flags)
        (append flags
                '("--disable-module-relay")))))
    (synopsis "Client to the anonymous Tor network")
    (description
     "Tor protects you by bouncing your communications around a distributed
network of relays run by volunteers all around the world: it prevents
somebody watching your Internet connection from learning what sites you
visit, and it prevents the sites you visit from learning your physical
location.  Tor works with many of your existing applications, including
web browsers, instant messaging clients, remote login, and other
applications based on the TCP protocol.

To @code{torify} applications (to take measures to ensure that an application,
which has not been designed for use with Tor such as ssh, will use only Tor for
internet connectivity, and also ensures that there are no leaks from DNS, UDP or
the application layer) you need to install @code{torsocks}.

This package only provides a client to the Tor Network.")))

(define-public torsocks
  (package
    (name "torsocks")
    (version "2.3.0")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://people.torproject.org/~dgoulet/"
                                  "torsocks/torsocks-" version ".tar.xz"))
              (sha256
               (base32
                "08inrkap29gikb6sdmb58z43hw4abwrfw7ny40c4xzdkss0vkwdr"))))
    (build-system gnu-build-system)
    (inputs
     `(("libcap" ,libcap)))
    (arguments
     `(#:phases (modify-phases %standard-phases
                  (add-after 'build 'absolutize
                    (lambda* (#:key inputs #:allow-other-keys)
                      (substitute* "src/bin/torsocks"
                        (("getcap=.*")
                         (string-append "getcap=" (which "getcap") "\n")))
                      #t)))))
    (home-page "https://www.torproject.org/")
    (synopsis "Use socks-friendly applications with Tor")
    (description
     "Torsocks allows you to use most socks-friendly applications in a safe
way with Tor.  It ensures that DNS requests are handled safely and explicitly
rejects UDP traffic from the application you're using.")

    ;; All the files explicitly say "version 2 only".
    (license license:gpl2)))

(define-public privoxy
  (package
    (name "privoxy")
    (version "3.0.32")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://sourceforge/ijbswa/Sources/"
                                 version "%20%28stable%29/privoxy-"
                                 version "-stable-src.tar.gz"))
             (sha256
              (base32
               "1mzfxwnvnf1jkvfcrsivm6mjwdzjrc3h89qziz0mwi32ih0f87f6"))))
    (build-system gnu-build-system)
    (arguments
     '(;; The default 'sysconfdir' is $out/etc; change that to
       ;; $out/etc/privoxy.
       #:configure-flags (list (string-append "--sysconfdir="
                                              (assoc-ref %outputs "out")
                                              "/etc/privoxy")
                               "--localstatedir=/var"
                               "--with-brotli"
                               "--with-openssl")
       #:tests? #f                      ; no test suite
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'patch-default-logging
           (lambda _
             (with-fluids ((%default-port-encoding "ISO-8859-1"))
               ;; Do not create /var/run nor /var/log/privoxy/logfile.
               (substitute* "GNUmakefile.in"
                 (("(logfile \\|\\| exit )1" _ match)
                  (string-append match "0"))
                 (("(\\$\\(DESTDIR\\)\\$\\(SHARE_DEST\\)) \\\\" _ match)
                  match)
                 ((".*\\$\\(LOG_DEST\\) \\$\\(DESTDIR\\)\\$\\(PID_DEST\\).*")
                  ""))
               ;; Disable logging in the default configuration to allow for
               ;; non-root users using it as is.
               (substitute* "config"
                 (("^logdir") "#logdir")
                 (("^logfile") "#logfile")))
             #t)))))
    (inputs
     `(("brotli" ,brotli)
       ("openssl" ,openssl)
       ("pcre" ,pcre)
       ("w3m" ,w3m)
       ("zlib" ,zlib)))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)))
    (home-page "https://www.privoxy.org")
    (synopsis "Web proxy with advanced filtering capabilities for enhancing privacy")
    (description
     "Privoxy is a non-caching web proxy with advanced filtering capabilities
for enhancing privacy, modifying web page data and HTTP headers, controlling
access, and removing ads and other obnoxious Internet junk.  Privoxy has a
flexible configuration and can be customized to suit individual needs and
tastes.  It has application for both stand-alone systems and multi-user
networks.")
    (license license:gpl2+)))

(define-public onionshare-cli
  (package
    (name "onionshare-cli")
    (version "2.3.1")
    (source
      (origin
        (method git-fetch)
        (uri (git-reference
              (url "https://github.com/micahflee/onionshare")
              (commit (string-append "v" version))))
        (file-name (git-file-name name version))
        (sha256
         (base32 "1llvnvb676s2cs6a4y7isxdj75ddfvskw1p93v5m35vsw7f72kqz"))))
    (build-system python-build-system)
    (native-inputs
     `(("python-pytest" ,python-pytest)))
    (inputs
     ;; TODO: obfs4proxy
     `(("python-click" ,python-click)
       ("python-eventlet" ,python-eventlet)
       ("python-flask" ,python-flask)
       ("python-flask-httpauth" ,python-flask-httpauth)
       ("python-flask-socketio" ,python-flask-socketio)
       ("python-psutil" ,python-psutil)
       ("python-pycryptodome" ,python-pycryptodome)
       ("python-pysocks" ,python-pysocks)
       ("python-requests" ,python-requests)
       ("python-stem" ,python-stem)
       ("python-unidecode" ,python-unidecode)
       ("python-urllib3" ,python-urllib3)
       ("tor" ,tor)))
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'bake-tor
           (lambda* (#:key inputs #:allow-other-keys)
             (substitute* (list "cli/onionshare_cli/common.py"
                                "desktop/src/onionshare/gui_common.py")
               (("shutil\\.which\\(\\\"tor\\\"\\)")
                (string-append "\"" (which "tor") "\"")))
             #t))
         (add-before 'build 'change-directory
           (lambda _ (chdir "cli") #t))
         (replace 'check
           (lambda _
             (setenv "HOME" "/tmp")
             ;; Greendns is not needed for testing, and if eventlet tries to
             ;; load it, an OSError is thrown when getprotobyname is called.
             ;; Thankfully there is an environment variable to disable the
             ;; greendns import, so use it:
             (setenv "EVENTLET_NO_GREENDNS" "yes")
             (invoke "pytest" "-v" "./tests"))))))
    (home-page "https://onionshare.org/")
    (synopsis "Securely and anonymously share files")
    (description "OnionShare lets you securely and anonymously share files,
host websites, and chat with friends using the Tor network.

This package contains @code{onionshare-cli}, a command-line interface to
OnionShare.")
    ;; Bundled, minified jquery and socket.io are expat licensed.
    (license (list license:gpl3+ license:expat))))

(define-public onionshare
  (package (inherit onionshare-cli)
    (name "onionshare")
    (arguments
     (substitute-keyword-arguments (package-arguments onionshare-cli)
      ((#:phases phases)
       `(modify-phases ,phases
         (replace 'change-directory
           (lambda _ (chdir "desktop/src") #t))
         (add-after 'unpack 'patch-tests
           (lambda _
             ;; Disable tests that require starting servers, which will hang
             ;; during build:
             ;; - test_autostart_and_autostop_timer_mismatch
             ;; - test_autostart_timer
             ;; - test_autostart_timer_too_short
             ;; - test_autostop_timer_too_short
             (substitute* "desktop/tests/test_gui_share.py"
               (("( *)def test_autost(art|op)_(timer(_too_short)?|and_[^(]*)\\(" & >)
                (string-append > "@pytest.mark.skip\n" &)))
             ;; - test_13_quit_with_server_started_should_warn
             (substitute* "desktop/tests/test_gui_tabs.py"
               (("( *)def test_13" & >)
                (string-append > "@pytest.mark.skip\n" &)))
             ;; Remove multiline load-path adjustment, so that onionshare-cli
             ;; modules are loaded from input
             (use-modules (ice-9 regex)
                          (ice-9 rdelim))
             (with-atomic-file-replacement "desktop/tests/conftest.py"
               (let ((start-rx (make-regexp "^# Allow importing")))
                 (lambda (in out)
                   (let loop ()
                     (let ((line (read-line in 'concat)))
                       (if (regexp-exec start-rx line)
                           (begin      ; slurp until closing paren
                             (let slurp ()
                               (let ((line (read-line in 'concat)))
                                 (if (string=? line ")\n")
                                     (dump-port in out) ; done
                                     (slurp)))))
                           (begin
                             (display line out)
                             (loop))))))))))
         (replace 'check
           (lambda _
             ;; Some tests need a writable homedir:
             (setenv "HOME" "/tmp")
             ;; Ensure installed modules can be found:
             (setenv "PYTHONPATH"
                     (string-append %output "/lib/python"
                                    ,(version-major+minor (package-version python))
                                    "/site-packages:"
                                    (getenv "PYTHONPATH")))
             ;; Avoid `getprotobyname` issues:
             (setenv "EVENTLET_NO_GREENDNS" "yes")
             ;; Make Qt render "offscreen":
             (setenv "QT_QPA_PLATFORM" "offscreen")
             ;; Must be run from "desktop" dir:
             (chdir "..")
             (invoke "./tests/run.sh")))
         (add-after 'install 'install-data
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (share (string-append out "/share")))
               (install-file "org.onionshare.OnionShare.svg"
                             (string-append share "/icons/hicolor/scalable/apps"))
               (install-file "org.onionshare.OnionShare.desktop"
                             (string-append share "/applications"))
               #t)))))))
    (native-inputs
     `(("python-pytest" ,python-pytest)))
    (inputs
     ;; TODO: obfs4proxy
     `(("onionshare-cli" ,onionshare-cli)
       ("python-shiboken-2" ,python-shiboken-2)
       ("python-pyside-2" ,python-pyside-2)
       ("python-qrcode" ,python-qrcode)
       ;; The desktop client uses onionshare-cli like a python module.  But
       ;; propagating onionshare-cli's inputs is not great, since a user would
       ;; not expect to have those installed when using onionshare-cli as a
       ;; standalone utility.  So add onionshare-cli's inputs here.
       ,@(package-inputs onionshare-cli)))
    (description "OnionShare lets you securely and anonymously share files,
host websites, and chat with friends using the Tor network.")))

(define-public nyx
  (package
    (name "nyx")
    (version "2.1.0")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri name version))
       (sha256
        (base32
         "02rrlllz2ci6i6cs3iddyfns7ang9a54jrlygd2jw1f9s6418ll8"))))
    (build-system python-build-system)
    (inputs
     `(("python-stem" ,python-stem)))
    (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'install 'install-man-page
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (man (string-append out "/share/man")))
               (install-file "nyx.1" (string-append man "/man1"))
               #t)))
         (add-after 'install 'install-sample-configuration
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (doc (string-append out "/share/doc/" ,name "-" ,version)))
               (install-file "web/nyxrc.sample" doc)
               #t))))
       ;; XXX The tests seem to require more of a real terminal than the build
       ;; environment provides:
       ;;   _curses.error: setupterm: could not find terminal
       ;; With TERM=linux, the tests try to move the cursor and still fail:
       ;;   _curses.error: cbreak() returned ERR
       #:tests? #f))
    (home-page "https://nyx.torproject.org/")
    (synopsis "Tor relay status monitor")
    (description
     "Nyx monitors the performance of relays participating in the
@uref{https://www.torproject.org/, Tor anonymity network}.  It displays this
information visually and in real time, using a curses-based terminal interface.
This makes Nyx well-suited for remote shell connections and servers without a
graphical display.  It's like @command{top} for Tor, providing detailed
statistics and status reports on:

@enumerate
@item connections (with IP address, hostname, fingerprint, and consensus data),
@item bandwidth, processor, and memory usage,
@item the relay's current configuration,
@item logged events,
@item and much more.
@end enumerate

Potential client and exit connections are scrubbed of sensitive information.")
    (license license:gpl3+)))

(define-public obfs4
  (package
    (name "obfs4")
    (version "0.0.11")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://git.torproject.org/pluggable-transports/obfs4.git")
             (commit (string-append "obfs4proxy-" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "1y2kjwrk64l1h8b87m4iqsanib5rn68gzkdri1vd132qrlypycjn"))))
    (build-system go-build-system)
    (arguments
     '(#:import-path "git.torproject.org/pluggable-transports/obfs4.git"
       #:tests? #f ;; No test files
       #:phases
       (modify-phases %standard-phases
         (replace 'build
           (lambda* (#:key outputs configure-flags #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (copy-recursively
                "src/git.torproject.org/pluggable-transports/obfs4.git"
                "src/gitlab.com/yawning/obfs4.git"
                #:log (%make-void-port "w"))
               (with-directory-excursion
                   "src/git.torproject.org/pluggable-transports/obfs4.git/obfs4proxy"
                 (invoke "go" "build" "-ldflags" "-s"))
               #t)))
         (replace 'install
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (src "src/git.torproject.org/pluggable-transports/obfs4.git")
                    (bin (string-append out "/bin"))
                    (share (string-append out "/share"))
                    (doc (string-append share "/doc"))
                    (man (string-append share "/man/man1")))
               (mkdir-p man)
               (mkdir bin)
               (mkdir doc)
               (with-directory-excursion
                   (string-append src "/obfs4proxy")
                 (copy-file "obfs4proxy"
                            (string-append bin "/obfs4proxy")))
               (with-directory-excursion
                   (string-append src "/doc")
                 (copy-file "obfs4proxy.1"
                            (string-append man "/obfs4proxy.1"))
                 (copy-file "obfs4-spec.txt"
                            (string-append doc "/obfs4-spec.txt")))
               #t))))))
    (propagated-inputs
     `(("go-torproject-org-ptlib" ,go-torproject-org-ptlib)
       ("go-github-com-agl-ed25519" ,go-github-com-agl-ed25519)
       ("go-github-com-dchest-siphash" ,go-github-com-dchest-siphash)
       ("go-github-com-dchest-uniuri" ,go-github-com-dchest-uniuri)
       ("go-github-com-dsnet-compress" ,go-github-com-dsnet-compress)
       ("go-schwanenlied-me-yawning-bsaes" ,go-schwanenlied-me-yawning-bsaes)
       ("go-gitlab-com-yawning-utls" ,go-gitlab-com-yawning-utls)
       ("go-golang-org-x-net" ,go-golang-org-x-net)
       ("go-golang-org-x-crypto" ,go-golang-org-x-crypto)
       ("go-golang-org-x-text" ,go-golang-org-x-text)))
    (home-page "https://git.torproject.org/pluggable-transports/obfs4.git")
    (synopsis "Obfs4 implements an obfuscation protocol")
    (description "This is a look-like nothing obfuscation protocol that
incorporates ideas and concepts from Philipp Winter's ScrambleSuit protocol.
The obfs naming was chosen primarily because it was shorter, in terms of
protocol ancestery obfs4 is much closer to ScrambleSuit than obfs2/obfs3.")
    (license license:gpl3+)))

;; torbrowser and tor-browser-builder build versions are not always in sync
(define %torbrowser-version "78.11.0esr-10.0-1")
(define %tbb-build-version "10.0.17")
(define %torbrowser-build "build1")
(define %tbb-build "build1")
(define %torbrowser-build-id "20210602000000");must be of the form YYYYMMDDhhmmss

;; Fonts for Tor Browser. Avoid downloading 4Gb+ git repo on
;; https://github.com/googlei18n/noto-fonts.git to use just a handful.
;; Use the fonts on Tor Browser release tarball.
(define torbrowser-fonts
  (package
    (name "torbrowser-fonts")
    (version %tbb-build-version)
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://archive.torproject.org/tor-package-archive/torbrowser/"
                           version "/tor-browser-linux64-"
                           version "_en-US.tar.xz"))
       (sha256
        (base32
         "13x38n1cvqmxjz0jf2fda8lx2k25szzmg7gvv08z3q5na7109m2m"))))
    (build-system trivial-build-system)
    (native-inputs
     `(("tar" ,tar)
       ("xz" ,xz)))
    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
                   (use-modules (guix build utils))
                   (let ((src (assoc-ref %build-inputs "source"))
                         (src-dir "tor-browser_en-US/Browser/fonts")
                         (fonts (string-append %output "/share/fonts"))
                         (tar (assoc-ref %build-inputs "tar"))
                         (xz (assoc-ref %build-inputs "xz")))
                     (mkdir-p fonts)
                     (format #t "Untaring torbrowser ball ...~%")
                     (invoke (string-append tar "/bin/tar") "-xf" src
                             "-C" fonts "--strip-components=3"
                             (string-append "--use-compress-program=" xz "/bin/xz")
                             src-dir)
                     #t))))
    (home-page "https://github.com/googlei18n/noto-fonts")
    (synopsis "Tor Browser bundled fonts")
    (description "Free fonts bundled with Tor Browser.  Includes a subset of Noto,
Arimo, Cousine, Tinos and STIX fonts.")
    (license license:silofl1.1)))

(define tor-browser-build
  (let ((commit (string-append "tbb-desktop-" %tbb-build-version
                               "-" %tbb-build)))
    (package
      (name "tor-browser-build")
      (version %tbb-build-version)
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://git.torproject.org/builders/tor-browser-build.git")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32
           "1qwgghy79wx0w1yz132yyaln4g42s72133n6gbdf07rkf5n44izc"))))
      (build-system trivial-build-system)
      (arguments
       `(#:modules ((guix build utils))
         #:builder (begin
                     (use-modules (guix build utils))
                     (format #t "Copying build scripts ...~%")
                     (copy-recursively (string-append
                                        (assoc-ref %build-inputs "source")
                                        "/projects/tor-browser")
                                       %output
                                       #:log (%make-void-port "w")))))
      (home-page "https://www.torproject.org")
      (synopsis "Tor Browser build scripts")
      (description "Tor Browser runtime scripts.")
      (license (license:non-copyleft "file://LICENSE")))))

(define tor-launcher
  (package
    (name "tor-launcher")
    (version "0.2.28")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://archive.torproject.org/tor-package-archive/torbrowser/"
                           %tbb-build-version "/src-" name "-"
                           version ".tar.xz"))
       (sha256
        (base32
         "0mbd1q46d8nqisn6n79sp6m29332ymb2pf13xzgq1ml7rfcy6jjy"))))
    (build-system trivial-build-system)
    (native-inputs
     `(("tar" ,tar)
       ("xz" ,xz)))
    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
                   (use-modules (guix build utils))
		   (format #t "Extracting source ...~%")
                   (let ((src (assoc-ref %build-inputs "source"))
                         (tar (assoc-ref %build-inputs "tar"))
                         (xz (assoc-ref %build-inputs "xz")))
                     (mkdir-p %output)
                     (format #t "Extracting source ...~%")
                     (invoke (string-append tar "/bin/tar") "-xf" src
                             "-C" %output "--strip-components=1"
                             (string-append "--use-compress-program=" xz "/bin/xz"))))))
    (home-page "https://www.torproject.org")
    (synopsis "Tor Browser built-in controler extension")
    (description "Browser extension that starts the tor process (which
connects the browser and other applications to the Tor Network), and
which helps people configure and use @code{tor}. The first window that
you see when you start Tor Browser is displayed by this extension.")
    (license (license:non-copyleft "file://src/LICENSE"))))

(define https-everywhere-lib-wasm
  (let ((commit "45b1622f1240659aca4762fa336aad1322d6d50f"))
    (package
      (name "https-everywhere-lib-wasm")
      (version "2021.4.15")
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/EFForg/https-everywhere-lib-wasm")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32
           "1lq62rzypdzmnnzvfns3ccvv1g7p7g9s8jx788zzigr3gnmkpffx"))))
      (build-system trivial-build-system)
      (arguments
       `(#:modules ((guix build utils))
         #:builder (begin
                     (use-modules (guix build utils))
                     (format #t "Copying source ...~%")
                     (copy-recursively (assoc-ref %build-inputs "source")
                                       %output
                                       #:log (%make-void-port "w")))))
      (home-page "https://github.com/EFForg/https-everywhere-lib-wasm")
      (synopsis "Browser extension for protection against known attacks")
      (description "Browser extension that protects users from a range of
known attacks on web browsing activity such as Cross-site scripting, clickjack and
makes possible for the users to block or choose on a per site basis which remote
javascript to run while browsing the web.")
      (license license:gpl2+))))

;; Both https-everywhere and noscript are rellying on some precompiled code for now.
;; Also read on the work on chromium extensions on gnu/build/chromium-extensions.scm
;; to see if can be adapted.
(define-public https-everywhere
  (package
    (name "https-everywhere")
    (version "2021.4.15")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://github.com/EFForg/" name "/archive/"
                           version ".tar.gz"))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32
         "1bknx8l8gxmpwb13pvn6pdbavknci8q0jhygdaz50ilc1xld89i3"))))
    (build-system trivial-build-system)
    (native-inputs
     `(("bash" ,bash)
       ("coreutils" ,coreutils)
       ("findutils" ,findutils)
       ("git" ,git)
       ("grep" ,grep)
       ("gzip" ,gzip)
       ("https-everywhere-lib-wasm"
        ,https-everywhere-lib-wasm)
       ("libxml2" ,libxml2)
       ("libxslt" ,libxslt)
       ("openssl" ,openssl)
       ("python" ,python)
       ("rsync" ,rsync)
       ("sed" ,sed)
       ("tar" ,tar)
       ("util-linux" ,util-linux) ; for getopt
       ("xxd" ,xxd)
       ("which" ,which)
       ("zip" ,zip)))
    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
                   (use-modules (guix build utils))
                   (let ((src (assoc-ref %build-inputs "source"))
                         (httpse-libwasm (assoc-ref %build-inputs
                                                    "https-everywhere-lib-wasm"))
                         (bash (assoc-ref %build-inputs "bash"))
                         (coreutils (assoc-ref %build-inputs "coreutils"))
                         (python (assoc-ref %build-inputs "python"))
                         (openssl (assoc-ref %build-inputs "openssl"))
                         (git (assoc-ref %build-inputs "git"))
                         (grep (assoc-ref %build-inputs "grep"))
                         (findutils (assoc-ref %build-inputs "findutils"))
                         (sed (assoc-ref %build-inputs "sed"))
                         (which (assoc-ref %build-inputs "which"))
                         (rsync (assoc-ref %build-inputs "rsync"))
                         (libxml2 (assoc-ref %build-inputs "libxml2"))
                         (libxslt (assoc-ref %build-inputs "libxslt"))
                         (util-linux (assoc-ref %build-inputs "util-linux"))
                         (xxd (assoc-ref %build-inputs "xxd"))
                         (zip (assoc-ref %build-inputs "zip"))
                         (tar (assoc-ref %build-inputs "tar"))
                         (gzip (assoc-ref %build-inputs "gzip")))
                     (setenv "SHELL" (string-append bash "/bin/bash"))
                     (set-path-environment-variable
                      "PATH" '("bin")
                      (list bash sed findutils which git python tar openssl rsync
                            libxml2 libxslt util-linux grep xxd gzip zip coreutils))
                     (set-path-environment-variable
                      "LIBRARY_PATH" '("lib")
                      (list bash sed findutils which git python tar openssl rsync
                            libxml2 libxslt util-linux grep xxd gzip zip coreutils))
                     (format #t "Untaring source tarball ...~%")
                     (invoke "tar" "-xf" src "--strip-components=1")
                     ;; Python3.6 is hardcoded on these scripts. Using v3.8 appears to
                     ;; be harmless.
                     (substitute* '("install-dev-dependencies.sh"
                                    "make.sh"
                                    "hooks/precommit"
                                    "test/firefox.sh"
                                    "test/manual.sh"
                                    "test/rules/src/https_everywhere_checker/check_rules.py"
                                    "test/script.py"
                                    "test/validations.sh"
                                    "test/validations/filename/run.py"
                                    "test/validations/relaxng/run.py"
                                    "test/validations/securecookie/run.py"
                                    "test/validations/special/run.py"
                                    "utils/create_zip.py"
                                    "utils/chromium-translations.py"
                                    "utils/create-platform-certs/split_combined_cert_file.py"
                                    ;; "utils/mk-client-whitelist/dbconnect.py"
                                    ;; "utils/mk-client-whitelist/run.py"
                                    "utils/merge-rulesets.py"
                                    "utils/setversion.py"
                                    "utils/zipfile_deterministic.py")
                       (("python3.6") "python3"))
                     (make-file-writable "lib-wasm")
                     (copy-recursively httpse-libwasm
                                       "lib-wasm"
                                       #:log (%make-void-port "w"))
                     ;; Remove precompiled binaries from source. This breaks
                     ;; http-everywhere at runtime, but building is successful.
                     ;; For now building takes the precompiled version included with sources.
		     ;; Tor Browser upstream does the same. In case you want to remove the
		     ;; precompiled version, use the routine below. It successfully builds
		     ;; but at run time rules seem to be broken.
                     ;(with-directory-excursion "lib-wasm/pkg"
                     ;  (for-each (lambda (file)
                     ;              (if (file-exists? file)
                     ;                  (delete-file file)
                     ;                  (display (string-append
                     ;                            "Warning: file " file
                     ;                            " not found! Skipping...\n"))))
                     ;            '("https_everywhere_lib_wasm.js"
                     ;              "https_everywhere_lib_wasm_bg.wasm")))
                     (for-each patch-shebang
                               (find-files "."
                                           (lambda (file stat)
                                             ;; Filter out symlinks.
                                             (eq? 'regular (stat:type stat)))
                                           #:stat lstat))
                     ;; Failing to generate the xpi, but copy-dir appears to be enough.
                     ;; Failing on missing 'wasm'? Not generating rulesets. Once lib-wasm
		     ;; gets cross-compiled, try to move the '.xpi' extension instead.
                     (invoke "./make.sh")
                     (copy-recursively "pkg/xpi-eff" %output
                                       #:log (%make-void-port "w"))
                     #t))))
    (home-page "https://www.eff.org/https-everywhere")
    (synopsis "Browser extension for automatic HTTPS usage")
    (description "Browser extension that automatically makes the browser to use
HTTPS instead of plain HTTP when the remote destination makes it available to users.")
    (license license:gpl2+)))

(define noscript
  (package
    (name "noscript")
    (version "11.2.8")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://secure.informaction.com/download/releases/"
                           name "-" version ".xpi"))
       (sha256
        (base32
         "0rrlhlzljlmgns7j49c43ilb8wij2zcysrbpap1xxsfbkbczji27"))))
    (build-system trivial-build-system)
    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
		   ;; Fake build for now. Upstream Tor Browser does not build it as well.
                   (format #t "Copying source ...~%")
                   (copy-file (assoc-ref %build-inputs "source")
                              %output))))
    (home-page "https://noscript.net")
    (synopsis "Browser extension for protection against known attacks")
    (description "Browser extension that protects users from a range of
known attacks on web browsing activity such as Cross-site scripting, clickjack and
makes possible for the users to block or choose on a per site basis which remote
javascript to run while browsing the web.")
    (license license:gpl2+)))

;; (Un)fortunatly Tor Browser has it's own reproducible build system - RBM - which
;; automates the build process for them and compiles Tor Browser from a range of
;; repositories and produces a range of tarballs for different architectures and
;; locales. So we need to cherry-pick what is needed for guix and produce our own
;; tarball. See https://gitweb.torproject.org/builders/tor-browser-build.git/projects/\
;; {tor-browser,firefox}/{build,config} for the rationale applied here. See also
;; the Hacking on Tor Browser document for a high level introduction at
;; https://trac.torproject.org/projects/tor/wiki/doc/Tor Browser/Hacking).
;;
;; TODO: Import langpacks from https://archive.torproject.org/tor-package-archive/\
;; torbrowser/'version'/langpacks-tor-browser-linux64-version.tar.xz
(define-public torbrowser-unbundle
  (let ((commit (string-append "tor-browser-" %torbrowser-version
                               "-" %torbrowser-build)))
    (package
      (inherit icecat)
      (name "torbrowser-unbundle")
      (version %tbb-build-version)
      (source
       (origin
	 (method url-fetch)
	 (uri (string-append "https://archive.torproject.org/tor-package-archive/torbrowser/"
			     %tbb-build-version
			     "/src-firefox-tor-browser-"
			     %torbrowser-version "-" %torbrowser-build
			     ".tar.xz"))
	 (sha256
          (base32
           "1jnb7v9zn7y2fk7gqvq1ijlwl16i7wf83y1xn2djqcp1j42n1yvq"))))
      (build-system gnu-build-system)
      (inputs
       `(("obfs4" ,obfs4)
	 ("tor" ,tor-client)
	 ,@(package-inputs icecat)))
      (native-inputs
       `(("https-everywhere" ,https-everywhere)
	 ("noscript" ,noscript)
	 ("tor-browser-build" ,tor-browser-build)
	 ("tor-launcher" ,tor-launcher)
	 ("torbrowser-fonts" ,torbrowser-fonts)
	 ("torbrowser-start-script.patch"
          ,(search-patch "torbrowser-start-script.patch"))
	 ("torbrowser-start-desktop.patch"
          ,(search-patch "torbrowser-start-desktop.patch"))
	 ,@(package-native-inputs icecat)))
      (properties '())
      (arguments
       (substitute-keyword-arguments (package-arguments icecat)
	 ((#:phases phases)
          `(modify-phases ,phases
             ;; On mach build system this is done on configure.
             (delete 'bootstrap)
             ;; Doesn't seem to be needed for TorBrowser
             (delete 'fix-ffmpeg-runtime-linker)
             ;; Tried to make use of these using let, but inheritance appears to block it.
             (delete 'install-icons)
             (delete 'install-desktop-entry)
             (add-after 'unpack 'make-bundle
               (lambda* (#:key inputs native-inputs #:allow-other-keys)
		 (let ((tor-launcher (assoc-ref inputs "tor-launcher"))
                       (tor-launcher-dir "browser/extensions/tor-launcher")
                       (tbb (assoc-ref inputs "tor-browser-build"))
                       (tbb-scripts-dir "tbb-scripts"))

                   (format #t "Copying tor-launcher ...~%")
                   (copy-recursively tor-launcher tor-launcher-dir
                                     #:log (%make-void-port "w"))
                   (format #t "Copying tor-browser-build ...~%")
                   (mkdir tbb-scripts-dir)
                   (copy-recursively tbb tbb-scripts-dir
                                     #:log (%make-void-port "w"))
		   (make-file-writable "browser/app/profile/000-tor-browser.js")
		   (make-file-writable (string-append tbb-scripts-dir
						      "/RelativeLink/start-tor-browser"))
                   (make-file-writable (string-append tbb-scripts-dir
						      "/RelativeLink/start-tor-browser.desktop")))
		 #t))
             (replace 'apply-guix-specific-patches
               (lambda* (#:key inputs native-inputs #:allow-other-keys)
		 (let ((patch (string-append (assoc-ref (or native-inputs inputs)
							"patch")
                                             "/bin/patch")))
                   (for-each (match-lambda
                               ((label . file)
				;; Only difference to icecat is browser name.
				(when (and (string-prefix? "torbrowser-" label)
                                           (string-suffix? ".patch" label))
                                  (format #t "applying '~a'...~%" file)
                                  (invoke patch "--force" "--no-backup-if-mismatch"
                                          "-p1" "--input" file))))
                             (or native-inputs inputs)))
		 #t))
             (add-after 'apply-guix-specific-patches 'merge-bridge-preferences
               (lambda* (#:key inputs native-inputs #:allow-other-keys)
		 (begin
                   (let ((tbb-prefs (open-file
                                     "browser/app/profile/000-tor-browser.js" "a"))
			 (bridge-prefs
                          (open-input-file
                           "tbb-scripts/Bundle-Data/PTConfigs/bridge_prefs.js")))
                     (display (get-string-all bridge-prefs) tbb-prefs)
                     (close-output-port tbb-prefs)))
		 #t))
             (replace 'configure
               (lambda* (#:key inputs outputs configure-flags #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(bash (which "bash"))
			(flags `(,(string-append "--prefix=" out)
				 ,@configure-flags)))
                   (setenv "SHELL" bash)
                   (setenv "AUTOCONF" (string-append
                                       (assoc-ref %build-inputs "autoconf")
                                       "/bin/autoconf"))
                   (setenv "CONFIG_SHELL" bash)
                   (setenv "PYTHON" (string-append (assoc-ref inputs "python-2")
                                                   "/bin/python"))
                   (setenv "CC" "gcc")  ; needed when Stylo is enabled
                   (setenv "MOZ_BUILD_DATE" ,%torbrowser-build-id) ; avoid timestamp.
                   (setenv "LDFLAGS" (string-append "-Wl,-rpath="
                                                    (assoc-ref outputs "out")
                                                    "/lib"))
                   (substitute* ".mozconfig"
                     ;; Arch independent builddir.
                     (("(mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj).*" _ m)
                      (string-append m "dir\n"))
                     (("ac_add_options --disable-tor-launcher") "")
                     ;; We won't be building incrementals.
                     (("ac_add_options --enable-signmar") "")
                     (("ac_add_options --enable-verify-mar") "")
                     (("ac_add_options --with-tor-browser-version=dev-build")
		      ;; If we decide to rebrand this browser, here is the place to do it.
                      (string-append
                       "ac_add_options --with-tor-browser-version=org.gnu\n"
                       "ac_add_options --with-unsigned-addon-scopes=app,system\n"
                       "ac_add_options --allow-addon-sideload\n"
                       "ac_add_options --enable-pulseaudio\n"
                       "ac_add_options --disable-debug-symbols\n"
                       "ac_add_options --disable-updater\n"
                       "ac_add_options --enable-system-pixman\n"
                       "ac_add_options --enable-system-ffi\n"
                       "ac_add_options --with-system-icu\n"
                       "ac_add_options --with-system-jpeg\n"
                       "ac_add_options --with-system-libevent\n"
                       ;;"ac_add_options --with-system-nspr\n" ;; broken for now, see icecat.
                       ;;"ac_add_options --with-system-nss\n"
                       "ac_add_options --with-system-zlib\n"
                       ;; Without these clang is not found.
                       "ac_add_options --with-clang-path="
                       (assoc-ref %build-inputs "clang") "/bin/clang\n"
                       "ac_add_options --with-libclang-path="
                       (assoc-ref %build-inputs "clang") "/lib\n")))
                   (substitute* "browser/app/profile/000-tor-browser.js"
                     ;; Tor Browser updates are disabled on mozconfig, but let's make sure.
                     (("(pref\\(\"extensions.torbutton.versioncheck_enabled\").*" _ m)
                      (string-append m ",false);\n"))
                     ;; Snowflake is not built on gnu targets.
                     (("pref\\(\"extensions.torlauncher.default_bridge.snowflake.1\".*")
                      "\n"))
                   (substitute*
                       "browser/extensions/tor-launcher/src/defaults/preferences/torlauncher-prefs.js"
                     ;; Not multilingual. See tor-browser/build:141. Currently disabled on
                     ;; tor-launcher, but let's make sure while missing langpacks.
                     (("(pref\\(\"extensions.torlauncher.prompt_for_locale\").*" _ m)
                      (string-append m ", false);\n")))
                   ;; For user data outside the guix store.
                   (substitute* "xpcom/io/TorFileUtils.cpp"
                     (("ANDROID") "GNUGUIX"))
                   (substitute* "old-configure.in"
                     (("(AC_SUBST\\(TOR_BROWSER_DISABLE_TOR_LAUNCHER\\))" _ m)
                      (string-append m "\n AC_DEFINE(GNUGUIX)\n")))
                   (format #t "Invoking mach configure ...~%")
                   (invoke "./mach" "configure"))
		 #t))
             (add-after 'configure 'install-desk-icons
               (lambda* (#:key outputs #:allow-other-keys)
		 (let ((out (assoc-ref outputs "out")))
                   (with-directory-excursion "browser/branding/official"
                     (for-each
                      (lambda (file)
			(let* ((size (string-filter char-numeric? file))
                               (icons (string-append out "/share/icons/hicolor/"
                                                     size "x" size "/apps")))
                          (mkdir-p icons)
                          (copy-file file (string-append icons "/torbrowser.png"))))
                      '("default16.png" "default22.png" "default24.png"
			"default32.png" "default48.png" "default64.png"
			"default128.png" "default256.png" "default512.png"))
                     #t))))
             (replace 'build
               (lambda _
		 (make-file-writable "Cargo.lock")
		 (invoke "./mach" "build")
                 #t))
             (replace 'neutralise-store-references
               (lambda _
		 ;; difference from icecat "objdir" preffix. We could use find-files there.
		 (substitute*
                     "objdir/dist/bin/chrome/toolkit/content/global/buildconfig.html"
                   (((format #f "(~a/)([0-9a-df-np-sv-z]{32})"
                             (regexp-quote (%store-directory))) _ store hash)
                    (string-append store
                                   (string-take hash 8)
                                   "<!-- Guix: not a runtime dependency -->"
                                   (string-drop hash 8))))
		 #t))
             ;; Tor Browser just do a stage-package here and copy files to its places.
             (replace 'install
               (lambda* (#:key inputs native-inputs outputs
			 configure-flags #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(applications (string-append out "/share/applications"))
			(build "objdir/dist/firefox")
			(bin (string-append out "/bin"))
			(lib (string-append out "/lib"))
			(start-script "tbb-scripts/RelativeLink/start-tor-browser")
			(desktop-file "tbb-scripts/RelativeLink/start-tor-browser.desktop"))
                   (invoke "./mach" "build" "stage-package")
                   ;; Tor Browser doesn't use those.
                   ;; See: tor-browser-build.git/projects/firefox/build:167
                   (format #t "Deleting spurious files ...~%")
                   (with-directory-excursion build
                     (for-each (lambda (file)
				 (if (file-exists? file)
                                     (delete-file file)
                                     (display (string-append
                                               "Warning: file " file
                                               " not found! Skipping...\n"))))
                               '("firefox-bin" "fonts/TwemojiMozilla.ttf")))
                   (rmdir (string-append build "/fonts"))
                   (format #t "Creating install dirs ...~%")
                   (mkdir-p applications)
                   (mkdir-p lib)
                   (mkdir bin)
                   (format #t "Copying files to install dirs ...~%")
                   (copy-recursively build (string-append lib "/")
                                     #:log (%make-void-port "w"))
                   (copy-file start-script
                              (string-append lib "/start-tor-browser"))
                   (copy-file desktop-file
                              (string-append lib "/start-tor-browser.desktop"))
                   (chmod (string-append lib "/start-tor-browser") #o555)
                   (chmod (string-append lib "/start-tor-browser.desktop") #o555)
                   (format #t "Linking start-tor-browser script ...~%")
                   (symlink (string-append lib "/start-tor-browser")
                            (string-append bin "/start-tor-browser"))
                   (format #t "Installing desktop file ...~%")
                   (install-file desktop-file applications))
		 #t))
             (add-after 'install 'install-fonts
               (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(lib (string-append out "/lib/"))
			(fonts  (string-append (or (assoc-ref native-inputs
                                                              "torbrowser-fonts")
                                                   (assoc-ref inputs
                                                              "torbrowser-fonts"))
                                               "/share")))
                   (copy-recursively fonts lib
                                     #:log (%make-void-port "w"))
                   (symlink (string-append lib "/fonts")
                            (string-append out "/share/fonts")))
		 #t))
             (add-after 'install-fonts 'install-extensions
               (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(lib (string-append out "/lib"))
			(ext (string-append lib "/browser/extensions"))
			(torb-ext (string-append lib
						 "/chrome/torbutton/content/extensions"))
			(httpse-id "https-everywhere")
			(noscript-id "{73a6fe31-595d-460b-a920-fcc0f8843232}")
			(httpse (assoc-ref inputs "https-everywhere"))
			(noscript (assoc-ref inputs "noscript")))
                   (mkdir-p ext)
                   (mkdir-p torb-ext)
                   (copy-file noscript (string-append
					ext "/" noscript-id ".xpi"))
                   (copy-recursively httpse
                                     (string-append torb-ext "/" httpse-id)
                                     #:log (%make-void-port "w"))
                   (chmod (string-append ext "/" noscript-id ".xpi") #o555)
                   ;; Make httpse available as a builtin extension. This step is
		   ;; changing some timestamps and making everything non-deterministic.
		   ;; To check insert 'resource://torbutton/content/extensions/https-everywhere/'
		   ;; on the browser address field. Check 'reset-gzip-timestamps' to see what
		   ;; can be done.
		   ;; https://gitweb.torproject.org/builders/tor-browser-build.git/tree/projects/\
		   ;; tor-browser/build?h=tbb-desktop-10.0.17-build1&id=16fa8c3bf91a9c1a827a7d23be344de599cd10bb#n77g
                   (with-directory-excursion lib
                     (make-file-writable "omni.ja")
                     (for-each (lambda (file)
				 (invoke "zip" "-X" "omni.ja" file))
                               (find-files "chrome" ".*"))))
		 #t))
             (add-after 'install-extensions 'link-binaries
               (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(tordir (string-append out "/lib/TorBrowser/Tor"))
			(ptdir (string-append tordir "/PluggableTransports"))
			(obfs4 (string-append (assoc-ref inputs "obfs4")
                                              "/bin/obfs4proxy"))
			(tor (string-append (assoc-ref inputs "tor")
                                            "/bin/tor")))
                   (mkdir-p ptdir)
                   (symlink tor (string-append tordir "/tor"))
                   (symlink obfs4 (string-append ptdir "/obfs4proxy")))
		 #t))
             (add-after 'link-binaries 'copy-bundle-data
               (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(lib (string-append out "/lib"))
			(tbb "tbb-scripts")
			(ptconf (string-append tbb "/Bundle-Data/PTConfigs"))
			(docs (string-append lib "/TorBrowser/Docs"))
			(data (string-append lib "/TorBrowser/Data")))
                   (mkdir-p data)
                   (mkdir docs)
                   (with-directory-excursion
                       (string-append tbb "/Bundle-Data/linux/Data")
                     (for-each (lambda (file)
				 (copy-recursively file
                                                   (string-append data "/" file)
                                                   #:log (%make-void-port "w")))
                               '("Browser" "fontconfig" "Tor")))
                   (copy-file (string-append ptconf "/linux/torrc-defaults-appendix")
                              (string-append data "/Tor/torrc-defaults-appendix"))
                   (copy-recursively (string-append tbb "/Bundle-Data/Docs")
                                     (string-append docs "/")
                                     #:log (%make-void-port "w")))
		 #t))
             ;; This fixes the file chooser crash that happens with GTK 3
             (replace 'wrap-program
               (lambda* (#:key inputs outputs #:allow-other-keys)
		 (let* ((out (assoc-ref outputs "out"))
			(lib (string-append out "/lib"))
			(gtk (assoc-ref inputs "gtk+"))
			(gtk-share (string-append gtk "/share"))
			(mesa (assoc-ref inputs "mesa"))
			(mesa-lib (string-append mesa "/lib"))
			(pulseaudio (assoc-ref inputs "pulseaudio"))
			(pulseaudio-lib (string-append pulseaudio "/lib"))
			(libxscrnsaver (assoc-ref inputs "libxscrnsaver"))
			(libxscrnsaver-lib (string-append libxscrnsaver "/lib")))
                   ;; Only difference to icecat is browser name.
                   (wrap-program (car (find-files lib "^firefox$"))
                     `("XDG_DATA_DIRS" prefix (,gtk-share))
                     `("LD_LIBRARY_PATH" prefix (,pulseaudio-lib ,mesa-lib
								 ,libxscrnsaver-lib))))
		 #t))))))
      (home-page "https://www.torproject.org")
      (synopsis "Anonymous browser derived from Mozilla Firefox")
      (description
       "Tor Browser is the Tor Project version of Firefox browser.  It is the only
recommended way to anonymously browse the web that is supported by the project.
It modifies Firefox in order to avoid many know application level attacks on
the privacy of Tor users.

WARNING: This is not the official Tor Browser and is currently on testing.  Use
at your own risk and please report back on guix channels if you find any
issues.")
      (license license:mpl2.0)))) ;and others, see toolkit/content/license.html

debug log:

solving d5832b19df ...
found d5832b19df in https://yhetil.org/guix-patches/347e91d0ce7f96882f70a081b208c388153cd6b8.1622693271.git.nandre@riseup.net/
found 52d78cba79 in https://yhetil.org/guix-patches/66abc6eeaeab68a209c54740678b64f1d96ecd87.1622687706.git.nandre@riseup.net/
found bd11dd3a75 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 bd11dd3a75c2a527e052103d65a8d05c7069b1b9	gnu/packages/tor.scm

applying [1/2] https://yhetil.org/guix-patches/66abc6eeaeab68a209c54740678b64f1d96ecd87.1622687706.git.nandre@riseup.net/
diff --git a/gnu/packages/tor.scm b/gnu/packages/tor.scm
index bd11dd3a75..52d78cba79 100644


applying [2/2] https://yhetil.org/guix-patches/347e91d0ce7f96882f70a081b208c388153cd6b8.1622693271.git.nandre@riseup.net/
diff --git a/gnu/packages/tor.scm b/gnu/packages/tor.scm
index 52d78cba79..d5832b19df 100644

Checking patch gnu/packages/tor.scm...
Applied patch gnu/packages/tor.scm cleanly.
Checking patch gnu/packages/tor.scm...
Applied patch gnu/packages/tor.scm cleanly.

index at:
100644 d5832b19df78e25aef537ab4ddd148ed5c614f9c	gnu/packages/tor.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).