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.

2736 lines
88 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
  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.
  527. #+BEGIN_SRC nix :noweb yes :tangle modules/hugo.nix
  528. # <<file-warning>>
  529. { config, pkgs, ... }:
  530. let
  531. myUpdateSite = pkgs.writeShellScriptBin "update-site" ''
  532. rsync -aP /etc/dotfiles/docs/public/ ubuntu@chrishayward.xyz:/var/www/chrishayward
  533. '';
  534. in {
  535. environment.systemPackages = [
  536. pkgs.hugo
  537. myUpdateSite
  538. ];
  539. }
  540. #+END_SRC
  541. ** Flakes
  542. #+NAME: module-flakes
  543. #+BEGIN_SRC nix
  544. ./modules/flakes.nix
  545. #+END_SRC
  546. [[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.
  547. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  548. # <<file-warning>>
  549. { config, pkgs, inputs, ... }:
  550. {
  551. nix = {
  552. package = pkgs.nixUnstable;
  553. extraOptions = ''
  554. experimental-features = nix-command flakes
  555. '';
  556. };
  557. nixpkgs = {
  558. config = { allowUnfree = true; };
  559. overlays = [ inputs.emacs-overlay.overlay ];
  560. };
  561. }
  562. #+END_SRC
  563. ** Cachix
  564. #+NAME: module-cachix
  565. #+BEGIN_SRC nix
  566. ./modules/cachix.nix
  567. #+END_SRC
  568. [[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.
  569. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  570. # <<file-warning>>
  571. { config, ... }:
  572. {
  573. nix = {
  574. settings = {
  575. substituters = [
  576. "https://nix-community.cachix.org"
  577. ];
  578. trusted-public-keys = [
  579. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  580. ];
  581. };
  582. };
  583. }
  584. #+END_SRC
  585. ** Docker
  586. #+NAME: module-docker
  587. #+BEGIN_SRC nix
  588. ./modules/docker.nix
  589. #+END_SRC
  590. [[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.
  591. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  592. { config, pkgs, ... }:
  593. {
  594. # Enable the docker virutalization platform.
  595. virtualisation.docker = {
  596. enable = true;
  597. enableOnBoot = true;
  598. autoPrune.enable = true;
  599. };
  600. # Required for the `docker' command.
  601. users.users.chris.extraGroups = [ "docker" ];
  602. }
  603. #+END_SRC
  604. ** Firefox
  605. #+NAME: module-firefox
  606. #+BEGIN_SRC nix
  607. ./modules/firefox.nix
  608. #+END_SRC
  609. [[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.
  610. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  611. # <<file-warning>>
  612. { config, pkgs, ... }:
  613. let
  614. myFirefox = pkgs.writeShellScriptBin "firefox" ''
  615. HOME=~/.local/share/mozilla ${pkgs.firefox-bin}/bin/firefox
  616. '';
  617. in {
  618. # NOTE: Use the binary until module is developed.
  619. environment.systemPackages = [
  620. myFirefox
  621. ];
  622. }
  623. #+END_SRC
  624. ** Home Manager
  625. [[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.
  626. #+NAME: module-home-manager
  627. #+BEGIN_SRC nix :noweb yes
  628. inputs.home-manager.nixosModules.home-manager {
  629. home-manager.useGlobalPkgs = true;
  630. home-manager.useUserPackages = true;
  631. home-manager.users.chris = {
  632. imports = [
  633. <<module-git>>
  634. <<module-gpg>>
  635. <<module-vim>>
  636. <<module-gtk>>
  637. <<module-emacs>>
  638. ];
  639. };
  640. }
  641. #+END_SRC
  642. Certain modules have to be included within home manager or they will not function correctly.
  643. #+NAME: home-manager-warning
  644. #+BEGIN_SRC text
  645. This module MUST be included within home manager
  646. #+END_SRC
  647. *** Git
  648. #+NAME: module-git
  649. #+BEGIN_SRC nix
  650. ./modules/git.nix
  651. #+END_SRC
  652. [[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.
  653. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  654. # <<file-warning>>
  655. # <<home-manager-warning>>
  656. { pkgs, ... }:
  657. let
  658. # Fix any corruptions in the local copy.
  659. myGitFix = pkgs.writeShellScriptBin "git-fix" ''
  660. if [ -d .git/objects/ ]; then
  661. find .git/objects/ -type f -empty | xargs rm -f
  662. git fetch -p
  663. git fsck --full
  664. fi
  665. exit 1
  666. '';
  667. in {
  668. home.packages = [ myGitFix ];
  669. programs.git = {
  670. enable = true;
  671. userName = "Christopher James Hayward";
  672. userEmail = "chris@chrishayward.xyz";
  673. signing = {
  674. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  675. signByDefault = true;
  676. };
  677. };
  678. }
  679. #+END_SRC
  680. *** Gpg
  681. #+NAME: module-gpg
  682. #+BEGIN_SRC nix
  683. ./modules/gpg.nix
  684. #+END_SRC
  685. [[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.
  686. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  687. # <<file-warning>>
  688. # <<home-manager-warning>>
  689. { pkgs, ... }:
  690. {
  691. services.gpg-agent = {
  692. enable = true;
  693. defaultCacheTtl = 1800;
  694. enableSshSupport = true;
  695. pinentryFlavor = "gtk2";
  696. };
  697. }
  698. #+END_SRC
  699. *** Vim
  700. #+NAME: module-vim
  701. #+BEGIN_SRC nix
  702. ./modules/vim.nix
  703. #+END_SRC
  704. [[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
  705. + Simplify maintenance and encourage contributions
  706. + Split the work between multiple developers
  707. + Enable advanced UIs without core modification
  708. + Maximize extensibility
  709. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  710. # <<file-warning>>
  711. # <<home-manager-warning>>
  712. { pkgs, ... }:
  713. {
  714. programs.neovim = {
  715. enable = true;
  716. viAlias = true;
  717. vimAlias = true;
  718. vimdiffAlias = true;
  719. extraConfig = ''
  720. set number relativenumber
  721. set nobackup
  722. '';
  723. extraPackages = [
  724. pkgs.nixfmt
  725. ];
  726. plugins = with pkgs.vimPlugins; [
  727. vim-nix
  728. vim-airline
  729. vim-polyglot
  730. ];
  731. };
  732. }
  733. #+END_SRC
  734. *** GTK
  735. #+NAME: module-gtk
  736. #+BEGIN_SRC nix
  737. ./modules/gtk.nix
  738. #+END_SRC
  739. [[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.
  740. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  741. # <<file-warning>>
  742. # <<home-manager-warning>>
  743. { pkgs, ... }:
  744. {
  745. home.packages = [
  746. pkgs.nordic
  747. pkgs.arc-icon-theme
  748. pkgs.lxappearance
  749. ];
  750. home.file.".gtkrc-2.0" = {
  751. text = ''
  752. gtk-theme-name="Nordic-darker"
  753. gtk-icon-theme-name="Arc"
  754. gtk-font-name="Iosevka 11"
  755. gtk-cursor-theme-size=0
  756. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  757. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  758. gtk-button-images=0
  759. gtk-menu-images=0
  760. gtk-enable-event-sounds=1
  761. gtk-enable-input-feedback-sounds=1
  762. gtk-xft-antialias=1
  763. gtk-xft-hinting=1
  764. gtk-xft-hintstyle="hintmedium"
  765. '';
  766. };
  767. home.file.".config/gtk-2.0/gtkfilechooser.ini" = {
  768. text = ''
  769. [Filechooser Settings]
  770. LocationMode=path-bar
  771. ShowHidden=false
  772. ShowSizeColumn=true
  773. GeometryX=442
  774. GeometryY=212
  775. GeometryWidth=1036
  776. GeometryHeight=609
  777. SortColumn=name
  778. SortOrder=ascending
  779. StartupMode=recent
  780. '';
  781. };
  782. home.file.".config/gtk-3.0/settings.ini" = {
  783. text = ''
  784. [Settings]
  785. gtk-theme-name=Nordic-darker
  786. gtk-icon-theme-name=Arc
  787. gtk-font-name=Iosevka 11
  788. gtk-cursor-theme-size=0
  789. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  790. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  791. gtk-button-images=0
  792. gtk-menu-images=0
  793. gtk-enable-event-sounds=1
  794. gtk-enable-input-feedback-sounds=1
  795. gtk-xft-antialias=1
  796. gtk-xft-hinting=1
  797. gtk-xft-hintstyle=hintmedium
  798. '';
  799. };
  800. }
  801. #+END_SRC
  802. * Emacs Configuration
  803. #+NAME: module-emacs
  804. #+BEGIN_SRC nix
  805. ./modules/emacs.nix
  806. #+END_SRC
  807. [[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:
  808. + Highly customizable
  809. + Full Unicopde support
  810. + Content-aware editing modes
  811. + Complete built-in documentation
  812. + Wide range of functionality beyond text editing
  813. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  814. # <<file-warning>>
  815. # <<home-manager-warning>>
  816. { pkgs, ... }:
  817. let
  818. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  819. config = ../README.org;
  820. package = <<emacs-native-comp-package>>
  821. alwaysEnsure = true;
  822. alwaysTangle = true;
  823. extraEmacsPackages = epkgs: [
  824. # Required packages...
  825. <<emacs-exwm-package>>
  826. <<emacs-evil-package>>
  827. <<emacs-general-package>>
  828. <<emacs-which-key-package>>
  829. # Optional packages.
  830. <<emacs-org-package>>
  831. <<emacs-org-roam-package>>
  832. <<emacs-org-roam-ui-package>>
  833. <<emacs-org-drill-package>>
  834. <<emacs-pomodoro-package>>
  835. <<emacs-writegood-package>>
  836. <<emacs-http-package>>
  837. <<emacs-hugo-package>>
  838. <<emacs-pass-package>>
  839. <<emacs-docker-package>>
  840. <<emacs-mu4e-package>>
  841. <<emacs-dired-package>>
  842. <<emacs-icons-package>>
  843. <<emacs-emoji-package>>
  844. <<emacs-eshell-package>>
  845. <<emacs-vterm-package>>
  846. <<emacs-magit-package>>
  847. <<emacs-hydra-package>>
  848. <<emacs-elfeed-package>>
  849. <<emacs-nix-mode-package>>
  850. <<emacs-projectile-package>>
  851. <<emacs-lsp-package>>
  852. <<emacs-company-package>>
  853. <<emacs-ccls-package>>
  854. <<emacs-golang-package>>
  855. <<emacs-python-package>>
  856. <<emacs-rustic-package>>
  857. <<emacs-plantuml-package>>
  858. <<emacs-protobuf-package>>
  859. # User interface packages.
  860. <<emacs-swiper-package>>
  861. <<emacs-desktop-package>>
  862. <<emacs-doom-themes-package>>
  863. <<emacs-doom-modeline-package>>
  864. ];
  865. };
  866. in {
  867. home.packages = [
  868. <<emacs-exwm-extras>>
  869. <<emacs-pass-extras>>
  870. <<emacs-mu4e-extras>>
  871. <<emacs-aspell-extras>>
  872. <<emacs-texlive-extras>>
  873. <<emacs-desktop-extras>>
  874. <<emacs-plantuml-extras>>
  875. <<emacs-nix-mode-extras>>
  876. <<emacs-doom-themes-extras>>
  877. ];
  878. programs.emacs = {
  879. enable = true;
  880. package = myEmacs;
  881. };
  882. <<emacs-exwm-config>>
  883. <<emacs-exwm-xinitrc>>
  884. <<emacs-mu4e-config>>
  885. }
  886. #+END_SRC
  887. 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.
  888. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  889. ;; <<file-warning>>
  890. ;; Required inputs.
  891. <<emacs-exwm-elisp>>
  892. <<emacs-evil-elisp>>
  893. <<emacs-general-elisp>>
  894. <<emacs-which-key-elisp>>
  895. ;; Optional inputs.
  896. <<emacs-org-elisp>>
  897. <<emacs-org-roam-elisp>>
  898. <<emacs-org-roam-ui-elisp>>
  899. <<emacs-org-drill-elisp>>
  900. <<emacs-org-agenda-elisp>>
  901. <<emacs-pomodoro-elisp>>
  902. <<emacs-writegood-elisp>>
  903. <<emacs-aspell-elisp>>
  904. <<emacs-eww-elisp>>
  905. <<emacs-http-elisp>>
  906. <<emacs-hugo-elisp>>
  907. <<emacs-pass-elisp>>
  908. <<emacs-docker-elisp>>
  909. <<emacs-erc-elisp>>
  910. <<emacs-mu4e-elisp>>
  911. <<emacs-dired-elisp>>
  912. <<emacs-icons-elisp>>
  913. <<emacs-emoji-elisp>>
  914. <<emacs-eshell-elisp>>
  915. <<emacs-vterm-elisp>>
  916. <<emacs-magit-elisp>>
  917. <<emacs-fonts-elisp>>
  918. <<emacs-frames-elisp>>
  919. <<emacs-elfeed-elisp>>
  920. <<emacs-projectile-elisp>>
  921. <<emacs-lsp-elisp>>
  922. <<emacs-company-elisp>>
  923. <<emacs-golang-elisp>>
  924. <<emacs-python-elisp>>
  925. <<emacs-rustic-elisp>>
  926. <<emacs-plantuml-elisp>>
  927. <<emacs-desktop-elisp>>
  928. ;; User interface.
  929. <<emacs-swiper-elisp>>
  930. <<emacs-transparency-elisp>>
  931. <<emacs-doom-themes-elisp>>
  932. <<emacs-doom-modeline-elisp>>
  933. #+END_SRC
  934. 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=.
  935. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  936. ;; <<file-warning>>
  937. <<emacs-disable-ui-elisp>>
  938. <<emacs-native-comp-elisp>>
  939. <<emacs-backup-files-elisp>>
  940. <<emacs-shell-commands-elisp>>
  941. <<emacs-improved-prompts>>
  942. #+END_SRC
  943. ** Native Comp
  944. #+NAME: emacs-native-comp-package
  945. #+BEGIN_SRC nix
  946. pkgs.emacsGcc;
  947. #+END_SRC
  948. 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.
  949. #+NAME: emacs-native-comp-elisp
  950. #+BEGIN_SRC emacs-lisp
  951. ;; Silence warnings from packages that don't support `native-comp'.
  952. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  953. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  954. #+END_SRC
  955. ** Disable UI
  956. [[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.
  957. #+NAME: emacs-disable-ui-elisp
  958. #+BEGIN_SRC emacs-lisp
  959. ;; Disable unwanted UI elements.
  960. (tooltip-mode -1)
  961. (menu-bar-mode -1)
  962. (tool-bar-mode -1)
  963. (scroll-bar-mode -1)
  964. ;; Fix the scrolling behaviour.
  965. (setq scroll-conservatively 101)
  966. ;; Fix mouse-wheel scrolling behaviour.
  967. (setq mouse-wheel-follow-mouse t
  968. mouse-wheel-progressive-speed t
  969. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  970. ;; Start in fullscreen/maximized.
  971. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  972. #+END_SRC
  973. ** Backup Files
  974. [[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.
  975. #+NAME: emacs-backup-files-elisp
  976. #+BEGIN_SRC emacs-lisp
  977. ;; Disable unwanted features.
  978. (setq make-backup-files nil
  979. create-lockfiles nil)
  980. #+END_SRC
  981. ** Shell Commands
  982. Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
  983. 1) Method to run an external process, launching any application on a new process without interference
  984. 2) Method to apply commands to the current call process, effecting the running instance
  985. #+NAME: emacs-shell-commands-elisp
  986. #+BEGIN_SRC emacs-lisp
  987. ;; Define a method to run an external process.
  988. (defun dotfiles/run (cmd)
  989. "Run an external process."
  990. (interactive (list (read-shell-command "λ ")))
  991. (start-process-shell-command cmd nil cmd))
  992. ;; Define a method to run a background process.
  993. (defun dotfiles/run-in-background (cmd)
  994. (let ((command-parts (split-string cmd "[ ]+")))
  995. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  996. #+END_SRC
  997. ** Improved prompts
  998. 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.
  999. #+NAME: emacs-improved-prompts
  1000. #+BEGIN_SRC emacs-lisp
  1001. ;; Use 'y' and 'n' instead of 'yes' and 'no'.
  1002. (defalias 'yes-or-no-p 'y-or-n-p)
  1003. #+END_SRC
  1004. ** Nix Mode
  1005. #+NAME: emacs-nix-mode-extras
  1006. #+BEGIN_SRC nix
  1007. pkgs.nixfmt
  1008. pkgs.rnix-lsp
  1009. #+END_SRC
  1010. [[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.
  1011. #+NAME: emacs-nix-mode-package
  1012. #+BEGIN_SRC nix
  1013. epkgs.nix-mode
  1014. #+END_SRC
  1015. ** Evil Mode
  1016. [[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.
  1017. #+NAME: emacs-evil-package
  1018. #+BEGIN_SRC nix
  1019. epkgs.evil
  1020. epkgs.evil-collection
  1021. epkgs.evil-surround
  1022. epkgs.evil-nerd-commenter
  1023. #+END_SRC
  1024. 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]].
  1025. #+NAME: emacs-evil-elisp
  1026. #+BEGIN_SRC emacs-lisp
  1027. ;; Enable the Extensible VI Layer for Emacs.
  1028. (setq evil-want-integration t ;; Required for `evil-collection.'
  1029. evil-want-keybinding nil ;; Same as above.
  1030. evil-want-C-i-jump nil) ;; Disable jumping in terminal.
  1031. (evil-mode +1)
  1032. ;; Configure `evil-collection'.
  1033. (evil-collection-init)
  1034. ;; Configure `evil-surround'.
  1035. (global-evil-surround-mode +1)
  1036. ;; Configure `evil-nerd-commenter'.
  1037. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1038. ;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
  1039. (evil-define-key 'normal 'org-mode-map (kbd "<tab>") #'org-cycle)
  1040. #+END_SRC
  1041. ** EXWM
  1042. #+NAME: emacs-exwm-package
  1043. #+BEGIN_SRC nix
  1044. epkgs.exwm
  1045. #+END_SRC
  1046. [[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:
  1047. + Fully keyboard-driven operations
  1048. + Hybrid layout modes (tiling & stacking)
  1049. + Dynamic workspace support
  1050. + ICCM/EWMH compliance
  1051. #+NAME: emacs-exwm-extras
  1052. #+BEGIN_SRC nix
  1053. pkgs.nitrogen
  1054. pkgs.autorandr
  1055. #+END_SRC
  1056. 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]].
  1057. #+NAME: emacs-exwm-config
  1058. #+BEGIN_SRC nix
  1059. xsession = {
  1060. enable = true;
  1061. windowManager.command = ''
  1062. ${pkgs.nitrogen}/bin/nitrogen --restore
  1063. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1064. ${myEmacs}/bin/emacsclient -c
  1065. '';
  1066. };
  1067. #+END_SRC
  1068. [[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=.
  1069. #+NAME: emacs-exwm-xinitrc
  1070. #+BEGIN_SRC nix
  1071. home.file.".xinitrc" = {
  1072. text = ''
  1073. exec ./.xsession
  1074. '';
  1075. };
  1076. #+END_SRC
  1077. #+NAME: emacs-exwm-elisp
  1078. #+BEGIN_SRC emacs-lisp
  1079. ;; Configure `exwm'.
  1080. (setq exwm-workspace-number 5
  1081. exwm-layout-show-all-buffers t
  1082. exwm-worspace-show-all-buffers t)
  1083. ;; Configure input keys.
  1084. (setq exwm-input-prefix-keys
  1085. '(?\M-x
  1086. ?\C-g
  1087. ?\C-\ ))
  1088. (setq exwm-input-global-keys
  1089. `(([?\s-r] . exwm-reset)
  1090. ,@(mapcar (lambda (i)
  1091. `(,(kbd (format "s-%d" i)) .
  1092. (lambda ()
  1093. (interactive)
  1094. (exwm-workspace-switch-create ,i))))
  1095. (number-sequence 0 9))))
  1096. ;; Configure `exwm-randr'.
  1097. (require 'exwm-randr)
  1098. (exwm-randr-enable)
  1099. ;; Configure custom hooks.
  1100. (setq display-time-day-and-date t)
  1101. (add-hook 'exwm-init-hook
  1102. (lambda ()
  1103. (display-battery-mode +1) ;; Display battery info (if available).
  1104. (display-time-mode +1))) ;; Display the time in the modeline.
  1105. ;; Setup buffer display names.
  1106. (add-hook 'exwm-update-class-hook
  1107. (lambda ()
  1108. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1109. ;; Configure monitor hot-swapping.
  1110. (add-hook 'exwm-randr-screen-change-hook
  1111. (lambda ()
  1112. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1113. #+END_SRC
  1114. ** General
  1115. #+NAME: emacs-general-package
  1116. #+BEGIN_SRC nix
  1117. epkgs.general
  1118. #+END_SRC
  1119. [[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.
  1120. #+NAME: emacs-general-elisp
  1121. #+BEGIN_SRC emacs-lisp
  1122. ;; Use <SPC> as a leader key via `general.el'.
  1123. (general-create-definer dotfiles/leader
  1124. :keymaps '(normal insert visual emacs)
  1125. :prefix "SPC"
  1126. :global-prefix "C-SPC")
  1127. ;; Setup general to work with `evil-mode'.
  1128. (setq general-evil-setup t)
  1129. ;; Find files with <SPC> <period> ...
  1130. ;; Switch buffers with <SPC> <comma> ...
  1131. (dotfiles/leader
  1132. "." '(find-file :which-key "File")
  1133. "," '(switch-to-buffer :which-key "Buffer")
  1134. "k" '(kill-buffer :which-key "Kill")
  1135. "c" '(kill-buffer-and-window :which-key "Close"))
  1136. ;; Add keybindings for executing shell commands.
  1137. (dotfiles/leader
  1138. "r" '(:ignore t :which-key "Run")
  1139. "rr" '(dotfiles/run :which-key "Run")
  1140. "ra" '(async-shell-command :which-key "Async"))
  1141. ;; Add keybindings for quitting Emacs.
  1142. (dotfiles/leader
  1143. "q" '(:ignore t :which-key "Quit")
  1144. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1145. "qw" '(kill-emacs :which-key "Now")
  1146. "qf" '(delete-frame :which-key "Frame"))
  1147. ;; Add keybindings for toggles / tweaks.
  1148. (dotfiles/leader
  1149. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1150. #+END_SRC
  1151. ** Which Key
  1152. [[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.
  1153. #+NAME: emacs-which-key-package
  1154. #+BEGIN_SRC nix
  1155. epkgs.which-key
  1156. #+END_SRC
  1157. #+NAME: emacs-which-key-elisp
  1158. #+BEGIN_SRC emacs-lisp
  1159. ;; Configure `which-key' to see keyboard bindings in the
  1160. ;; mini-buffer and when using M-x.
  1161. (setq which-key-idle-delay 0.0)
  1162. (which-key-mode +1)
  1163. #+END_SRC
  1164. ** EWW
  1165. [[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.
  1166. + Use ~eww~ as the default browser
  1167. + Don't use any special fonts or colours
  1168. #+NAME: emacs-eww-elisp
  1169. #+BEGIN_SRC emacs-lisp
  1170. ;; Set `eww' as the default browser.
  1171. (setq browse-url-browser-function 'eww-browse-url)
  1172. ;; Configure the `shr' rendering engine.
  1173. (setq shr-use-fonts nil
  1174. shr-use-colors nil)
  1175. #+END_SRC
  1176. ** ERC
  1177. [[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.
  1178. #+NAME: emacs-erc-elisp
  1179. #+BEGIN_SRC emacs-lisp
  1180. ;; Configure `erc'.
  1181. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
  1182. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1183. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1184. ;; Configure `erc-fill-column'.
  1185. (add-hook 'window-configuration-change-hook
  1186. '(lambda ()
  1187. (setq erc-fill-column (- (window-width) 12))))
  1188. ;; Connect to IRC via `erc'.
  1189. (defun dotfiles/erc-connect ()
  1190. "Connected to IRC via `erc'."
  1191. (interactive)
  1192. (erc-tls :server "irc.libera.chat"
  1193. :port 6697
  1194. :nick "megaphone"
  1195. :password (password-store-get "megaphone@libera.chat")
  1196. :full-name "Chris Hayward"))
  1197. ;; Configure keybindings.
  1198. (dotfiles/leader
  1199. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1200. #+END_SRC
  1201. ** Dired
  1202. #+NAME: emacs-dired-package
  1203. #+BEGIN_SRC nix
  1204. epkgs.dired-single
  1205. #+END_SRC
  1206. [[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.
  1207. #+NAME: emacs-dired-elisp
  1208. #+BEGIN_SRC emacs-lisp
  1209. ;; Include `dired-x' for the `jump' method.
  1210. (require 'dired-x)
  1211. ;; Configure `dired-single' to support `evil' keys.
  1212. (evil-collection-define-key 'normal 'dired-mode-map
  1213. "h" 'dired-single-up-directory
  1214. "l" 'dired-single-buffer)
  1215. ;; Configure keybindings for `dired'.
  1216. (dotfiles/leader
  1217. "d" '(dired-jump :which-key "Dired"))
  1218. #+END_SRC
  1219. ** Icons
  1220. #+NAME: emacs-icons-package
  1221. #+BEGIN_SRC nix
  1222. epkgs.all-the-icons
  1223. epkgs.all-the-icons-dired
  1224. epkgs.all-the-icons-ivy-rich
  1225. #+END_SRC
  1226. [[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]].
  1227. #+NAME: emacs-icons-elisp
  1228. #+BEGIN_SRC emacs-lisp
  1229. ;; Setup `all-the-icons-dired'.
  1230. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1231. ;; Disable monochrome icons.
  1232. (setq all-the-icons-dired-monochrome nil)
  1233. ;; Display default font ligatures.
  1234. (global-prettify-symbols-mode +1)
  1235. #+END_SRC
  1236. ** Emojis
  1237. #+NAME: emacs-emoji-package
  1238. #+BEGIN_SRC nix
  1239. epkgs.emojify
  1240. #+END_SRC
  1241. [[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.
  1242. #+NAME: emacs-emoji-elisp
  1243. #+BEGIN_SRC emacs-lisp
  1244. ;; Setup `emojify'.
  1245. (add-hook 'after-init-hook 'global-emojify-mode)
  1246. #+END_SRC
  1247. ** EShell
  1248. #+NAME: emacs-eshell-package
  1249. #+BEGIN_SRC nix
  1250. epkgs.eshell-prompt-extras
  1251. #+END_SRC
  1252. [[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.
  1253. #+NAME: emacs-eshell-elisp
  1254. #+BEGIN_SRC emacs-lisp
  1255. ;; Configure `eshell'.
  1256. (setq eshell-highlight-prompt nil
  1257. eshell-prefer-lisp-functions nil)
  1258. ;; Configure the lambda prompt.
  1259. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1260. (setq eshell-prompt-function 'epe-theme-lambda)
  1261. ;; Configure keybindings for `eshell'.
  1262. (dotfiles/leader
  1263. "e" '(eshell :which-key "EShell"))
  1264. #+END_SRC
  1265. ** VTerm
  1266. [[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.
  1267. #+NAME: emacs-vterm-package
  1268. #+BEGIN_SRC nix
  1269. epkgs.vterm
  1270. #+END_SRC
  1271. #+NAME: emacs-vterm-elisp
  1272. #+BEGIN_SRC emacs-lisp
  1273. ;; Add keybindings for interacting with the shell(s).
  1274. (dotfiles/leader
  1275. "v" '(vterm :which-key "VTerm"))
  1276. #+END_SRC
  1277. ** Magit
  1278. [[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.
  1279. #+NAME: emacs-magit-package
  1280. #+BEGIN_SRC nix
  1281. epkgs.magit
  1282. #+END_SRC
  1283. #+NAME: emacs-magit-elisp
  1284. #+BEGIN_SRC emacs-lisp
  1285. ;; Add keybindings for working with `magit'.
  1286. (dotfiles/leader
  1287. "g" '(:ignore t :which-key "Git")
  1288. "gg" '(magit-status :which-key "Status")
  1289. "gc" '(magit-clone :which-key "Clone")
  1290. "gf" '(magit-fetch :which-key "Fetch")
  1291. "gp" '(magit-pull :which-key "Pull"))
  1292. #+END_SRC
  1293. ** Hydra
  1294. #+NAME: emacs-hydra-package
  1295. #+BEGIN_SRC nix
  1296. epkgs.hydra
  1297. #+END_SRC
  1298. [[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.
  1299. ** Fonts
  1300. [[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.
  1301. #+NAME: emacs-fonts-elisp
  1302. #+BEGIN_SRC emacs-lisp
  1303. ;; Configure the font when running as `emacs-server'.
  1304. (custom-set-faces
  1305. '(default ((t (:inherit nil :height 120 :family "Iosevka")))))
  1306. ;; Define a `hydra' function for scaling the text interactively.
  1307. (defhydra hydra-text-scale (:timeout 4)
  1308. "Scale the text in the current buffer."
  1309. ("k" text-scale-decrease "Decrease")
  1310. ("j" text-scale-increase "Increase")
  1311. ("f" nil "Finished" :exit t))
  1312. ;; Create keybinding for calling the function.
  1313. (dotfiles/leader
  1314. "tf" '(hydra-text-scale/body :which-key "Font"))
  1315. #+END_SRC
  1316. ** Frames
  1317. 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:
  1318. #+NAME: emacs-frames-elisp
  1319. #+BEGIN_SRC emacs-lisp
  1320. ;; Define a `hydra' function for resizing the current frame.
  1321. (defhydra hydra-resize-frame (:timeout 4)
  1322. "Scale the current frame."
  1323. ("h" shrink-window-horizontally "Left")
  1324. ("j" enlarge-window "Down")
  1325. ("k" shrink-window "Up")
  1326. ("l" enlarge-window-horizontally "Right")
  1327. ("f" nil "Finished" :exit t))
  1328. ;; Add keybindings for working with frames to replace
  1329. ;; the C-x <num> <num> method of bindings, which is awful.
  1330. (dotfiles/leader
  1331. "w" '(:ignore t :which-key "Windows")
  1332. "ww" '(window-swap-states :which-key "Swap")
  1333. "wc" '(delete-window :which-key "Close")
  1334. "wh" '(windmove-left :which-key "Left")
  1335. "wj" '(windmove-down :which-key "Down")
  1336. "wk" '(windmove-up :which-key "Up")
  1337. "wl" '(windmove-right :which-key "Right")
  1338. "ws" '(:ignore t :which-key "Split")
  1339. "wsj" '(split-window-below :which-key "Below")
  1340. "wsl" '(split-window-right :which-key "Right")
  1341. "wr" '(hydra-resize-frame/body :which-key "Resize"))
  1342. #+END_SRC
  1343. ** Elfeed
  1344. #+NAME: emacs-elfeed-package
  1345. #+BEGIN_SRC nix
  1346. epkgs.elfeed
  1347. #+END_SRC
  1348. [[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.
  1349. #+NAME: emacs-elfeed-elisp
  1350. #+BEGIN_SRC emacs-lisp
  1351. ;; Configure `elfeed'.
  1352. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1353. ;; Add custom feeds for `elfeed' to fetch.
  1354. (setq elfeed-feeds (quote
  1355. (("https://hexdsl.co.uk/rss.xml")
  1356. ("https://lukesmith.xyz/rss.xml")
  1357. ("https://friendo.monster/rss.xml")
  1358. ("https://chrishayward.xyz/index.xml")
  1359. ("https://protesilaos.com/master.xml"))))
  1360. ;; Add custom keybindings for `elfeed'.
  1361. (dotfiles/leader
  1362. "f" '(:ignore t :which-key "Elfeed")
  1363. "fl" '(elfeed :which-key "Open")
  1364. "fu" '(elfeed-update :which-key "Update"))
  1365. #+END_SRC
  1366. ** Org Mode
  1367. #+NAME: emacs-org-package
  1368. #+BEGIN_SRC nix
  1369. epkgs.org
  1370. #+END_SRC
  1371. [[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.
  1372. #+NAME: emacs-org-elisp
  1373. #+BEGIN_SRC emacs-lisp
  1374. ;; Configure `org-mode' source blocks.
  1375. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1376. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1377. org-hide-emphasis-markers t ;; Don't show emphasis markup.
  1378. org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
  1379. org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
  1380. ;; Add an `org-mode-hook'.
  1381. (add-hook 'org-mode-hook
  1382. (lambda ()
  1383. (org-indent-mode)
  1384. (visual-line-mode)))
  1385. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1386. (setq org-export-html-validation-link nil
  1387. org-html-validation-link nil)
  1388. ;; Configure the keywords in the TODO -> DONE sequence.
  1389. (setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  1390. ;; Track ids globally.
  1391. (setq org-id-track-globally t)
  1392. ;; Configure `org-babel' languages.
  1393. (org-babel-do-load-languages
  1394. 'org-babel-load-languages
  1395. '((C . t)))
  1396. ;; Log / Clock into property drawers.
  1397. (setq org-log-into-drawer t
  1398. org-clock-into-drawer t)
  1399. ;; Encrypt files with the public key.
  1400. (setq epa-file-select-keys 2
  1401. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1402. epa-cache-passphrase-for-symmetric-encryption t)
  1403. ;; TODO: Configure default structure templates.
  1404. ;; (require 'org-tempo)
  1405. ;; Apply custom keybindings.
  1406. (dotfiles/leader
  1407. "o" '(:ignore t :which-key "Org")
  1408. "oe" '(org-export-dispatch :which-key "Export")
  1409. "ot" '(org-babel-tangle :which-key "Tangle")
  1410. "oi" '(org-toggle-inline-images :which-key "Images")
  1411. "of" '(:ignore t :which-key "Footnotes")
  1412. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1413. #+END_SRC
  1414. ** Org Roam
  1415. #+NAME: emacs-org-roam-package
  1416. #+BEGIN_SRC nix
  1417. epkgs.org-roam
  1418. #+END_SRC
  1419. [[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.
  1420. #+NAME: emacs-org-roam-elisp
  1421. #+BEGIN_SRC emacs-lisp
  1422. ;; Setup `org-roam'.
  1423. (require 'org-roam)
  1424. ;; Silence the migration warnings.
  1425. (setq org-roam-v2-ack t)
  1426. ;; Enable `visual-line-mode' in `org-roam' buffer.
  1427. (add-hook 'org-roam-mode-hook
  1428. (lambda ()
  1429. (visual-line-mode +1)))
  1430. ;; Enable completion everywhere.
  1431. (setq org-roam-completion-everywhere t)
  1432. ;; Set the roam directories.
  1433. (setq org-roam-directory (expand-file-name "/etc/dotfiles")
  1434. org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
  1435. ;; Clear the deafult capture templates.
  1436. (setq org-roam-capture-templates '()
  1437. org-roam-dailies-capture-templates '())
  1438. ;; Override the default slug method.
  1439. (cl-defmethod org-roam-node-slug ((node org-roam-node))
  1440. (let ((title (org-roam-node-title node))
  1441. (slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
  1442. 769 ; U+0301 COMBINING ACUTE ACCENT
  1443. 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
  1444. 771 ; U+0303 COMBINING TILDE
  1445. 772 ; U+0304 COMBINING MACRON
  1446. 774 ; U+0306 COMBINING BREVE
  1447. 775 ; U+0307 COMBINING DOT ABOVE
  1448. 776 ; U+0308 COMBINING DIAERESIS
  1449. 777 ; U+0309 COMBINING HOOK ABOVE
  1450. 778 ; U+030A COMBINING RING ABOVE
  1451. 780 ; U+030C COMBINING CARON
  1452. 795 ; U+031B COMBINING HORN
  1453. 803 ; U+0323 COMBINING DOT BELOW
  1454. 804 ; U+0324 COMBINING DIAERESIS BELOW
  1455. 805 ; U+0325 COMBINING RING BELOW
  1456. 807 ; U+0327 COMBINING CEDILLA
  1457. 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
  1458. 814 ; U+032E COMBINING BREVE BELOW
  1459. 816 ; U+0330 COMBINING TILDE BELOW
  1460. 817 ; U+0331 COMBINING MACRON BELOW
  1461. )))
  1462. (cl-flet* ((nonspacing-mark-p (char)
  1463. (memq char slug-trim-chars))
  1464. (strip-nonspacing-marks (s)
  1465. (ucs-normalize-NFC-string
  1466. (apply #'string (seq-remove #'nonspacing-mark-p
  1467. (ucs-normalize-NFD-string s)))))
  1468. (cl-replace (title pair)
  1469. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1470. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
  1471. ("--*" . "-")
  1472. ("^-" . "")
  1473. ("-$" . "")))
  1474. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1475. (downcase slug)))))
  1476. ;; Configure capture templates.
  1477. ;; Standard document.
  1478. (add-to-list 'org-roam-capture-templates
  1479. '("d" "Default" plain "%?"
  1480. :target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
  1481. "
  1482. ,#+TITLE: ${title}
  1483. ,#+AUTHOR: Christopher James Hayward
  1484. ,#+EMAIL: chris@chrishayward.xyz
  1485. "
  1486. )
  1487. :unnarrowed t))
  1488. ;; Daily notes.
  1489. (add-to-list 'org-roam-dailies-capture-templates
  1490. '("d" "Default" entry "* %?"
  1491. :target (file+head "%<%Y-%m-%d>.org.gpg"
  1492. "
  1493. ,#+TITLE: %<%Y-%m-%d>
  1494. ,#+AUTHOR: Christopher James Hayward
  1495. ,#+EMAIL: chris@chrishayward.xyz
  1496. ")))
  1497. ;; Apply custom keybindings.
  1498. (dotfiles/leader
  1499. "or" '(:ignore t :which-key "Roam")
  1500. "ori" '(org-roam-node-insert :which-key "Insert")
  1501. "orf" '(org-roam-node-find :which-key "Find")
  1502. "orc" '(org-roam-capture :which-key "Capture")
  1503. "orb" '(org-roam-buffer-toggle :which-key "Buffer"))
  1504. ;; Apply custom keybindings for dailies.
  1505. (dotfiles/leader
  1506. "ord" '(:ignore t :which-key "Dailies")
  1507. "ordd" '(org-roam-dailies-goto-date :which-key "Date")
  1508. "ordt" '(org-roam-dailies-goto-today :which-key "Today")
  1509. "ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
  1510. "ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
  1511. ;; Run the setup command.
  1512. (org-roam-setup)
  1513. #+END_SRC
  1514. ** Org Roam UI
  1515. #+NAME: emacs-org-roam-ui-package
  1516. #+BEGIN_SRC nix
  1517. epkgs.org-roam-ui
  1518. epkgs.websocket
  1519. epkgs.simple-httpd
  1520. #+END_SRC
  1521. [[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]].
  1522. #+NAME: emacs-org-roam-ui-elisp
  1523. #+BEGIN_SRC emacs-lisp
  1524. ;; HACK: Set up `org-roam-ui'.
  1525. ;; (add-to-list 'load-path "~/.local/source/org-roam-ui")
  1526. (load-library "org-roam-ui")
  1527. ;; Configure `org-roam-ui'.
  1528. (setq org-roam-ui-follow t
  1529. org-roam-ui-sync-theme t
  1530. org-roam-ui-open-on-start t
  1531. org-roam-ui-update-on-save t
  1532. org-roam-ui-browser-function #'browse-url-firefox)
  1533. ;; Configure keybindings.
  1534. (dotfiles/leader
  1535. "oru" '(:ignore t :which-key "UI")
  1536. "oruu" '(org-roam-ui-mode :which-key "Toggle UI")
  1537. "orut" '(orui-sync-theme :which-key "Sync Theme"))
  1538. #+END_SRC
  1539. ** Org Drill
  1540. #+NAME: emacs-org-drill-package
  1541. #+BEGIN_SRC nix
  1542. epkgs.org-drill
  1543. #+END_SRC
  1544. [[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.
  1545. #+NAME: emacs-org-drill-elisp
  1546. #+BEGIN_SRC emacs-lisp
  1547. ;; Exclude :drill: items from `org-roam'.
  1548. (setq org-roam-db-node-include-function
  1549. (defun dotfiles/org-roam-include ()
  1550. (not (member "drill" (org-get-tags)))))
  1551. ;; Configure keybindings for `org-drill'.
  1552. (dotfiles/leader
  1553. "od" '(:ignore t :which-key "Drill")
  1554. "odd" '(org-drill :which-key "Drill")
  1555. "odc" '(org-drill-cram :which-key "Cram")
  1556. "odr" '(org-drill-resume :which-key "Resume"))
  1557. #+END_SRC
  1558. ** Org Agenda
  1559. 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.
  1560. #+NAME: emacs-org-agenda-elisp
  1561. #+BEGIN_SRC emacs-lisp
  1562. ;; Configure `org-agenda' to use the project files.
  1563. (setq org-agenda-files '("/etc/dotfiles/"
  1564. "/etc/dotfiles/docs/"
  1565. "/etc/dotfiles/docs/daily/"))
  1566. ;; Include files encrypted with `gpg'.
  1567. (require 'org)
  1568. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1569. (setq org-agenda-file-regexp
  1570. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1571. org-agenda-file-regexp)))
  1572. ;; Open an agenda buffer with SPC o a.
  1573. (dotfiles/leader
  1574. "oa" '(org-agenda :which-key "Agenda"))
  1575. #+END_SRC
  1576. ** Org Pomodoro
  1577. #+NAME: emacs-pomodoro-package
  1578. #+BEGIN_SRC nix
  1579. epkgs.org-pomodoro
  1580. #+END_SRC
  1581. [[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.
  1582. #+NAME: emacs-pomodoro-elisp
  1583. #+BEGIN_SRC emacs-lisp
  1584. ;; Configure `org-pomodor' with the overtime workflow.
  1585. (setq org-pomodoro-manual-break t
  1586. org-pomodoro-keep-killed-time t)
  1587. ;; Configure keybindings.
  1588. (dotfiles/leader
  1589. "op" '(org-pomodoro :which-key "Pomodoro"))
  1590. #+END_SRC
  1591. ** Writegood Mode
  1592. #+NAME: emacs-writegood-package
  1593. #+BEGIN_SRC nix
  1594. epkgs.writegood-mode
  1595. #+END_SRC
  1596. [[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:
  1597. + Weasel Words
  1598. + Passive Voice
  1599. + Duplicate Words
  1600. #+NAME: emacs-writegood-elisp
  1601. #+BEGIN_SRC emacs-lisp
  1602. ;; Configure `writegood-mode'.
  1603. (dotfiles/leader
  1604. "tg" '(writegood-mode :which-key "Grammar"))
  1605. #+END_SRC
  1606. ** Aspell
  1607. #+NAME: emacs-aspell-extras
  1608. #+BEGIN_SRC nix
  1609. pkgs.aspell
  1610. pkgs.aspellDicts.en
  1611. pkgs.aspellDicts.en-science
  1612. pkgs.aspellDicts.en-computers
  1613. #+END_SRC
  1614. [[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.
  1615. #+NAME: emacs-aspell-elisp
  1616. #+BEGIN_SRC emacs-lisp
  1617. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1618. (setq ispell-program-name "aspell"
  1619. ispell-eextra-args '("--sug-mode=fast"))
  1620. ;; Configure the built-in `flyspell-mode'.
  1621. (dotfiles/leader
  1622. "ts" '(flyspell-mode :which-key "Spelling"))
  1623. #+END_SRC
  1624. ** TexLive
  1625. [[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/:
  1626. | Name | Derivation | Comment |
  1627. |---------+---------------------------------+------------------------------------------------------------|
  1628. | Full | texlive.combined.scheme-full | Contains every TeX Live package |
  1629. | Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
  1630. | Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
  1631. | Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
  1632. | Minimal | texlive.combined.scheme-minimal | Contains plain only |
  1633. #+NAME: emacs-texlive-extras
  1634. #+BEGIN_SRC nix
  1635. # pkgs.texlive.combined.scheme-full
  1636. #+END_SRC
  1637. ** Http
  1638. #+NAME: emacs-http-package
  1639. #+BEGIN_SRC nix
  1640. epkgs.ob-http
  1641. #+END_SRC
  1642. 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.
  1643. #+NAME: emacs-http-elisp
  1644. #+BEGIN_SRC emacs-lisp
  1645. ;; Required to setup `ob-http'.
  1646. (org-babel-do-load-languages
  1647. 'org-babel-load-languages
  1648. '((http . t)))
  1649. #+END_SRC
  1650. ** Hugo
  1651. #+NAME: emacs-hugo-package
  1652. #+BEGIN_SRC nix
  1653. epkgs.ox-hugo
  1654. #+END_SRC
  1655. [[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/.
  1656. #+NAME: emacs-hugo-elisp
  1657. #+BEGIN_SRC emacs-lisp
  1658. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  1659. (require 'ox-hugo)
  1660. ;; Set up the base directory.
  1661. (setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
  1662. ;; Capture templates.
  1663. ;; Shared content
  1664. ;; (add-to-list 'org-roam-capture-templates
  1665. ;; '("p" "Post" plain "%?"
  1666. ;; :target (file+head "docs/posts/${slug}.org.gpg"
  1667. ;; "
  1668. ;; ,#+TITLE: ${title}
  1669. ;; ,#+AUTHOR: Christopher James Hayward
  1670. ;; ,#+DATE: %<%Y-%m-%d>
  1671. ;; ,#+EXPORT_FILE_NAME: ${slug}
  1672. ;; ,#+OPTIONS: num:nil todo:nil tasks:nil
  1673. ;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  1674. ;; ,#+HUGO_BASE_DIR: ../
  1675. ;; ,#+HUGO_AUTO_SET_LASTMOD: t
  1676. ;; ,#+HUGO_SECTION: posts
  1677. ;; ,#+HUGO_DRAFT: true
  1678. ;; "
  1679. ;; )
  1680. ;; :unnarrowed t))
  1681. #+END_SRC
  1682. ** Passwords
  1683. #+NAME: emacs-pass-extras
  1684. #+BEGIN_SRC nix
  1685. pkgs.pass
  1686. #+END_SRC
  1687. 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.
  1688. #+NAME: emacs-pass-package
  1689. #+BEGIN_SRC nix
  1690. epkgs.password-store
  1691. #+END_SRC
  1692. Configure keybindings for passwords behind =SPC p=:
  1693. #+NAME: emacs-pass-elisp
  1694. #+BEGIN_SRC emacs-lisp
  1695. ;; Set the path to the password store.
  1696. (setq password-store-dir (expand-file-name "~/.password-store"))
  1697. ;; Apply custom keybindings.
  1698. (dotfiles/leader
  1699. "p" '(:ignore t :which-key "Passwords")
  1700. "pp" '(password-store-copy :which-key "Copy")
  1701. "pe" '(password-store-edit :which-key "Edit")
  1702. "pi" '(password-store-insert :which-key "Insert")
  1703. "pr" '(password-store-rename :which-key "Rename")
  1704. "pg" '(password-store-generate :which-key "Generate"))
  1705. #+END_SRC
  1706. ** Docker
  1707. #+NAME: emacs-docker-package
  1708. #+BEGIN_SRC nix
  1709. epkgs.docker
  1710. epkgs.dockerfile-mode
  1711. #+END_SRC
  1712. 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.
  1713. #+NAME: emacs-docker-elisp
  1714. #+BEGIN_SRC emacs-lisp
  1715. ;; Apply custom keybindings.
  1716. (dotfiles/leader
  1717. "n" '(:ignore t :which-key "Containers")
  1718. "nd" '(docker :which-key "Docker"))
  1719. #+END_SRC
  1720. ** MU4E
  1721. #+NAME: emacs-mu4e-extras
  1722. #+BEGIN_SRC nix
  1723. pkgs.mu
  1724. pkgs.isync
  1725. #+END_SRC
  1726. #+NAME: emacs-mu4e-package
  1727. #+BEGIN_SRC nix
  1728. epkgs.mu4e-alert
  1729. #+END_SRC
  1730. #+NAME: emacs-mu4e-config
  1731. #+BEGIN_SRC nix
  1732. # Deploy the authinfo file.
  1733. home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
  1734. # Deploy the isync configuration file.
  1735. home.file.".mbsyncrc" = {
  1736. text = ''
  1737. IMAPStore xyz-remote
  1738. Host mail.chrishayward.xyz
  1739. User chris@chrishayward.xyz
  1740. PassCmd "pass chrishayward.xyz/chris"
  1741. SSLType IMAPS
  1742. MaildirStore xyz-local
  1743. Path ~/.cache/mail/
  1744. Inbox ~/.cache/mail/inbox
  1745. SubFolders Verbatim
  1746. Channel xyz
  1747. Far :xyz-remote:
  1748. Near :xyz-local:
  1749. Patterns * !Archives
  1750. Create Both
  1751. Expunge Both
  1752. SyncState *
  1753. '';
  1754. };
  1755. #+END_SRC
  1756. #+BEGIN_SRC sh
  1757. mbsync -a
  1758. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  1759. mu index
  1760. #+END_SRC
  1761. #+NAME: emacs-mu4e-elisp
  1762. #+BEGIN_SRC emacs-lisp
  1763. ;; Add the `mu4e' shipped with `mu' to the load path.
  1764. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  1765. (require 'mu4e)
  1766. ;; Confiugure `mu4e'.
  1767. (setq mu4e-maildir "~/.cache/mail"
  1768. mu4e-update-interval (* 5 60)
  1769. mu4e-get-mail-command "mbsync -a"
  1770. mu4e-compose-format-flowed t
  1771. mu4e-change-filenames-when-moving t
  1772. mu4e-compose-signature (concat "Chris Hayward\n"
  1773. "chris@chrishayward.xyz"))
  1774. ;; Sign all outbound email with GPG.
  1775. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  1776. (setq message-send-mail-function 'smtpmail-send-it
  1777. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  1778. ;; Setup `mu4e' accounts.
  1779. (setq mu4e-contexts
  1780. (list
  1781. ;; Main
  1782. ;; chris@chrishayward.xyz
  1783. (make-mu4e-context
  1784. :name "Main"
  1785. :match-func
  1786. (lambda (msg)
  1787. (when msg
  1788. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  1789. :vars
  1790. '((user-full-name . "Christopher James Hayward")
  1791. (user-mail-address . "chris@chrishayward.xyz")
  1792. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  1793. (smtpmail-smtp-service . 587)
  1794. (smtpmail-stream-type . starttls)))))
  1795. ;; Setup `mu4e-alert'.
  1796. (setq mu4e-alert-set-default-style 'libnotify)
  1797. (mu4e-alert-enable-notifications)
  1798. (mu4e-alert-enable-mode-line-display)
  1799. ;; Open the `mu4e' dashboard.
  1800. (dotfiles/leader
  1801. "m" '(mu4e :which-key "Mail"))
  1802. #+END_SRC
  1803. ** Projectile
  1804. #+NAME: emacs-projectile-package
  1805. #+BEGIN_SRC nix
  1806. epkgs.projectile
  1807. #+END_SRC
  1808. [[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.
  1809. #+NAME: emacs-projectile-elisp
  1810. #+BEGIN_SRC emacs-lisp
  1811. ;; Configure the `projectile-project-search-path'.
  1812. (setq projectile-project-search-path '("~/.local/source"))
  1813. (projectile-mode +1)
  1814. #+END_SRC
  1815. ** LSP Mode
  1816. #+NAME: emacs-lsp-package
  1817. #+BEGIN_SRC nix
  1818. epkgs.lsp-mode
  1819. epkgs.lsp-ui
  1820. #+END_SRC
  1821. 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:
  1822. + Auto Complete
  1823. + Go To Defintion
  1824. + Find All References
  1825. #+NAME: emacs-lsp-elisp
  1826. #+BEGIN_SRC emacs-lisp
  1827. ;; Configure `lsp-mode'.
  1828. (setq lsp-idle-delay 0.5
  1829. lsp-prefer-flymake t)
  1830. ;; Configure `lsp-ui'.
  1831. (setq lsp-ui-doc-position 'at-point
  1832. lsp-ui-doc-delay 0.5)
  1833. ;; Add custom keybindings for `lsp'.
  1834. (dotfiles/leader
  1835. "tl" '(lsp :which-key "LSP"))
  1836. #+END_SRC
  1837. ** CCLS
  1838. #+NAME: emacs-ccls-package
  1839. #+BEGIN_SRC nix
  1840. epkgs.ccls
  1841. #+END_SRC
  1842. [[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.
  1843. #+NAME: emacs-ccls-elisp
  1844. #+BEGIN_SRC emacs-lisp
  1845. ;; Configure `ccls' to work with `lsp-mode'.
  1846. (defun dotfiles/ccls-hook ()
  1847. (require 'ccls)
  1848. (lsp))
  1849. ;; Configure `ccls' mode hooks.
  1850. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  1851. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  1852. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  1853. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  1854. #+END_SRC
  1855. ** Company Mode
  1856. #+NAME: emacs-company-package
  1857. #+BEGIN_SRC nix
  1858. epkgs.company
  1859. #+END_SRC
  1860. [[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.
  1861. #+NAME: emacs-company-elisp
  1862. #+BEGIN_SRC emacs-lisp
  1863. ;; Configure `company-mode'.
  1864. (setq company-backend 'company-capf
  1865. lsp-completion-provider :capf)
  1866. ;; Enable it globally.
  1867. (global-company-mode +1)
  1868. #+END_SRC
  1869. ** Go Mode
  1870. #+NAME: emacs-golang-package
  1871. #+BEGIN_SRC nix
  1872. epkgs.go-mode
  1873. #+END_SRC
  1874. [[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.
  1875. #+NAME: emacs-golang-elisp
  1876. #+BEGIN_SRC emacs-lisp
  1877. ;; Configure `go-mode' to work with `lsp-mode'.
  1878. (defun dotfiles/go-hook ()
  1879. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  1880. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  1881. ;; Configure a custom `before-save-hook'.
  1882. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  1883. #+END_SRC
  1884. ** Rustic
  1885. #+NAME: emacs-rustic-package
  1886. #+BEGIN_SRC nix
  1887. epkgs.rustic
  1888. #+END_SRC
  1889. 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!
  1890. #+NAME: emacs-rustic-elisp
  1891. #+BEGIN_SRC emacs-lisp
  1892. ;; Configure `rustic' with `lsp-mode'.
  1893. (setq rustic-format-on-save t
  1894. rustic-lsp-server 'rls)
  1895. #+END_SRC
  1896. ** Python Mode
  1897. #+NAME: emacs-python-package
  1898. #+BEGIN_SRC nix
  1899. epkgs.pretty-mode
  1900. #+END_SRC
  1901. 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.
  1902. #+NAME: emacs-python-elisp
  1903. #+BEGIN_SRC emacs-lisp
  1904. ;; Configure `pretty-mode' to work with `python-mode'.
  1905. (add-hook 'python-mode-hook
  1906. (lambda ()
  1907. (turn-on-pretty-mode)))
  1908. #+END_SRC
  1909. ** Protobuf Mode
  1910. #+NAME: emacs-protobuf-package
  1911. #+BEGIN_SRC nix
  1912. epkgs.protobuf-mode
  1913. #+END_SRC
  1914. ** PlantUML
  1915. #+NAME: emacs-plantuml-extras
  1916. #+BEGIN_SRC nix
  1917. pkgs.plantuml
  1918. #+END_SRC
  1919. [[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.
  1920. #+NAME: emacs-plantuml-package
  1921. #+BEGIN_SRC nix
  1922. epkgs.plantuml-mode
  1923. #+END_SRC
  1924. [[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]].
  1925. #+NAME: emacs-plantuml-elisp
  1926. #+BEGIN_SRC emacs-lisp
  1927. ;; Configure `plantuml-mode'.
  1928. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  1929. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  1930. (setq plantuml-default-exec-mode 'executable
  1931. org-plantuml-exec-mode 'plantuml)
  1932. #+END_SRC
  1933. ** Swiper
  1934. #+NAME: emacs-swiper-package
  1935. #+BEGIN_SRC nix
  1936. epkgs.ivy
  1937. epkgs.counsel
  1938. epkgs.ivy-rich
  1939. epkgs.ivy-posframe
  1940. epkgs.ivy-prescient
  1941. #+END_SRC
  1942. [[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.
  1943. #+NAME: emacs-swiper-elisp
  1944. #+BEGIN_SRC emacs-lisp
  1945. ;; Configure `ivy'.
  1946. (setq counsel-linux-app-format-function
  1947. #'counsel-linux-app-format-function-name-only)
  1948. (ivy-mode +1)
  1949. (counsel-mode +1)
  1950. ;; Configure `ivy-rich'.
  1951. (ivy-rich-mode +1)
  1952. ;; Configure `ivy-posframe'.
  1953. (setq ivy-posframe-parameters '((parent-frame nil))
  1954. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  1955. (ivy-posframe-mode +1)
  1956. ;; Configure `ivy-prescient'.
  1957. (setq ivy-prescient-enable-filtering nil)
  1958. (ivy-prescient-mode +1)
  1959. #+END_SRC
  1960. ** Transparency
  1961. 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.
  1962. #+NAME: emacs-transparency-elisp
  1963. #+BEGIN_SRC emacs-lisp
  1964. ;; Configure the default frame transparency.
  1965. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  1966. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  1967. #+END_SRC
  1968. ** Desktop Environment
  1969. #+NAME: emacs-desktop-extras
  1970. #+BEGIN_SRC nix
  1971. pkgs.brightnessctl
  1972. #+END_SRC
  1973. 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]].
  1974. #+NAME: emacs-desktop-package
  1975. #+BEGIN_SRC nix
  1976. epkgs.desktop-environment
  1977. #+END_SRC
  1978. 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.
  1979. #+NAME: emacs-desktop-elisp
  1980. #+BEGIN_SRC emacs-lisp
  1981. ;; Configure `desktop-environment'.
  1982. (require 'desktop-environment)
  1983. (desktop-environment-mode +1)
  1984. #+END_SRC
  1985. ** Doom Themes
  1986. #+NAME: emacs-doom-themes-package
  1987. #+BEGIN_SRC nix
  1988. epkgs.doom-themes
  1989. #+END_SRC
  1990. [[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.
  1991. #+NAME: emacs-doom-themes-elisp
  1992. #+BEGIN_SRC emacs-lisp
  1993. ;; Include modern themes from `doom-themes'.
  1994. (setq doom-themes-enable-bold t
  1995. doom-themes-enable-italic t)
  1996. ;; Load the `doom-nord' and `doom-nord-light' themes.
  1997. ;; (load-theme 'doom-nord-light t)
  1998. (load-theme 'doom-nord t)
  1999. ;; Define a method for returning information about the current theme.
  2000. ;; This is based off the function `org-roam-ui-get-theme'.
  2001. (defun dotfiles/theme ()
  2002. "Return information about the current theme."
  2003. (list `(bg . ,(face-background hl-line-face))
  2004. `(bg-alt . ,(face-background 'default))
  2005. `(fg . ,(face-foreground 'default))
  2006. `(fg-alt . ,(face-foreground font-lock-comment-face))
  2007. `(red . ,(face-foreground 'error))
  2008. `(orange . ,(face-foreground 'warning))
  2009. `(yellow . ,(face-foreground font-lock-builtin-face))
  2010. `(green . ,(face-foreground 'success))
  2011. `(cyan . ,(face-foreground font-lock-constant-face))
  2012. `(blue . ,(face-foreground font-lock-keyword-face))
  2013. `(violet . ,(face-foreground font-lock-constant-face))
  2014. `(magenta . ,(face-foreground font-lock-preprocessor-face))))
  2015. ;; Load a new theme with <SPC> t t.
  2016. (dotfiles/leader
  2017. "tt" '(counsel-load-theme :which-key "Theme"))
  2018. #+END_SRC
  2019. Create a shell command that returns a JSON string of the current theme in the following format:
  2020. #+BEGIN_SRC json
  2021. {
  2022. "bg": "#272C36",
  2023. "bg-alt": "#2E3440",
  2024. "fg": "#ECEFF4",
  2025. "fg-alt": "#6f7787",
  2026. "red": "#BF616A",
  2027. "orange": "#EBCB8B",
  2028. "yellow": "#81A1C1",
  2029. "green": "#A3BE8C",
  2030. "cyan": "#81A1C1",
  2031. "blue": "#81A1C1",
  2032. "violet": "#81A1C1",
  2033. "magenta": "#81A1C1"
  2034. }
  2035. #+END_SRC
  2036. #+NAME: emacs-doom-themes-extras
  2037. #+BEGIN_SRC nix
  2038. (pkgs.writeShellScriptBin "dotfiles-theme" ''
  2039. ${myEmacs}/bin/emacsclient --no-wait --eval '(json-encode (dotfiles/theme))' | sed "s/\\\\//g" | sed -e 's/^"//' -e 's/"$//'
  2040. '')
  2041. #+END_SRC
  2042. ** Doom Modeline
  2043. #+NAME: emacs-doom-modeline-package
  2044. #+BEGIN_SRC nix
  2045. epkgs.doom-modeline
  2046. #+END_SRC
  2047. [[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.
  2048. #+NAME: emacs-doom-modeline-elisp
  2049. #+BEGIN_SRC emacs-lisp
  2050. ;; Configure `doom-modeline'.
  2051. (require 'doom-modeline)
  2052. (setq doom-modeline-height 16
  2053. doom-modeline-icon t)
  2054. ;; Launch after initialization.
  2055. (add-hook 'after-init-hook 'doom-modeline-mode)
  2056. ;; Define a modeline segment to show the workspace information.
  2057. (doom-modeline-def-segment dotfiles/workspaces
  2058. (exwm-workspace--update-switch-history)
  2059. (concat
  2060. (doom-modeline-spc)
  2061. (elt (let* ((num (exwm-workspace--count))
  2062. (sequence (number-sequence 0 (1- num)))
  2063. (not-empty (make-vector num nil)))
  2064. (dolist (i exwm--id-buffer-alist)
  2065. (with-current-buffer (cdr i)
  2066. (when exwm--frame
  2067. (setf (aref not-empty
  2068. (exwm-workspace--position exwm--frame))
  2069. t))))
  2070. (mapcar
  2071. (lambda (i)
  2072. (mapconcat
  2073. (lambda (j)
  2074. (format (if (= i j) "[%s]" " %s ")
  2075. (propertize
  2076. (apply exwm-workspace-index-map (list j))
  2077. 'face
  2078. (cond ((frame-parameter (elt exwm-workspace--list j)
  2079. 'exwm-urgency)
  2080. '(:inherit warning :weight bold))
  2081. ((= i j) '(:inherit underline :weight bold))
  2082. ((aref not-empty j) '(:inherit success :weight bold))
  2083. (t `((:foreground ,(face-foreground 'mode-line-inactive))))))))
  2084. sequence ""))
  2085. sequence))
  2086. (exwm-workspace--position (selected-frame)))))
  2087. ;; Define a custom modeline to override the default.
  2088. (doom-modeline-def-modeline 'dotfiles/modeline
  2089. '(bar workspace-name dotfiles/workspaces window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info)
  2090. '(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))
  2091. ;; Define a method to load the modeline.
  2092. (defun dotfiles/load-modeline ()
  2093. "Load the default modeline."
  2094. (doom-modeline-set-modeline 'dotfiles/modeline 'default))
  2095. ;; Enable `doom-modeline'.
  2096. (add-hook 'doom-modeline-mode-hook 'dotfiles/load-modeline)
  2097. (doom-modeline-mode +1)
  2098. (doom-modeline-set-modeline 'dotfiles/modeline 'default)
  2099. #+END_SRC
  2100. * Website Configuration
  2101. My [[https://chrishayward.xyz][personal website]] is a static HTML page written with [[https://gohugo.io][Hugo]], and is fully integrated into this configuration.
  2102. It uses the ~config.toml~, ~config.yaml~, or ~config.json~ file (found in the sites root directory) as the default site config.
  2103. #+BEGIN_SRC conf :noweb yes :tangle docs/config.toml
  2104. # <<file-warning>>
  2105. title = "Chris Hayward"
  2106. copyright = "Licensed under Attribution 4.0 International (CC BY 4.0)"
  2107. baseURL = "https://chrishayward.xyz/"
  2108. theme = "hello-friend-ng"
  2109. languageCode = "en-us"
  2110. defaultContentLanguage = "en"
  2111. pygmentsCodefences = true
  2112. pygmentsUseClasses = true
  2113. <<website-params>>
  2114. <<website-privacy>>
  2115. <<website-layout>>
  2116. #+END_SRC
  2117. ** Params
  2118. Dates are important in [[https://gohugo.io][Hugo]], and they configure how dates are assigned and displayed in your content pages.
  2119. Themes are also able to extract information from the configuration to display, including social media icons, subtitles, and footer sections.
  2120. #+NAME: website-params
  2121. #+BEGIN_SRC conf
  2122. [params]
  2123. dateform = "Jan 2, 2006"
  2124. dateformShort = "Jan 2"
  2125. dateformNum = "2006-01-02"
  2126. dateformNumTime = "2006-01-02 15:04 -0700"
  2127. authorName = "Christopher James Hayward"
  2128. homeSubtitle = "Airplanes, Linux, and Metalcore"
  2129. footerCopyright = ' &#183; <a href="http://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC BY 4.0</a>'
  2130. [[params.social]]
  2131. name = "paypal"
  2132. url = "https://paypal.me/chrishaywardxyz"
  2133. [[params.social]]
  2134. name = "github"
  2135. url = "https://github.com/chayward1/"
  2136. [[params.social]]
  2137. name = "gitlab"
  2138. url = "https://gitlab.com/chayward1/"
  2139. [[params.social]]
  2140. name = "email"
  2141. url = "mailto:chris@chrishayward.xyz"
  2142. #+END_SRC
  2143. ** Privacy
  2144. 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.
  2145. #+NAME: website-privacy
  2146. #+BEGIN_SRC conf
  2147. [privacy]
  2148. [privacy.disqus]
  2149. disable = true
  2150. [privacy.googleAnalytics]
  2151. disable = true
  2152. [privacy.instagram]
  2153. disable = true
  2154. [privacy.twitter]
  2155. disable = true
  2156. [privacy.vimeo]
  2157. disable = true
  2158. [privacy.youtube]
  2159. disable = true
  2160. #+END_SRC
  2161. ** Layout
  2162. 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.
  2163. #+NAME: website-layout
  2164. #+BEGIN_SRC conf
  2165. [menu]
  2166. [[menu.main]]
  2167. identifier = "cloud"
  2168. name = "Cloud"
  2169. url = "https://cloud.chrishayward.xyz"
  2170. [[menu.main]]
  2171. identifier = "dotfiles"
  2172. name = "Dotfiles"
  2173. url = "/dotfiles"
  2174. [[menu.main]]
  2175. identifier = "projects"
  2176. name = "Projects"
  2177. url = "https://git.chrishayward.xyz"
  2178. #+END_SRC
  2179. * Footnotes