Subject: [PATCH]: gnu: nix: Update to 2.4.

From: Zhu Zihao <[email-masked]>
Date: Wed, 10 Nov 2021 20:35:38 +0800

>From 935afdd36fee52fe3930991245ac67e48c0a00ff Mon Sep 17 00:00:00 2001
From: Zhu Zihao <[email-masked]>
Date: Wed, 10 Nov 2021 19:21:45 +0800
Subject: [PATCH 1/3] gnu: Add lowdown.

* gnu/packages/markup.scm(lowdown): New variables.
---
 gnu/packages/markup.scm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/gnu/packages/markup.scm b/gnu/packages/markup.scm
index 368976bfde..4ec606f892 100644
--- a/gnu/packages/markup.scm
+++ b/gnu/packages/markup.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2020 Marius Bakke <[email-masked]>
 ;;; Copyright © 2020 EuAndreh <[email-masked]>
 ;;; Copyright © 2021 Noisytoot <[email-masked]>
+;;; Copyright © 2021 Zhu Zihao <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -36,6 +37,7 @@ (define-module (gnu packages markup)
   #:use-module (guix utils)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
@@ -324,3 +326,35 @@ (define-public python-mistletoe
 swap out renderers for different output formats, without touching any of the
 core components.")
     (license expat)))
+
+(define-public lowdown
+  (package
+    (name "lowdown")
+    (version "0.10.0")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://kristaps.bsd.lv/lowdown/snapshots/lowdown-"
+                           version ".tar.gz"))
+       (sha256
+        (base32 "15v2kk4ffqw3n6y6n9plch4qcib3ynnhw0ih8wn2v9qgn4jssp5p"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f                      ;No test
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'configure
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((out (assoc-ref outputs "out")))
+               (invoke "./configure"
+                       (string-append "PREFIX=" out)
+                       (string-append "MANDIR=" out "/share/man"))))))
+       ;; the shared library of nix is linked with lowdown.
+       #:make-flags '("CFLAGS=-fPIC")))
+    (native-inputs
+     `(("which" ,which)))
+    (home-page "https://kristaps.bsd.lv/lowdown")
+    (synopsis "Simple Markdown translator")
+    (description "Lowdown is a Markdown translator producing HTML5,
+roff documents in the ms and man formats, LaTeX, gemini, and terminal output.")
+    (license isc)))
-- 
2.33.1

>From d38e131913a006d47d611ce6ebabfb1823d804b8 Mon Sep 17 00:00:00 2001
From: Zhu Zihao <[email-masked]>
Date: Wed, 10 Nov 2021 19:31:28 +0800
Subject: [PATCH 2/3] gnu: Add libcpuid.

gnu/packages/hardware.scm(libcpuid): New variable.
---
 gnu/packages/hardware.scm | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/gnu/packages/hardware.scm b/gnu/packages/hardware.scm
index 2bf3576d5a..df7fb4b716 100644
--- a/gnu/packages/hardware.scm
+++ b/gnu/packages/hardware.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2021 Petr Hodina <[email-masked]>
 ;;; Copyright © 2021 Raghav Gururajan <[email-masked]>
 ;;; Copyright © 2021 Vinicius Monego <[email-masked]>
+;;; Copyright © 2021 Zhu Zihao <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -834,3 +835,22 @@ (define-public tpm2-tss
 libtss2-esys, libtss2-sys, libtss2-mu, libtss2-tcti-device, libtss2-tcti-swtpm
 and libtss2-tcti-mssim.")
     (license license:bsd-2)))
+
+(define-public libcpuid
+  (package
+    (name "libcpuid")
+    (version "0.5.1")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://github.com/anrieff/libcpuid/releases/download/v"
+                           version "/libcpuid-" version ".tar.gz"))
+       (sha256
+        (base32 "1nksdqk2w1c56lkrjcvh3nss9vq454j81j3yq14lwdn4x8bvmwfr"))))
+    (build-system gnu-build-system)
+    (supported-systems '("x86_64-linux" "i686-linux"))
+    (home-page "https://libcpuid.sourceforge.net/")
+    (synopsis "A small library for x86 CPU detection and feature extraction")
+    (description "Libcpuid is a small C library to get vendor, model, branding
+string, code name and other information from x86 CPU.")
+    (license license:bsd-2)))
-- 
2.33.1

>From 51a7de78cebf893ebd15169f6af154b04b734e31 Mon Sep 17 00:00:00 2001
From: Zhu Zihao <[email-masked]>
Date: Wed, 10 Nov 2021 19:36:01 +0800
Subject: [PATCH 3/3] gnu: nix: Update to 2.4.

* gnu/packages/package-management.scm(nix): Update to 2.4.

[source]: Switch to Github repository since upstream no longer provides
tarball.
[native-inputs]: Add autoconf, autoconf-archive, automake, bison, flex, gcc,
googletest, jq, libtool
[inputs]: Add libarchive, libcpuid, lowdown, zlib.

* gnu/packages/patches/nix-dont-build-html-doc.diff: New file.
* gnu/local.mk(dist_patch_DATA): Add corresponding entry.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/package-management.scm           | 67 +++++++++++++------
 .../patches/nix-dont-build-html-doc.diff      | 26 +++++++
 3 files changed, 74 insertions(+), 20 deletions(-)
 create mode 100644 gnu/packages/patches/nix-dont-build-html-doc.diff

diff --git a/gnu/local.mk b/gnu/local.mk
index 3a849ed2b0..28c01a02ca 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1529,6 +1529,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/nettle-3.5-check-_pkcs1_sec_decrypt-msg-len.patch \
   %D%/packages/patches/nettle-3.5-CVE-2021-3580-pt1.patch	\
   %D%/packages/patches/nettle-3.5-CVE-2021-3580-pt2.patch	\
+  %D%/packages/patches/nix-dont-build-html-doc.diff		\
   %D%/packages/patches/nfs4-acl-tools-0.3.7-fixpaths.patch	\
   %D%/packages/patches/ngircd-handle-zombies.patch		\
   %D%/packages/patches/ngless-unliftio.patch		\
diff --git a/gnu/packages/package-management.scm b/gnu/packages/package-management.scm
index 3c9d4da941..f45d09db78 100644
--- a/gnu/packages/package-management.scm
+++ b/gnu/packages/package-management.scm
@@ -19,6 +19,7 @@
 ;;; Copyright © 2020 Vincent Legoll <[email-masked]>
 ;;; Copyright © 2021 Ivan Gankevich <[email-masked]>
 ;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Zhu Zihao <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -60,6 +61,8 @@ (define-module (gnu packages package-management)
   #:use-module (gnu packages dbm)
   #:use-module (gnu packages docbook)
   #:use-module (gnu packages file)
+  #:use-module (gnu packages flex)
+  #:use-module (gnu packages gcc)
   #:use-module (gnu packages gettext)
   #:use-module (gnu packages glib)
   #:use-module (gnu packages gnome)
@@ -68,12 +71,14 @@ (define-module (gnu packages package-management)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages guile-xyz)
+  #:use-module (gnu packages hardware)
   #:use-module (gnu packages hurd)
   #:use-module (gnu packages less)
   #:use-module (gnu packages libedit)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages lisp)
   #:use-module (gnu packages man)
+  #:use-module (gnu packages markup)
   #:use-module (gnu packages nettle)
   #:use-module (gnu packages networking)
   #:use-module (gnu packages ninja)
@@ -596,14 +601,18 @@ (define-public current-guix
 (define-public nix
   (package
     (name "nix")
-    (version "2.3.16")
-    (source (origin
-             (method url-fetch)
-             (uri (string-append "https://releases.nixos.org/nix/nix-"
-                                 version "/nix-" version ".tar.xz"))
-             (sha256
-              (base32
-               "1g5aqavr6i3c1xln53w1pdh1kvlxrpnknb105m4jbd85kyv83rky"))))
+    (version "2.4")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "http://github.com/NixOS/nix")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1abgfw5ndqklm0x533li32l4azifz3f6lhaxm6s74b704043r7m2"))
+       (patches
+        (search-patches "nix-dont-build-html-doc.diff"))))
     (build-system gnu-build-system)
     (arguments
      `(#:configure-flags '("--sysconfdir=/etc" "--enable-gc")
@@ -619,18 +628,36 @@ (define-public nix
                       (string-append "sysconfdir=" etc)
                       (string-append "profiledir=" etc "/profile.d")
                       make-flags)))))))
-    (native-inputs `(("pkg-config" ,pkg-config)))
-    (inputs `(("boost" ,boost)
-              ("brotli" ,brotli)
-              ("bzip2" ,bzip2)
-              ("curl" ,curl)
-              ("editline" ,editline)
-              ("libgc" ,libgc)
-              ("libseccomp" ,libseccomp)
-              ("libsodium" ,libsodium)
-              ("openssl" ,openssl)
-              ("sqlite" ,sqlite)
-              ("xz" ,xz)))
+    (native-inputs
+     `(("autoconf" ,autoconf)
+       ("autoconf-archive" ,autoconf-archive)
+       ("automake" ,automake)
+       ("bison" ,bison)
+       ("flex" ,flex)
+       ("gcc" ,gcc-9)                   ;non-trivial designated initializers
+       ("googletest" ,googletest)
+       ("jq" ,jq)
+       ("libtool" ,libtool)
+       ("pkg-config" ,pkg-config)))
+    (inputs
+     `(("boost" ,boost)
+       ("brotli" ,brotli)
+       ("bzip2" ,bzip2)
+       ("curl" ,curl)
+       ("editline" ,editline)
+       ("libarchive" ,libarchive)
+       ,@(if (string-prefix? "x86_64" (or (%current-target-system)
+                                          (%current-system)))
+             `(("libcpuid" ,libcpuid))
+             '())
+       ("libgc" ,libgc)
+       ("libseccomp" ,libseccomp)
+       ("libsodium" ,libsodium)
+       ("lowdown" ,lowdown)
+       ("openssl" ,openssl)
+       ("sqlite" ,sqlite)
+       ("xz" ,xz)
+       ("zlib" ,zlib)))
     (home-page "https://nixos.org/nix/")
     (synopsis "The Nix package manager")
     (description
diff --git a/gnu/packages/patches/nix-dont-build-html-doc.diff b/gnu/packages/patches/nix-dont-build-html-doc.diff
new file mode 100644
index 0000000000..79142bc215
--- /dev/null
+++ b/gnu/packages/patches/nix-dont-build-html-doc.diff
@@ -0,0 +1,26 @@
+"--enable-doc-gen" configure flag will enable HTML document generation that requires mdbook.
+We can't simply disable it because we need manpages.
+
+Author: Zhu Zihao <[email-masked]>
+
+diff --git a/doc/manual/local.mk b/doc/manual/local.mk
+index e43d9f2fb..c323d1847 100644
+--- a/doc/manual/local.mk
++++ b/doc/manual/local.mk
+@@ -69,8 +69,6 @@ $(d)/builtins.json: $(bindir)/nix
+ 	$(trace-gen) $(dummy-env) NIX_PATH=nix/corepkgs=corepkgs $(bindir)/nix __dump-builtins > $@.tmp
+ 	@mv $@.tmp $@
+ 
+-# Generate the HTML manual.
+-install: $(docdir)/manual/index.html
+ 
+ # Generate 'nix' manpages.
+ install: $(mandir)/man1/nix3-manpages
+@@ -94,7 +92,5 @@ doc/manual/generated/man1/nix3-manpages: $(d)/src/command-ref/new-cli
+ 	done
+ 	@touch $@
+ 
+-$(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/custom.css $(d)/src/SUMMARY.md $(d)/src/command-ref/new-cli $(d)/src/command-ref/conf-file.md $(d)/src/expressions/builtins.md $(call rwildcard, $(d)/src, *.md)
+-	$(trace-gen) RUST_LOG=warn mdbook build doc/manual -d $(DESTDIR)$(docdir)/manual
+ 
+ endif
-- 
2.33.1

-- 
Retrieve my PGP public key:

  gpg --recv-keys D47A9C8B2AE3905B563D9135BE42B352A9F6821F

Zihao