guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proof of Concept: Import Emacs' use-packaged packages into Guix' man


From: Mitchell Schmeisser
Subject: Re: Proof of Concept: Import Emacs' use-packaged packages into Guix' manifest.scm
Date: Thu, 2 Feb 2023 21:31:38 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

Finally, I'm not sure if installing packages from my custom local guix-channel succeeded. I need to retry and investigate more.

This is a quirk with `emacs-guix`. It doesn't seem to use the pulled guix and I'm not sure how to fix that.


On 2/2/23 04:44, Mekeor Melire wrote:
2022-12-27 19:51 mitchellschmeisser@librem.one:

Mekeor Melire <mekeor@posteo.de> writes:

Here is a naive implementation which extends use-package to use guix to ensure packages.

Thank you very much for this great snippet of code. I just successfully set it up locally and I'm very happy.

Would you like to create a public Git repository for this elisp-package so that we can collaborate on it? If you don't have time to do it, I can create a public Git repository (with your copyright note; under GPLv3+?; formally owned by an "organization").

Personally, I'm also very much of a noob in things elisp. But intuitively, I'd suggest these changes:

It is a bit annoying at first because it prompts for y/n verification for every package but I think this behavior is desirable.

Personally, I found that behaviour a little tidyous. I'd suggest to make it at least configurable.

#+BEGIN_SRC emacs-lisp
(require 'guix)
(require 'guix-profiles)
(require 'guix-read)
(require 'guix-ui-package)


(defgroup use-package-guix nil

What do you think about naming this package/feature "use-package-ensure-guix" and using that as a prefix for all other functions and variables -- except for use-package-ensure-guix? I think "use-package-ensure-guix" would be a good package name because it's pretty much the only (important) function which this packages aims to offer. So, …

  "use-package support for guix" :group 'use-package-ensure)

(defcustom use-package-profile (concat (getenv "HOME") "/.emacs.d/guix-profile")

… this variable would then perhaps be renamed into "use-package-ensure-guix-profile" or so.

  "Location of use-package guix profile" :type 'string :group
'use-package-guix)

(defun guix-package-installed-p (package)
  (bui-assoc-value package 'installed))

(defun canonicalize-name (package-name)
  "Make sure package name has \"emacs-\" prefix"
  (if (string-match "^emacs-.+" package-name)
      package-name
    (concat "emacs-" package-name)))

(defun emacs-package->guix-package (package)
  "Return guix package from package name"
  (car (guix-output-list-get-entries use-package-profile 'name
                                     (canonicalize-name                                      package))))

(defun guix-package-id (package)
  (bui-entry-non-void-value package 'id))

(This function could be removed, I think.)

(defun guix-install-package (package)
  (if (guix-package-installed-p package)
      t
    (guix-process-package-actions
     use-package-profile
     `((install (,(string-to-number (car (split-string (bui-entry-id package) ":"))) "out"))))
     (current-buffer)))

(defun guix-installed-packages ()
  (guix-output-list-get-entries use-package-profile 'installed))


(defun use-package-ensure-guix (name args _state &optional _no-refresh)
  (dolist (ensure args)
    (let ((package
           (or (and (eq ensure t)
                    (use-package-as-symbol name))
               ensure)))
      (when package
        (when (consp package)
          (use-package-pin-package (car package) (cdr package))
          (setq package (car package)))

        (let ((package (emacs-package->guix-package (use-package-as-string package))))
          (unless (guix-package-installed-p package)
            (condition-case-unless-debug err
                (progn
                  (when (assoc package (bound-and-true-p
package-pinned-packages))
                    (package-read-all-archive-contents))
                  (if (assoc package package-archive-contents)
                      (package-install package)
                    (package-refresh-contents)
                    (when (assoc package (bound-and-true-p
package-pinned-packages))
                      (package-read-all-archive-contents))
                    (guix-install-package package))
                  t)

What is the purpose of this long (progn …)? Could we instead simply write (guix-install-package package)?


              (error (display-warning 'use-package (format               "Failed to
        install %s: %s" name (error-message-string err))
        :error)))))))))

I'd suggest to miss the "error" label on this message, and rather label it as "warning" (which is the default). We could also suggest to add ":ensure nil" if it's a built-in feature. (E.g. in case of (use-package recentf).)

;;;###autoload
(add-to-list 'load-path (concat use-package-profile "/share/emacs/site-lisp"))

(provide 'use-package-guix)
#+END_SRC

Finally, I'm not sure if installing packages from my custom local guix-channel succeeded. I need to retry and investigate more.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]