jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.4k stars 260 forks source link

Packages are always being re-installed on every start #1045

Closed TLINDEN closed 1 year ago

TLINDEN commented 1 year ago

I'm trying to switch to use-package and package.el, but it fails miserably for now. When I have :ensure enabled anywhere (or globally), packages are being re-installed every time I start emacs.

Here's the relevant part of my config:

(require 'package)
(add-to-list 'package-archives '("gnu"   . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

(setq package-enable-at-startup nil)

(unless (package-installed-p 'use-package)
  (package-install 'use-package))
(eval-and-compile
  (setq use-package-always-ensure t
        use-package-expand-minimally t))

(use-package persistent-scratch
             :config
             (setq persistent-scratch-save-file (expand-file-name "scratches.el" user-emacs-directory))
             (persistent-scratch-setup-default)

             (setq persistent-scratch-scratch-buffer-p-function 'tvd-autoscratch-p))

This is being logged (every time I start emacs):

Generating autoloads for persistent-scratch.el...done
  INFO     Scraping files for persistent-scratch-autoloads.el...done
Wrote /home/scip/.emacs-init.d/elpa-27.1/persistent-scratch-20230225.1439/persistent-scratch-autoloads.el
Checking /home/scip/.emacs-init.d/elpa-27.1/persistent-scratch-20230225.1439... [3 times]
Compiling /home/scip/.emacs-init.d/elpa-27.1/persistent-scratch-20230225.1439/persistent-scratch.el...done
Wrote /home/scip/.emacs-init.d/elpa-27.1/persistent-scratch-20230225.1439/persistent-scratch.elc
Checking /home/scip/.emacs-init.d/elpa-27.1/persistent-scratch-20230225.1439...
Done (Total of 1 file compiled, 2 skipped)

And the files in the folder elpa/persistent-scratch-20230225.1439/ are indeed being overwritten each time.

What's also interesting, after everyting has been loaded, I can use the mode default-text-scale but package.el seems to think it's not being installed:

ELISP> (package-desc-p 'default-text-scale)
nil
;; but:
ELISP> (package-installed-p 'default-text-scale)
t

So, how can I disable this behavior? What I want is, that a package is being installed if it is not currently being installed, but otherwise kept as is. I want to update myself manually.

TLINDEN commented 1 year ago

I solved it myself.

I had a custom package-user-dir set before executing (package-initialize) (not shown in the config snippet above). So, package.el looked into the default directory for packages - which is empty - and installed every package.

Putting (package-initialize) after the customization fixed it, that is:

(require 'package)

;; needs to be set before init
(setq package-user-dir
      (expand-file-name (format "elpa-%s.%s" emacs-major-version emacs-minor-version)
                        tvd-config-dir))

(add-to-list 'package-archives '("gnu"   . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

(package-initialize)

So, this had noting to do with use-package, which works as expected.