diff --git a/README.org b/README.org index 64f0bc1..5430b5f 100644 --- a/README.org +++ b/README.org @@ -19,35 +19,110 @@ Portable [[https://gnu.org/software/emacs][GNU/Emacs]][fn:1] dotfiles. Built for + 100% Immutable + 100% Reproducible -* Init +* Options + +All of the options available for configuration are defined here. They may be overriden in a host configuration, and are read by the definitions in the modules. All of the variables are prefixed with ~dotfiles/~ to avoid name collision with other functions and packages. -This project makes heavy use of modern features and libraries. Since [[https://orgmode.org/worg/org-contrib/babel/intro.html][Org-babel]][fn:2]'s used during the initialization, [[https://orgmode.org][Org-mode]][fn:3] must load prior to importing any custom modules. My solution includes the introduction of some early intitialization code written in [[https://gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]][fn:4]. +** Modules definitions + +All of the available modules are defined in ~dotfiles/modules-p~. The variable is constant, meaning it cannot be modified. Each time a new module is added, it must be included in this list. #+begin_src emacs-lisp -(load-file "~/.emacs.d/bin/options.el") -(load-file "~/.emacs.d/bin/cleanup.el") -(load-file "~/.emacs.d/bin/packages.el") +(defconst dotfiles/modules-p + '(core + editor + shell + email + terminal + encryption + desktop + writing + presentations + website + capture + projects + development + interface + dashboard) + "All of the available modules.") #+end_src -** Load host definition +After the host configuration has loaded, the modules defined in ~dotfiles/modules~ are loaded sequentially. By default, the value of ~dotfiles/modules~ is equal to ~dotfiles/modules-p~. This means that all of the modules will load by default. Remove symbols from this list in a host configuration, or override it entirely to modify this behaviour. -Begin the process by loading any host specific option overrides. The host configuration tangles, and loads (if it exist) using the systems name. If a host definition doesn't exist the default values remain. +#+begin_src emacs-lisp +(defvar dotfiles/modules dotfiles/modules-p + "All of the enable modules, default value equal to `dotfiles/modules-p'.") +#+end_src + +** Environment variables + +Some of the behaviour in Emacs depends on the values of mutable environment variables. To reduce confusion in my own configuration, the values are read when Emacs starts, and then written to once the configuration has loaded. This allows the values to be overriden in a host configuration, without modifying the environment variable prior to starting. #+begin_src emacs-lisp -(let ((host-file (concat dotfiles/home "/hosts/" system-name ".org"))) - (when (file-exists-p host-file) - (org-babel-load-file host-file))) +(defvar dotfiles/browser (getenv "BROWSER") + "Default system web browser.") + +(defvar dotfiles/language (getenv "LANG") + "Default system dictionary language.") #+end_src -** Load enabled modules +** Look and feel -All of the modules in ~dotfiles/modules~ load after the host overrides. By default, all of the packages defined in ~dotfiles/modules-p~ load. Override this behaviour in a host configuration file. +Define the options for the unified system font. The default is =Fira Code= due to its readability and support for ligatures. All font faces will be set with this value. Any variations to the font sizes are based on the value defined here as well, reducing the number of places to make modifications to when changing fonts. #+begin_src emacs-lisp -(dolist (m dotfiles/modules) - (let ((mod-file (concat dotfiles/home "/modules/" (symbol-name m) ".org"))) - (when (file-exists-p mod-file) - (org-babel-load-file mod-file)))) +(defvar dotfiles/font "Fira Code" + "Unified system font family.") + +(defvar dotfiles/font-size 96 + "Unified system font size.") +#+end_src + +Certain actions like code completions, or binding suggestions, can be configured to wait for a specific delay before offering their respective choices. I prefer to keep this value low, so that suggestions are shown immediately. This can have an affect on the performance of Emacs on older hardware. Adjust accordingly. + +#+begin_src emacs-lisp +(defvar dotfiles/idle 0.0 + "Delay time before offering suggestions and completions.") +#+end_src + +Prefix all of the custom keybinding actions with =SPC=, a tehcnique that comes from Doom / Spacemacs. In some situations, namely when using the [[file:modules/desktop.org][Desktop]] module, the leader key may not always be available. The global prefix should be used in these circumstances. + +#+begin_src emacs-lisp +(defvar dotfiles/leader-key "SPC" + "The all-powerful leader key.") + +(defvar dotfiles/leader-key-global + (concat "C-" dotfiles/leader-key) + "Global prefix for the all-powerful leader key.") +#+end_src + +** Productivity + +The location of source code projects for indexing in the [[file:modules/projects.org][Projects]] module are defined here. These projects will integrate their TODOs with the local Agenda. Override this setting in a host configuration, with the =DOTFILES_PROJECTS= environment variable, or use the default value of =~/.local/source/= in compliance with the XDG Base Directory specification. + +#+begin_src emacs-lisp +(defvar dotfiles/projects + (or (getenv "DOTFILES_PROJECTS") + (expand-file-name "~/.local/source")) + "Location of source code projects.") +#+end_src + +** Security + +The local password store should be cloned prior to initialization. Override this setting in a host configuration, with the =DOTFILES_PASSWORDS= environment variable, or use the default value of =~/.password-store=, which is what GNU pass will assume. + +#+begin_src emacs-lisp +(defvar dotfiles/passwords + (or (getenv "DOTFILES_PASSWORDS") + (expand-file-name "~/.password-store")) + "Location of the local password store.") +#+end_src + +Since I keep all of my writing in this repository, I encrypt *most* of my Org files with GPG. Define the key to encrypt them for / to. Override this in a host configuration file. + +#+begin_src emacs-lisp +(defvar dotfiles/public-key "37AB1CB72B741E478CA026D43025DCBD46F81C0F" + "GPG kley to encrpy org files for/to.") #+end_src * Hosts @@ -60,56 +135,17 @@ Each host machines configuration loaded immediately after declaring the options, + [[file:hosts/raspberry.org][Raspberry]] + [[file:hosts/virtualbox.org][VirtualBox]] -* Modules - -Breaking down the project into logical units or chapters to keep the code more maintainable and organized. This is also a fundamental requirement to achieve the goal of modularity. Below are details of the modules, and their respective dependencies. +Begin the process by loading any host specific option overrides. The host configuration tangles, and loads (if it exist) using the systems name. If a host definition doesn't exist the default values remain. -#+begin_src plantuml :file docs/images/modules.png :exports none -left to right direction -allowmixing - -package Core -package Editor -package Shell -package Email -package Terminal -package Encryption -package Desktop -package Writing -package Presentations -package Website -package Capture -package Projects -package Development -package Interface -package Dashboard - -Editor --> Core - -Shell --> Editor -Email --> Editor -Projects --> Editor -Terminal --> Editor -Interface --> Editor -Encryption --> Editor - -Desktop --> Shell - -Writing --> Encryption - -Capture --> Writing -Website --> Writing -Presentations --> Writing - -Development --> Projects - -Dashboard --> Interface +#+begin_src emacs-lisp +(let ((host-file (concat dotfiles/home "/hosts/" system-name ".org"))) + (when (file-exists-p host-file) + (org-babel-load-file host-file))) #+end_src -#+ATTR_ORG: :width 420px -#+ATTR_HTML: :width 420px -#+ATTR_LATEX: :width 420px -[[./docs/images/modules.png]] +* Modules + +Breaking down the project into logical units or chapters to keep the code more maintainable and organized. This is also a fundamental requirement to achieve the goal of modularity. Below are details of the modules, and their respective dependencies. + [[file:modules/capture.org][Capture]] + [[file:modules/core.org][Core]] @@ -127,42 +163,15 @@ Dashboard --> Interface + [[file:modules/website.org][Website]] + [[file:modules/writing.org][Writing]] -* Options -Here's a complete list of all of the options configurable for each host, and their default values. - -+ All variables prefixed with ~dotfiles/~ -+ Initialized prior to loading of packages or hosts - -** Constants - -| Symbol | Default | Description | -|----------------------+------------------+---------------------------------------------| -| ~dotfiles/home~ | =~/.emacs.d= | Origininal value of ~user-emacs-directory~. | -| ~dotfiles/cache~ | =~/.cache/emacs= | Redirection target of ~user-emacs-dictory~. | -| ~dotfiles/modules-p~ | [[file:modules/][Modules]] | All of the available system modules. | - -** Variables - -| Symbol | Default | Description | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/browser~ | =$BROWSER= | Default system web browser. | -| ~dotfiles/language~ | =$LANG= | Default system language. | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/modules~ | ~dotfiles/modules-p~ | All of the enabled modules. | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/font~ | Fira Code | Unified system font family. | -| ~dotfiles/font-size~ | 96 | Unified system font size. | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/idle~ | 0.0 | Completion delay time. | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/leader-key~ | SPC | All powerful leader key. | -| ~dotfiles/leader-key-global~ | C-(dotfiles/leader-key) | Global prefix for the leader key. | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/projects~ | =~/.local/source= | Location of source code projects. | -| ~dotfiles/passwords~ | =~/.password-store= | Location of local password store. | -|------------------------------+-------------------------+-----------------------------------| -| ~dotfiles/public-key~ | =5EAG356GFAE...= | GPG key to encrypt org files for. | +All of the modules in ~dotfiles/modules~ load after the host overrides. By default, all of the packages defined in ~dotfiles/modules-p~ load. Override this behaviour in a host configuration file. + +#+begin_src emacs-lisp +(dolist (m dotfiles/modules) + (let ((mod-file (concat dotfiles/home "/modules/" (symbol-name m) ".org"))) + (when (file-exists-p mod-file) + (org-babel-load-file mod-file)))) +#+end_src * Footnotes diff --git a/bin/.git-keep b/bin/.git-keep new file mode 100644 index 0000000..e69de29 diff --git a/bin/cleanup.el b/bin/cleanup.el deleted file mode 100644 index 0d5ee2e..0000000 --- a/bin/cleanup.el +++ /dev/null @@ -1,17 +0,0 @@ -;; Emacs creates a lot of files relative to `user-emacs-directory'. -;; These files are not part of this immutable configuration and do not belong in the emacs directory. - -;; How can we solve this issue? - -;; Shortly after initialization, before most packages load, we change the value to `dotfiles/cache'. -;; I elaborate more on the technique in my post https://chrishayward.xyz/immutable-emacs/. - -(setq user-emacs-directory dotfiles/cache) - -;; Because this project uses version-control, we can disable more unwanted features: - -;; + Lock files -;; + Backup files - -(setq create-lockfiles nil - make-backup-files nil) diff --git a/bin/options.el b/bin/options.el deleted file mode 100644 index 5fa01b0..0000000 --- a/bin/options.el +++ /dev/null @@ -1,63 +0,0 @@ -;; All of the options available in the framework. -;; Please see README.org for more information. - -(defvar dotfiles/home user-emacs-directory - "Original value of `user-emacs-directory'.") - -(defvar dotfiles/cache (expand-file-name "~/.cache/emacs") - "Redirection target of `user-emacs-directory'.") - -(defvar dotfiles/browser (getenv "BROWSER") - "Default system web browser.") - -(defvar dotfiles/language (getenv "LANG") - "Default system dictionary language.") - -(defconst dotfiles/modules-p - '(core - editor - shell - email - terminal - encryption - desktop - writing - presentations - website - capture - projects - development - interface - dashboard) - "All of the available modules.") - -(defvar dotfiles/modules dotfiles/modules-p - "All of the enabled modules.") - -(defvar dotfiles/font "Fira Code" - "Unified system font family.") - -(defvar dotfiles/font-size 96 - "Unified system font size.") - -(defvar dotfiles/idle 0.0 - "Delay time before offering suggestions and completions.") - -(defvar dotfiles/leader-key "SPC" - "All powerful leader key.") - -(defvar dotfiles/leader-key-global - (concat "C-" dotfiles/leader-key) - "Global prefix for the leader key.") - -(defvar dotfiles/projects - (expand-file-name "~/.local/source/") - "Location of source code projects.") - -(defvar dotfiles/passwords - (expand-file-name "~/.password-store/") - "Location of local password store.") - -(defvar dotfiles/public-key - "37AB1CB72B741E478CA026D43025DCBD46F81C0F" - "GPG key to encrypt org files for.") diff --git a/bin/packages.el b/bin/packages.el deleted file mode 100644 index fb8d587..0000000 --- a/bin/packages.el +++ /dev/null @@ -1,31 +0,0 @@ -;; Download and instll packages using https://github.com/raxod502/straight.el -;; It's a functional package manager that integrates with https://github.com/jwiegley/use-package - -;; + Use the development branch -;; + Integrate with use-package - -;; Apply the configurations prior to bootstrapping the package manager. - -(setq straight-repository-branch "develop" - straight-use-package-by-default t) - -;; Bootstrap the package manager. -;; Download, Install, or Configuring depending on the state of the configuration. -;; All packages build from source, pinned to specific git commit hashes. - -(defvar bootstrap-version) -(let ((bootstrap-file - (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) - (bootstrap-version 5)) - (unless (file-exists-p bootstrap-file) - (with-current-buffer - (url-retrieve-synchronously - "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" - 'silent 'inhibit-cookies) - (goto-char (point-max)) - (eval-print-last-sexp))) - (load bootstrap-file nil 'nomessage)) - -;; Integrate with use-package by installing it with straight. - -(straight-use-package 'use-package) diff --git a/docs/images/modules.png b/docs/images/modules.png deleted file mode 100644 index fa88adc..0000000 Binary files a/docs/images/modules.png and /dev/null differ diff --git a/docs/tasks.org.gpg b/docs/tasks.org.gpg index a8f487b..87712d7 100644 Binary files a/docs/tasks.org.gpg and b/docs/tasks.org.gpg differ diff --git a/early-init.el b/early-init.el index f71e991..04ec04a 100644 --- a/early-init.el +++ b/early-init.el @@ -1 +1,68 @@ +;; Emacs creates a lot of files relative to `user-emacs-directory'. +;; These files are not part of this immutable configuration and do not belong in the emacs directory. + +(defconst dotfiles/home + (or (getenv "DOTFILES_HOME") + (expand-file-name user-emacs-directory))) + +(defconst dotfiles/cache + (or (getenv "DOTFILES_CACHE") + (expand-file-name "~/.cache/emacs"))) + +;; How can we solve this issue? + +(unless (file-exists-p dotfiles/cache) + (make-directory dotfiles/cache t)) + +;; Shortly after initialization, before most packages load, we change the value to `dotfiles/cache'. +;; I elaborate more on the technique in my post https://chrishayward.xyz/immutable-emacs/. + +(setq user-emacs-directory dotfiles/cache) + +;; Disable error messages for packages that do not yet support native compilation. + (setq comp-async-report-warnings-errors nil) + +;; Because this project uses version-control, we can disable more unwanted features: + +;; + Lock files +;; + Backup files + +(setq make-backup-files nil + create-lockfiles nil) + +;; Download and instll packages using https://github.com/raxod502/straight.el +;; It's a functional package manager that integrates with https://github.com/jwiegley/use-package + +;; + Use the development branch +;; + Integrate with use-package + +;; Apply the configurations prior to bootstrapping the package manager. + +(setq straight-repository-branch "develop" + straight-use-package-by-default t + package-enable-at-startup nil) + +;; Bootstrap the package manager. +;; Download, Install, or Configuring depending on the state of the configuration. +;; All packages build from source, pinned to specific git commit hashes. + +(defvar bootstrap-version) +(let ((bootstrap-file + (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) + (bootstrap-version 5)) + (unless (file-exists-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil 'nomessage)) + +;; Integrate with use-package by installing it with straight. Override some package sources to +;; avoid the default package shipped with Emacs. + +(straight-use-package 'use-package) +(straight-use-package 'no-littering) +(straight-use-package '(org :local-repo nil)) diff --git a/init.el b/init.el index 55ab6fb..44414a1 100644 --- a/init.el +++ b/init.el @@ -1,13 +1,113 @@ -;; Init +;; Modules definitions -;; This project makes heavy use of modern features and libraries. Since [[https://orgmode.org/worg/org-contrib/babel/intro.html][Org-babel]][fn:2]'s used during the initialization, [[https://orgmode.org][Org-mode]][fn:3] must load prior to importing any custom modules. My solution includes the introduction of some early intitialization code written in [[https://gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]][fn:4]. +;; All of the available modules are defined in ~dotfiles/modules-p~. The variable is constant, meaning it cannot be modified. Each time a new module is added, it must be included in this list. -(load-file "~/.emacs.d/bin/options.el") -(load-file "~/.emacs.d/bin/cleanup.el") -(load-file "~/.emacs.d/bin/packages.el") +(defconst dotfiles/modules-p + '(core + editor + shell + email + terminal + encryption + desktop + writing + presentations + website + capture + projects + development + interface + dashboard) + "All of the available modules.") -;; Load host definition + + +;; After the host configuration has loaded, the modules defined in ~dotfiles/modules~ are loaded sequentially. By default, the value of ~dotfiles/modules~ is equal to ~dotfiles/modules-p~. This means that all of the modules will load by default. Remove symbols from this list in a host configuration, or override it entirely to modify this behaviour. + + +(defvar dotfiles/modules dotfiles/modules-p + "All of the enable modules, default value equal to `dotfiles/modules-p'.") + +;; Environment variables + +;; Some of the behaviour in Emacs depends on the values of mutable environment variables. To reduce confusion in my own configuration, the values are read when Emacs starts, and then written to once the configuration has loaded. This allows the values to be overriden in a host configuration, without modifying the environment variable prior to starting. + + +(defvar dotfiles/browser (getenv "BROWSER") + "Default system web browser.") + +(defvar dotfiles/language (getenv "LANG") + "Default system dictionary language.") + +;; Look and feel + +;; Define the options for the unified system font. The default is =Fira Code= due to its readability and support for ligatures. All font faces will be set with this value. Any variations to the font sizes are based on the value defined here as well, reducing the number of places to make modifications to when changing fonts. + + +(defvar dotfiles/font "Fira Code" + "Unified system font family.") + +(defvar dotfiles/font-size 96 + "Unified system font size.") + + + +;; Certain actions like code completions, or binding suggestions, can be configured to wait for a specific delay before offering their respective choices. I prefer to keep this value low, so that suggestions are shown immediately. This can have an affect on the performance of Emacs on older hardware. Adjust accordingly. + + +(defvar dotfiles/idle 0.0 + "Delay time before offering suggestions and completions.") + + + +;; Prefix all of the custom keybinding actions with =SPC=, a tehcnique that comes from Doom / Spacemacs. In some situations, namely when using the [[file:modules/desktop.org][Desktop]] module, the leader key may not always be available. The global prefix should be used in these circumstances. + + +(defvar dotfiles/leader-key "SPC" + "The all-powerful leader key.") + +(defvar dotfiles/leader-key-global + (concat "C-" dotfiles/leader-key) + "Global prefix for the all-powerful leader key.") + +;; Productivity + +;; The location of source code projects for indexing in the [[file:modules/projects.org][Projects]] module are defined here. These projects will integrate their TODOs with the local Agenda. Override this setting in a host configuration, with the =DOTFILES_PROJECTS= environment variable, or use the default value of =~/.local/source/= in compliance with the XDG Base Directory specification. + + +(defvar dotfiles/projects + (or (getenv "DOTFILES_PROJECTS") + (expand-file-name "~/.local/source")) + "Location of source code projects.") + +;; Security + +;; The local password store should be cloned prior to initialization. Override this setting in a host configuration, with the =DOTFILES_PASSWORDS= environment variable, or use the default value of =~/.password-store=, which is what GNU pass will assume. + + +(defvar dotfiles/passwords + (or (getenv "DOTFILES_PASSWORDS") + (expand-file-name "~/.password-store")) + "Location of the local password store.") + + + +;; Since I keep all of my writing in this repository, I encrypt *most* of my Org files with GPG. Define the key to encrypt them for / to. Override this in a host configuration file. + + +(defvar dotfiles/public-key "37AB1CB72B741E478CA026D43025DCBD46F81C0F" + "GPG kley to encrpy org files for/to.") + +;; Hosts + +;; Each host machines configuration loaded immediately after declaring the options, before applying any configuration. This allows system to system control while remaining immutable. Override any of the available options configurations in a host file. Here's some examples to get started: + +;; + [[file:hosts/acernitro.org][Acernitro]] +;; + [[file:hosts/gamingpc.org][GamingPC]] +;; + [[file:hosts/localhost.org][Termux]] +;; + [[file:hosts/raspberry.org][Raspberry]] +;; + [[file:hosts/virtualbox.org][VirtualBox]] ;; Begin the process by loading any host specific option overrides. The host configuration tangles, and loads (if it exist) using the systems name. If a host definition doesn't exist the default values remain. @@ -16,7 +116,26 @@ (when (file-exists-p host-file) (org-babel-load-file host-file))) -;; Load enabled modules +;; Modules + +;; Breaking down the project into logical units or chapters to keep the code more maintainable and organized. This is also a fundamental requirement to achieve the goal of modularity. Below are details of the modules, and their respective dependencies. + +;; + [[file:modules/capture.org][Capture]] +;; + [[file:modules/core.org][Core]] +;; + [[file:modules/dashboard.org][Dashboard]] +;; + [[file:modules/desktop.org][Desktop]] +;; + [[file:modules/development.org][Development]] +;; + [[file:modules/editor.org][Editor]] +;; + [[file:modules/email.org][Email]] +;; + [[file:modules/encryption.org][Encryption]] +;; + [[file:modules/interface.org][Interface]] +;; + [[file:modules/presentations.org][Presentations]] +;; + [[file:modules/projects.org][Projects]] +;; + [[file:modules/shell.org][Shell]] +;; + [[file:modules/terminal.org][Terminal]] +;; + [[file:modules/website.org][Website]] +;; + [[file:modules/writing.org][Writing]] + ;; All of the modules in ~dotfiles/modules~ load after the host overrides. By default, all of the packages defined in ~dotfiles/modules-p~ load. Override this behaviour in a host configuration file.