Hello Guix,

There was several discussions about adding file-system utils packages to
the system profile based on the types in the “file-systems” field.

I tried implementing this in the attached patch but I'm currently stuck and need some help. I've probably overlooked something basic but I can;t put a
finger on it... Guix compile successfully with the patch and testing
“file-system-utils” in “guix repl” returns a list of packages as expected.
But when I try building a system/vm the packages aren't added to the
system's profile as I expected. From what I understand, that function as
used in “file-system-service-type” should get as arguments the list of
file-systems defined in the operating-system and should return a list of
packages, themselves appended to the system's profile list of packages.

Halp! What am I missing?

I also welcome any suggestion UI wise, currently the only change is the
additions of the “utils?” filed in the “file-system” record.

- Brice
From 57a6dc8c6ba2fb2b5ce97bffa26d61a430d2c16b Mon Sep 17 00:00:00 2001
From: Brice Waegeneire <br...@waegenei.re>
Date: Mon, 6 Apr 2020 18:00:11 +0200
Subject: [PATCH] services: Add file-system utils to profile.

---
 gnu/services/base.scm       | 42 +++++++++++++++++++++++++++++++++++--
 gnu/system/file-systems.scm |  6 +++++-
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 070765ab83..16519b5a7b 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -44,13 +44,20 @@
                 #:select (file-system-packages))
   #:use-module (gnu packages admin)
   #:use-module ((gnu packages linux)
-                #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools))
+                #:select (alsa-utils btrfs-progs crda eudev eudev/btrfs-fix
+                          e2fsprogs f2fs-tools fuse gpm kbd lvm2 rng-tools
+                          util-linux xfsprogs))
   #:use-module (gnu packages bash)
   #:use-module ((gnu packages base)
                 #:select (canonical-package coreutils glibc glibc-utf8-locales))
   #:use-module (gnu packages package-management)
   #:use-module ((gnu packages gnupg) #:select (guile-gcrypt))
-  #:use-module (gnu packages linux)
+  #:use-module ((gnu packages disk)
+                #:select (dosfstools))
+  #:use-module ((gnu packages file-systems)
+                #:select (bcachefs-tools jfsutils zfs))
+  #:use-module ((gnu packages mtools)
+                #:select (exfat-utils))
   #:use-module (gnu packages terminals)
   #:use-module ((gnu build file-systems)
                 #:select (mount-flags->bit-mask))
@@ -59,8 +66,10 @@
   #:use-module (guix modules)
   #:use-module ((guix self) #:select (make-config.scm))
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-2)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
   #:use-module (ice-9 format)
   #:export (fstab-service-type
             root-file-system-service
@@ -535,6 +544,33 @@ FILE-SYSTEM."
                 (memq 'bind-mount (file-system-flags file-system))))
           file-systems))
 
+(define (file-system-type->utils type)
+  "Return a utils package for file system TYPE."
+  (define pattern->utils
+    `(("ext[234]" . ,e2fsprogs)
+      ("btrfs" . ,btrfs-progs)
+      ("jfs" . ,jfsutils)
+      ("exfat" . ,exfat-utils)
+      ("bachefs" . ,bcachefs-tools)
+      ("xfs" . ,xfsprogs)
+      ("fat" . ,dosfstools)
+      ("f2fs" . ,f2fs-tools)
+      ("zfs" . ,zfs)))
+  (and-let* ((utils
+              (find (lambda (a) (string-match (car a) type)) pattern->utils)))
+    (cdr utils)))
+
+(define (file-system-utils file-systems)
+  "Return the list of file-system utils packages for FILE-SYSTEMS"
+  (fold (lambda (file-system prev)
+          (let ((utils? (file-system-utils? file-system))
+                (utils (file-system-type->utils (file-system-type file-system))))
+            (if (and utils? utils
+                     (not (member utils prev)))
+                (cons* utils prev)
+                prev)))
+        '() file-systems))
+
 (define file-system-service-type
   (service-type (name 'file-systems)
                 (extensions
@@ -542,6 +578,8 @@ FILE-SYSTEM."
                                           file-system-shepherd-services)
                        (service-extension fstab-service-type
                                           file-system-fstab-entries)
+                       (service-extension profile-service-type
+                                          file-system-utils)
 
                        ;; Have 'user-processes' depend on 'file-systems'.
                        (service-extension user-processes-service-type
diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm
index 3b599efa8e..9bc1687696 100644
--- a/gnu/system/file-systems.scm
+++ b/gnu/system/file-systems.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <l...@gnu.org>
+;;; Copyright © 2020 Brice Waegeneire <br...@waegenei.re>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -42,6 +43,7 @@
             file-system-create-mount-point?
             file-system-dependencies
             file-system-location
+            file-system-utils?
 
             file-system-type-predicate
 
@@ -111,7 +113,9 @@
                     (default '()))                ; or <mapped-device>
   (location         file-system-location
                     (default (current-source-location))
-                    (innate)))
+                    (innate))
+  (utils?           file-system-utils?            ; Boolean
+                    (default #t)))
 
 ;; A file system label for use in the 'device' field.
 (define-record-type <file-system-label>
-- 
2.26.0

Reply via email to