Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use pkgs.emacsWithPackagesFromUsePackage to tangle init.el (and put it under ~/.config/emacs) from org config file? #393

Open
NovaViper opened this issue Apr 9, 2024 · 0 comments

Comments

@NovaViper
Copy link

NovaViper commented Apr 9, 2024

Hey, I'm trying to figure out how to use emacsWithPackagesFromUsePackage to create the ~/.config/emacs/init.el file from my config.org file? There isn't much documentation showing how to do this with org files in particular (nor showing how to put the files in ~/.config/emacs
Declaration in Home-Manager

  programs.emacs = {
      enable = true;
      #package = pack;
      #extraPackages = epkgs: with epkgs; [ tramp pdf-tools ];
      package = (pkgs.emacsWithPackagesFromUsePackage {
        #config = ./init.el;
        config = ./config.org;
        alwaysTangle = true;
        package = pack;
        extraEmacsPackages = epkgs: with epkgs; [ tramp ];
      });
  };

config.org file

:DOC-CONFIG:
# Tangle by default to init.el, which is the most common case
#+PROPERTY: header-args:emacs-lisp :tangle init.el
#+PROPERTY: header-args :mkdirp yes :comments no
:END:

#+title: Emacs Configuration

* General Configuration
** Startup Performance
#+begin_src emacs-lisp
  ;; The default is 800 kilobytes.  Measured in bytes.
  (setq gc-cons-threshold (* 50 1000 1000))

  (defun efs/display-startup-time ()
    (message "Emacs loaded in %s with %d garbage collections."
             (format "%.2f seconds"
                     (float-time
                       (time-subtract after-init-time before-init-time)))
             gcs-done))

  (add-hook 'emacs-startup-hook #'efs/display-startup-time)
#+end_src
** Package System Setup
Emacs has a built in package manager but it doesn't make it easy to automatically install packages on a new system the first time you pull down your configuration.  [[https://github.com/jwiegley/use-package][use-package]] is a really helpful package used in this configuration to make it a lot easier to automate the installation and configuration of everything else we use.
#+begin_src emacs-lisp

  ;; Initialize package sources
  (require 'package)

  (setq package-archives '(("melpa" . "https://melpa.org/packages/")
                           ("org" . "https://orgmode.org/elpa/")
                           ("elpa" . "https://elpa.gnu.org/packages/")))

  (package-initialize)
  (unless package-archive-contents
    (package-refresh-contents))

    ;; Initialize use-package on non-Linux platforms
  (unless (package-installed-p 'use-package)
    (package-install 'use-package))

  (require 'use-package)
  (setq use-package-always-ensure t)
#+end_src

** Automatic Package Updates
The auto-package-update package helps us keep our Emacs packages up to date!  It will prompt you after a certain number of days either at startup or at a specific time of day to remind you to update your packages.
You can also use =M-x auto-package-update-now= to update right now!

#+begin_src emacs-lisp
  (use-package auto-package-update
    :custom
    (auto-package-update-interval 7)
    (auto-package-update-prompt-before-update t)
    (auto-package-update-hide-results t)
    :config
    (auto-package-update-maybe)
    (auto-package-update-at-time "09:00"))
#+end_src

** Directory Variables
Declares paths for various functions
#+begin_src emacs-lisp
(setq mail_directory "~/.local/share")
#+end_src

Edit: Added additional context
When I add in defaultInitFile = true;, I get this error here

default.el> building '/nix/store/rwflh65434aqzankqk46g1ak84h2lx3c-default.el.drv'
default.el> Tangled 5 code blocks from config.org
default.el> mv: cannot stat 'config.el': No such file or directory
error: builder for '/nix/store/rwflh65434aqzankqk46g1ak84h2lx3c-default.el.drv' failed with exit code 1;
       last 2 log lines:
       > Tangled 5 code blocks from config.org
       > mv: cannot stat 'config.el': No such file or directory
       For full logs, run 'nix log /nix/store/rwflh65434aqzankqk46g1ak84h2lx3c-default.el.drv'.
error: 1 dependencies of derivation '/nix/store/l2dg0lgij8006xjlbkhzdnfv8fycy2nj-emacs-default-0.1.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/nlkxhr4g3sv003d7pxylnig1sp9vf0jx-emacs-pgtk-with-packages-29.3.drv' failed to build
error: 1 dependencies of derivation '/nix/store/p9wliri19ilcqd98pvl4i78a7a2qqfvh-emacs-pgtk-with-packages-with-packages-29.3.drv' failed to build
error: 1 dependencies of derivation '/nix/store/y941070jfi6xj72yqx2aim1zhzc81mqy-emacs.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/i66al4acwvd8qjzv4d9xgp2cl3zsc9ir-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/rx6640gzhb8ikqfyipd8qp73xgcx5s2w-home-manager-generation.drv' failed to build
┏━ 1 Errors:
┃ error: builder for '/nix/store/rwflh65434aqzankqk46g1ak84h2lx3c-default.el.drv' failed with exit code 1;
┃        last 2 log lines:
┃        > Tangled 5 code blocks from config.org
┃        > mv: cannot stat 'config.el': No such file or directory
┃        For full logs, run 'nix log /nix/store/rwflh65434aqzankqk46g1ak84h2lx3c-default.el.drv'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant