From 7b073643e1e9b4970cf309d201c092cccff375ab Mon Sep 17 00:00:00 2001 From: AAaronson Date: Mon, 26 Apr 2021 10:56:29 +0000 Subject: [PATCH 1/7] nongnu: installation-os-nonfree: Add prefilled channels.scm to install image. Remove requirement to define 'nonguix channel on build system. * nongnu/system/install.scm (installation-os-nonfree): Add channels.scm to skeletons %channels (%channels, %channels-file) (inferior-channel, linux, linux-firmware ): Add variables. --- nongnu/system/install.scm | 64 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/nongnu/system/install.scm b/nongnu/system/install.scm index 275bcaa..3f87076 100644 --- a/nongnu/system/install.scm +++ b/nongnu/system/install.scm @@ -20,13 +20,73 @@ (define-module (nongnu system install) #:use-module (gnu system) #:use-module (gnu system install) - #:use-module (nongnu packages linux) + #:use-module (guix channels) + #:use-module (guix ci) + #:use-module (guix gexp) + #:use-module (guix inferior) + #:use-module (ice-9 pretty-print) #:export (installation-os-nonfree)) +; List of guix channels. Used in both inferior-channel and the +; "/etc/skel/.config/guix/channels.scm" definitions. +; %default-guix-channel is configured to pull package definitions from +; the Guix substitute server, to save compiling during a guix pull. +(define %channels + '(list (channel + (name 'nonguix) + (url "https://gitlab.com/nonguix/nonguix") + (introduction + (make-channel-introduction + "897c1a470da759236cc11798f4e0a5f7d4d59fbc" + (openpgp-fingerprint + "2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))) + (channel-with-substitutes-available + %default-guix-channel + "https://ci.guix.gnu.org"))) + +; Create the plain-file definition of "channels.scm" to add to the install. +(define %channels-file + (let ((port (open-output-string))) + (pretty-print '(use-modules + (guix ci)) ; for channel-with-substitutes-availabe + port) + (pretty-print %channels + port) + (plain-file "channels.scm" + (get-output-string port)))) + +; inferior-for-channels allows for looking up packages WITHOUT a channel +; definition in place. Requires the 'guix channel as well so reuse of the +; %channels definition is done with eval. +(define inferior-channel + (inferior-for-channels + (eval %channels + (current-dynamic-state)))) + +(define linux ; latest linux package from inferior-channel + (car (lookup-inferior-packages inferior-channel + "linux"))) + +(define linux-firmware ; latest linux-firmware package from inferior-channel + (car (lookup-inferior-packages inferior-channel + "linux-firmware"))) + +; Currently the best way to add the "channels.scm" file to the install is via +; the skeletons record type. +; The following service definition for the global channel file is also viable: +; (service special-files-service-type +; `(("/etc/guix/channels.scm" ,%channel-file))) +; However even when using (operating-system-services installation-os) without +; modifying it, a "more than one target service of type 'account" error occurs. (define installation-os-nonfree (operating-system (inherit installation-os) (kernel linux) - (firmware (list linux-firmware)))) + (firmware (list linux-firmware)) + (skeletons + (cons ; add "channels.scm" to the "~/.config/guix" folder + `(".config" ,(file-union "guix" + `(("guix/channels.scm" ,%channels-file)))) + (operating-system-skeletons installation-os))))) installation-os-nonfree From 578731166cc47ac51a7e05754ec0e1ae5f73f1f5 Mon Sep 17 00:00:00 2001 From: AAaronson Date: Wed, 28 Apr 2021 09:44:52 +0000 Subject: [PATCH 2/7] nongnu: Append to copyright * nongnu/system/install.scm (%channels): Fix indentation spacing --- nongnu/system/install.scm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nongnu/system/install.scm b/nongnu/system/install.scm index 3f87076..97c81db 100644 --- a/nongnu/system/install.scm +++ b/nongnu/system/install.scm @@ -1,5 +1,6 @@ ;;; Copyright © 2019 Alex Griffin ;;; Copyright © 2019 Pierre Neidhardt +;;; Copyright © 2021 Kyle Cassidy <123_kbc@pm.me> ;;; ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by @@ -36,10 +37,10 @@ (name 'nonguix) (url "https://gitlab.com/nonguix/nonguix") (introduction - (make-channel-introduction - "897c1a470da759236cc11798f4e0a5f7d4d59fbc" - (openpgp-fingerprint - "2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))) + (make-channel-introduction + "897c1a470da759236cc11798f4e0a5f7d4d59fbc" + (openpgp-fingerprint + "2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))) (channel-with-substitutes-available %default-guix-channel "https://ci.guix.gnu.org"))) From 3078c10168eb2edcf290fd029a4f11e3008d7972 Mon Sep 17 00:00:00 2001 From: AAaronson <6002905-Abcdefp@users.noreply.gitlab.com> Date: Tue, 4 May 2021 09:49:29 +0000 Subject: [PATCH 3/7] nongnu: Create build script for iso images. Remove inferior packages from install.scm * nongnu/system/build-image.scm Add functions to build iso image * nongnu/system/install.scm (inferior-channel, linux, linux-firmware ) Remove definitions --- nongnu/system/build-image.scm | 91 +++++++++++++++++++++++++++++++++++ nongnu/system/install.scm | 24 ++------- 2 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 nongnu/system/build-image.scm diff --git a/nongnu/system/build-image.scm b/nongnu/system/build-image.scm new file mode 100644 index 0000000..493ccda --- /dev/null +++ b/nongnu/system/build-image.scm @@ -0,0 +1,91 @@ +#!/usr/bin/env -S guile \\ +-e build-image -s +!# ;; Guile uses a meta switch '\' which env requires escaping to passthru. +;; See: https://pingus.seul.org/~grumbel/tmp/guile-1.6.0/guile_10.html#SEC27 + +;;; Copyright © 2021 Kyle Cassidy <123_kbc@pm.me> +;;; +;;; This program 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. +;;; +;;; This program 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 this program. If not, see . + +;; Generate a bootable image with: +;; $ ./nongnu/system/build-image.scm + +; Searches through Scheme file for 'define and 'define* expressions +; such as (define ... ) or (define ( ...) ...) +(define (search-for-define scheme-file define-name) + (call-with-input-file scheme-file + (lambda (port) + (let next ((exp (read port))) + (cond ((eof-object? exp) #f) + ((and (list? exp) + (or (equal? 'define (car exp)) + (equal? 'define* (car exp))) + (if (list? (cadr exp)) + (equal? define-name (caadr exp)) + (equal? define-name (cadr exp)))) + exp) + (#t (next (read port)))))))) + +; Writes channel-list to a tmpfile defined by (tmpnam) +(define (make-tmp-channel channel-list) + (let ((tmpath (tmpnam))) + (call-with-output-file tmpath + (lambda (port) + (write '(use-modules (guix ci)) port) + (write channel-list port))) + tmpath)) + +; Main function called when run at command line. +; Parses "nongnu/system/install.scm" for channel definition +; Creates tmpfile containing channel definition +; Performs a guix pull using tmpfile as channel file +; Deletes tmpfile file +; Builds image (currently iso only) +; supportes "--uncompress" command line argument +; If "--roll-back" is used as an argument, reverts guix pull +; Returns #t if exit-code of build is 0, else returns #f +(define (build-image . args) + (let* ((image-type 'iso) ; todo: parse args for supported image types + (image-label "guix-nonfree-install") + (channel-define-name '%channels) + (config-dir (dirname (current-filename))) + (config-file-name "install.scm") + (install-config (string-append config-dir + file-name-separator-string + config-file-name)) + (channels (caddr (search-for-define + install-config + channel-define-name))) + (tmp-channel-file-path (make-tmp-channel (cadr channels))) + (exit-code #f)) + (system* "guix" "pull" (string-append "--channels=" tmp-channel-file-path)) + (delete-file tmp-channel-file-path) + (cond ((equal? image-type 'iso) + (let ((image-link (string-append config-dir + file-name-separator-string + image-label + ".iso"))) + (set! exit-code + (system* "guix" + "system" + "image" + (if (member "--uncompress" args) + "--image-type=uncompressed-iso9660" + "--image-type=iso9660") ; remove once image types supported + (string-append "--label=" image-label) + (string-append "--root=" image-link) + install-config))))) + (and (member "--roll-back" args) + (system* "guix" "pull" "--roll-back")) + (equal? exit-code 0))) diff --git a/nongnu/system/install.scm b/nongnu/system/install.scm index 97c81db..a64d190 100644 --- a/nongnu/system/install.scm +++ b/nongnu/system/install.scm @@ -21,15 +21,13 @@ (define-module (nongnu system install) #:use-module (gnu system) #:use-module (gnu system install) - #:use-module (guix channels) + #:use-module (nongnu packages linux) #:use-module (guix ci) #:use-module (guix gexp) - #:use-module (guix inferior) #:use-module (ice-9 pretty-print) #:export (installation-os-nonfree)) -; List of guix channels. Used in both inferior-channel and the -; "/etc/skel/.config/guix/channels.scm" definitions. +; List of guix channels for the "/etc/skel/.config/guix/channels.scm" file. ; %default-guix-channel is configured to pull package definitions from ; the Guix substitute server, to save compiling during a guix pull. (define %channels @@ -56,22 +54,6 @@ (plain-file "channels.scm" (get-output-string port)))) -; inferior-for-channels allows for looking up packages WITHOUT a channel -; definition in place. Requires the 'guix channel as well so reuse of the -; %channels definition is done with eval. -(define inferior-channel - (inferior-for-channels - (eval %channels - (current-dynamic-state)))) - -(define linux ; latest linux package from inferior-channel - (car (lookup-inferior-packages inferior-channel - "linux"))) - -(define linux-firmware ; latest linux-firmware package from inferior-channel - (car (lookup-inferior-packages inferior-channel - "linux-firmware"))) - ; Currently the best way to add the "channels.scm" file to the install is via ; the skeletons record type. ; The following service definition for the global channel file is also viable: @@ -85,7 +67,7 @@ (kernel linux) (firmware (list linux-firmware)) (skeletons - (cons ; add "channels.scm" to the "~/.config/guix" folder + (cons ; adds "channels.scm" to "/etc/skel/.config/guix/" `(".config" ,(file-union "guix" `(("guix/channels.scm" ,%channels-file)))) (operating-system-skeletons installation-os))))) From 3a9213e4e664605c5e28642f354abcc1480e18f4 Mon Sep 17 00:00:00 2001 From: AAaronson <6002905-Abcdefp@users.noreply.gitlab.com> Date: Tue, 4 May 2021 10:07:27 +0000 Subject: [PATCH 4/7] Fix typos --- nongnu/system/build-image.scm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nongnu/system/build-image.scm b/nongnu/system/build-image.scm index 493ccda..ee55ec2 100644 --- a/nongnu/system/build-image.scm +++ b/nongnu/system/build-image.scm @@ -50,11 +50,11 @@ ; Parses "nongnu/system/install.scm" for channel definition ; Creates tmpfile containing channel definition ; Performs a guix pull using tmpfile as channel file -; Deletes tmpfile file +; Deletes tmpfile ; Builds image (currently iso only) -; supportes "--uncompress" command line argument +; supports "--uncompressed" command line argument ; If "--roll-back" is used as an argument, reverts guix pull -; Returns #t if exit-code of build is 0, else returns #f +; Returns #t if exit-code is 0, else returns #f (define (build-image . args) (let* ((image-type 'iso) ; todo: parse args for supported image types (image-label "guix-nonfree-install") @@ -80,7 +80,7 @@ (system* "guix" "system" "image" - (if (member "--uncompress" args) + (if (member "--uncompressed" args) "--image-type=uncompressed-iso9660" "--image-type=iso9660") ; remove once image types supported (string-append "--label=" image-label) From 389e355f91537a2deda69dbf128dc98fd10a99d7 Mon Sep 17 00:00:00 2001 From: AAaronson <6002905-Abcdefp@users.noreply.gitlab.com> Date: Tue, 4 May 2021 10:27:00 +0000 Subject: [PATCH 5/7] Added two additional comments for clarity --- nongnu/system/build-image.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nongnu/system/build-image.scm b/nongnu/system/build-image.scm index ee55ec2..3e4b9e5 100644 --- a/nongnu/system/build-image.scm +++ b/nongnu/system/build-image.scm @@ -38,6 +38,7 @@ (#t (next (read port)))))))) ; Writes channel-list to a tmpfile defined by (tmpnam) +; 'use-module is assumed to be needed, does not do anything if not used. TODO: remove assumption. (define (make-tmp-channel channel-list) (let ((tmpath (tmpnam))) (call-with-output-file tmpath @@ -48,6 +49,7 @@ ; Main function called when run at command line. ; Parses "nongnu/system/install.scm" for channel definition +; (current-filename) used to locate in same dir as this file ; Creates tmpfile containing channel definition ; Performs a guix pull using tmpfile as channel file ; Deletes tmpfile @@ -57,7 +59,7 @@ ; Returns #t if exit-code is 0, else returns #f (define (build-image . args) (let* ((image-type 'iso) ; todo: parse args for supported image types - (image-label "guix-nonfree-install") + (image-label "nonguix-install") (channel-define-name '%channels) (config-dir (dirname (current-filename))) (config-file-name "install.scm") From 12d6628ba30bd85845588e87a92af60ff714d5fa Mon Sep 17 00:00:00 2001 From: AAaronson <6002905-Abcdefp@users.noreply.gitlab.com> Date: Tue, 4 May 2021 12:04:13 +0000 Subject: [PATCH 6/7] Replace use of depreciated function 'tmpnam. Fix command line argument nesting. Update comment for usage at comment line. --- nongnu/system/build-image.scm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/nongnu/system/build-image.scm b/nongnu/system/build-image.scm index 3e4b9e5..541ea0b 100644 --- a/nongnu/system/build-image.scm +++ b/nongnu/system/build-image.scm @@ -19,7 +19,7 @@ ;;; along with this program. If not, see . ;; Generate a bootable image with: -;; $ ./nongnu/system/build-image.scm +;; $ chmod +x build-image.scm && ./build-image.scm ; Searches through Scheme file for 'define and 'define* expressions ; such as (define ... ) or (define ( ...) ...) @@ -37,15 +37,20 @@ exp) (#t (next (read port)))))))) -; Writes channel-list to a tmpfile defined by (tmpnam) +; Writes channel-list to a tmpfile ; 'use-module is assumed to be needed, does not do anything if not used. TODO: remove assumption. +; TODO: get mkstemp! to work (result of using it was a blank file) (define (make-tmp-channel channel-list) - (let ((tmpath (tmpnam))) - (call-with-output-file tmpath - (lambda (port) - (write '(use-modules (guix ci)) port) - (write channel-list port))) - tmpath)) + (let loop ((tmpath (string-append "/tmp/guix-channel" + (number->string (random 1000000))))) + (cond ((file-exists? tmpath) + (loop (string-append "/tmp/guix-channel" + (number->string (random 1000000))))) + (#t (call-with-output-file tmpath + (lambda (port) + (write '(use-modules (guix ci)) port) + (write channel-list port))) + tmpath)))) ; Main function called when run at command line. ; Parses "nongnu/system/install.scm" for channel definition @@ -54,10 +59,10 @@ ; Performs a guix pull using tmpfile as channel file ; Deletes tmpfile ; Builds image (currently iso only) -; supports "--uncompressed" command line argument +; supports "--uncompressed" command line argument ; If "--roll-back" is used as an argument, reverts guix pull ; Returns #t if exit-code is 0, else returns #f -(define (build-image . args) +(define (build-image args) (let* ((image-type 'iso) ; todo: parse args for supported image types (image-label "nonguix-install") (channel-define-name '%channels) From f9227ab655faa364595dee3b5293a48dfedb7f6b Mon Sep 17 00:00:00 2001 From: AAaronson <6002905-Abcdefp@users.noreply.gitlab.com> Date: Tue, 4 May 2021 15:09:56 +0000 Subject: [PATCH 7/7] * nongnu/system/install.scm Refactored %channels-file creation to make build-image cleaner. * nongnu/system/build-image.scm Refactored make-tmp-channel to use mkstemp! and improved %channels-file. Improved readability of build-image function. --- nongnu/system/build-image.scm | 50 +++++++++++++++++------------------ nongnu/system/install.scm | 34 +++++++++++------------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/nongnu/system/build-image.scm b/nongnu/system/build-image.scm index 541ea0b..e18c8da 100644 --- a/nongnu/system/build-image.scm +++ b/nongnu/system/build-image.scm @@ -1,7 +1,9 @@ + #!/usr/bin/env -S guile \\ -e build-image -s -!# ;; Guile uses a meta switch '\' which env requires escaping to passthru. -;; See: https://pingus.seul.org/~grumbel/tmp/guile-1.6.0/guile_10.html#SEC27 +!# +; Guile uses a meta switch '\' which env requires escaping to passthru. +; See: https://pingus.seul.org/~grumbel/tmp/guile-1.6.0/guile_10.html#SEC27 ;;; Copyright © 2021 Kyle Cassidy <123_kbc@pm.me> ;;; @@ -21,6 +23,8 @@ ;; Generate a bootable image with: ;; $ chmod +x build-image.scm && ./build-image.scm +(use-modules (ice-9 pretty-print)) + ; Searches through Scheme file for 'define and 'define* expressions ; such as (define ... ) or (define ( ...) ...) (define (search-for-define scheme-file define-name) @@ -37,47 +41,41 @@ exp) (#t (next (read port)))))))) -; Writes channel-list to a tmpfile -; 'use-module is assumed to be needed, does not do anything if not used. TODO: remove assumption. -; TODO: get mkstemp! to work (result of using it was a blank file) -(define (make-tmp-channel channel-list) - (let loop ((tmpath (string-append "/tmp/guix-channel" - (number->string (random 1000000))))) - (cond ((file-exists? tmpath) - (loop (string-append "/tmp/guix-channel" - (number->string (random 1000000))))) - (#t (call-with-output-file tmpath - (lambda (port) - (write '(use-modules (guix ci)) port) - (write channel-list port))) - tmpath)))) +; Writes channel-list to a temp file +(define (make-temp-channel channel-list) + (let ((port (mkstemp! (string-copy "/tmp/guix-channel-XXXXXX") "a"))) + (map (lambda (_) (pretty-print _ port)) + channel-list) + (force-output port) + (port-filename port))) ; Main function called when run at command line. ; Parses "nongnu/system/install.scm" for channel definition ; (current-filename) used to locate in same dir as this file -; Creates tmpfile containing channel definition -; Performs a guix pull using tmpfile as channel file -; Deletes tmpfile +; Creates a temp file containing channel definition +; Performs a guix pull using temp file as channel file +; Deletes temp file ; Builds image (currently iso only) ; supports "--uncompressed" command line argument ; If "--roll-back" is used as an argument, reverts guix pull ; Returns #t if exit-code is 0, else returns #f (define (build-image args) - (let* ((image-type 'iso) ; todo: parse args for supported image types + (let* ((image-type 'iso) ; TODO: parse args for supported image types (image-label "nonguix-install") - (channel-define-name '%channels) (config-dir (dirname (current-filename))) (config-file-name "install.scm") (install-config (string-append config-dir file-name-separator-string config-file-name)) + (name-to-search 'nonguix-channels) ; lookup in install-config (channels (caddr (search-for-define install-config - channel-define-name))) - (tmp-channel-file-path (make-tmp-channel (cadr channels))) + name-to-search))) + (temp-channel-file-path (make-temp-channel (cadr channels))) (exit-code #f)) - (system* "guix" "pull" (string-append "--channels=" tmp-channel-file-path)) - (delete-file tmp-channel-file-path) + (system* "guix" "pull" (string-append "--channels=" temp-channel-file-path)) + (delete-file temp-channel-file-path) + (cond ((equal? image-type 'iso) (let ((image-link (string-append config-dir file-name-separator-string @@ -93,6 +91,8 @@ (string-append "--label=" image-label) (string-append "--root=" image-link) install-config))))) + (and (member "--roll-back" args) (system* "guix" "pull" "--roll-back")) + (equal? exit-code 0))) diff --git a/nongnu/system/install.scm b/nongnu/system/install.scm index a64d190..8542c27 100644 --- a/nongnu/system/install.scm +++ b/nongnu/system/install.scm @@ -27,30 +27,28 @@ #:use-module (ice-9 pretty-print) #:export (installation-os-nonfree)) -; List of guix channels for the "/etc/skel/.config/guix/channels.scm" file. +; Guix channel for the "/etc/skel/.config/guix/channels.scm" file. ; %default-guix-channel is configured to pull package definitions from ; the Guix substitute server, to save compiling during a guix pull. -(define %channels - '(list (channel - (name 'nonguix) - (url "https://gitlab.com/nonguix/nonguix") - (introduction - (make-channel-introduction - "897c1a470da759236cc11798f4e0a5f7d4d59fbc" - (openpgp-fingerprint - "2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))) - (channel-with-substitutes-available - %default-guix-channel - "https://ci.guix.gnu.org"))) +(define nonguix-channels + '((use-modules (guix ci)) ; required for channel-with-substitutes-available + (list (channel + (name 'nonguix) + (url "https://gitlab.com/nonguix/nonguix") + (introduction + (make-channel-introduction + "897c1a470da759236cc11798f4e0a5f7d4d59fbc" + (openpgp-fingerprint + "2A39 3FFF 68F4 EF7A 3D29 12AF 6F51 20A0 22FB B2D5")))) + (channel-with-substitutes-available + %default-guix-channel + "https://ci.guix.gnu.org")))) ; Create the plain-file definition of "channels.scm" to add to the install. (define %channels-file (let ((port (open-output-string))) - (pretty-print '(use-modules - (guix ci)) ; for channel-with-substitutes-availabe - port) - (pretty-print %channels - port) + (map (lambda (_) (pretty-print _ port)) + nonguix-channels) (plain-file "channels.scm" (get-output-string port))))