I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2744 lines
89 KiB

3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. :PROPERTIES:
  2. :ID: e4ad3dd5-0996-45bc-92ab-6bdbf16e4310
  3. :ROAM_REFS: https://chrishayward.xyz/dotfiles/
  4. :END:
  5. #+TITLE: Dotfiles
  6. #+AUTHOR: Christopher James Hayward
  7. #+EMAIL: chris@chrishayward.xyz
  8. #+STARTUP: overview
  9. #+STARTUP: hideblocks
  10. #+EXPORT_FILE_NAME: dotfiles
  11. #+HUGO_BASE_DIR: docs
  12. #+HUGO_AUTO_SET_LASTMOD: t
  13. #+HUGO_SECTION:
  14. #+HUGO_DRAFT: false
  15. #+HTML: <a href="https://nixos.org"><img src="https://img.shields.io/badge/NixOS-unstable-blue.svg?style=flat-square&logo=NixOS&logoColor=white"></a>
  16. #+HTML: <a href="https://www.gnu.org/software/emacs/"><img src="https://img.shields.io/badge/Emacs-28.0.92-blueviolet.svg?style=flat-square&logo=GNU%20Emacs&logoColor=white"></a>
  17. #+HTML: <a href="https://orgmode.org"><img src="https://img.shields.io/badge/Org-9.5.2-%2377aa99?style=flat-square&logo=org&logoColor=white"></a>
  18. #+NAME: description
  19. #+BEGIN_SRC text
  20. Immutable NixOS dotfiles.
  21. #+END_SRC
  22. #+ATTR_ORG: :width 800px
  23. #+ATTR_HTML: :width 800px
  24. #+ATTR_LATEX: :width 800px
  25. [[./docs/images/desktop-example.png]]
  26. Built for Life, Liberty, and the Open Road.
  27. + 100% Immutable
  28. + 100% Declarative
  29. + 100% Reproducible
  30. * Introduction
  31. This is my personal configuration for [[https://linux.org][GNU/Linux]] systems. It enables a consistent experience and computing environment across all of my machines. This project is written with [[https://gnu.org/software/emacs/][GNU/Emacs]], leveraging its capabilities for [[https://doi.org/10.1093/comjnl/27.2.97][Literate Programming]], a technique where programs are written in a natural language, such as English, interspersed with snippets of code to describe a software project.
  32. #+NAME: file-warning
  33. #+BEGIN_SRC text
  34. This file is controlled by /etc/dotfiles/README.org
  35. #+END_SRC
  36. ** Getting Started
  37. 1) [[https://nixos.org/download.html][Download the latest version of NixOS]]
  38. 2) [[https://nixos.org/manual/nixos/stable/#sec-installation-partitioning][Partition your drives and mount the file system]]
  39. 3) Clone the project ~git clone git@git.chrishayward.xyz:chris/dotfiles /mnt/etc/dotfiles~
  40. 4) Load the default shell ~nix-shell /mnt/etc/dotfiles~
  41. 5) Install the system ~sudo nixos-install --impure --flake /mnt/etc/dotfiles#nixos~
  42. 6) Reboot, login and start a graphical system ~startx~
  43. ** Making Changes
  44. The ~nixos-rebuild~ command updates the system so that it corresponds to the configuration specified in the module. It builds the new system in =/nix/store/=, runs the activation scripts, and restarts and system services (if needed). The command has one required argument, which specifies the desired operation:
  45. #+NAME: rebuild-command-table
  46. | Command | Description |
  47. |----------+---------------------------------------------------------------------------------|
  48. | boot | Build the new configuration and make it the boot default, without activation |
  49. | test | Build and activate the new configuration, without adding it to the boot menu |
  50. | switch | Build and activate the new configuration, making it the new boot default |
  51. | build | Build the new configuration, without activation, nor adding it to the boot menu |
  52. | build-vm | Build a script that starts a virtual machine with the desired configuration |
  53. After making changes to the configuration the ~switch~ command will build and activate a new configuration.
  54. #+BEGIN_SRC shell
  55. # Build and activate a new configuration.
  56. sudo nixos-rebuild switch --flake $FLAKE#$HOSTNAME
  57. #+END_SRC
  58. Instead of building a new configuration, it's possible to rollback to a previous generation using the ~nixos-rebuild~ command, by supplying the ~--rollback~ argument.
  59. #+BEGIN_SRC shell
  60. # Rollback to the previous generation.
  61. sudo nixos-rebuild switch --rollback
  62. #+END_SRC
  63. ** Docker Container
  64. It's possible to use parts of this configuration using a [[https://docker.org][Docker]] container. By default, sandboxing is turned /off/ inside of the container, even though it's enabled in new installations. This can lead to differences between derivations built inside containers, versus those built without any containerization. This is especially true if a derivation relies on sandboxing to block sideloading of dependencies.
  65. Install from the command line: ~docker pull ghcr.io/chayward1/dotfiles:main~
  66. #+BEGIN_SRC dockerfile :tangle Dockerfile :noweb yes
  67. # <<file-warning>>
  68. # Derive from the official image.
  69. FROM nixos/nix
  70. # Setup the default environment.
  71. WORKDIR /etc/dotfiles
  72. COPY . .
  73. # Load the default system shell.
  74. RUN nix-shell /etc/dotfiles/shell.nix
  75. #+END_SRC
  76. * Operating System
  77. [[https://nixos.org][NixOS]] is a purely functional Linux distribution built on top of the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]]. It uses a declarative configuration language to define entire computer systems, and allows reliable system upgrades and rollbacks. [[https://nixos.org][NixOS]] also has tool dedicated to DevOps and deployment tasks, and makes it trivial to share development environments.
  78. #+BEGIN_SRC nix :noweb yes :tangle flake.nix
  79. # <<file-warning>>
  80. {
  81. description = "<<description>>";
  82. inputs = {
  83. <<os-nixpkgs>>
  84. <<os-home-manager>>
  85. <<os-emacs-overlay>>
  86. <<os-nixos-hardware>>
  87. <<os-nix-on-droid>>
  88. };
  89. outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, ... }: {
  90. nixosConfigurations = {
  91. <<host-default>>
  92. };
  93. nixOnDroidConfigurations = {
  94. <<host-android>>
  95. };
  96. };
  97. }
  98. #+END_SRC
  99. ** Nixpkgs
  100. [[https://nixos.org/manual/nixpkgs/stable][Nixpkgs]] is a collection of over 60,000 software packages that can be installed with the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]]. Two main branches are offered:
  101. 1) The current stable release
  102. 2) The Unstable branch following the latest development
  103. #+NAME: os-nixpkgs
  104. #+BEGIN_SRC nix
  105. nixpkgs.url = "nixpkgs/nixos-unstable";
  106. nixpkgs-unstable.url = "nixpkgs/master";
  107. #+END_SRC
  108. ** Home Manager
  109. [[https://nixos.wiki/wiki/Home_Manager][Home Manager]] provides a basic system for managing user environments using the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]] together with the Nix libraries found in [[https://nixos.org/manual/nixpkgs/stable][Nixpkgs]]. It allows declarative configuration of user specific (non-global) packages and files.
  110. #+NAME: os-home-manager
  111. #+BEGIN_SRC nix
  112. home-manager.url = "github:nix-community/home-manager";
  113. home-manager.inputs.nixpkgs.follows = "nixpkgs";
  114. #+END_SRC
  115. ** Emacs Overlay
  116. Adding the [[https://github.com/nix-community/emacs-overlay][Emacs Overlay]] extends the [[https://gnu.org/software/emacs/][GNU/Emacs]] package set to contain the latest versions, and daily generations from popular package sources, including the needed dependencies to run Emacs as a Window Manager.
  117. #+NAME: os-emacs-overlay
  118. #+BEGIN_SRC nix
  119. emacs-overlay.url = "github:nix-community/emacs-overlay";
  120. #+END_SRC
  121. ** NixOS Hardware
  122. [[https://github.com/nixos/nixos-hardware][NixOS Hardware]] is a collection of [[https://nixos.org][NixOS]] modules covering specific hardware quirks. Unlike the channel, this will update the git repository on a rebuild. However, it's easy to pin particular revisions for more stability.
  123. #+NAME: os-nixos-hardware
  124. #+BEGIN_SRC nix
  125. nixos-hardware.url = "github:nixos/nixos-hardware";
  126. #+END_SRC
  127. ** Nix On Droid
  128. [[https://github.com/t184256/nix-on-droid][Nix On Droid]] is a deployment of the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]] on [[https://android.com][Android]], in a single-click installable package. It does not require =root=, user namespace support, or disabling SELinux, but relies on =proot=. It has no relation to the Termux distribution.
  129. #+NAME: os-nix-on-droid
  130. #+BEGIN_SRC nix
  131. nix-on-droid.url = "github:t184256/nix-on-droid/master";
  132. nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
  133. #+END_SRC
  134. * Development Shells
  135. The command ~nix-shell~ will build the dependencies of the specified derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation /path/ have been set to their corresponding values.
  136. Import this shell with ~nix-shell /etc/dotfiles/shell.nix~.
  137. #+BEGIN_SRC nix :noweb yes :tangle shell.nix
  138. # <<file-warning>>
  139. { pkgs ? import <nixpkgs> { } }:
  140. with pkgs;
  141. let
  142. nixBin = writeShellScriptBin "nix" ''
  143. exec ${nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
  144. '';
  145. in mkShell {
  146. buildInputs = [
  147. git
  148. ];
  149. shellHook = ''
  150. export FLAKE="$(pwd)"
  151. export PATH="$FLAKE/bin:${nixBin}/bin:$PATH"
  152. '';
  153. }
  154. #+END_SRC
  155. ** Go
  156. [[https://golang.org][Go]] is an open-source programming language that makes it easy to build simple, reliable, and efficient software. It's statically typed and compiled programming language. It's syntactically similar to C, but with memory safety, garbage collection, structural typing, and CSP-style concurrency.
  157. Import this shell with ~nix-shell /etc/dotfiles/shells/go.nix~
  158. #+BEGIN_SRC nix :noweb yes :tangle shells/go.nix
  159. # <<file-warning>>
  160. { pkgs ? import <nixpkgs> { } }:
  161. with pkgs;
  162. mkShell {
  163. buildInputs = [
  164. go
  165. gopls
  166. protoc-gen-go
  167. protoc-gen-go-grpc
  168. ];
  169. shellHook = ''
  170. export GO111MODULE=on
  171. export GOPATH=$XDG_DATA_HOME/go
  172. export PATH=$GOPATH/bin:$PATH
  173. '';
  174. }
  175. #+END_SRC
  176. ** Rust
  177. [[https://rust-lang.org/][Rust]] is a multi-paradigm programming language designed for performance and safety, especially safe concurrency. It is syntactically similar to C++, but can garantee memory safety by using a borrow checker to validate references. Rust achieves memory safety /without/ garbage collection, and reference counting is optional.
  178. Import this shell with ~nix-shell /etc/dotfiles/shells/rust.nix~.
  179. #+BEGIN_SRC nix :noweb yes :tangle shells/rust.nix
  180. # <<file-warning>>
  181. { pkgs ? import <nixpkgs> { } }:
  182. with pkgs;
  183. mkShell {
  184. buildInputs = [
  185. rustup
  186. ];
  187. shellHook = ''
  188. export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
  189. export CARGO_HOME="$XDG_DATA_HOME/cargo"
  190. export PATH="$CARGO_HOME/bin:$PATH"
  191. '';
  192. }
  193. #+END_SRC
  194. ** Node
  195. [[https://nodejs.org][NodeJS]] is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine, and executes JavaScript code outside of a web browser. NodeJS lets developers user JavaScript to write command line tools, and for server-side scripting to produce dynamic web page content.
  196. Import this shell with ~nix-shell /etc/dotfiles/shells/node.nix~.
  197. #+BEGIN_SRC nix :noweb yes :tangle shells/node.nix
  198. # <<file-warning>>
  199. { pkgs ? import <nixpkgs> { } }:
  200. with pkgs;
  201. mkShell {
  202. buildInputs = [
  203. nodejs
  204. yarn
  205. ];
  206. shellHook = ''
  207. export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
  208. export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
  209. export NPM_CACHE_PREFIX="$XDG_CACHE_HOME/npm"
  210. export PATH="$(yarn global bin):$PATH"
  211. '';
  212. }
  213. #+END_SRC
  214. ** Java
  215. [[https://openjdk.java.net][OpenJDK]] is a free and open-source implementation of the [[https://en.wikipedia.org/wiki/Java_(software_platform)][Java]] Platform, Standard Edition. It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GNU General Public License Version 2 with a linking exception.
  216. Import this shell with ~nix-shell /etc/dotfiles/shells/java.nix~.
  217. #+BEGIN_SRC nix :noweb yes :tangle shells/java.nix
  218. # <<file-warning>>
  219. { pkgs ? import <nixpkgs> { } }:
  220. with pkgs;
  221. mkShell {
  222. buildInputs = [
  223. # openjdk8 # Legacy Java 8 VM.
  224. # openjdk11 # Current LTS version of OpenJDK.
  225. openjdk14 # Current version of OpenJDK.
  226. ];
  227. shellHook = ''
  228. '';
  229. }
  230. #+END_SRC
  231. ** gRPC
  232. [[https://grpc.io][gRPC]] is a modern open-source, high-performance Remote Procedure Call (RPC) framework that can run in any environment. It can efficiently connect services in and across data centres with pluggable support for load balancing, tracing, health checking, and authentication.
  233. Import this shell with ~nix-shell /etc/dotfiles/shells/grpc.nix~.
  234. #+BEGIN_SRC nix :noweb yes :tangle shells/grpc.nix
  235. # <<file-warning>>
  236. { pkgs ? import <nixpkgs> { } }:
  237. with pkgs;
  238. mkShell {
  239. buildInputs = [
  240. grpc
  241. grpcui
  242. grpcurl
  243. grpc-tools
  244. ];
  245. shellHook = ''
  246. '';
  247. }
  248. #+END_SRC
  249. ** C/C++
  250. [[https://iso.org/standard/74528.html][C]] is a general-purpose, procedural computer programming language support structured programming, lexical variable scope, and recursion. It has a static type system, and by design provides constructs that map efficiently to typical machine instructions. [[https://en.wikipedia.org/wiki/C++/][C++]] is a general-purpose programming language created as an extension of the C programming language.
  251. Import this shell with ~nix-shell /etc/dotfiles/shells/cc.nix~.
  252. #+BEGIN_SRC nix :noweb yes :tangle shells/cc.nix
  253. # <<file-warning>>
  254. { pkgs ? import <nixpkgs> { } }:
  255. with pkgs;
  256. mkShell {
  257. buildInputs = [
  258. gdb
  259. ccls
  260. cmake
  261. gnumake
  262. gcc-unwrapped
  263. ];
  264. shellHook = ''
  265. '';
  266. }
  267. #+END_SRC
  268. ** Python
  269. [[https://python.org][Python]] is an interpreted high-level, general-purpose programming language. Its design philosophy emphasizes code readability, with its notable use of significant indentation. Its language constructs, as well as its object-oriented approach aim to help programmers write clear, logical, code for small and large projects.
  270. Import this shell with ~nix-shell /etc/dotfiles/shells/python.nix~
  271. #+BEGIN_SRC nix :noweb yes :tangle shells/python.nix
  272. # <<file-warning>>
  273. { pkgs ? import <nixpkgs> { } }:
  274. with pkgs;
  275. mkShell {
  276. buildInputs = [
  277. python310Packages.pip
  278. python310Packages.pip-tools
  279. python310Packages.python-lsp-black
  280. python310Packages.python-lsp-server
  281. python310Packages.python-lsp-jsonrpc
  282. ];
  283. shellHook = ''
  284. '';
  285. }
  286. #+END_SRC
  287. ** Docker
  288. [[https://docker.org][Docker]] is a set of platform as a service tools that use OS level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuratuion files.
  289. [[https://docs.docker.com/compose/][Compose]] is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application services. Then, with a single command, you create and start all of the services from your configuration.
  290. [[https://docs.docker.com/machine/][Machine]] is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with ~docker-machine~ commands. You can use Machine to create hosts on your local box, company network, data center, or on any cloud provider.
  291. Import this shell with ~nix-shell /etc/dotfiles/shells/docker.nix~
  292. #+BEGIN_SRC nix :noweb yes :tangle shells/docker.nix
  293. # <<file-warning>>
  294. { pkgs ? import <nixpkgs> { } }:
  295. with pkgs;
  296. mkShell {
  297. buildInputs = [
  298. docker-compose
  299. docker-machine
  300. ];
  301. shellHook = ''
  302. '';
  303. }
  304. #+END_SRC
  305. ** Heroku
  306. [[https://heroku.com][Heroku]] is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language. It now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.
  307. Import this shell with ~nix-shell /etc/dotfiles/shells/heroku.nix~
  308. #+BEGIN_SRC nix :noweb yes :tangle shells/heroku.nix
  309. # <<file-warning>>
  310. { pkgs ? import <nixpkgs> { } }:
  311. with pkgs;
  312. mkShell {
  313. buildInputs = [
  314. heroku
  315. ];
  316. shellHook = ''
  317. '';
  318. }
  319. #+END_SRC
  320. * Host Configurations
  321. [[https://nixos.org/][NixOS]] typically stores the current machine configuration in =/etc/nixos/configuration.nix=. In this project, this file is stored in =/etc/dotfiles/hosts/$HOSTNAME/...=, and imported, along with the generated hardware configurations. This ensures that multiple host machines can share the same modules, and generating new host definitions is trivial. It also makes it easier to share common configurations amongst all of the hosts, such as with pre-configured wireless networking:
  322. #+NAME: host-config-wifi
  323. #+BEGIN_SRC nix
  324. networking.wireless.networks = {
  325. MyWiFi_5C1870 = {
  326. priority = 3;
  327. pskRaw = "409b3c85fef1c5737f284d2f82f20dc6023e41804e862d4fa26265ef8193b326";
  328. };
  329. SM-G975W3034 = {
  330. priority = 1;
  331. pskRaw = "74835d96a98ca2c56ffe4eaf92223f8a555168b59ec2bb22b1e46b2a333adc80";
  332. };
  333. };
  334. #+END_SRC
  335. It's helpful to add the machine hostnames to the networking configuration, so I can refer to another host across the network by name. Some devices that can have more than one IP (WIFI / Ethernet) will have the wireless hostname suffixed:
  336. #+NAME: host-config-home
  337. #+BEGIN_SRC nix
  338. networking.hosts = {
  339. # "192.168.3.105" = [ "gamingpc" ];
  340. # "192.168.3.163" = [ "acernitro" ];
  341. # "192.168.3.182" = [ "raspberry" ];
  342. # "192.168.3.183" = [ "homecloud" ];
  343. };
  344. #+END_SRC
  345. Setting up new machines, especially headless ones like the Raspberry Pi Zero, can be difficult with NixOS. I find it easier to setup automatic network configuration, and wait for the machine to appear on the network. This is complimented with a pre-authorized SSH key, making it simple to connect and complete the installation headlessly.
  346. #+NAME: host-config-ssh
  347. #+BEGIN_SRC nix
  348. users.users.chris.openssh.authorizedKeys.keys = [
  349. "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4wka/LfG3pto15DIm9LIRbb6rWr7/ipCRiCdAKSlY4 chris@chrishayward.xyz"
  350. ];
  351. #+END_SRC
  352. ** Default
  353. The default host, built using [[https://qemu.org][QEMU]], a free and open-source emulator that can perform hardware virtualization. It features a lightweight system optimized for development, running [[https://gnu.org/software/emacs/][GNU/Emacs]] + [[https://github.com/ch11ng/exwm][EXWM]] as the graphical environment.
  354. #+NAME: host-default
  355. #+BEGIN_SRC nix :noweb yes
  356. nixos = nixpkgs.lib.nixosSystem {
  357. system = "x86_64-linux";
  358. specialArgs = { inherit inputs; };
  359. modules = [
  360. ./hosts/nixos
  361. <<module-x11>>
  362. <<module-ssh>>
  363. <<module-hugo>>
  364. <<module-flakes>>
  365. <<module-cachix>>
  366. <<module-firefox>>
  367. <<module-home-manager>>
  368. ];
  369. };
  370. #+END_SRC
  371. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#nixos~.
  372. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/default.nix
  373. # <<file-warning>>
  374. { ... }:
  375. {
  376. imports = [
  377. ./configuration.nix
  378. ./hardware.nix
  379. ];
  380. }
  381. #+END_SRC
  382. *** Configuration
  383. This is a basic default configuration that specified the indended default configuration of the system. Because [[https://nixos.org/][NixOS]] has a declarative configuration model, you can create or edit a description of the desired configuration, and update it from one file.
  384. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/configuration.nix
  385. # <<file-warning>>
  386. { config, pkgs, inputs, ... }:
  387. {
  388. time.timeZone = "America/Toronto";
  389. networking.hostName = "nixos";
  390. networking.useDHCP = false;
  391. networking.firewall.enable = false;
  392. networking.interfaces.ens3.useDHCP = true;
  393. <<host-config-home>>
  394. <<host-config-ssh>>
  395. programs.mtr.enable = true;
  396. programs.fish.enable = true;
  397. programs.gnupg.agent.enable = true;
  398. users.users.chris = {
  399. shell = pkgs.fish;
  400. isNormalUser = true;
  401. extraGroups = [ "wheel" ];
  402. };
  403. }
  404. #+END_SRC
  405. *** Hardware
  406. The file system for this host is a single 24GB =QCOW= file, a format for disk images used by [[https://qemu.org][QEMU]]. The file can be recreated easily by following the steps listed in the [[https://nixos.org/][NixOS]] installation manual, specifically the section on disk formatting.
  407. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/hardware.nix
  408. # <<file-warning>>
  409. { config, lib, pkgs, modulesPath, ... }:
  410. {
  411. imports =
  412. [ (modulesPath + "/profiles/qemu-guest.nix")
  413. ];
  414. boot.initrd.availableKernelModules = [ "ata_piix" "floppy" "sd_mod" "sr_mod" ];
  415. boot.initrd.kernelModules = [ ];
  416. boot.kernelModules = [ ];
  417. boot.extraModulePackages = [ ];
  418. boot.loader.grub.enable = true;
  419. boot.loader.grub.version = 2;
  420. boot.loader.grub.device = "/dev/sda";
  421. fileSystems."/" =
  422. { device = "/dev/disk/by-label/nixos";
  423. fsType = "ext4";
  424. };
  425. swapDevices =
  426. [ { device = "/dev/disk/by-label/swap"; }
  427. ];
  428. }
  429. #+END_SRC
  430. ** Android
  431. This is my [[https://samsung.com/us/mobile/galaxy-s10/buy/][Samsung Galaxy S10+]] running [[https://github.com/t184256/nix-on-droid][Nix On Droid]] with the experimental support for [[https://nixos.wiki/wiki/Flakes][Flakes]] being used to manage the configuration.
  432. #+NAME: host-android
  433. #+BEGIN_SRC nix
  434. android = {
  435. device = inputs.nix-on-droid.lib.nixOnDroidConfiguration {
  436. config = ./hosts/android/nix-on-droid.nix;
  437. system = "aarch64-linux";
  438. specialArgs = { inherit inputs; };
  439. };
  440. };
  441. #+END_SRC
  442. Build and activate the configuration with ~nix-on-droid switch --flake .#android~. Currently this cannot be built with a pure flake because of hardcoded store paths for =proot=. Every evaluation will be executed with the =--impure= flag.
  443. #+BEGIN_SRC nix :noweb yes :tangle hosts/android/nix-on-droid.nix
  444. # <<file-warning>>
  445. { pkgs, ... }:
  446. {
  447. environment.packages = [
  448. pkgs.git
  449. pkgs.vim
  450. pkgs.pass
  451. pkgs.gnupg
  452. pkgs.openssh
  453. ];
  454. }
  455. #+END_SRC
  456. * Module Definitions
  457. Modules are files combined by [[https://nixos.org/][NixOS]] to produce the full system configuration. Modules wre introduced to allow extending NixOS without modifying its source code. They also allow splitting up =configuration.nix=, making the system configuration easier to maintain and use.
  458. ** X11
  459. #+NAME: module-x11
  460. #+BEGIN_SRC nix
  461. ./modules/x11.nix
  462. #+END_SRC
  463. [[https://x.org/wiki/][X11]], or X is the generic name for the X Window System Display Server. All graphical [[https://linux.org][GNU/Linux]] applications connect to an X-Window (or Wayland) to display graphical data on the monitor of a computer. Its a program that acts as the interface between graphical applications and the graphics subsystem of the computer.
  464. #+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
  465. # <<file-warning>>
  466. { config, pkgs, ... }:
  467. {
  468. services.xserver.enable = true;
  469. services.xserver.layout = "us";
  470. services.xserver.libinput.enable = true;
  471. services.xserver.displayManager.startx.enable = true;
  472. environment = {
  473. variables = {
  474. XDG_DESKTOP_DIR = "$HOME/";
  475. XDG_CACHE_HOME = "$HOME/.cache";
  476. XDG_CONFIG_HOME = "$HOME/.config";
  477. XDG_DATA_HOME = "$HOME/.local/share";
  478. XDG_BIN_HOME = "$HOME/.local/bin";
  479. };
  480. systemPackages = with pkgs; [
  481. pkgs.sqlite
  482. pkgs.pfetch
  483. pkgs.cmatrix
  484. pkgs.asciiquarium
  485. ];
  486. extraInit = ''
  487. export XAUTHORITY=/tmp/Xauthority
  488. export xserverauthfile=/tmp/xserverauth
  489. [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
  490. [ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
  491. '';
  492. };
  493. services.picom.enable = true;
  494. services.printing.enable = true;
  495. fonts.fonts = with pkgs; [
  496. iosevka-bin
  497. emacs-all-the-icons-fonts
  498. ];
  499. }
  500. #+END_SRC
  501. ** SSH
  502. #+NAME: module-ssh
  503. #+BEGIN_SRC nix
  504. ./modules/ssh.nix
  505. #+END_SRC
  506. [[https://openssh.com][OpenSSH]] is a suite of secure networking utilities based on the [[https://en.wikipedia.org/wiki/Secure_Shell][Secure Shell Protocol]], which provides a secure channel over an unsecured network in a client-server architecture. OpenSSH started as a fork of the free SSH program; later versions were proprietary software.
  507. Apply some configuration to the default settings:
  508. + Disable logging in as =root=
  509. + Disable password authentication
  510. #+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
  511. # <<file-warning>>
  512. { config, pkgs, ... }:
  513. {
  514. services.openssh = {
  515. enable = true;
  516. permitRootLogin = "no";
  517. passwordAuthentication = false;
  518. };
  519. }
  520. #+END_SRC
  521. ** Hugo
  522. #+NAME: module-hugo
  523. #+BEGIN_SRC nix
  524. ./modules/hugo.nix
  525. #+END_SRC
  526. [[https://gohugo.io][Hugo]] is one of the most popular open-source static site generators. I use it to build https://chrishayward.xyz which is included in a later section of this configuration. This module adds a custom package to push the site to the server.
  527. #+BEGIN_SRC nix :noweb yes :tangle modules/hugo.nix
  528. # <<file-warning>>
  529. { config, pkgs, ... }:
  530. let
  531. mySiteDir = "/etc/dotfiles/docs/public/";
  532. mySiteTgt = "ubuntu@chrishayward.xyz:/var/www/wedding";
  533. mySiteBuild = pkgs.writeShellScriptBin "my-site-build" ''
  534. pushd ${mySiteDir}../ && ${pkgs.hugo}/bin/hugo -v && popd
  535. '';
  536. mySiteUpdate = pkgs.writeShellScriptBin "my-site-update" ''
  537. ${pkgs.rsync}/bin/rsync -aP ${mySiteDir} ${mySiteTgt}
  538. '';
  539. in {
  540. environment.systemPackages = [
  541. mySiteBuild
  542. mySiteUpdate
  543. ];
  544. }
  545. #+END_SRC
  546. ** Flakes
  547. #+NAME: module-flakes
  548. #+BEGIN_SRC nix
  549. ./modules/flakes.nix
  550. #+END_SRC
  551. [[https://nixos.wiki/wiki/Flakes][Nix Flakes]] are an upcoming feature of the [[https://nixos.org/manual/nix/stable/][Nix Package Manager]]. They allow you to specify your codes dependencies in a declarative way, simply by listing them inside of a ~flake.nix~ file. Each dependency is then pinned to a specific git-hash. Flakes replace the =nix-channels= command and things like ~builtins.fetchGit~, keeping dependencies at the top of the tree, and channels always in sync. Currently, Flakes are not available unless explicitly enabled.
  552. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  553. # <<file-warning>>
  554. { config, pkgs, inputs, ... }:
  555. {
  556. nix = {
  557. package = pkgs.nixUnstable;
  558. extraOptions = ''
  559. experimental-features = nix-command flakes
  560. '';
  561. };
  562. nixpkgs = {
  563. config = { allowUnfree = true; };
  564. overlays = [ inputs.emacs-overlay.overlay ];
  565. };
  566. }
  567. #+END_SRC
  568. ** Cachix
  569. #+NAME: module-cachix
  570. #+BEGIN_SRC nix
  571. ./modules/cachix.nix
  572. #+END_SRC
  573. [[https://nix-community.cachix.org][Cachix]] is a Command line client for [[https://nixos.org/manual/nix/stable/][Nix]] binary cache hosting. This allows downloading and usage of pre-compiled binaries for applications on /nearly/ every available system architecture. This speeds up the time it takes to rebuild configurations.
  574. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  575. # <<file-warning>>
  576. { config, ... }:
  577. {
  578. nix = {
  579. settings = {
  580. substituters = [
  581. "https://nix-community.cachix.org"
  582. ];
  583. trusted-public-keys = [
  584. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  585. ];
  586. };
  587. };
  588. }
  589. #+END_SRC
  590. ** Docker
  591. #+NAME: module-docker
  592. #+BEGIN_SRC nix
  593. ./modules/docker.nix
  594. #+END_SRC
  595. [[https://docker.org][Docker]] is a set of platform as a service tools that use OS level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels.
  596. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  597. { config, pkgs, ... }:
  598. {
  599. # Enable the docker virutalization platform.
  600. virtualisation.docker = {
  601. enable = true;
  602. enableOnBoot = true;
  603. autoPrune.enable = true;
  604. };
  605. # Required for the `docker' command.
  606. users.users.chris.extraGroups = [ "docker" ];
  607. }
  608. #+END_SRC
  609. ** Firefox
  610. #+NAME: module-firefox
  611. #+BEGIN_SRC nix
  612. ./modules/firefox.nix
  613. #+END_SRC
  614. [[https://firefox.com][Firefox Browser]], also known as Mozilla Firefox or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. Firefox uses the Gecko layout engine to render web pages, which implements current and anticipated web standards. In 2017, Firefox began incorporating new technology under the code name Quantum to promote parallelism and a more intuitive user interface.
  615. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  616. # <<file-warning>>
  617. { config, pkgs, ... }:
  618. let
  619. myFirefox = pkgs.writeShellScriptBin "firefox" ''
  620. HOME=~/.local/share/mozilla ${pkgs.firefox-bin}/bin/firefox
  621. '';
  622. in {
  623. # NOTE: Use the binary until module is developed.
  624. environment.systemPackages = [
  625. myFirefox
  626. ];
  627. }
  628. #+END_SRC
  629. ** Home Manager
  630. [[https://nixos.wiki/wiki/Home_Manager][Home Manager]] includes a =flake.nix= file for compatibility with Nix Flakes, a feature utilized heavily in this project. When using flakes, switching to a new configuration is done /only/ for the entire system, using the command ~nixos-rebuild switch --flake <path>~, instead of ~nixos-rebuild~, and ~home-manager~ seperately.
  631. #+NAME: module-home-manager
  632. #+BEGIN_SRC nix :noweb yes
  633. inputs.home-manager.nixosModules.home-manager {
  634. home-manager.useGlobalPkgs = true;
  635. home-manager.useUserPackages = true;
  636. home-manager.users.chris = {
  637. imports = [
  638. <<module-git>>
  639. <<module-gpg>>
  640. <<module-vim>>
  641. <<module-gtk>>
  642. <<module-emacs>>
  643. ];
  644. };
  645. }
  646. #+END_SRC
  647. Certain modules have to be included within home manager or they will not function correctly.
  648. #+NAME: home-manager-warning
  649. #+BEGIN_SRC text
  650. This module MUST be included within home manager
  651. #+END_SRC
  652. *** Git
  653. #+NAME: module-git
  654. #+BEGIN_SRC nix
  655. ./modules/git.nix
  656. #+END_SRC
  657. [[https://git.scm.com][Git]] is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is easy to learn, has a tiny footprint, and lighting fast performance. It outclasses every other version control tool such as: SCM, Subversion, CVS, ClearCase, with features like cheap local branching, convinient staging areas, and multiple workflows.
  658. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  659. # <<file-warning>>
  660. # <<home-manager-warning>>
  661. { pkgs, ... }:
  662. let
  663. # Fix any corruptions in the local copy.
  664. myGitFix = pkgs.writeShellScriptBin "git-fix" ''
  665. if [ -d .git/objects/ ]; then
  666. find .git/objects/ -type f -empty | xargs rm -f
  667. git fetch -p
  668. git fsck --full
  669. fi
  670. exit 1
  671. '';
  672. in {
  673. home.packages = [ myGitFix ];
  674. programs.git = {
  675. enable = true;
  676. userName = "Christopher James Hayward";
  677. userEmail = "chris@chrishayward.xyz";
  678. signing = {
  679. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  680. signByDefault = true;
  681. };
  682. };
  683. }
  684. #+END_SRC
  685. *** Gpg
  686. #+NAME: module-gpg
  687. #+BEGIN_SRC nix
  688. ./modules/gpg.nix
  689. #+END_SRC
  690. [[https://gnupg.org][GNU Privacy Guard]] is a free-software replacement for Symantec's PGP cryptographic software suite. It is compliant with RFC 4880, the IETF standards-track specification of OpenPGP. Modern versions of PGP are interoperable with GnuPG and other OpenPGP-compliant systems.
  691. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  692. # <<file-warning>>
  693. # <<home-manager-warning>>
  694. { pkgs, ... }:
  695. {
  696. services.gpg-agent = {
  697. enable = true;
  698. defaultCacheTtl = 1800;
  699. enableSshSupport = true;
  700. pinentryFlavor = "gtk2";
  701. };
  702. }
  703. #+END_SRC
  704. *** Vim
  705. #+NAME: module-vim
  706. #+BEGIN_SRC nix
  707. ./modules/vim.nix
  708. #+END_SRC
  709. [[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
  710. + Simplify maintenance and encourage contributions
  711. + Split the work between multiple developers
  712. + Enable advanced UIs without core modification
  713. + Maximize extensibility
  714. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  715. # <<file-warning>>
  716. # <<home-manager-warning>>
  717. { pkgs, ... }:
  718. {
  719. programs.neovim = {
  720. enable = true;
  721. viAlias = true;
  722. vimAlias = true;
  723. vimdiffAlias = true;
  724. extraConfig = ''
  725. set number relativenumber
  726. set nobackup
  727. '';
  728. extraPackages = [
  729. pkgs.nixfmt
  730. ];
  731. plugins = with pkgs.vimPlugins; [
  732. vim-nix
  733. vim-airline
  734. vim-polyglot
  735. ];
  736. };
  737. }
  738. #+END_SRC
  739. *** GTK
  740. #+NAME: module-gtk
  741. #+BEGIN_SRC nix
  742. ./modules/gtk.nix
  743. #+END_SRC
  744. [[https://gtk.org][GTK]] is a free and open-source, cross-platform widget toolkit for graphical user interfaces. It's one of the most popular toolkits for the [[https://wayland.freedesktop.org][Wayland]] and [[https://x.org/wiki/][X11]] windowing systems.
  745. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  746. # <<file-warning>>
  747. # <<home-manager-warning>>
  748. { pkgs, ... }:
  749. {
  750. home.packages = [
  751. pkgs.nordic
  752. pkgs.arc-icon-theme
  753. pkgs.lxappearance
  754. ];
  755. home.file.".gtkrc-2.0" = {
  756. text = ''
  757. gtk-theme-name="Nordic-darker"
  758. gtk-icon-theme-name="Arc"
  759. gtk-font-name="Iosevka 11"
  760. gtk-cursor-theme-size=0
  761. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  762. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  763. gtk-button-images=0
  764. gtk-menu-images=0
  765. gtk-enable-event-sounds=1
  766. gtk-enable-input-feedback-sounds=1
  767. gtk-xft-antialias=1
  768. gtk-xft-hinting=1
  769. gtk-xft-hintstyle="hintmedium"
  770. '';
  771. };
  772. home.file.".config/gtk-2.0/gtkfilechooser.ini" = {
  773. text = ''
  774. [Filechooser Settings]
  775. LocationMode=path-bar
  776. ShowHidden=false
  777. ShowSizeColumn=true
  778. GeometryX=442
  779. GeometryY=212
  780. GeometryWidth=1036
  781. GeometryHeight=609
  782. SortColumn=name
  783. SortOrder=ascending
  784. StartupMode=recent
  785. '';
  786. };
  787. home.file.".config/gtk-3.0/settings.ini" = {
  788. text = ''
  789. [Settings]
  790. gtk-theme-name=Nordic-darker
  791. gtk-icon-theme-name=Arc
  792. gtk-font-name=Iosevka 11
  793. gtk-cursor-theme-size=0
  794. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  795. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  796. gtk-button-images=0
  797. gtk-menu-images=0
  798. gtk-enable-event-sounds=1
  799. gtk-enable-input-feedback-sounds=1
  800. gtk-xft-antialias=1
  801. gtk-xft-hinting=1
  802. gtk-xft-hintstyle=hintmedium
  803. '';
  804. };
  805. }
  806. #+END_SRC
  807. * Emacs Configuration
  808. [[./docs/images/emacs.png]]
  809. #+NAME: module-emacs
  810. #+BEGIN_SRC nix
  811. ./modules/emacs.nix
  812. #+END_SRC
  813. [[https://gnu.org/software/emacs/][GNU/Emacs]] is an extensible, customizable, free/libre text editor -- and more. At its core is an interpreter for [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]], a dialect of the Lisp programming language with extensions to support text editing. Other features include:
  814. + Highly customizable
  815. + Full Unicopde support
  816. + Content-aware editing modes
  817. + Complete built-in documentation
  818. + Wide range of functionality beyond text editing
  819. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  820. # <<file-warning>>
  821. # <<home-manager-warning>>
  822. { pkgs, ... }:
  823. let
  824. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  825. config = ../README.org;
  826. package = <<emacs-native-comp-package>>
  827. alwaysEnsure = true;
  828. alwaysTangle = true;
  829. extraEmacsPackages = epkgs: [
  830. # Required packages...
  831. <<emacs-exwm-package>>
  832. <<emacs-evil-package>>
  833. <<emacs-general-package>>
  834. <<emacs-which-key-package>>
  835. # Optional packages.
  836. <<emacs-org-package>>
  837. <<emacs-org-roam-package>>
  838. <<emacs-org-roam-ui-package>>
  839. <<emacs-org-drill-package>>
  840. <<emacs-pomodoro-package>>
  841. <<emacs-writegood-package>>
  842. <<emacs-http-package>>
  843. <<emacs-hugo-package>>
  844. <<emacs-pass-package>>
  845. <<emacs-docker-package>>
  846. <<emacs-mu4e-package>>
  847. <<emacs-dired-package>>
  848. <<emacs-icons-package>>
  849. <<emacs-emoji-package>>
  850. <<emacs-eshell-package>>
  851. <<emacs-vterm-package>>
  852. <<emacs-magit-package>>
  853. <<emacs-hydra-package>>
  854. <<emacs-elfeed-package>>
  855. <<emacs-nix-mode-package>>
  856. <<emacs-projectile-package>>
  857. <<emacs-lsp-package>>
  858. <<emacs-company-package>>
  859. <<emacs-ccls-package>>
  860. <<emacs-golang-package>>
  861. <<emacs-python-package>>
  862. <<emacs-rustic-package>>
  863. <<emacs-plantuml-package>>
  864. <<emacs-protobuf-package>>
  865. # User interface packages.
  866. <<emacs-swiper-package>>
  867. <<emacs-desktop-package>>
  868. <<emacs-doom-themes-package>>
  869. <<emacs-doom-modeline-package>>
  870. ];
  871. };
  872. in {
  873. home.packages = [
  874. <<emacs-exwm-extras>>
  875. <<emacs-pass-extras>>
  876. <<emacs-mu4e-extras>>
  877. <<emacs-aspell-extras>>
  878. <<emacs-texlive-extras>>
  879. <<emacs-desktop-extras>>
  880. <<emacs-plantuml-extras>>
  881. <<emacs-nix-mode-extras>>
  882. <<emacs-doom-themes-extras>>
  883. ];
  884. programs.emacs = {
  885. enable = true;
  886. package = myEmacs;
  887. };
  888. <<emacs-exwm-config>>
  889. <<emacs-exwm-xinitrc>>
  890. <<emacs-mu4e-config>>
  891. }
  892. #+END_SRC
  893. When Emacs is started, it normally tries to load a Lisp program from an ititialization file, or /init/ file. This file, if it exists, specifies how to initialize and configure Emacs.
  894. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  895. ;; <<file-warning>>
  896. ;; Required inputs.
  897. <<emacs-exwm-elisp>>
  898. <<emacs-evil-elisp>>
  899. <<emacs-general-elisp>>
  900. <<emacs-which-key-elisp>>
  901. ;; Optional inputs.
  902. <<emacs-org-elisp>>
  903. <<emacs-org-roam-elisp>>
  904. <<emacs-org-roam-ui-elisp>>
  905. <<emacs-org-drill-elisp>>
  906. <<emacs-org-agenda-elisp>>
  907. <<emacs-pomodoro-elisp>>
  908. <<emacs-writegood-elisp>>
  909. <<emacs-aspell-elisp>>
  910. <<emacs-eww-elisp>>
  911. <<emacs-http-elisp>>
  912. <<emacs-hugo-elisp>>
  913. <<emacs-pass-elisp>>
  914. <<emacs-docker-elisp>>
  915. <<emacs-erc-elisp>>
  916. <<emacs-mu4e-elisp>>
  917. <<emacs-dired-elisp>>
  918. <<emacs-icons-elisp>>
  919. <<emacs-emoji-elisp>>
  920. <<emacs-eshell-elisp>>
  921. <<emacs-vterm-elisp>>
  922. <<emacs-magit-elisp>>
  923. <<emacs-fonts-elisp>>
  924. <<emacs-frames-elisp>>
  925. <<emacs-elfeed-elisp>>
  926. <<emacs-projectile-elisp>>
  927. <<emacs-lsp-elisp>>
  928. <<emacs-company-elisp>>
  929. <<emacs-golang-elisp>>
  930. <<emacs-python-elisp>>
  931. <<emacs-rustic-elisp>>
  932. <<emacs-plantuml-elisp>>
  933. <<emacs-desktop-elisp>>
  934. ;; User interface.
  935. <<emacs-swiper-elisp>>
  936. <<emacs-transparency-elisp>>
  937. <<emacs-doom-themes-elisp>>
  938. <<emacs-doom-modeline-elisp>>
  939. #+END_SRC
  940. It's somtimes desirable to have customization that takes effect during Emacs startup earlier than the normal init file. Place these configurations in =~/.emacs.d/early-init.el=. Most customizations should be put in the normal init file =~/.emacs.d/init.el=.
  941. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  942. ;; <<file-warning>>
  943. <<emacs-disable-ui-elisp>>
  944. <<emacs-native-comp-elisp>>
  945. <<emacs-backup-files-elisp>>
  946. <<emacs-shell-commands-elisp>>
  947. <<emacs-improved-prompts>>
  948. #+END_SRC
  949. ** Native Comp
  950. #+NAME: emacs-native-comp-package
  951. #+BEGIN_SRC nix
  952. pkgs.emacsGcc;
  953. #+END_SRC
  954. Native Comp, also known as GccEmacs, refers to the ~--with-native-compilation~ configuration option when building [[https://gnu.org/software/emacs/][GNU/Emacs]]. It adds support for compiling [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]] to native code using ~libgccjit~. All of the Emacs Lisp packages shipped with Emacs are native-compiled, providing a noticable performance iomprovement out-of-the-box.
  955. #+NAME: emacs-native-comp-elisp
  956. #+BEGIN_SRC emacs-lisp
  957. ;; Silence warnings from packages that don't support `native-comp'.
  958. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  959. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  960. #+END_SRC
  961. ** Disable UI
  962. [[https://gnu.org/software/emacs/][Emacs]] has been around since the 1980s, and it's painfully obvious when you're greeted with the default user interface. Disable some unwanted features to clean it up, and bring the appearance to something closer to a modern editor.
  963. #+NAME: emacs-disable-ui-elisp
  964. #+BEGIN_SRC emacs-lisp
  965. ;; Disable unwanted UI elements.
  966. (tooltip-mode -1)
  967. (menu-bar-mode -1)
  968. (tool-bar-mode -1)
  969. (scroll-bar-mode -1)
  970. ;; Fix the scrolling behaviour.
  971. (setq scroll-conservatively 101)
  972. ;; Fix mouse-wheel scrolling behaviour.
  973. (setq mouse-wheel-follow-mouse t
  974. mouse-wheel-progressive-speed t
  975. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  976. ;; Start in fullscreen/maximized.
  977. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  978. #+END_SRC
  979. ** Backup Files
  980. [[https://gnu.org/software/emacs/][Emacs]] makes a backup for a file only the first time the file is saved from a buffer. No matter how many times the file is subsequently written to, the backup remains unchanged. For files managed by a version control system, backup files are redundant since the previous versions are already stored.
  981. #+NAME: emacs-backup-files-elisp
  982. #+BEGIN_SRC emacs-lisp
  983. ;; Disable unwanted features.
  984. (setq make-backup-files nil
  985. create-lockfiles nil)
  986. #+END_SRC
  987. ** Shell Commands
  988. Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
  989. 1) Method to run an external process, launching any application on a new process without interference
  990. 2) Method to apply commands to the current call process, effecting the running instance
  991. #+NAME: emacs-shell-commands-elisp
  992. #+BEGIN_SRC emacs-lisp
  993. ;; Define a method to run an external process.
  994. (defun dotfiles/run (cmd)
  995. "Run an external process."
  996. (interactive (list (read-shell-command "λ ")))
  997. (start-process-shell-command cmd nil cmd))
  998. ;; Define a method to run a background process.
  999. (defun dotfiles/run-in-background (cmd)
  1000. (let ((command-parts (split-string cmd "[ ]+")))
  1001. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  1002. #+END_SRC
  1003. ** Improved prompts
  1004. By default Emacs will ask you to enter 'Yes' or 'No' instead of 'Y' or 'N'. This is a relatively conservative design decision, based on the fact that certain prompts may be important enough to warrant typing three characters.
  1005. #+NAME: emacs-improved-prompts
  1006. #+BEGIN_SRC emacs-lisp
  1007. ;; Use 'y' and 'n' instead of 'yes' and 'no'.
  1008. (defalias 'yes-or-no-p 'y-or-n-p)
  1009. #+END_SRC
  1010. ** Nix Mode
  1011. #+NAME: emacs-nix-mode-extras
  1012. #+BEGIN_SRC nix
  1013. pkgs.nixfmt
  1014. pkgs.rnix-lsp
  1015. #+END_SRC
  1016. [[https://github.com/nixos/nix-mode][Nix Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] major mode for editing [[https://nixos.org/manual/nix/stable/][Nix]] expressions. This provides basic handling of =.nix= files. Syntax highlighting and indentation support using =SMIE= are provided. [[https:github.com/nix-community/rnix-lsp][rnix-lsp]] is a work-in-progress language server for Nix with syntax checking and basic completion.
  1017. #+NAME: emacs-nix-mode-package
  1018. #+BEGIN_SRC nix
  1019. epkgs.nix-mode
  1020. #+END_SRC
  1021. ** Evil Mode
  1022. [[https://evil.readthedocs.io/en/latest/overview.html][Evil Mode]] is an extensible VI layer for [[https://gnu.org/software/emacs/][GNU/Emacs]]. It emulates the main features of [[https://neovim.io][Vim]], transforming GNU/Emacs into a modal editor.
  1023. #+NAME: emacs-evil-package
  1024. #+BEGIN_SRC nix
  1025. epkgs.evil
  1026. epkgs.evil-collection
  1027. epkgs.evil-surround
  1028. epkgs.evil-nerd-commenter
  1029. #+END_SRC
  1030. The next time [[https://gnu.org/software/emacs/][Emacs]] is started, it will come up in /normal state/, denoted by =<N>= in the modeline. This is where the main ~vi~ bindings are defined. Like Emacs in general, [[https://evil.readthedocs.io/en/latest/overview.html][Evil Mode]] is extensible in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]].
  1031. #+NAME: emacs-evil-elisp
  1032. #+BEGIN_SRC emacs-lisp
  1033. ;; Enable the Extensible VI Layer for Emacs.
  1034. (setq evil-want-integration t ;; Required for `evil-collection.'
  1035. evil-want-keybinding nil ;; Same as above.
  1036. evil-want-C-i-jump nil) ;; Disable jumping in terminal.
  1037. (evil-mode +1)
  1038. ;; Configure `evil-collection'.
  1039. (evil-collection-init)
  1040. ;; Configure `evil-surround'.
  1041. (global-evil-surround-mode +1)
  1042. ;; Configure `evil-nerd-commenter'.
  1043. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1044. ;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
  1045. (evil-define-key 'normal 'org-mode-map (kbd "<tab>") #'org-cycle)
  1046. #+END_SRC
  1047. ** EXWM
  1048. #+NAME: emacs-exwm-package
  1049. #+BEGIN_SRC nix
  1050. epkgs.exwm
  1051. #+END_SRC
  1052. [[https://github.com/ch11ng/exwm][EXWM]] (Emacs X Window Manager) is a full-featured tiling [[https://x.org/wiki/][X11]] window manager for [[https://gnu.org/software/emacs/][GNU/Emacs]] built on-top of XELB. It features:
  1053. + Fully keyboard-driven operations
  1054. + Hybrid layout modes (tiling & stacking)
  1055. + Dynamic workspace support
  1056. + ICCM/EWMH compliance
  1057. #+NAME: emacs-exwm-extras
  1058. #+BEGIN_SRC nix
  1059. pkgs.nitrogen
  1060. pkgs.autorandr
  1061. #+END_SRC
  1062. I wanted to leave ~(exwm-enable)~ out of my Emacs configuration (which does no harm anyways). This can be called when using the daemon to start [[https://github.com/ch11ng/exwm][EXWM]].
  1063. #+NAME: emacs-exwm-config
  1064. #+BEGIN_SRC nix
  1065. xsession = {
  1066. enable = true;
  1067. windowManager.command = ''
  1068. ${pkgs.nitrogen}/bin/nitrogen --restore
  1069. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1070. ${myEmacs}/bin/emacsclient -c
  1071. '';
  1072. };
  1073. #+END_SRC
  1074. [[https://github.com/ch11ng/exwm][EXWM]] cannot make an [[https://x.org/wiki/][X]] window manager by itself, this is by design; You must tell X to do it. Override the =~/.xinitrc= file to start the =xsession=.
  1075. #+NAME: emacs-exwm-xinitrc
  1076. #+BEGIN_SRC nix
  1077. home.file.".xinitrc" = {
  1078. text = ''
  1079. exec ./.xsession
  1080. '';
  1081. };
  1082. #+END_SRC
  1083. #+NAME: emacs-exwm-elisp
  1084. #+BEGIN_SRC emacs-lisp
  1085. ;; Configure `exwm'.
  1086. (setq exwm-workspace-number 5
  1087. exwm-layout-show-all-buffers t
  1088. exwm-worspace-show-all-buffers t)
  1089. ;; Configure input keys.
  1090. (setq exwm-input-prefix-keys
  1091. '(?\M-x
  1092. ?\C-g
  1093. ?\C-\ ))
  1094. (setq exwm-input-global-keys
  1095. `(([?\s-r] . exwm-reset)
  1096. ,@(mapcar (lambda (i)
  1097. `(,(kbd (format "s-%d" i)) .
  1098. (lambda ()
  1099. (interactive)
  1100. (exwm-workspace-switch-create ,i))))
  1101. (number-sequence 0 9))))
  1102. ;; Configure `exwm-randr'.
  1103. (require 'exwm-randr)
  1104. (exwm-randr-enable)
  1105. ;; Configure custom hooks.
  1106. (setq display-time-day-and-date t)
  1107. (add-hook 'exwm-init-hook
  1108. (lambda ()
  1109. (display-battery-mode +1) ;; Display battery info (if available).
  1110. (display-time-mode +1))) ;; Display the time in the modeline.
  1111. ;; Setup buffer display names.
  1112. (add-hook 'exwm-update-class-hook
  1113. (lambda ()
  1114. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1115. ;; Configure monitor hot-swapping.
  1116. (add-hook 'exwm-randr-screen-change-hook
  1117. (lambda ()
  1118. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1119. #+END_SRC
  1120. ** General
  1121. #+NAME: emacs-general-package
  1122. #+BEGIN_SRC nix
  1123. epkgs.general
  1124. #+END_SRC
  1125. [[https://github.com/noctuid/general.el][General.el]] provides a more convenient method for binding keys in [[https://gnu.org/software/emacs/][Emacs]], providing a unified interface for key definitions. Its primary purpose is to build on /existing/ functionality to make key definitions more clear and concise.
  1126. #+NAME: emacs-general-elisp
  1127. #+BEGIN_SRC emacs-lisp
  1128. ;; Use <SPC> as a leader key via `general.el'.
  1129. (general-create-definer dotfiles/leader
  1130. :keymaps '(normal insert visual emacs)
  1131. :prefix "SPC"
  1132. :global-prefix "C-SPC")
  1133. ;; Setup general to work with `evil-mode'.
  1134. (setq general-evil-setup t)
  1135. ;; Find files with <SPC> <period> ...
  1136. ;; Switch buffers with <SPC> <comma> ...
  1137. (dotfiles/leader
  1138. "." '(find-file :which-key "File")
  1139. "," '(switch-to-buffer :which-key "Buffer")
  1140. "k" '(kill-buffer :which-key "Kill")
  1141. "c" '(kill-buffer-and-window :which-key "Close"))
  1142. ;; Add keybindings for executing shell commands.
  1143. (dotfiles/leader
  1144. "r" '(:ignore t :which-key "Run")
  1145. "rr" '(dotfiles/run :which-key "Run")
  1146. "ra" '(async-shell-command :which-key "Async"))
  1147. ;; Add keybindings for quitting Emacs.
  1148. (dotfiles/leader
  1149. "q" '(:ignore t :which-key "Quit")
  1150. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1151. "qw" '(kill-emacs :which-key "Now")
  1152. "qf" '(delete-frame :which-key "Frame"))
  1153. ;; Add keybindings for toggles / tweaks.
  1154. (dotfiles/leader
  1155. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1156. #+END_SRC
  1157. ** Which Key
  1158. [[https://github.com/justbur/emacs-which-key][Which Key]] is an [[https://gnu.org/software/emacs/][Emacs]] minor mode that displays the key bindings following your currently entered incomplete command (prefix) in a popup or mini-buffer.
  1159. #+NAME: emacs-which-key-package
  1160. #+BEGIN_SRC nix
  1161. epkgs.which-key
  1162. #+END_SRC
  1163. #+NAME: emacs-which-key-elisp
  1164. #+BEGIN_SRC emacs-lisp
  1165. ;; Configure `which-key' to see keyboard bindings in the
  1166. ;; mini-buffer and when using M-x.
  1167. (setq which-key-idle-delay 0.0)
  1168. (which-key-mode +1)
  1169. #+END_SRC
  1170. ** EWW
  1171. [[https://emacswiki.org/emacs/eww][Emacs Web Wowser (EWW)]] is a Web browser written in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]] based on the ~shr.el~ library. It's my primary browser when it comes to text-based browsing.
  1172. + Use ~eww~ as the default browser
  1173. + Don't use any special fonts or colours
  1174. #+NAME: emacs-eww-elisp
  1175. #+BEGIN_SRC emacs-lisp
  1176. ;; Set `eww' as the default browser.
  1177. (setq browse-url-browser-function 'eww-browse-url)
  1178. ;; Configure the `shr' rendering engine.
  1179. (setq shr-use-fonts nil
  1180. shr-use-colors nil)
  1181. #+END_SRC
  1182. ** ERC
  1183. [[https://gnu.org/software/emacs/erc.html][ERC]] is a powerful, modular, and extensible IRC client for [[https://gnu.org/software/emacs/][GNU/Emacs]]. It's part of the GNU project, and included in Emacs.
  1184. #+NAME: emacs-erc-elisp
  1185. #+BEGIN_SRC emacs-lisp
  1186. ;; Configure `erc'.
  1187. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
  1188. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1189. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1190. ;; Configure `erc-fill-column'.
  1191. (add-hook 'window-configuration-change-hook
  1192. '(lambda ()
  1193. (setq erc-fill-column (- (window-width) 12))))
  1194. ;; Connect to IRC via `erc'.
  1195. (defun dotfiles/erc-connect ()
  1196. "Connected to IRC via `erc'."
  1197. (interactive)
  1198. (erc-tls :server "irc.libera.chat"
  1199. :port 6697
  1200. :nick "megaphone"
  1201. :password (password-store-get "megaphone@libera.chat")
  1202. :full-name "Chris Hayward"))
  1203. ;; Configure keybindings.
  1204. (dotfiles/leader
  1205. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1206. #+END_SRC
  1207. ** Dired
  1208. #+NAME: emacs-dired-package
  1209. #+BEGIN_SRC nix
  1210. epkgs.dired-single
  1211. #+END_SRC
  1212. [[https://emacswiki.org/emacs/DiredMode][Dired Mode]] shows a directory listing inside of an [[https://gnu.org/software/emacs/][Emacs]] buffer that can be used to perform various file operations on files and subdirectories. The operations you can perform are numerous, from creating subdirectories, byte-compiling files, searching, and editing files. [[https://emacswiki.org/emacs/DiredExtra#Dired_X][Dired Extra]] provides extra functionality.
  1213. #+NAME: emacs-dired-elisp
  1214. #+BEGIN_SRC emacs-lisp
  1215. ;; Include `dired-x' for the `jump' method.
  1216. (require 'dired-x)
  1217. ;; Configure `dired-single' to support `evil' keys.
  1218. (evil-collection-define-key 'normal 'dired-mode-map
  1219. "h" 'dired-single-up-directory
  1220. "l" 'dired-single-buffer)
  1221. ;; Configure keybindings for `dired'.
  1222. (dotfiles/leader
  1223. "d" '(dired-jump :which-key "Dired"))
  1224. #+END_SRC
  1225. ** Icons
  1226. #+NAME: emacs-icons-package
  1227. #+BEGIN_SRC nix
  1228. epkgs.all-the-icons
  1229. epkgs.all-the-icons-dired
  1230. epkgs.all-the-icons-ivy-rich
  1231. #+END_SRC
  1232. [[https://github.com/domtronn/all-the-icons.el][All The Icons]] is a utility package to collect various Icon Fonts and prioritize them within [[https://gnu.org/software/emacs/][GNU/Emacs]].
  1233. #+NAME: emacs-icons-elisp
  1234. #+BEGIN_SRC emacs-lisp
  1235. ;; Setup `all-the-icons-dired'.
  1236. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1237. ;; Disable monochrome icons.
  1238. (setq all-the-icons-dired-monochrome nil)
  1239. ;; Display default font ligatures.
  1240. (global-prettify-symbols-mode +1)
  1241. #+END_SRC
  1242. ** Emojis
  1243. #+NAME: emacs-emoji-package
  1244. #+BEGIN_SRC nix
  1245. epkgs.emojify
  1246. #+END_SRC
  1247. [[https://github.com/iqbalansari/emacs-emojify][Emojify]] is an [[https://gnu.org/software/emacs/][Emacs]] extension to display Emojis. It can display GitHub style Emojis like :smile: or plain ascii ones such as :). It tries to be as efficient as possible, while also providing flexibility.
  1248. #+NAME: emacs-emoji-elisp
  1249. #+BEGIN_SRC emacs-lisp
  1250. ;; Setup `emojify'.
  1251. (add-hook 'after-init-hook 'global-emojify-mode)
  1252. #+END_SRC
  1253. ** EShell
  1254. #+NAME: emacs-eshell-package
  1255. #+BEGIN_SRC nix
  1256. epkgs.eshell-prompt-extras
  1257. #+END_SRC
  1258. [[https://gnu.org/software/emacs/manual/html_mono/eshell.html][EShell]] is a shell-like command interpreter for [[https://gnu.org/software/emacs/][GNU/Emacs]] implemented in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]]. It invokes no external processes except for those requested by the user. It's intended to be an alternative for IELM, and a full REPL envionment for Emacs.
  1259. #+NAME: emacs-eshell-elisp
  1260. #+BEGIN_SRC emacs-lisp
  1261. ;; Configure `eshell'.
  1262. (setq eshell-highlight-prompt nil
  1263. eshell-prefer-lisp-functions nil)
  1264. ;; Configure the lambda prompt.
  1265. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1266. (setq eshell-prompt-function 'epe-theme-lambda)
  1267. ;; Configure keybindings for `eshell'.
  1268. (dotfiles/leader
  1269. "e" '(eshell :which-key "EShell"))
  1270. #+END_SRC
  1271. ** VTerm
  1272. [[https://github.com/akermu/emacs-libvterm][Emacs Libvterm (VTerm)]] is a fully-fledged terminal emulator inside [[https://gnu.org/software/emacs/][GNU/Emacs]] based on [[https://github.com/neovim/libvterm][Libvterm]], a blazing fast C library used in [[https://neovim.io][Neovim]]. As a result of using compiled code (instead of [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]]), VTerm is capable, fast, and it can seamlessly handle large outputs.
  1273. #+NAME: emacs-vterm-package
  1274. #+BEGIN_SRC nix
  1275. epkgs.vterm
  1276. #+END_SRC
  1277. #+NAME: emacs-vterm-elisp
  1278. #+BEGIN_SRC emacs-lisp
  1279. ;; Add keybindings for interacting with the shell(s).
  1280. (dotfiles/leader
  1281. "v" '(vterm :which-key "VTerm"))
  1282. #+END_SRC
  1283. ** Magit
  1284. [[https://magit.vc][Magit]] is an interface to the [[https://git-scm.com][Git]] version control system, implemented as a [[https://gnu.org/software/emacs/][GNU/Emacs]] package written in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]]. It fills the glaring gap between the Git command line interface and various GUIs, letting you perform trivial as well as elaborate version control tasks within a few mnemonic key presses.
  1285. #+NAME: emacs-magit-package
  1286. #+BEGIN_SRC nix
  1287. epkgs.magit
  1288. #+END_SRC
  1289. #+NAME: emacs-magit-elisp
  1290. #+BEGIN_SRC emacs-lisp
  1291. ;; Add keybindings for working with `magit'.
  1292. (dotfiles/leader
  1293. "g" '(:ignore t :which-key "Git")
  1294. "gg" '(magit-status :which-key "Status")
  1295. "gc" '(magit-clone :which-key "Clone")
  1296. "gf" '(magit-fetch :which-key "Fetch")
  1297. "gp" '(magit-pull :which-key "Pull"))
  1298. #+END_SRC
  1299. ** Hydra
  1300. #+NAME: emacs-hydra-package
  1301. #+BEGIN_SRC nix
  1302. epkgs.hydra
  1303. #+END_SRC
  1304. [[https://github.com/abo-abo/hydra][Hydra]] allows you to create keymaps for related commands, with the ability to easily repeat commands using a single keystroke.
  1305. ** Fonts
  1306. [[https://typeof.net/Iosevka][Iosevka]] is an open-source, sans-serif + slab-serif, monospace + quasi-proportional typeface family, designed for writing code, using in terminals, and preparing technical documents. Configure it as the default font face inside of [[https://gnu.org/software/emacs/][Emacs]] and define a [[https://github.com/abo-abo/hydra][Hydra]] command for quickly scaling text.
  1307. #+NAME: emacs-fonts-elisp
  1308. #+BEGIN_SRC emacs-lisp
  1309. ;; Configure the font when running as `emacs-server'.
  1310. (custom-set-faces
  1311. '(default ((t (:inherit nil :height 120 :family "Iosevka")))))
  1312. ;; Define a `hydra' function for scaling the text interactively.
  1313. (defhydra hydra-text-scale (:timeout 4)
  1314. "Scale the text in the current buffer."
  1315. ("k" text-scale-decrease "Decrease")
  1316. ("j" text-scale-increase "Increase")
  1317. ("f" nil "Finished" :exit t))
  1318. ;; Create keybinding for calling the function.
  1319. (dotfiles/leader
  1320. "tf" '(hydra-text-scale/body :which-key "Font"))
  1321. #+END_SRC
  1322. ** Frames
  1323. Sometimes it's useful to resize the current frame without using the mouse (always). The default behaviour when calling ~shrink-window~ and ~enlarge-window~ only changes the size by a small margin. I solved this problem with the same method used for scaling text:
  1324. #+NAME: emacs-frames-elisp
  1325. #+BEGIN_SRC emacs-lisp
  1326. ;; Define a `hydra' function for resizing the current frame.
  1327. (defhydra hydra-resize-frame (:timeout 4)
  1328. "Scale the current frame."
  1329. ("h" shrink-window-horizontally "Left")
  1330. ("j" enlarge-window "Down")
  1331. ("k" shrink-window "Up")
  1332. ("l" enlarge-window-horizontally "Right")
  1333. ("f" nil "Finished" :exit t))
  1334. ;; Add keybindings for working with frames to replace
  1335. ;; the C-x <num> <num> method of bindings, which is awful.
  1336. (dotfiles/leader
  1337. "w" '(:ignore t :which-key "Windows")
  1338. "ww" '(window-swap-states :which-key "Swap")
  1339. "wc" '(delete-window :which-key "Close")
  1340. "wh" '(windmove-left :which-key "Left")
  1341. "wj" '(windmove-down :which-key "Down")
  1342. "wk" '(windmove-up :which-key "Up")
  1343. "wl" '(windmove-right :which-key "Right")
  1344. "ws" '(:ignore t :which-key "Split")
  1345. "wsj" '(split-window-below :which-key "Below")
  1346. "wsl" '(split-window-right :which-key "Right")
  1347. "wr" '(hydra-resize-frame/body :which-key "Resize"))
  1348. #+END_SRC
  1349. ** Elfeed
  1350. #+NAME: emacs-elfeed-package
  1351. #+BEGIN_SRC nix
  1352. epkgs.elfeed
  1353. #+END_SRC
  1354. [[https://github.com/skeeto/elfeed][Elfeed]] is an extensible web feed reader for [[https://gnu.org/software/emacs/][GNU/Emacs]], support both =Atom= and =RSS=. It requires =Emacs 24.3+= and is available for download from the standard repositories.
  1355. #+NAME: emacs-elfeed-elisp
  1356. #+BEGIN_SRC emacs-lisp
  1357. ;; Configure `elfeed'.
  1358. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1359. ;; Add custom feeds for `elfeed' to fetch.
  1360. (setq elfeed-feeds (quote
  1361. (("https://hexdsl.co.uk/rss.xml")
  1362. ("https://lukesmith.xyz/rss.xml")
  1363. ("https://friendo.monster/rss.xml")
  1364. ("https://chrishayward.xyz/index.xml")
  1365. ("https://protesilaos.com/master.xml"))))
  1366. ;; Add custom keybindings for `elfeed'.
  1367. (dotfiles/leader
  1368. "f" '(:ignore t :which-key "Elfeed")
  1369. "fl" '(elfeed :which-key "Open")
  1370. "fu" '(elfeed-update :which-key "Update"))
  1371. #+END_SRC
  1372. ** Org Mode
  1373. #+NAME: emacs-org-package
  1374. #+BEGIN_SRC nix
  1375. epkgs.org
  1376. #+END_SRC
  1377. [[https://orgmode.org][Org Mode]] is a document editing and organizing mode, designed for notes, planning, and authoring within the free software text editor [[https://gnu.org/software/emacs/][GNU/Emacs]]. The name is used to encompass plain text files (such as this one) that include simple marks to indicate levels of a hierarchy, and an editor with functions that can read the markup and manipulate the hierarchy elements.
  1378. #+NAME: emacs-org-elisp
  1379. #+BEGIN_SRC emacs-lisp
  1380. ;; Configure `org-mode' source blocks.
  1381. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1382. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1383. org-hide-emphasis-markers t ;; Don't show emphasis markup.
  1384. org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
  1385. org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
  1386. ;; Add an `org-mode-hook'.
  1387. (add-hook 'org-mode-hook
  1388. (lambda ()
  1389. (org-indent-mode)
  1390. (visual-line-mode)))
  1391. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1392. (setq org-export-html-validation-link nil
  1393. org-html-validation-link nil)
  1394. ;; Configure the keywords in the TODO -> DONE sequence.
  1395. (setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  1396. ;; Track ids globally.
  1397. (setq org-id-track-globally t)
  1398. ;; Configure `org-babel' languages.
  1399. (org-babel-do-load-languages
  1400. 'org-babel-load-languages
  1401. '((C . t)))
  1402. ;; Log / Clock into property drawers.
  1403. (setq org-log-into-drawer t
  1404. org-clock-into-drawer t)
  1405. ;; Encrypt files with the public key.
  1406. (setq epa-file-select-keys 2
  1407. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1408. epa-cache-passphrase-for-symmetric-encryption t)
  1409. ;; TODO: Configure default structure templates.
  1410. ;; (require 'org-tempo)
  1411. ;; Apply custom keybindings.
  1412. (dotfiles/leader
  1413. "o" '(:ignore t :which-key "Org")
  1414. "oe" '(org-export-dispatch :which-key "Export")
  1415. "ot" '(org-babel-tangle :which-key "Tangle")
  1416. "oi" '(org-toggle-inline-images :which-key "Images")
  1417. "of" '(:ignore t :which-key "Footnotes")
  1418. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1419. #+END_SRC
  1420. ** Org Roam
  1421. #+NAME: emacs-org-roam-package
  1422. #+BEGIN_SRC nix
  1423. epkgs.org-roam
  1424. #+END_SRC
  1425. [[https://github.com/org-roam/org-roam][Org Roam]] is a plain-text knowledge management system. It borrows principles from the [[https://zettelkasten.de][Zettelkasten]] method, providing a solution for non-hierarchical note-taking. It should also work as a plug-and-play solution for anyone already using [[https://orgmode.org][Org Mode]] for their personal wiki.
  1426. #+NAME: emacs-org-roam-elisp
  1427. #+BEGIN_SRC emacs-lisp
  1428. ;; Setup `org-roam'.
  1429. (require 'org-roam)
  1430. ;; Silence the migration warnings.
  1431. (setq org-roam-v2-ack t)
  1432. ;; Enable `visual-line-mode' in `org-roam' buffer.
  1433. (add-hook 'org-roam-mode-hook
  1434. (lambda ()
  1435. (visual-line-mode +1)))
  1436. ;; Enable completion everywhere.
  1437. (setq org-roam-completion-everywhere t)
  1438. ;; Set the roam directories.
  1439. (setq org-roam-directory (expand-file-name "/etc/dotfiles")
  1440. org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
  1441. ;; Clear the deafult capture templates.
  1442. (setq org-roam-capture-templates '()
  1443. org-roam-dailies-capture-templates '())
  1444. ;; Override the default slug method.
  1445. (cl-defmethod org-roam-node-slug ((node org-roam-node))
  1446. (let ((title (org-roam-node-title node))
  1447. (slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
  1448. 769 ; U+0301 COMBINING ACUTE ACCENT
  1449. 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
  1450. 771 ; U+0303 COMBINING TILDE
  1451. 772 ; U+0304 COMBINING MACRON
  1452. 774 ; U+0306 COMBINING BREVE
  1453. 775 ; U+0307 COMBINING DOT ABOVE
  1454. 776 ; U+0308 COMBINING DIAERESIS
  1455. 777 ; U+0309 COMBINING HOOK ABOVE
  1456. 778 ; U+030A COMBINING RING ABOVE
  1457. 780 ; U+030C COMBINING CARON
  1458. 795 ; U+031B COMBINING HORN
  1459. 803 ; U+0323 COMBINING DOT BELOW
  1460. 804 ; U+0324 COMBINING DIAERESIS BELOW
  1461. 805 ; U+0325 COMBINING RING BELOW
  1462. 807 ; U+0327 COMBINING CEDILLA
  1463. 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
  1464. 814 ; U+032E COMBINING BREVE BELOW
  1465. 816 ; U+0330 COMBINING TILDE BELOW
  1466. 817 ; U+0331 COMBINING MACRON BELOW
  1467. )))
  1468. (cl-flet* ((nonspacing-mark-p (char)
  1469. (memq char slug-trim-chars))
  1470. (strip-nonspacing-marks (s)
  1471. (ucs-normalize-NFC-string
  1472. (apply #'string (seq-remove #'nonspacing-mark-p
  1473. (ucs-normalize-NFD-string s)))))
  1474. (cl-replace (title pair)
  1475. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1476. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
  1477. ("--*" . "-")
  1478. ("^-" . "")
  1479. ("-$" . "")))
  1480. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1481. (downcase slug)))))
  1482. ;; Configure capture templates.
  1483. ;; Standard document.
  1484. (add-to-list 'org-roam-capture-templates
  1485. '("d" "Default" plain "%?"
  1486. :target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
  1487. "
  1488. ,#+TITLE: ${title}
  1489. ,#+AUTHOR: Christopher James Hayward
  1490. ,#+EMAIL: chris@chrishayward.xyz
  1491. "
  1492. )
  1493. :unnarrowed t))
  1494. ;; Daily notes.
  1495. (add-to-list 'org-roam-dailies-capture-templates
  1496. '("d" "Default" entry "* %?"
  1497. :target (file+head "%<%Y-%m-%d>.org.gpg"
  1498. "
  1499. ,#+TITLE: %<%Y-%m-%d>
  1500. ,#+AUTHOR: Christopher James Hayward
  1501. ,#+EMAIL: chris@chrishayward.xyz
  1502. ")))
  1503. ;; Apply custom keybindings.
  1504. (dotfiles/leader
  1505. "or" '(:ignore t :which-key "Roam")
  1506. "ori" '(org-roam-node-insert :which-key "Insert")
  1507. "orf" '(org-roam-node-find :which-key "Find")
  1508. "orc" '(org-roam-capture :which-key "Capture")
  1509. "orb" '(org-roam-buffer-toggle :which-key "Buffer"))
  1510. ;; Apply custom keybindings for dailies.
  1511. (dotfiles/leader
  1512. "ord" '(:ignore t :which-key "Dailies")
  1513. "ordd" '(org-roam-dailies-goto-date :which-key "Date")
  1514. "ordt" '(org-roam-dailies-goto-today :which-key "Today")
  1515. "ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
  1516. "ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
  1517. ;; Run the setup command.
  1518. (org-roam-setup)
  1519. #+END_SRC
  1520. ** Org Roam UI
  1521. #+NAME: emacs-org-roam-ui-package
  1522. #+BEGIN_SRC nix
  1523. epkgs.org-roam-ui
  1524. epkgs.websocket
  1525. epkgs.simple-httpd
  1526. #+END_SRC
  1527. [[https://github.com/org-roam/org-roam-ui][Org Roam UI]] is a graphical frontend for exploring your [[https://github.com/org-roam/org-roam][Org Roam]] [[https://zettelkasten.de][Zettelkasten]]. It's meant as a successor to [[https://github.com/org-roam/org-roam-server][Org Roam Server]] that extends functionality of Org Roam with a web application that runs side-by-side with [[https://gnu.org/software/emacs/][Emacs]].
  1528. #+NAME: emacs-org-roam-ui-elisp
  1529. #+BEGIN_SRC emacs-lisp
  1530. ;; HACK: Set up `org-roam-ui'.
  1531. ;; (add-to-list 'load-path "~/.local/source/org-roam-ui")
  1532. (load-library "org-roam-ui")
  1533. ;; Configure `org-roam-ui'.
  1534. (setq org-roam-ui-follow t
  1535. org-roam-ui-sync-theme t
  1536. org-roam-ui-open-on-start t
  1537. org-roam-ui-update-on-save t
  1538. org-roam-ui-browser-function #'browse-url-firefox)
  1539. ;; Configure keybindings.
  1540. (dotfiles/leader
  1541. "oru" '(:ignore t :which-key "UI")
  1542. "oruu" '(org-roam-ui-mode :which-key "Toggle UI")
  1543. "orut" '(orui-sync-theme :which-key "Sync Theme"))
  1544. #+END_SRC
  1545. ** Org Drill
  1546. #+NAME: emacs-org-drill-package
  1547. #+BEGIN_SRC nix
  1548. epkgs.org-drill
  1549. #+END_SRC
  1550. [[https://orgmode.org/worg/org-contrib/org-drill.html][Org Drill]] is an extension for [[https://orgmode.org][Org Mode]] that uses a spaced repition algorithm to conduct interactive /Drill Sessions/ using Org files as sources of facts to be memorized.
  1551. #+NAME: emacs-org-drill-elisp
  1552. #+BEGIN_SRC emacs-lisp
  1553. ;; Exclude :drill: items from `org-roam'.
  1554. (setq org-roam-db-node-include-function
  1555. (defun dotfiles/org-roam-include ()
  1556. (not (member "drill" (org-get-tags)))))
  1557. ;; Configure keybindings for `org-drill'.
  1558. (dotfiles/leader
  1559. "od" '(:ignore t :which-key "Drill")
  1560. "odd" '(org-drill :which-key "Drill")
  1561. "odc" '(org-drill-cram :which-key "Cram")
  1562. "odr" '(org-drill-resume :which-key "Resume"))
  1563. #+END_SRC
  1564. ** Org Agenda
  1565. The way [[https://orgmode.org][Org Mode]] works, TODO items, time-stamped items, and tagged headlines can be scattered throughout a file, or even a number of files. To get an overview of open action items, or of events that are important for a particular date, this information must be collected, sorted, and displayed in an organized way.
  1566. #+NAME: emacs-org-agenda-elisp
  1567. #+BEGIN_SRC emacs-lisp
  1568. ;; Configure `org-agenda' to use the project files.
  1569. (setq org-agenda-files '("/etc/dotfiles/"
  1570. "/etc/dotfiles/docs/"
  1571. "/etc/dotfiles/docs/daily/"))
  1572. ;; Include files encrypted with `gpg'.
  1573. (require 'org)
  1574. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1575. (setq org-agenda-file-regexp
  1576. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1577. org-agenda-file-regexp)))
  1578. ;; Open an agenda buffer with SPC o a.
  1579. (dotfiles/leader
  1580. "oa" '(org-agenda :which-key "Agenda"))
  1581. #+END_SRC
  1582. ** Org Pomodoro
  1583. #+NAME: emacs-pomodoro-package
  1584. #+BEGIN_SRC nix
  1585. epkgs.org-pomodoro
  1586. #+END_SRC
  1587. [[https://github.com/marcinkoziej/org-pomodoro][Org Pomodoro]] adds basic support for the [[https://en.wikipedia.org/wiki/Pomodoro_Technique][Pomodoro Technique]] in [[https://gnu.org/software/emacs/][GNU/Emacs]]. It can be started for the task at point, or the last task time was clocked for. Each session starts a timer of 25 minutes, finishing with a break of 5 minutes. After 4 sessions, ther will be a break of 20 minutes. All values are customizable.
  1588. #+NAME: emacs-pomodoro-elisp
  1589. #+BEGIN_SRC emacs-lisp
  1590. ;; Configure `org-pomodor' with the overtime workflow.
  1591. (setq org-pomodoro-manual-break t
  1592. org-pomodoro-keep-killed-time t)
  1593. ;; Configure keybindings.
  1594. (dotfiles/leader
  1595. "op" '(org-pomodoro :which-key "Pomodoro"))
  1596. #+END_SRC
  1597. ** Writegood Mode
  1598. #+NAME: emacs-writegood-package
  1599. #+BEGIN_SRC nix
  1600. epkgs.writegood-mode
  1601. #+END_SRC
  1602. [[https://github.com/bnbeckwith/writegood-mode][Writegood Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] minor mode to aid in finding common writing problems. It highlights the text based on the following criteria:
  1603. + Weasel Words
  1604. + Passive Voice
  1605. + Duplicate Words
  1606. #+NAME: emacs-writegood-elisp
  1607. #+BEGIN_SRC emacs-lisp
  1608. ;; Configure `writegood-mode'.
  1609. (dotfiles/leader
  1610. "tg" '(writegood-mode :which-key "Grammar"))
  1611. #+END_SRC
  1612. ** Aspell
  1613. #+NAME: emacs-aspell-extras
  1614. #+BEGIN_SRC nix
  1615. pkgs.aspell
  1616. pkgs.aspellDicts.en
  1617. pkgs.aspellDicts.en-science
  1618. pkgs.aspellDicts.en-computers
  1619. #+END_SRC
  1620. [[https://aspell.net][GNU Aspell]] is a Free and Open Source spell checker designed to replace ISpell. It can be used as a library, or an independent spell checker. Its main feature is that it does a superior job of suggesting possible replacements for mis-spelled words than any other spell checker for the English language.
  1621. #+NAME: emacs-aspell-elisp
  1622. #+BEGIN_SRC emacs-lisp
  1623. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1624. (setq ispell-program-name "aspell"
  1625. ispell-eextra-args '("--sug-mode=fast"))
  1626. ;; Configure the built-in `flyspell-mode'.
  1627. (dotfiles/leader
  1628. "ts" '(flyspell-mode :which-key "Spelling"))
  1629. #+END_SRC
  1630. ** TexLive
  1631. [[https://wikipedia.org/wiki/Tex_Live][TeX Live]] is a free software distributution for the TeX typesetting system that includes major TeX-related programs, macro packages, and fonts. Since TeX Live consists of /thousands/ of packages, to make managing it easier, NixOS replicates the organization of Tex Live into /schemes/ and /collections/:
  1632. | Name | Derivation | Comment |
  1633. |---------+---------------------------------+------------------------------------------------------------|
  1634. | Full | texlive.combined.scheme-full | Contains every TeX Live package |
  1635. | Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
  1636. | Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
  1637. | Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
  1638. | Minimal | texlive.combined.scheme-minimal | Contains plain only |
  1639. #+NAME: emacs-texlive-extras
  1640. #+BEGIN_SRC nix
  1641. # pkgs.texlive.combined.scheme-full
  1642. #+END_SRC
  1643. ** Http
  1644. #+NAME: emacs-http-package
  1645. #+BEGIN_SRC nix
  1646. epkgs.ob-http
  1647. #+END_SRC
  1648. It's possible to make HTTP requests from Org Mode buffers using [[https://github.com/zweifisch/ob-http][ob-http]], this relies on Org Babel (included with [[https://orgmode.org][Org Mode]]) being present and configured properly.
  1649. #+NAME: emacs-http-elisp
  1650. #+BEGIN_SRC emacs-lisp
  1651. ;; Required to setup `ob-http'.
  1652. (org-babel-do-load-languages
  1653. 'org-babel-load-languages
  1654. '((http . t)))
  1655. #+END_SRC
  1656. ** Hugo
  1657. #+NAME: emacs-hugo-package
  1658. #+BEGIN_SRC nix
  1659. epkgs.ox-hugo
  1660. #+END_SRC
  1661. [[https://oxhugo.scripter.co][Ox Hugo]] is an [[https://orgmode.org][Org Mode]] exporter for [[https://gohugo.io][Hugo]] compabile markdown. My dotfiles are a result of this, and are available to view here https://chrishayward.xyz/dotfiles/.
  1662. #+NAME: emacs-hugo-elisp
  1663. #+BEGIN_SRC emacs-lisp
  1664. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  1665. (require 'ox-hugo)
  1666. ;; Set up the base directory.
  1667. (setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
  1668. ;; Capture templates.
  1669. ;; Shared content
  1670. ;; (add-to-list 'org-roam-capture-templates
  1671. ;; '("p" "Post" plain "%?"
  1672. ;; :target (file+head "docs/posts/${slug}.org.gpg"
  1673. ;; "
  1674. ;; ,#+TITLE: ${title}
  1675. ;; ,#+AUTHOR: Christopher James Hayward
  1676. ;; ,#+DATE: %<%Y-%m-%d>
  1677. ;; ,#+EXPORT_FILE_NAME: ${slug}
  1678. ;; ,#+OPTIONS: num:nil todo:nil tasks:nil
  1679. ;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  1680. ;; ,#+HUGO_BASE_DIR: ../
  1681. ;; ,#+HUGO_AUTO_SET_LASTMOD: t
  1682. ;; ,#+HUGO_SECTION: posts
  1683. ;; ,#+HUGO_DRAFT: true
  1684. ;; "
  1685. ;; )
  1686. ;; :unnarrowed t))
  1687. #+END_SRC
  1688. ** Passwords
  1689. #+NAME: emacs-pass-extras
  1690. #+BEGIN_SRC nix
  1691. pkgs.pass
  1692. #+END_SRC
  1693. With [[https://password-store.org][Pass]], each password lives inside of an encrypted [[https://gnupg.org][GPG]] file, whose name is the title of the website or resource that requires the password. These encrypted files may be organized into meaningful folder hierarchies, compies from computer to computer, and in general, manipulated using standard command line tools.
  1694. #+NAME: emacs-pass-package
  1695. #+BEGIN_SRC nix
  1696. epkgs.password-store
  1697. #+END_SRC
  1698. Configure keybindings for passwords behind =SPC p=:
  1699. #+NAME: emacs-pass-elisp
  1700. #+BEGIN_SRC emacs-lisp
  1701. ;; Set the path to the password store.
  1702. (setq password-store-dir (expand-file-name "~/.password-store"))
  1703. ;; Apply custom keybindings.
  1704. (dotfiles/leader
  1705. "p" '(:ignore t :which-key "Passwords")
  1706. "pp" '(password-store-copy :which-key "Copy")
  1707. "pe" '(password-store-edit :which-key "Edit")
  1708. "pi" '(password-store-insert :which-key "Insert")
  1709. "pr" '(password-store-rename :which-key "Rename")
  1710. "pg" '(password-store-generate :which-key "Generate"))
  1711. #+END_SRC
  1712. ** Docker
  1713. #+NAME: emacs-docker-package
  1714. #+BEGIN_SRC nix
  1715. epkgs.docker
  1716. epkgs.dockerfile-mode
  1717. #+END_SRC
  1718. Manage Docker from inside of Emacs using [[https://github.com/Silex/docker.el][Docker.el]]. This is a full docker porcelain similar to Magit, allowing complete control of a Docker system. Add syntax highlighting to Dockerfiles using [[https://github.com/spotify/dockerfile-mode][dockerfile-mode]] from Spotify.
  1719. #+NAME: emacs-docker-elisp
  1720. #+BEGIN_SRC emacs-lisp
  1721. ;; Apply custom keybindings.
  1722. (dotfiles/leader
  1723. "n" '(:ignore t :which-key "Containers")
  1724. "nd" '(docker :which-key "Docker"))
  1725. #+END_SRC
  1726. ** MU4E
  1727. #+NAME: emacs-mu4e-extras
  1728. #+BEGIN_SRC nix
  1729. pkgs.mu
  1730. pkgs.isync
  1731. #+END_SRC
  1732. #+NAME: emacs-mu4e-package
  1733. #+BEGIN_SRC nix
  1734. epkgs.mu4e-alert
  1735. #+END_SRC
  1736. #+NAME: emacs-mu4e-config
  1737. #+BEGIN_SRC nix
  1738. # Deploy the authinfo file.
  1739. home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
  1740. # Deploy the isync configuration file.
  1741. home.file.".mbsyncrc" = {
  1742. text = ''
  1743. IMAPStore xyz-remote
  1744. Host mail.chrishayward.xyz
  1745. User chris@chrishayward.xyz
  1746. PassCmd "pass chrishayward.xyz/chris"
  1747. SSLType IMAPS
  1748. MaildirStore xyz-local
  1749. Path ~/.cache/mail/
  1750. Inbox ~/.cache/mail/inbox
  1751. SubFolders Verbatim
  1752. Channel xyz
  1753. Far :xyz-remote:
  1754. Near :xyz-local:
  1755. Patterns * !Archives
  1756. Create Both
  1757. Expunge Both
  1758. SyncState *
  1759. '';
  1760. };
  1761. #+END_SRC
  1762. #+BEGIN_SRC sh
  1763. mbsync -a
  1764. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  1765. mu index
  1766. #+END_SRC
  1767. #+NAME: emacs-mu4e-elisp
  1768. #+BEGIN_SRC emacs-lisp
  1769. ;; Add the `mu4e' shipped with `mu' to the load path.
  1770. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  1771. (require 'mu4e)
  1772. ;; Confiugure `mu4e'.
  1773. (setq mu4e-maildir "~/.cache/mail"
  1774. mu4e-update-interval (* 5 60)
  1775. mu4e-get-mail-command "mbsync -a"
  1776. mu4e-compose-format-flowed t
  1777. mu4e-change-filenames-when-moving t
  1778. mu4e-compose-signature (concat "Chris Hayward\n"
  1779. "chris@chrishayward.xyz"))
  1780. ;; Sign all outbound email with GPG.
  1781. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  1782. (setq message-send-mail-function 'smtpmail-send-it
  1783. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  1784. ;; Setup `mu4e' accounts.
  1785. (setq mu4e-contexts
  1786. (list
  1787. ;; Main
  1788. ;; chris@chrishayward.xyz
  1789. (make-mu4e-context
  1790. :name "Main"
  1791. :match-func
  1792. (lambda (msg)
  1793. (when msg
  1794. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  1795. :vars
  1796. '((user-full-name . "Christopher James Hayward")
  1797. (user-mail-address . "chris@chrishayward.xyz")
  1798. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  1799. (smtpmail-smtp-service . 587)
  1800. (smtpmail-stream-type . starttls)))))
  1801. ;; Setup `mu4e-alert'.
  1802. (setq mu4e-alert-set-default-style 'libnotify)
  1803. (mu4e-alert-enable-notifications)
  1804. (mu4e-alert-enable-mode-line-display)
  1805. ;; Open the `mu4e' dashboard.
  1806. (dotfiles/leader
  1807. "m" '(mu4e :which-key "Mail"))
  1808. #+END_SRC
  1809. ** Projectile
  1810. #+NAME: emacs-projectile-package
  1811. #+BEGIN_SRC nix
  1812. epkgs.projectile
  1813. #+END_SRC
  1814. [[https://projectile.mx][Projectile]] is a project interaction library for [[https://gnu.org/software/emacs/][GNU/Emacs]]. Its goal is to provide a nice set of features operating on a project level, without introducing external dependencies.
  1815. #+NAME: emacs-projectile-elisp
  1816. #+BEGIN_SRC emacs-lisp
  1817. ;; Configure the `projectile-project-search-path'.
  1818. (setq projectile-project-search-path '("~/.local/source"))
  1819. (projectile-mode +1)
  1820. #+END_SRC
  1821. ** LSP Mode
  1822. #+NAME: emacs-lsp-package
  1823. #+BEGIN_SRC nix
  1824. epkgs.lsp-mode
  1825. epkgs.lsp-ui
  1826. #+END_SRC
  1827. The [[https://microsoft.github.io/language-server-protocol][Language Server Protocol (LSP)]] defines the protocol used between an Editor or IDE, and a language server that provides features like:
  1828. + Auto Complete
  1829. + Go To Defintion
  1830. + Find All References
  1831. #+NAME: emacs-lsp-elisp
  1832. #+BEGIN_SRC emacs-lisp
  1833. ;; Configure `lsp-mode'.
  1834. (setq lsp-idle-delay 0.5
  1835. lsp-prefer-flymake t)
  1836. ;; Configure `lsp-ui'.
  1837. (setq lsp-ui-doc-position 'at-point
  1838. lsp-ui-doc-delay 0.5)
  1839. ;; Add custom keybindings for `lsp'.
  1840. (dotfiles/leader
  1841. "tl" '(lsp :which-key "LSP"))
  1842. #+END_SRC
  1843. ** CCLS
  1844. #+NAME: emacs-ccls-package
  1845. #+BEGIN_SRC nix
  1846. epkgs.ccls
  1847. #+END_SRC
  1848. [[https://github.com/MaskRay/emacs-ccls][Emacs CCLS]] is a client for CCLS, a C/C++/Objective-C language server supporting multi-million line C++ code bases, powered by libclang.
  1849. #+NAME: emacs-ccls-elisp
  1850. #+BEGIN_SRC emacs-lisp
  1851. ;; Configure `ccls' to work with `lsp-mode'.
  1852. (defun dotfiles/ccls-hook ()
  1853. (require 'ccls)
  1854. (lsp))
  1855. ;; Configure `ccls' mode hooks.
  1856. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  1857. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  1858. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  1859. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  1860. #+END_SRC
  1861. ** Company Mode
  1862. #+NAME: emacs-company-package
  1863. #+BEGIN_SRC nix
  1864. epkgs.company
  1865. #+END_SRC
  1866. [[https://company-mode.github.io][Company Mode]] is a text completion framework for [[https://gnu.org/software/emacs/][GNU/Emacs]]. The name stands for =Complete Anything=. It uses pluggable back-ends and front-ends to retieve and display completion candidates.
  1867. #+NAME: emacs-company-elisp
  1868. #+BEGIN_SRC emacs-lisp
  1869. ;; Configure `company-mode'.
  1870. (setq company-backend 'company-capf
  1871. lsp-completion-provider :capf)
  1872. ;; Enable it globally.
  1873. (global-company-mode +1)
  1874. #+END_SRC
  1875. ** Go Mode
  1876. #+NAME: emacs-golang-package
  1877. #+BEGIN_SRC nix
  1878. epkgs.go-mode
  1879. #+END_SRC
  1880. [[https://emacswiki.org/emacs/GoMode][Go Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] major mode for editing [[https://golang.org][Golang]] source code.
  1881. #+NAME: emacs-golang-elisp
  1882. #+BEGIN_SRC emacs-lisp
  1883. ;; Configure `go-mode' to work with `lsp-mode'.
  1884. (defun dotfiles/go-hook ()
  1885. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  1886. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  1887. ;; Configure a custom `before-save-hook'.
  1888. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  1889. #+END_SRC
  1890. ** Rustic
  1891. #+NAME: emacs-rustic-package
  1892. #+BEGIN_SRC nix
  1893. epkgs.rustic
  1894. #+END_SRC
  1895. Rustic is a fork of Rust Mode that integrates well with the [[https://microsoft.github.io/language-server-protocol][Language Server Protocol (LSP)]]. Include the rust shell before launching [[https://gnu.org/software/emacs/][GNU/Emacs]] to use this!
  1896. #+NAME: emacs-rustic-elisp
  1897. #+BEGIN_SRC emacs-lisp
  1898. ;; Configure `rustic' with `lsp-mode'.
  1899. (setq rustic-format-on-save t
  1900. rustic-lsp-server 'rls)
  1901. #+END_SRC
  1902. ** Python Mode
  1903. #+NAME: emacs-python-package
  1904. #+BEGIN_SRC nix
  1905. epkgs.pretty-mode
  1906. #+END_SRC
  1907. The built in [[https://emacswiki.org/emacs/PythonProgrammingInEmacs][Python Mode]] has a nice feature set for working with [[https://python.org][Python]] code in [[https://gnu.org/software/emacs/][GNU/Emacs]]. It is complimented with the addition of a [[https://microsoft.github.io/language-server-protocol][Language Server Protocol (LSP)]] server. These tools are included in the Development Shell for Python.
  1908. #+NAME: emacs-python-elisp
  1909. #+BEGIN_SRC emacs-lisp
  1910. ;; Configure `pretty-mode' to work with `python-mode'.
  1911. (add-hook 'python-mode-hook
  1912. (lambda ()
  1913. (turn-on-pretty-mode)))
  1914. #+END_SRC
  1915. ** Protobuf Mode
  1916. #+NAME: emacs-protobuf-package
  1917. #+BEGIN_SRC nix
  1918. epkgs.protobuf-mode
  1919. #+END_SRC
  1920. ** PlantUML
  1921. #+NAME: emacs-plantuml-extras
  1922. #+BEGIN_SRC nix
  1923. pkgs.plantuml
  1924. #+END_SRC
  1925. [[https://plantuml.com][PlantUML]] is an open-source tool allowing users to create diagrams from a plain-text language. Besides various UML diagrams, PlantUML has support for various other software developmented related formats, as well as visualizations of =JSON= and =YAML= files.
  1926. #+NAME: emacs-plantuml-package
  1927. #+BEGIN_SRC nix
  1928. epkgs.plantuml-mode
  1929. #+END_SRC
  1930. [[https://github.com/skuro/plantuml-mode][PlantUML Mode]] is a major mode for editing [[https://plantuml.com][PlantUML]] sources in [[https://gnu.org/software/emacs/][GNU/Emacs]].
  1931. #+NAME: emacs-plantuml-elisp
  1932. #+BEGIN_SRC emacs-lisp
  1933. ;; Configure `plantuml-mode'.
  1934. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  1935. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  1936. (setq plantuml-default-exec-mode 'executable
  1937. org-plantuml-exec-mode 'plantuml)
  1938. #+END_SRC
  1939. ** Swiper
  1940. #+NAME: emacs-swiper-package
  1941. #+BEGIN_SRC nix
  1942. epkgs.ivy
  1943. epkgs.counsel
  1944. epkgs.ivy-rich
  1945. epkgs.ivy-posframe
  1946. epkgs.ivy-prescient
  1947. #+END_SRC
  1948. [[https://github.com/abo-abo/swiper][Ivy (Swiper)]] is a generic completion mechanism for [[https://gnu.org/software/emacs/][GNU/Emacs]]. While operating similarily to other completion schemes like =icomplete-mode=, it aims to be more efficient, smaller, simpler, and smoother to use, while remaining highly customizable.
  1949. #+NAME: emacs-swiper-elisp
  1950. #+BEGIN_SRC emacs-lisp
  1951. ;; Configure `ivy'.
  1952. (setq counsel-linux-app-format-function
  1953. #'counsel-linux-app-format-function-name-only)
  1954. (ivy-mode +1)
  1955. (counsel-mode +1)
  1956. ;; Configure `ivy-rich'.
  1957. (ivy-rich-mode +1)
  1958. ;; Configure `ivy-posframe'.
  1959. (setq ivy-posframe-parameters '((parent-frame nil))
  1960. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  1961. (ivy-posframe-mode +1)
  1962. ;; Configure `ivy-prescient'.
  1963. (setq ivy-prescient-enable-filtering nil)
  1964. (ivy-prescient-mode +1)
  1965. #+END_SRC
  1966. ** Transparency
  1967. It's possible to control the frame opacity in [[https://gnu.org/software/emacs/][GNU/Emacs]]. Unlike other transparency hacks, it's not merely showing the desktop background image, but is true transparency -- you can see other windows behind the Emacs window.
  1968. #+NAME: emacs-transparency-elisp
  1969. #+BEGIN_SRC emacs-lisp
  1970. ;; Configure the default frame transparency.
  1971. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  1972. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  1973. #+END_SRC
  1974. ** Desktop Environment
  1975. #+NAME: emacs-desktop-extras
  1976. #+BEGIN_SRC nix
  1977. pkgs.brightnessctl
  1978. #+END_SRC
  1979. The [[https://github.com/DamienCassou/desktop-environment][Desktop Environment]] package provides commands and a global minor mode for controlling your [[https://linux.org][GNU/Linux]] desktop from within [[https://gnu.org/software/emacs/][GNU/Emacs]].
  1980. #+NAME: emacs-desktop-package
  1981. #+BEGIN_SRC nix
  1982. epkgs.desktop-environment
  1983. #+END_SRC
  1984. You can control the brightness, volume, take screenshots, and lock / unlock the screen. The package depends on the availability of shell commands to do the heavy lifting. They can be changed by customizing the appropriate variables.
  1985. #+NAME: emacs-desktop-elisp
  1986. #+BEGIN_SRC emacs-lisp
  1987. ;; Configure `desktop-environment'.
  1988. (require 'desktop-environment)
  1989. (desktop-environment-mode +1)
  1990. #+END_SRC
  1991. ** Doom Themes
  1992. #+NAME: emacs-doom-themes-package
  1993. #+BEGIN_SRC nix
  1994. epkgs.doom-themes
  1995. #+END_SRC
  1996. [[https://github.com/hlissner/emacs-doom-themes][Doom Themes]] is a theme megapack for [[https://gnu.org/software/emacs/][GNU/Emacs]], inspired by community favourites.
  1997. #+NAME: emacs-doom-themes-elisp
  1998. #+BEGIN_SRC emacs-lisp
  1999. ;; Include modern themes from `doom-themes'.
  2000. (setq doom-themes-enable-bold t
  2001. doom-themes-enable-italic t)
  2002. ;; Load the `doom-nord' and `doom-nord-light' themes.
  2003. ;; (load-theme 'doom-nord-light t)
  2004. (load-theme 'doom-nord t)
  2005. ;; Define a method for returning information about the current theme.
  2006. ;; This is based off the function `org-roam-ui-get-theme'.
  2007. (defun dotfiles/theme ()
  2008. "Return information about the current theme."
  2009. (list `(bg . ,(face-background hl-line-face))
  2010. `(bg-alt . ,(face-background 'default))
  2011. `(fg . ,(face-foreground 'default))
  2012. `(fg-alt . ,(face-foreground font-lock-comment-face))
  2013. `(red . ,(face-foreground 'error))
  2014. `(orange . ,(face-foreground 'warning))
  2015. `(yellow . ,(face-foreground font-lock-builtin-face))
  2016. `(green . ,(face-foreground 'success))
  2017. `(cyan . ,(face-foreground font-lock-constant-face))
  2018. `(blue . ,(face-foreground font-lock-keyword-face))
  2019. `(violet . ,(face-foreground font-lock-constant-face))
  2020. `(magenta . ,(face-foreground font-lock-preprocessor-face))))
  2021. ;; Load a new theme with <SPC> t t.
  2022. (dotfiles/leader
  2023. "tt" '(counsel-load-theme :which-key "Theme"))
  2024. #+END_SRC
  2025. Create a shell command that returns a JSON string of the current theme in the following format:
  2026. #+BEGIN_SRC json
  2027. {
  2028. "bg": "#272C36",
  2029. "bg-alt": "#2E3440",
  2030. "fg": "#ECEFF4",
  2031. "fg-alt": "#6f7787",
  2032. "red": "#BF616A",
  2033. "orange": "#EBCB8B",
  2034. "yellow": "#81A1C1",
  2035. "green": "#A3BE8C",
  2036. "cyan": "#81A1C1",
  2037. "blue": "#81A1C1",
  2038. "violet": "#81A1C1",
  2039. "magenta": "#81A1C1"
  2040. }
  2041. #+END_SRC
  2042. #+NAME: emacs-doom-themes-extras
  2043. #+BEGIN_SRC nix
  2044. (pkgs.writeShellScriptBin "dotfiles-theme" ''
  2045. ${myEmacs}/bin/emacsclient --no-wait --eval '(json-encode (dotfiles/theme))' | sed "s/\\\\//g" | sed -e 's/^"//' -e 's/"$//'
  2046. '')
  2047. #+END_SRC
  2048. ** Doom Modeline
  2049. #+NAME: emacs-doom-modeline-package
  2050. #+BEGIN_SRC nix
  2051. epkgs.doom-modeline
  2052. #+END_SRC
  2053. [[https://github.com/seagle0128/doom-modeline][Doom Modeline]] is a fancy and fast modeline inspired by minimalism design. It's integrated into Centaur Emacs, Doom Emacs, and Spacemacs.
  2054. #+NAME: emacs-doom-modeline-elisp
  2055. #+BEGIN_SRC emacs-lisp
  2056. ;; Configure `doom-modeline'.
  2057. (require 'doom-modeline)
  2058. (setq doom-modeline-height 16
  2059. doom-modeline-icon t)
  2060. ;; Launch after initialization.
  2061. (add-hook 'after-init-hook 'doom-modeline-mode)
  2062. ;; Define a modeline segment to show the workspace information.
  2063. (doom-modeline-def-segment dotfiles/workspaces
  2064. (exwm-workspace--update-switch-history)
  2065. (concat
  2066. (doom-modeline-spc)
  2067. (elt (let* ((num (exwm-workspace--count))
  2068. (sequence (number-sequence 0 (1- num)))
  2069. (not-empty (make-vector num nil)))
  2070. (dolist (i exwm--id-buffer-alist)
  2071. (with-current-buffer (cdr i)
  2072. (when exwm--frame
  2073. (setf (aref not-empty
  2074. (exwm-workspace--position exwm--frame))
  2075. t))))
  2076. (mapcar
  2077. (lambda (i)
  2078. (mapconcat
  2079. (lambda (j)
  2080. (format (if (= i j) "[%s]" " %s ")
  2081. (propertize
  2082. (apply exwm-workspace-index-map (list j))
  2083. 'face
  2084. (cond ((frame-parameter (elt exwm-workspace--list j)
  2085. 'exwm-urgency)
  2086. '(:inherit warning :weight bold))
  2087. ((= i j) '(:inherit underline :weight bold))
  2088. ((aref not-empty j) '(:inherit success :weight bold))
  2089. (t `((:foreground ,(face-foreground 'mode-line-inactive))))))))
  2090. sequence ""))
  2091. sequence))
  2092. (exwm-workspace--position (selected-frame)))))
  2093. ;; Define a custom modeline to override the default.
  2094. (doom-modeline-def-modeline 'dotfiles/modeline
  2095. '(bar workspace-name dotfiles/workspaces window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info)
  2096. '(objed-state misc-info persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
  2097. ;; Define a method to load the modeline.
  2098. (defun dotfiles/load-modeline ()
  2099. "Load the default modeline."
  2100. (doom-modeline-set-modeline 'dotfiles/modeline 'default))
  2101. ;; Enable `doom-modeline'.
  2102. (add-hook 'doom-modeline-mode-hook 'dotfiles/load-modeline)
  2103. (doom-modeline-mode +1)
  2104. (doom-modeline-set-modeline 'dotfiles/modeline 'default)
  2105. #+END_SRC
  2106. * Website Configuration
  2107. #+ATTR_ORG: :width 800px
  2108. #+ATTR_HTML: :width 800px
  2109. #+ATTR_LATEX: :width 800px
  2110. [[./docs/images/website-example.png]]
  2111. My [[https://chrishayward.xyz][personal website]] is a static HTML page written with [[https://gohugo.io][Hugo]], and is fully integrated into this configuration. It uses the ~config.toml~, ~config.yaml~, or ~config.json~ file (found in the sites root directory) as the default site config. Working with this requires the module to be enabled.
  2112. #+BEGIN_SRC conf :noweb yes :tangle docs/config.toml
  2113. # <<file-warning>>
  2114. title = "Chris Hayward"
  2115. copyright = "Licensed under Attribution 4.0 International (CC BY 4.0)"
  2116. baseURL = "https://chrishayward.xyz/"
  2117. theme = "hello-friend-ng"
  2118. languageCode = "en-us"
  2119. defaultContentLanguage = "en"
  2120. pygmentsCodefences = true
  2121. pygmentsUseClasses = true
  2122. <<website-params>>
  2123. <<website-privacy>>
  2124. <<website-layout>>
  2125. #+END_SRC
  2126. ** Params
  2127. Dates are important in [[https://gohugo.io][Hugo]], and they configure how dates are assigned and displayed in your content pages. Themes are also able to extract information from the configuration to display, including social media icons, subtitles, and footer sections.
  2128. #+NAME: website-params
  2129. #+BEGIN_SRC conf
  2130. [params]
  2131. dateform = "Jan 2, 2006"
  2132. dateformShort = "Jan 2"
  2133. dateformNum = "2006-01-02"
  2134. dateformNumTime = "2006-01-02 15:04 -0700"
  2135. authorName = "Christopher James Hayward"
  2136. homeSubtitle = "Airplanes, Linux, and Metalcore"
  2137. footerCopyright = ' &#183; <a href="http://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC BY 4.0</a>'
  2138. [[params.social]]
  2139. name = "paypal"
  2140. url = "https://paypal.me/chrishaywardxyz"
  2141. [[params.social]]
  2142. name = "github"
  2143. url = "https://github.com/chayward1/"
  2144. [[params.social]]
  2145. name = "gitlab"
  2146. url = "https://gitlab.com/chayward1/"
  2147. [[params.social]]
  2148. name = "email"
  2149. url = "mailto:chris@chrishayward.xyz"
  2150. #+END_SRC
  2151. ** Privacy
  2152. I do not use any analytics or tracking in my website. Depending on the theme selected, some of these features may be enabled. I opt to override those settings here to make sure no unwanted trackers are loaded.
  2153. #+NAME: website-privacy
  2154. #+BEGIN_SRC conf
  2155. [privacy]
  2156. [privacy.disqus]
  2157. disable = true
  2158. [privacy.googleAnalytics]
  2159. disable = true
  2160. [privacy.instagram]
  2161. disable = true
  2162. [privacy.twitter]
  2163. disable = true
  2164. [privacy.vimeo]
  2165. disable = true
  2166. [privacy.youtube]
  2167. disable = true
  2168. #+END_SRC
  2169. ** Layout
  2170. Individual pages can be configured here to define the layout of the page. This is where quick links can be configured, and other sections such as blog posts, an about section, or a contact page can be added.
  2171. #+NAME: website-layout
  2172. #+BEGIN_SRC conf
  2173. [menu]
  2174. [[menu.main]]
  2175. identifier = "cloud"
  2176. name = "Cloud"
  2177. url = "https://cloud.chrishayward.xyz"
  2178. [[menu.main]]
  2179. identifier = "dotfiles"
  2180. name = "Dotfiles"
  2181. url = "/dotfiles"
  2182. [[menu.main]]
  2183. identifier = "projects"
  2184. name = "Projects"
  2185. url = "https://git.chrishayward.xyz"
  2186. #+END_SRC
  2187. * Footnotes