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.

2903 lines
83 KiB

4 years ago
4 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
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
  1. #+TITLE: Dotfiles
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+EXPORT_FILE_NAME: dotfiles
  5. #+ROAM_KEY: https://chrishayward.xyz/dotfiles
  6. #+HUGO_BASE_DIR: docs
  7. #+HUGO_AUTO_SET_LASTMOD: t
  8. #+HUGO_SECTION:
  9. #+HUGO_DRAFT: false
  10. #+NAME: description
  11. #+BEGIN_SRC text
  12. Immutable NixOS dotfiles.
  13. #+END_SRC
  14. #+ATTR_ORG: :width 420px
  15. #+ATTR_HTML: :width 420px
  16. #+ATTR_LATEX: :width 420px
  17. [[./docs/images/desktop-example.png]]
  18. Built for Life, Liberty, and the Open Road.
  19. + 100% Immutable
  20. + 100% Declarative
  21. + 100% Reproducible
  22. * Introduction
  23. This is my personal configuration(s) for GNU/Linux[fn:1] systems. It enables a consistent experience and computing environment across all of my machines. This project is written with GNU/Emacs[fn:2], leveraging its capabilities for Literate Programming[fn:3], a technique where programs are written in a natural language, such as English, interspersed with snippets of code to describe a software project.
  24. #+NAME: file-warning
  25. #+BEGIN_SRC text
  26. This file is controlled by /etc/dotfiles/README.org
  27. #+END_SRC
  28. ** Getting Started
  29. 1) Download the latest version of NixOS https://nixos.org/download.html
  30. 2) Partition drives and mount the file system https://nixos.org/manual/nixos/stable/#sec-installation-partitioning
  31. 3) Clone the project to =/mnt/etc/dotfiles= ~git clone git@git.chrishayward.xyz:chris/dotfiles /mnt/etc/dotfiles~
  32. 4) Load the default shell environment ~nix-shell /mnt/etc/dotfiles~
  33. 5) Install the default system ~sudo nixos-install --flake /mnt/etc/dotfiles#nixos~
  34. 6) Reboot and login, start a graphical system with ~startx~
  35. ** Making Changes
  36. 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:
  37. + boot :: Build the new configuration and make it the boot default, without activation
  38. + test :: Build and activate the new configuration, without adding it to the boot menu
  39. + switch :: Build and activate the new configuration, making it the new boot default
  40. + build :: Build the new configuration, without activation, nor adding it to the boot menu
  41. + build-vm :: Build a script that starts a virtual machine with the desired configuration
  42. #+BEGIN_SRC shell
  43. # Build and activate a new configuration.
  44. sudo nixos-rebuild switch --flake $FLAKE#$HOSTNAME
  45. #+END_SRC
  46. 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.
  47. #+BEGIN_SRC shell
  48. # Rollback to the previous generation.
  49. sudo nixos-rebuild switch --rollback
  50. #+END_SRC
  51. ** Docker Container
  52. It's possible to use parts of this configuration using the 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.
  53. #+BEGIN_SRC conf :tangle Dockerfile
  54. # Derive from the official image.
  55. FROM nixos/nix
  56. # Add the unstable channel.
  57. RUN nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
  58. RUN nix-channel --update
  59. # Setup the default environment.
  60. WORKDIR /etc/dotfiles
  61. COPY . .
  62. # Load the default system shell.
  63. RUN nix-shell /etc/dotfiles
  64. #+END_SRC
  65. * Operating System
  66. NixOS[fn:4] is a purely functional Linux distribution built on top of the Nix[fn:5] package manager. It uses a declarative configuration language to define entire computer systems, and allows reliable system upgrades and rollbacks. NixOS[fn:4] also has tool dedicated to DevOps and deployment tasks, and makes it trivial to share development environments.
  67. #+BEGIN_SRC nix :noweb yes :tangle flake.nix
  68. # <<file-warning>>
  69. {
  70. description = "<<description>>";
  71. inputs = {
  72. <<os-nixpkgs>>
  73. <<os-home-manager>>
  74. <<os-emacs-overlay>>
  75. <<os-nixos-hardware>>
  76. <<os-nix-on-droid>>
  77. };
  78. outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, ... }: {
  79. nixosConfigurations = {
  80. <<host-default>>
  81. <<host-acernitro>>
  82. <<host-raspberry>>
  83. <<host-homecloud>>
  84. <<host-zero-one>>
  85. <<host-zero-two>>
  86. <<host-android>>
  87. };
  88. };
  89. }
  90. #+END_SRC
  91. ** Nixpkgs
  92. Nixpkgs[fn:6] is a collection of over 60,000 software packages that can be installed with the Nix[fn:5] package manager. Two main branches are offered:
  93. 1) The current stable release
  94. 2) The Unstable branch following the latest development
  95. #+NAME: os-nixpkgs
  96. #+BEGIN_SRC nix
  97. nixpkgs.url = "nixpkgs/nixos-unstable";
  98. nixpkgs-unstable.url = "nixpkgs/master";
  99. #+END_SRC
  100. ** Home Manager
  101. Home Manager[fn:7] provides a basic system for managing user environments using the Nix[fn:5] package manager together with the Nix libraries found in Nixpkgs[fn:6]. It allows declarative configuration of user specific (non-global) packages and files.
  102. #+NAME: os-home-manager
  103. #+BEGIN_SRC nix
  104. home-manager.url = "github:nix-community/home-manager";
  105. home-manager.inputs.nixpkgs.follows = "nixpkgs";
  106. #+END_SRC
  107. ** Emacs Overlay
  108. Adding the Emacs Overlay[fn:8] extends the GNU/Emacs[fn:2] package set to contain the latest versions, and daily generations from popular package sources, including the needed dependencies to run GNU/Emacs[fn:2] as a Window Manager.
  109. #+NAME: os-emacs-overlay
  110. #+BEGIN_SRC nix
  111. emacs-overlay.url = "github:nix-community/emacs-overlay";
  112. #+END_SRC
  113. ** NixOS Hardware
  114. NixOS Hardware[fn:9] is a collection of NixOS[fn:4] 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.
  115. #+NAME: os-nixos-hardware
  116. #+BEGIN_SRC nix
  117. nixos-hardware.url = "github:nixos/nixos-hardware";
  118. #+END_SRC
  119. ** Nix On Droid
  120. Nix On Droid[fn:10] is a deployment of the Nix[fn:5] Package Manager on 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.
  121. #+NAME: os-nix-on-droid
  122. #+BEGIN_SRC nix
  123. nix-on-droid.url = "github:t184256/nix-on-droid/master";
  124. nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
  125. #+END_SRC
  126. * Development Shells
  127. The command ~nix-shell~[fn:11] 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.
  128. Import this shell with ~nix-shell /etc/dotfiles/shell.nix~.
  129. #+BEGIN_SRC nix :noweb yes :tangle shell.nix
  130. # <<file-warning>>
  131. { pkgs ? import <nixpkgs> { } }:
  132. with pkgs;
  133. let
  134. nixBin = writeShellScriptBin "nix" ''
  135. ${nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
  136. '';
  137. in mkShell {
  138. buildInputs = [
  139. git
  140. ];
  141. shellHook = ''
  142. export FLAKE="$(pwd)"
  143. export PATH="$FLAKE/bin:${nixBin}/bin:$PATH"
  144. '';
  145. }
  146. #+END_SRC
  147. ** Go
  148. Go[fn:12] 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.
  149. Import this shell with ~nix-shell /etc/dotfiles/shells/go.nix~
  150. #+BEGIN_SRC nix :noweb yes :tangle shells/go.nix
  151. # <<file-warning>>
  152. { pkgs ? import <nixpkgs> { } }:
  153. with pkgs;
  154. mkShell {
  155. buildInputs = [
  156. go
  157. gopls
  158. ];
  159. shellHook = ''
  160. export GO111MODULE=on
  161. export GOPATH=$XDG_DATA_HOME/go
  162. export PATH=$GOPATH/bin:$PATH
  163. '';
  164. }
  165. #+END_SRC
  166. ** Rust
  167. Rust[fn:13] 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[fn:13] achieves memory safety /without/ garbage collection, and reference counting is optional.
  168. Import this shell with ~nix-shell /etc/dotfiles/shells/rust.nix~.
  169. #+BEGIN_SRC nix :noweb yes :tangle shells/rust.nix
  170. # <<file-warning>>
  171. { pkgs ? import <nixpkgs> { } }:
  172. with pkgs;
  173. mkShell {
  174. buildInputs = [
  175. rustup
  176. ];
  177. shellHook = ''
  178. export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
  179. export CARGO_HOME="$XDG_DATA_HOME/cargo"
  180. export PATH="$CARGO_HOME/bin:$PATH"
  181. '';
  182. }
  183. #+END_SRC
  184. ** Node
  185. Node.js[fn:14] 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. Node.js[fn:14] lets developers user JavaScript to write command line tools, and for server-side scripting to produce dynamic web page content.
  186. Import this shell with ~nix-shell /etc/dotfiles/shells/node.nix~.
  187. #+BEGIN_SRC nix :noweb yes :tangle shells/node.nix
  188. # <<file-warning>>
  189. { pkgs ? import <nixpkgs> { } }:
  190. with pkgs;
  191. mkShell {
  192. buildInputs = [
  193. nodejs
  194. yarn
  195. ];
  196. shellHook = ''
  197. export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
  198. export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
  199. export NPM_CACHE_PREFIX="$XDG_CACHE_HOME/npm"
  200. export PATH="$(yarn global bin):$PATH"
  201. '';
  202. }
  203. #+END_SRC
  204. ** gRPC
  205. gRPC[fn:15] 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.
  206. Import this shell with ~nix-shell /etc/dotfiles/shells/grpc.nix~.
  207. #+BEGIN_SRC nix :noweb yes :tangle shells/grpc.nix
  208. # <<file-warning>>
  209. { pkgs ? import <nixpkgs> { } }:
  210. with pkgs;
  211. mkShell {
  212. buildInputs = [
  213. grpc
  214. grpc-tools
  215. grpcui
  216. grpcurl
  217. ];
  218. shellHook = ''
  219. '';
  220. }
  221. #+END_SRC
  222. ** C/C++
  223. C[fn:16] 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. C++[fn:17] is a general-purpose programming language created as an extension of the C[fn:16] programming language.
  224. Import this shell with ~nix-shell /etc/dotfiles/shells/cc.nix~.
  225. #+BEGIN_SRC nix :noweb yes :tangle shells/cc.nix
  226. # <<file-warning>>
  227. { pkgs ? import <nixpkgs> { } }:
  228. with pkgs;
  229. mkShell {
  230. buildInputs = [
  231. gdb
  232. ccls
  233. cmake
  234. gnumake
  235. libstdcxx5
  236. gcc-unwrapped
  237. llvmPackages.libcxx
  238. ];
  239. shellHook = ''
  240. '';
  241. }
  242. #+END_SRC
  243. ** Python
  244. Python[fn:18] 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.
  245. Import this shell with ~nix-shell /etc/dotfiles/shells/python.nix~
  246. #+BEGIN_SRC nix :noweb yes :tangle shells/python.nix
  247. # <<file-warning>>
  248. { pkgs ? import <nixpkgs> { } }:
  249. with pkgs;
  250. mkShell {
  251. buildInputs = [
  252. python38Packages.pip
  253. python38Packages.pip-tools
  254. python38Packages.pyls-mypy
  255. python38Packages.pyls-isort
  256. python38Packages.pyls-black
  257. ];
  258. shellHook = ''
  259. '';
  260. }
  261. #+END_SRC
  262. * Host Configurations
  263. NixOS[fn:4] 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:
  264. #+NAME: host-config-wifi
  265. #+BEGIN_SRC nix
  266. networking.wireless.networks.MyWiFi_5C1870.pskRaw =
  267. "409b3c85fef1c5737f284d2f82f20dc6023e41804e862d4fa26265ef8193b326";
  268. #+END_SRC
  269. 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:
  270. #+NAME: host-config-home
  271. #+BEGIN_SRC nix
  272. networking.hosts = {
  273. "192.168.3.105" = [ "gamingpc" ];
  274. # "" = [ "acernitro" ];
  275. "192.168.3.163" = [ "acernitro_" ];
  276. "192.168.3.182" = [ "raspberry" ];
  277. "192.168.3.123" = [ "raspberry_" ];
  278. "192.168.3.183" = [ "homecloud" ];
  279. # "" = [ "homecloud_" ];
  280. # "" = [ "zero-one" ];
  281. # "" = [ "zero-two" ];
  282. # "" = [ "android" ];
  283. };
  284. #+END_SRC
  285. ** Default
  286. The default host, built using QEMU[fn:19], a free and open-source emulator that can perform hardware virtualization. It features a lightweight system optimized for development, running GNU/Emacs[fn:2] + EXWM[fn:20] as the graphical environment.
  287. #+NAME: host-default
  288. #+BEGIN_SRC nix :noweb yes
  289. nixos = nixpkgs.lib.nixosSystem {
  290. system = "x86_64-linux";
  291. specialArgs = { inherit inputs; };
  292. modules = [
  293. ./hosts/nixos
  294. <<module-x11>>
  295. <<module-ssh>>
  296. <<module-flakes>>
  297. <<module-cachix>>
  298. <<module-home-manager>>
  299. ];
  300. };
  301. #+END_SRC
  302. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#nixos~.
  303. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/default.nix
  304. # <<file-warning>>
  305. { ... }:
  306. {
  307. imports = [
  308. ./configuration.nix
  309. ./hardware.nix
  310. ];
  311. }
  312. #+END_SRC
  313. *** Configuration
  314. This is a basic default configuration that specified the indended default configuration of the system. Because NixOS[fn:4] has a declarative configuration model, you can create or edit a description of the desired configuration, and update it from one file.
  315. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/configuration.nix
  316. # <<file-warning>>
  317. { config, pkgs, inputs, ... }:
  318. {
  319. time.timeZone = "America/Toronto";
  320. networking.hostName = "nixos";
  321. networking.useDHCP = false;
  322. networking.firewall.enable = false;
  323. networking.interfaces.ens3.useDHCP = true;
  324. <<host-config-home>>
  325. programs.mtr.enable = true;
  326. programs.fish.enable = true;
  327. programs.gnupg.agent.enable = true;
  328. users.users.chris = {
  329. shell = pkgs.fish;
  330. isNormalUser = true;
  331. extraGroups = [ "wheel" ];
  332. };
  333. }
  334. #+END_SRC
  335. *** Hardware
  336. The file system for this host is a single 24GB QCOW file, a format for disk images used by QEMU[fn:19]. The file can be recreated easily by following the steps listed in the NixOS[fn:4] installation manual, specifically the section on disk formatting.
  337. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/hardware.nix
  338. # <<file-warning>>
  339. { config, lib, pkgs, modulesPath, ... }:
  340. {
  341. imports =
  342. [ (modulesPath + "/profiles/qemu-guest.nix")
  343. ];
  344. boot.initrd.availableKernelModules = [ "ata_piix" "floppy" "sd_mod" "sr_mod" ];
  345. boot.initrd.kernelModules = [ ];
  346. boot.kernelModules = [ ];
  347. boot.extraModulePackages = [ ];
  348. boot.loader.grub.enable = true;
  349. boot.loader.grub.version = 2;
  350. boot.loader.grub.device = "/dev/sda";
  351. fileSystems."/" =
  352. { device = "/dev/disk/by-uuid/fddc37ff-a442-41fa-afc4-abf878be7c5a";
  353. fsType = "ext4";
  354. };
  355. swapDevices =
  356. [ { device = "/dev/disk/by-uuid/5fc0e3df-e796-4fe2-8482-c6acaed9d36f"; }
  357. ];
  358. }
  359. #+END_SRC
  360. ** Acernitro
  361. My gaming laptop, the model is an Acer Nitro AN-515-53[fn:21]. The Nitro 5 has more in common with the mid-range notebooks rather than the gaming models due to its cooling design, chassis, and overall construction.
  362. Here are the specs:
  363. | Slot | Component |
  364. |---------+---------------------------------------|
  365. | CPU | Intel Core i5-8300H |
  366. | GPU | NVIDIA GeForce GTX 1050Ti (4GB GDDR5) |
  367. | RAM | 16GB DDR4 |
  368. | Display | 15.6" Full HD (1920 x 1080), IPS |
  369. | Storage | 1000GB HDD |
  370. | Weight | 2.48kg (5.5 lbs) |
  371. #+NAME: host-acernitro
  372. #+BEGIN_SRC nix :noweb yes
  373. acernitro = nixpkgs.lib.nixosSystem {
  374. system = "x86_64-linux";
  375. specialArgs = { inherit inputs; };
  376. modules = [
  377. ./hosts/acernitro
  378. <<module-x11>>
  379. <<module-ssh>>
  380. <<module-flakes>>
  381. <<module-cachix>>
  382. <<module-nvidia>>
  383. <<module-firefox>>
  384. <<module-moonlight>>
  385. <<module-teamviewer>>
  386. <<module-home-manager>>
  387. ];
  388. };
  389. #+END_SRC
  390. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#acernitro~.
  391. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/default.nix
  392. # <<file-warning>>
  393. { ... }:
  394. {
  395. imports = [
  396. ./configuration.nix
  397. ./hardware.nix
  398. ];
  399. }
  400. #+END_SRC
  401. *** Configuration
  402. This configuration is nearly identical to the default, except for a few key differences:
  403. + Enables sound
  404. + Applies the desired hostname
  405. + It adds support for =UEFI= systems
  406. + Enables support for wireless networking
  407. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/configuration.nix
  408. # <<file-warning>>
  409. { config, pkgs, inputs, ... }:
  410. {
  411. time.timeZone = "America/Toronto";
  412. networking.hostName = "acernitro";
  413. networking.firewall.enable = false;
  414. networking.wireless.enable = true;
  415. networking.wireless.userControlled.enable = true;
  416. networking.useDHCP = false;
  417. networking.interfaces.enp6s0f1.useDHCP = true;
  418. networking.interfaces.wlp0s20f3.useDHCP = true;
  419. <<host-config-wifi>>
  420. <<host-config-home>>
  421. services.xserver.dpi = 96;
  422. services.printing.enable = true;
  423. programs.mtr.enable = true;
  424. programs.fish.enable = true;
  425. programs.gnupg.agent.enable = true;
  426. users.users.chris = {
  427. shell = pkgs.fish;
  428. isNormalUser = true;
  429. extraGroups = [ "wheel" ];
  430. };
  431. }
  432. #+END_SRC
  433. *** Hardware
  434. + Enables sound via PulseAudio
  435. + Adds support for the NVIDIA Hybrid GPU
  436. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/hardware.nix
  437. # <<file-warning>>
  438. { config, lib, pkgs, modulesPath, ... }:
  439. {
  440. imports =
  441. [ (modulesPath + "/installer/scan/not-detected.nix")
  442. ];
  443. boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ];
  444. boot.initrd.kernelModules = [ ];
  445. boot.kernelModules = [ "kvm-intel" ];
  446. boot.extraModulePackages = [ ];
  447. boot.loader.systemd-boot.enable = true;
  448. boot.loader.efi.canTouchEfiVariables = true;
  449. sound.enable = true;
  450. hardware.pulseaudio.enable = true;
  451. hardware.pulseaudio.support32Bit = true;
  452. fileSystems."/" =
  453. { device = "/dev/disk/by-uuid/2f548eb9-47ce-4280-950f-9c6d1d162852";
  454. fsType = "ext4";
  455. };
  456. fileSystems."/boot" =
  457. { device = "/dev/disk/by-uuid/5BC3-73F3";
  458. fsType = "vfat";
  459. };
  460. swapDevices =
  461. [ { device = "/dev/disk/by-uuid/bef7bf62-d26f-45b1-a1f8-1227c2f8b26a"; }
  462. ];
  463. powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  464. }
  465. #+END_SRC
  466. ** Raspberry
  467. The Raspberry Pi 400[fn:22] is your complete personal computer, built into a compact keyboard. It features a quad-core, 64-bit processor, 4GB of RAM, wireless networking, dual-display output, 4k video playback, as well as a 40-pin GPIO header. It's the most powerful Raspberry Pi computer yet.
  468. #+NAME: host-raspberry
  469. #+BEGIN_SRC nix :noweb yes
  470. raspberry = nixpkgs.lib.nixosSystem {
  471. system = "aarch64-linux";
  472. specialArgs = { inherit inputs; };
  473. modules = [
  474. ./hosts/raspberry
  475. <<module-x11>>
  476. <<module-ssh>>
  477. <<module-flakes>>
  478. <<module-cachix>>
  479. <<module-home-manager>>
  480. ];
  481. };
  482. #+END_SRC
  483. Deploy this configuration with ~sudo nixos-rebuild switch --flake /etc/dotfiles/#raspberry~.
  484. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/default.nix
  485. # <<file-warning>>
  486. { ... }:
  487. {
  488. imports = [
  489. ./configuration.nix
  490. ./hardware.nix
  491. ];
  492. }
  493. #+END_SRC
  494. *** Configuration
  495. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/configuration.nix
  496. # <<file-warning>>
  497. { config, pkgs, ... }:
  498. {
  499. time.timeZone = "America/Toronto";
  500. networking.hostName = "raspberry";
  501. networking.firewall.enable = false;
  502. networking.networkmanager.enable = true;
  503. networking.interfaces.eth0.useDHCP = true;
  504. networking.interfaces.wlan0.useDHCP = true;
  505. <<host-config-home>>
  506. environment.systemPackages = [
  507. pkgs.libraspberrypi
  508. pkgs.raspberrypi-eeprom
  509. ];
  510. programs.fish.enable = true;
  511. programs.gnupg.agent.enable = true;
  512. users.users.chris = {
  513. shell = pkgs.fish;
  514. isNormalUser = true;
  515. extraGroups = [ "wheel" "networkmanager" ];
  516. };
  517. }
  518. #+END_SRC
  519. *** Hardware
  520. This section is very much a work in progress. I have struggled to get this device to boot according to the NixOS documentation / wiki on the subject. It seems that when running with the vendored kernel there's an issue booting from the SD card. Nevertheless, the issue is avoided by using the standard kernel.
  521. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/hardware.nix
  522. # <<file-warning>>
  523. { config, pkgs, lib, inputs, ... }:
  524. {
  525. # imports = [
  526. # inputs.nixos-hardware.nixosModules.raspberry-pi-4
  527. # ];
  528. # boot.kernelPackages = pkgs.linuxPackages_rpi4;
  529. boot.tmpOnTmpfs = true;
  530. boot.initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
  531. boot.kernelParams = [
  532. "8250.nr_uarts=1"
  533. "console=ttyAMA0,115200"
  534. "console=tty1"
  535. "cma=128M"
  536. ];
  537. boot.loader.grub.enable = false;
  538. boot.loader.generic-extlinux-compatible.enable = true;
  539. boot.loader.raspberryPi = {
  540. enable = true;
  541. version = 4;
  542. firmwareConfig = ''
  543. hdmi_drive=2
  544. hdmi_force_hotplug=1
  545. dtparam=sd_poll_once=on
  546. dtparam=audio=on
  547. '';
  548. };
  549. # FIXME: Requires GPU support.
  550. services.xserver.videoDrivers = [ "fbdev" ];
  551. sound.enable = true;
  552. hardware.pulseaudio.enable = true;
  553. hardware.enableRedistributableFirmware = true;
  554. # hardware.raspberry-pi."4".fkms-3d.enable = true;
  555. fileSystems = {
  556. "/" = {
  557. device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
  558. fsType = "ext4";
  559. options = [ "noatime" ];
  560. };
  561. };
  562. powerManagement.cpuFreqGovernor = "ondemand";
  563. }
  564. #+END_SRC
  565. ** TODO Homecloud
  566. The Raspberry Pi Model B-8GB[fn:23] is the latest product in the popular Raspberry Pi range of computers. It offers groundbreaking increases in processor speed, multimedia performance, memory, and connectivity compared to the prior generation. On NixOS[fn:4], the Raspberry Pi family is /only/ supported on the =AArch64= platform, although there is community support for =armv6l= and =armv7l=.
  567. #+NAME: host-homecloud
  568. #+BEGIN_SRC nix :noweb yes
  569. homecloud = nixpkgs.lib.nixosSystem {
  570. system = "aarch64-linux";
  571. specialArgs = { inherit inputs; };
  572. modules = [
  573. ./hosts/homecloud
  574. <<module-ssh>>
  575. <<module-flakes>>
  576. <<module-cachix>>
  577. ];
  578. };
  579. #+END_SRC
  580. Deploy this configuration with ~sudo nixos-rebuild switch --flake /etc/dotfiles/#homecloud~.
  581. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/default.nix
  582. # <<file-warning>
  583. { ... }:
  584. {
  585. imports = [
  586. ./configuration.nix
  587. ./hardware.nix
  588. ];
  589. }
  590. #+END_SRC
  591. *** Configuration
  592. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/configuration.nix
  593. # <<file-warning>>
  594. { config, pkgs, ... }:
  595. {
  596. time.timeZone = "America/Toronto";
  597. networking.hostName = "homecloud";
  598. networking.firewall.enable = false;
  599. networking.networkmanager.enable = true;
  600. networking.interfaces.eth0.useDHCP = true;
  601. networking.interfaces.wlan0.useDHCP = true;
  602. <<host-config-wifi>>
  603. <<host-config-home>>
  604. environment.systemPackages = [
  605. pkgs.libraspberrypi
  606. pkgs.raspberrypi-eeprom
  607. ];
  608. users.users.chris = {
  609. isNormalUser = true;
  610. extraGroups = [ "wheel" "networkmanager" ];
  611. };
  612. }
  613. #+END_SRC
  614. *** Hardware
  615. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/hardware.nix
  616. # <<file-warning>>
  617. { config, pkgs, lib, inputs, ... }:
  618. {
  619. # imports = [
  620. # inputs.nixos-hardware.nixosModules.raspberry-pi-4
  621. # ];
  622. # boot.kernelPackages = pkgs.linuxPackages_rpi4;
  623. boot.tmpOnTmpfs = true;
  624. boot.initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
  625. boot.kernelParams = [
  626. "8250.nr_uarts=1"
  627. "console=ttyAMA0,115200"
  628. "console=tty1"
  629. "cma=128M"
  630. ];
  631. boot.loader.grub.enable = false;
  632. boot.loader.generic-extlinux-compatible.enable = true;
  633. boot.loader.raspberryPi = {
  634. enable = true;
  635. version = 4;
  636. firmwareConfig = ''
  637. hdmi_drive=2
  638. hdmi_force_hotplug=1
  639. dtparam=sd_poll_once=on
  640. dtparam=audio=on
  641. '';
  642. };
  643. # hardware.raspberry-pi."4".fkms-3d.enable = true;
  644. fileSystems = {
  645. "/" = {
  646. device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
  647. fsType = "ext4";
  648. options = [ "noatime" ];
  649. };
  650. };
  651. powerManagement.cpuFreqGovernor = "ondemand";
  652. }
  653. #+END_SRC
  654. ** TODO Zero-One
  655. TODO: Raspberry Pi Zero/Zero WH
  656. #+NAME: host-zero-one
  657. #+BEGIN_SRC nix
  658. zero-one = nixpkgs.lib.nixosSystem {
  659. system = "armv7l-linux";
  660. specialArgs = { inherit inputs; };
  661. modules = [
  662. ./hosts/zero-one
  663. ./modules/ssh.nix
  664. ./modules/flakes.nix
  665. ./modules/cachix.nix
  666. ];
  667. };
  668. #+END_SRC
  669. ** TODO Zero-Two
  670. #+NAME: host-zero-two
  671. #+BEGIN_SRC nix
  672. zero-two = nixpkgs.lib.nixosSystem {
  673. system = "armv7l-linux";
  674. specialArgs = { inherit inputs; };
  675. modules = [
  676. ./hosts/zero-two
  677. ./modules/ssh.nix
  678. ./modules/flakes.nix
  679. ./modules/cachix.nix
  680. ];
  681. };
  682. #+END_SRC
  683. ** TODO Android
  684. This is my Samsung Galaxy S10+[fn:24] running Nix On Droid[fn:10] with the experimental support for Flakes being used to manage the configuration.
  685. #+NAME: host-android
  686. #+BEGIN_SRC nix
  687. android = (inputs.nix-on-droid.lib.aarch64-linux.nix-on-droid {
  688. config = ./hosts/android/nix-on-droid.nix;
  689. }).activationPackage;
  690. #+END_SRC
  691. Build the activation package with ~nix build .#android --impure~, and activate it with =result/activate=.
  692. #+BEGIN_SRC nix :noweb yes :tangle hosts/android/nix-on-droid.nix
  693. # <<file-warning>>
  694. { pkgs, ... }:
  695. {
  696. environment.packages = [
  697. pkgs.git
  698. pkgs.vim
  699. pkgs.pass
  700. pkgs.gnupg
  701. pkgs.openssh
  702. ];
  703. }
  704. #+END_SRC
  705. * Module Definitions
  706. Modules are files combined by NixOS[fn:4] to produce the full system configuration. Modules wre introduced to allow extending NixOS[fn:4] without modifying its source code. They also allow splitting up =configuration.nix=, making the system configuration easier to maintain and use.
  707. ** X11
  708. #+NAME: module-x11
  709. #+BEGIN_SRC nix
  710. ./modules/x11.nix
  711. #+END_SRC
  712. X11, or X[fn:25] is the generic name for the X Window System Display Server. All graphical GNU/Linux[fn:1] applications connect to an X-Window[fn:25] (or Wayland[fn:26]) 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.
  713. #+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
  714. # <<file-warning>>
  715. { config, pkgs, ... }:
  716. {
  717. services.xserver.enable = true;
  718. services.xserver.layout = "us";
  719. services.xserver.libinput.enable = true;
  720. services.xserver.displayManager.startx.enable = true;
  721. environment = {
  722. systemPackages = with pkgs; [
  723. pkgs.sqlite
  724. pkgs.pfetch
  725. pkgs.cmatrix
  726. pkgs.asciiquarium
  727. ];
  728. extraInit = ''
  729. export XAUTHORITY=/tmp/Xauthority
  730. export xserverauthfile=/tmp/xserverauth
  731. [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
  732. [ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
  733. '';
  734. };
  735. services.picom.enable = true;
  736. services.printing.enable = true;
  737. fonts.fonts = with pkgs; [
  738. iosevka-bin
  739. emacs-all-the-icons-fonts
  740. ];
  741. }
  742. #+END_SRC
  743. ** SSH
  744. #+NAME: module-ssh
  745. #+BEGIN_SRC nix
  746. ./modules/ssh.nix
  747. #+END_SRC
  748. OpenSSH[fn:27] is a suite of secure networking utilities based on the Secure Shell Protocol, which provides a secure channel over an unsecured network in a client-server architecture. OpenSSH[fn:27] started as a fork of the free SSH program; later versions were proprietary software.
  749. Apply some configuration to the default settings:
  750. + Disable logging in as =root=
  751. + Disable password authentication
  752. #+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
  753. # <<file-warning>>
  754. { config, pkgs, ... }:
  755. {
  756. services.openssh = {
  757. enable = true;
  758. permitRootLogin = "no";
  759. passwordAuthentication = false;
  760. };
  761. }
  762. #+END_SRC
  763. ** Flakes
  764. #+NAME: module-flakes
  765. #+BEGIN_SRC nix
  766. ./modules/flakes.nix
  767. #+END_SRC
  768. Nix Flakes[fn:28] are an upcoming feature of the Nix package manager[fn:5]. 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[fn:28] 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[fn:28] are not available unless explicitly enabled.
  769. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  770. # <<file-warning>>
  771. { config, pkgs, inputs, ... }:
  772. {
  773. nix = {
  774. package = pkgs.nixUnstable;
  775. extraOptions = ''
  776. experimental-features = nix-command flakes
  777. '';
  778. };
  779. nixpkgs = {
  780. config = { allowUnfree = true; };
  781. overlays = [ inputs.emacs-overlay.overlay ];
  782. };
  783. }
  784. #+END_SRC
  785. ** Cachix
  786. #+NAME: module-cachix
  787. #+BEGIN_SRC nix
  788. ./modules/cachix.nix
  789. #+END_SRC
  790. Cachix[fn:29] is a Command line client for Nix[fn:5] 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.
  791. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  792. # <<file-warning>>
  793. { config, ... }:
  794. {
  795. nix = {
  796. binaryCaches = [
  797. "https://nix-community.cachix.org"
  798. ];
  799. binaryCachePublicKeys = [
  800. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  801. ];
  802. };
  803. }
  804. #+END_SRC
  805. ** Docker
  806. #+NAME: module-docker
  807. #+BEGIN_SRC nix
  808. ./modules/docker.nix
  809. #+END_SRC
  810. Docker [fn:30] is a set of platform as a service that uses 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.
  811. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  812. { config, pkgs, ... }:
  813. {
  814. virtualisation.docker = {
  815. enable = true;
  816. enableOnBoot = true;
  817. autoPrune.enable = true;
  818. };
  819. }
  820. #+END_SRC
  821. ** NVIDIA
  822. #+NAME: module-nvidia
  823. #+BEGIN_SRC nix
  824. ./modules/nvidia.nix
  825. #+END_SRC
  826. #+BEGIN_SRC nix :noweb yes :tangle modules/nvidia.nix
  827. { config, pkgs, ... }:
  828. let
  829. myIntelBusId = "PCI:0:2:0";
  830. myNvidiaBusId = "PCI:1:0:0";
  831. myNvidiaOffload = pkgs.writeShellScriptBin "nvidia-offload" ''
  832. export __NV_PRIME_RENDER_OFFLOAD=1
  833. export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
  834. export __GLX_VENDOR_LIBRARY_NAME=nvidia
  835. export __VK_LAYER_NV_optimus=NVIDIA_only
  836. exec -a "$0" "$@"
  837. '';
  838. in {
  839. # Add the offload script to the $PATH.
  840. environment.systemPackages = [ myNvidiaOffload ];
  841. # Enable the NVIDIA drivers.
  842. # NOTE: You may need to use either of the commands below:
  843. services.xserver.videoDrivers = [ "nvidia" ];
  844. # services.xserver.videoDrivers = [ "modesetting" "nvidia" ];
  845. # Configure `offload-mode'.
  846. hardware.nvidia.prime = {
  847. offload.enable = true;
  848. intelBusId = myIntelBusId;
  849. nvidiaBusId = myNvidiaBusId;
  850. };
  851. }
  852. #+END_SRC
  853. ** Firefox
  854. #+NAME: module-firefox
  855. #+BEGIN_SRC nix
  856. ./modules/firefox.nix
  857. #+END_SRC
  858. Firefox Browser[fn:31], 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.
  859. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  860. # <<file-warning>>
  861. { pkgs, ... }:
  862. {
  863. # NOTE: Use the binary until module is developed.
  864. environment.systemPackages = [
  865. pkgs.firefox-bin
  866. ];
  867. }
  868. #+END_SRC
  869. ** Jellyfin
  870. #+NAME: module-jellyfin
  871. #+BEGIN_SRC nix
  872. ./modules/jellyfin.nix
  873. #+END_SRC
  874. Jellyfin[fn:32] is a suite of multimedia applications designed to organize, manage, and share digital media files to networked devices. It consists of a server application installed on a machine, and another application running as a client on devices such as Smartphones, Tablets, SmartTVs, Streaming Media Players, Game Consoles, or in a Web Browser. It can also serve media to DLNA and Chromecast enabled devices. It's free and open-source software fork of Emby.
  875. #+BEGIN_SRC nix :noweb yes :tangle modules/jellyfin.nix
  876. # <<file-warning>>
  877. { config, pkgs, ... }:
  878. {
  879. services.jellyfin = {
  880. enable = true;
  881. };
  882. }
  883. #+END_SRC
  884. ** Moonlight
  885. #+NAME: module-moonlight
  886. #+BEGIN_SRC nix
  887. ./modules/moonlight.nix
  888. #+END_SRC
  889. Moonlight[fn:33] is an open-source implementation of NVIDIA's GameStream Protocol. You can stream your collection of PC games from your GameStream-compatible PC to any supported device and play them remotely. Moonlight[fn:33] is perfect for gaming on the go (or on GNU/Linux[fn:1]) without sacrificing the graphics and game selection available for the PC.
  890. #+BEGIN_SRC nix :noweb yes :tangle modules/moonlight.nix
  891. # <<file-warning>>
  892. { pkgs, ... }:
  893. {
  894. environment.systemPackages = [
  895. pkgs.moonlight-qt
  896. ];
  897. }
  898. #+END_SRC
  899. ** Teamviewer
  900. #+NAME: module-teamviewer
  901. #+BEGIN_SRC nix
  902. ./modules/teamviewer.nix
  903. #+END_SRC
  904. The Teamviewer[fn:34] remote connectivity cloud platform enables secure remote access to any device, across platforms, from anywhere, anytime. Teamviewer[fn:34] connects computers, smartphones, servers, IoT devices, robots -- anything -- with fast, high performance connections through their global access network. It has been used in outer-space low-bandwidth environments.
  905. #+BEGIN_SRC nix :noweb yes :tangle modules/teamviewer.nix
  906. # <<file-warning>>
  907. { pkgs, ... }:
  908. {
  909. # NOTE: Neither of these are working!
  910. # services.teamviewer.enable = true;
  911. # environment.systemPackages = [
  912. # pkgs.teamviewer
  913. # ];
  914. }
  915. #+END_SRC
  916. ** Home Manager
  917. Home Manager[fn:7] 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.
  918. #+NAME: module-home-manager
  919. #+BEGIN_SRC nix :noweb yes
  920. inputs.home-manager.nixosModules.home-manager {
  921. home-manager.useGlobalPkgs = true;
  922. home-manager.useUserPackages = true;
  923. home-manager.users.chris = {
  924. imports = [
  925. <<module-git>>
  926. <<module-gpg>>
  927. <<module-vim>>
  928. <<module-gtk>>
  929. <<module-emacs>>
  930. ];
  931. };
  932. }
  933. #+END_SRC
  934. *** Git
  935. #+NAME: module-git
  936. #+BEGIN_SRC nix
  937. ./modules/git.nix
  938. #+END_SRC
  939. Git[fn:35] 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.
  940. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  941. # <<file-warning>>
  942. { pkgs, ... }:
  943. {
  944. programs.git = {
  945. enable = true;
  946. userName = "Christopher James Hayward";
  947. userEmail = "chris@chrishayward.xyz";
  948. signing = {
  949. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  950. signByDefault = true;
  951. };
  952. };
  953. }
  954. #+END_SRC
  955. *** Gpg
  956. #+NAME: module-gpg
  957. #+BEGIN_SRC nix
  958. ./modules/gpg.nix
  959. #+END_SRC
  960. GNU Privacy Guard[fn:36] 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.
  961. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  962. # <<file-warning>>
  963. { pkgs, ... }:
  964. {
  965. services.gpg-agent = {
  966. enable = true;
  967. defaultCacheTtl = 1800;
  968. enableSshSupport = true;
  969. pinentryFlavor = "gtk2";
  970. };
  971. }
  972. #+END_SRC
  973. *** Vim
  974. #+NAME: module-vim
  975. #+BEGIN_SRC nix
  976. ./modules/vim.nix
  977. #+END_SRC
  978. Neovim[fn:37] is a project that seeks to aggressively refactor Vim in order to:
  979. + Simplify maintenance and encourage contributions
  980. + Split the work between multiple developers
  981. + Enable advanced UIs without core modification
  982. + Maximize extensibility
  983. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  984. # <<file-warning>>
  985. { pkgs, ... }:
  986. {
  987. programs.neovim = {
  988. enable = true;
  989. viAlias = true;
  990. vimAlias = true;
  991. vimdiffAlias = true;
  992. extraConfig = ''
  993. set number relativenumber
  994. set nobackup
  995. '';
  996. extraPackages = [
  997. pkgs.nixfmt
  998. ];
  999. plugins = with pkgs.vimPlugins; [
  1000. vim-nix
  1001. vim-airline
  1002. vim-polyglot
  1003. ];
  1004. };
  1005. }
  1006. #+END_SRC
  1007. *** GTK
  1008. #+NAME: module-gtk
  1009. #+BEGIN_SRC nix
  1010. ./modules/gtk.nix
  1011. #+END_SRC
  1012. GTK[fn:38] is a free and open-source, cross-platform widget toolkit for graphical user interfaces. It's one of the most popular toolkits for the Wayland[fn:26] and X11[fn:25] windowing systems.
  1013. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  1014. # <<file-warning>>
  1015. { pkgs, ... }:
  1016. {
  1017. home.packages = [
  1018. pkgs.arc-theme
  1019. pkgs.arc-icon-theme
  1020. pkgs.lxappearance
  1021. ];
  1022. home.file.".gtkrc-2.0" = {
  1023. text = ''
  1024. gtk-theme-name="Arc-Dark"
  1025. gtk-icon-theme-name="Arc"
  1026. gtk-font-name="Sans 10"
  1027. gtk-cursor-theme-size=0
  1028. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  1029. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  1030. gtk-button-images=0
  1031. gtk-menu-images=0
  1032. gtk-enable-event-sounds=1
  1033. gtk-enable-input-feedback-sounds=1
  1034. gtk-xft-antialias=1
  1035. gtk-xft-hinting=1
  1036. gtk-xft-hintstyle="hintmedium"
  1037. '';
  1038. };
  1039. }
  1040. #+END_SRC
  1041. * Emacs Configuration
  1042. #+NAME: module-emacs
  1043. #+BEGIN_SRC nix
  1044. ./modules/emacs.nix
  1045. #+END_SRC
  1046. GNU/Emacs[fn:2] is an extensible, customizable, free/libre text editor -- and more. At its core is an interpreter for Emacs Lisp[fn:36], a dialect of the Lisp programming language with extensions to support text editing. Other features include:
  1047. + Highly customizable
  1048. + Full Unicopde support
  1049. + Content-aware editing modes
  1050. + Complete built-in documentation
  1051. + Wide range of functionality beyond text editing
  1052. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  1053. # <<file-warning>>
  1054. { pkgs, ... }:
  1055. let
  1056. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  1057. config = ../README.org;
  1058. package = <<emacs-native-comp-package>>
  1059. alwaysEnsure = true;
  1060. alwaysTangle = true;
  1061. extraEmacsPackages = epkgs: [
  1062. # Required packages...
  1063. <<emacs-exwm-package>>
  1064. <<emacs-evil-package>>
  1065. <<emacs-general-package>>
  1066. <<emacs-which-key-package>>
  1067. # Optional packages.
  1068. <<emacs-org-package>>
  1069. <<emacs-org-roam-package>>
  1070. <<emacs-org-drill-package>>
  1071. <<emacs-pomodoro-package>>
  1072. <<emacs-writegood-package>>
  1073. <<emacs-hugo-package>>
  1074. <<emacs-reveal-package>>
  1075. <<emacs-pass-package>>
  1076. <<emacs-mu4e-package>>
  1077. <<emacs-dired-package>>
  1078. <<emacs-icons-package>>
  1079. <<emacs-emoji-package>>
  1080. <<emacs-eshell-package>>
  1081. <<emacs-vterm-package>>
  1082. <<emacs-magit-package>>
  1083. <<emacs-fonts-package>>
  1084. <<emacs-elfeed-package>>
  1085. <<emacs-nix-mode-package>>
  1086. <<emacs-projectile-package>>
  1087. <<emacs-lsp-package>>
  1088. <<emacs-company-package>>
  1089. <<emacs-golang-package>>
  1090. <<emacs-python-package>>
  1091. <<emacs-rustic-package>>
  1092. <<emacs-plantuml-package>>
  1093. <<emacs-swiper-package>>
  1094. <<emacs-desktop-package>>
  1095. <<emacs-doom-themes-package>>
  1096. <<emacs-doom-modeline-package>>
  1097. ];
  1098. };
  1099. in {
  1100. home.packages = [
  1101. <<emacs-exwm-extras>>
  1102. <<emacs-hugo-extras>>
  1103. <<emacs-pass-extras>>
  1104. <<emacs-mu4e-extras>>
  1105. <<emacs-aspell-extras>>
  1106. <<emacs-desktop-extras>>
  1107. <<emacs-plantuml-extras>>
  1108. <<emacs-nix-mode-extras>>
  1109. ];
  1110. programs.emacs = {
  1111. enable = true;
  1112. package = myEmacs;
  1113. };
  1114. <<emacs-exwm-config>>
  1115. <<emacs-exwm-xinitrc>>
  1116. <<emacs-mu4e-config>>
  1117. }
  1118. #+END_SRC
  1119. 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.
  1120. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  1121. ;; <<file-warning>>
  1122. ;; Required inputs.
  1123. <<emacs-exwm-elisp>>
  1124. <<emacs-evil-elisp>>
  1125. <<emacs-general-elisp>>
  1126. <<emacs-which-key-elisp>>
  1127. ;; Optional inputs.
  1128. <<emacs-org-elisp>>
  1129. <<emacs-org-roam-elisp>>
  1130. <<emacs-org-drill-elisp>>
  1131. <<emacs-org-agenda-elisp>>
  1132. <<emacs-pomodoro-elisp>>
  1133. <<emacs-writegood-elisp>>
  1134. <<emacs-aspell-elisp>>
  1135. <<emacs-eww-elisp>>
  1136. <<emacs-hugo-elisp>>
  1137. <<emacs-reveal-elisp>>
  1138. <<emacs-pass-elisp>>
  1139. <<emacs-erc-elisp>>
  1140. <<emacs-mu4e-elisp>>
  1141. <<emacs-dired-elisp>>
  1142. <<emacs-icons-elisp>>
  1143. <<emacs-emoji-elisp>>
  1144. <<emacs-eshell-elisp>>
  1145. <<emacs-vterm-elisp>>
  1146. <<emacs-magit-elisp>>
  1147. <<emacs-fonts-elisp>>
  1148. <<emacs-elfeed-elisp>>
  1149. <<emacs-projectile-elisp>>
  1150. <<emacs-lsp-elisp>>
  1151. <<emacs-company-elisp>>
  1152. <<emacs-golang-elisp>>
  1153. <<emacs-python-elisp>>
  1154. <<emacs-rustic-elisp>>
  1155. <<emacs-plantuml-elisp>>
  1156. <<emacs-desktop-elisp>>
  1157. ;; User interface.
  1158. <<emacs-swiper-elisp>>
  1159. <<emacs-transparency-elisp>>
  1160. <<emacs-doom-themes-elisp>>
  1161. <<emacs-doom-modeline-elisp>>
  1162. #+END_SRC
  1163. 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=.
  1164. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  1165. ;; <<file-warning>>
  1166. <<emacs-disable-ui-elisp>>
  1167. <<emacs-native-comp-elisp>>
  1168. <<emacs-backup-files-elisp>>
  1169. <<emacs-shell-commands-elisp>>
  1170. #+END_SRC
  1171. ** Disable UI
  1172. Emacs[fn:2] 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.
  1173. #+NAME: emacs-disable-ui-elisp
  1174. #+BEGIN_SRC emacs-lisp
  1175. ;; Disable unwanted UI elements.
  1176. (tooltip-mode -1)
  1177. (menu-bar-mode -1)
  1178. (tool-bar-mode -1)
  1179. (scroll-bar-mode -1)
  1180. ;; Fix the scrolling behaviour.
  1181. (setq scroll-conservatively 101)
  1182. ;; Fix mouse-wheel scrolling behaviour.
  1183. (setq mouse-wheel-follow-mouse t
  1184. mouse-wheel-progressive-speed t
  1185. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  1186. #+END_SRC
  1187. ** Native Comp
  1188. #+NAME: emacs-native-comp-package
  1189. #+BEGIN_SRC nix
  1190. pkgs.emacsGcc;
  1191. #+END_SRC
  1192. Native Comp, also known as GccEmacs, refers to the ~--with-native-compilation~ configuration option when building GNU/Emacs[fn:2]. It adds support for compiling 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.
  1193. #+NAME: emacs-native-comp-elisp
  1194. #+BEGIN_SRC emacs-lisp
  1195. ;; Silence warnings from packages that don't support `native-comp'.
  1196. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  1197. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  1198. #+END_SRC
  1199. ** Backup Files
  1200. Emacs[fn:2] 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.
  1201. #+NAME: emacs-backup-files-elisp
  1202. #+BEGIN_SRC emacs-lisp
  1203. ;; Disable unwanted features.
  1204. (setq make-backup-files nil
  1205. create-lockfiles nil)
  1206. #+END_SRC
  1207. ** Shell Commands
  1208. Define some methods for interaction between GNU/Emacs[fn:2], and the systems underyling shell:
  1209. 1) Method to run an external process, launching any application on a new process without interferring with Emacs[fn:2]
  1210. 2) Method to apply commands to the curren call process, effecting the running instance of Emacs[fn:2]
  1211. #+NAME: emacs-shell-commands-elisp
  1212. #+BEGIN_SRC emacs-lisp
  1213. ;; Define a method to run an external process.
  1214. (defun dotfiles/run (cmd)
  1215. "Run an external process."
  1216. (interactive (list (read-shell-command "λ ")))
  1217. (start-process-shell-command cmd nil cmd))
  1218. ;; Define a method to run a background process.
  1219. (defun dotfiles/run-in-background (cmd)
  1220. (let ((command-parts (split-string cmd "[ ]+")))
  1221. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  1222. #+END_SRC
  1223. ** Nix Mode
  1224. #+NAME: emacs-nix-mode-extras
  1225. #+BEGIN_SRC nix
  1226. pkgs.nixfmt
  1227. #+END_SRC
  1228. Nix-mode[fn:39] is an Emacs[fn:2] major mode for editing Nix[fn:5] expressions. This provides basic handling of =.nix= files. Syntax highlighting and indentation support using =SMIE= are provided.
  1229. #+NAME: emacs-nix-mode-package
  1230. #+BEGIN_SRC nix
  1231. epkgs.nix-mode
  1232. #+END_SRC
  1233. ** Evil Mode
  1234. Evil[fn:21] is an extensible VI layer for GNU/Emacs[fn:2]. It emulates the main features of Vim[fn:37], turning GNU/Emacs[fn:2] into a modal editor.
  1235. #+NAME: emacs-evil-package
  1236. #+BEGIN_SRC nix
  1237. epkgs.evil
  1238. epkgs.evil-collection
  1239. epkgs.evil-surround
  1240. epkgs.evil-nerd-commenter
  1241. #+END_SRC
  1242. The next time Emacs[fn:2] 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[fn:2] in general, Evil[fn:21] is extensible in Emacs Lisp[fn:36].
  1243. #+NAME: emacs-evil-elisp
  1244. #+BEGIN_SRC emacs-lisp
  1245. ;; Enable the Extensible VI Layer for Emacs.
  1246. (setq evil-want-integration t ;; Required for `evil-collection.'
  1247. evil-want-keybinding nil) ;; Same as above.
  1248. (evil-mode +1)
  1249. ;; Configure `evil-collection'.
  1250. (evil-collection-init)
  1251. ;; Configure `evil-surround'.
  1252. (global-evil-surround-mode +1)
  1253. ;; Configure `evil-nerd-commenter'.
  1254. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1255. #+END_SRC
  1256. ** EXWM
  1257. #+NAME: emacs-exwm-package
  1258. #+BEGIN_SRC nix
  1259. epkgs.exwm
  1260. #+END_SRC
  1261. EXWM (Emacs X Window Manager)[fn:20] is a full-featured tiling X window manager for GNU/Emacs[fn:2] built on-top of XELB. It features:
  1262. + Fully keyboard-driven operations
  1263. + Hybrid layout modes (tiling & stacking)
  1264. + Dynamic workspace support
  1265. + ICCM/EWMH compliance
  1266. #+NAME: emacs-exwm-extras
  1267. #+BEGIN_SRC nix
  1268. pkgs.nitrogen
  1269. pkgs.autorandr
  1270. #+END_SRC
  1271. 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 EXWM[fn:20].
  1272. #+NAME: emacs-exwm-config
  1273. #+BEGIN_SRC nix
  1274. xsession = {
  1275. enable = true;
  1276. windowManager.command = ''
  1277. ${pkgs.nitrogen}/bin/nitrogen --restore
  1278. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1279. ${myEmacs}/bin/emacsclient -c
  1280. '';
  1281. };
  1282. #+END_SRC
  1283. EXWM[fn:20] cannot make an X window manager by itself, this is by design; You must tell X to do it. Override the =~/.xinitrc= file to start the =xsession=.
  1284. #+NAME: emacs-exwm-xinitrc
  1285. #+BEGIN_SRC nix
  1286. home.file.".xinitrc" = {
  1287. text = ''
  1288. exec ./.xsession
  1289. '';
  1290. };
  1291. #+END_SRC
  1292. #+NAME: emacs-exwm-elisp
  1293. #+BEGIN_SRC emacs-lisp
  1294. ;; Configure `exwm'.
  1295. (setq exwm-worspace-show-all-buffers t)
  1296. (setq exwm-input-prefix-keys
  1297. '(?\M-x
  1298. ?\C-g
  1299. ?\C-\ ))
  1300. (setq exwm-input-global-keys
  1301. `(([?\s-r] . exwm-reset)
  1302. ,@(mapcar (lambda (i)
  1303. `(,(kbd (format "s-%d" i)) .
  1304. (lambda ()
  1305. (interactive)
  1306. (exwm-workspace-switch-create ,i))))
  1307. (number-sequence 1 9))))
  1308. ;; Configure `exwm-randr'.
  1309. (require 'exwm-randr)
  1310. (exwm-randr-enable)
  1311. ;; Configure custom hooks.
  1312. (setq display-time-and-date t)
  1313. (add-hook 'exwm-init-hook
  1314. (lambda ()
  1315. (display-battery-mode +1) ;; Display battery info (if available).
  1316. (display-time-mode +1))) ;; Display the time in the modeline.
  1317. ;; Setup buffer display names.
  1318. (add-hook 'exwm-update-class-hook
  1319. (lambda ()
  1320. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1321. ;; Configure monitor hot-swapping.
  1322. (add-hook 'exwm-randr-screen-change-hook
  1323. (lambda ()
  1324. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1325. #+END_SRC
  1326. ** General
  1327. #+NAME: emacs-general-package
  1328. #+BEGIN_SRC nix
  1329. epkgs.general
  1330. #+END_SRC
  1331. General[fn:40] provides a more convenient method for binding keys in Emacs[fn:2], providing a unified interface for key definitions. Its primary purpose is to build on /existing/ functionality to make key definitions more clear and concise.
  1332. #+NAME: emacs-general-elisp
  1333. #+BEGIN_SRC emacs-lisp
  1334. ;; Use <SPC> as a leader key via `general.el'.
  1335. (general-create-definer dotfiles/leader
  1336. :states '(normal motion)
  1337. :keymaps 'override
  1338. :prefix "SPC"
  1339. :global-prefix "C-SPC")
  1340. ;; Find files with <SPC> <period> ...
  1341. ;; Switch buffers with <SPC> <comma> ...
  1342. (dotfiles/leader
  1343. "." '(find-file :which-key "File")
  1344. "," '(switch-to-buffer :which-key "Buffer")
  1345. "k" '(kill-buffer :which-key "Kill")
  1346. "c" '(kill-buffer-and-window :which-key "Close"))
  1347. ;; Add keybindings for executing shell commands.
  1348. (dotfiles/leader
  1349. "r" '(:ignore t :which-key "Run")
  1350. "rr" '(dotfiles/run :which-key "Run")
  1351. "ra" '(async-shell-command :which-key "Async"))
  1352. ;; Add keybindings for quitting Emacs.
  1353. (dotfiles/leader
  1354. "q" '(:ignore t :which-key "Quit")
  1355. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1356. "qw" '(kill-emacs :which-key "Now")
  1357. "qf" '(delete-frame :which-key "Frame"))
  1358. ;; Add keybindings for toggles / tweaks.
  1359. (dotfiles/leader
  1360. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1361. ;; Add keybindings for working with frames to replace
  1362. ;; the C-x <num> <num> method of bindings, which is awful.
  1363. (dotfiles/leader
  1364. "w" '(:ignore t :which-key "Windows")
  1365. "ww" '(window-swap-states :which-key "Swap")
  1366. "wc" '(delete-window :which-key "Close")
  1367. "wh" '(windmove-left :which-key "Left")
  1368. "wj" '(windmove-down :which-key "Down")
  1369. "wk" '(windmove-up :which-key "Up")
  1370. "wl" '(windmove-right :which-key "Right")
  1371. "ws" '(:ignore t :which-key "Split")
  1372. "wsj" '(split-window-below :which-key "Below")
  1373. "wsl" '(split-window-right :which-key "Right"))
  1374. #+END_SRC
  1375. ** Which Key
  1376. Which-key[fn:41] is a minor mode for Emacs[fn:2] that displays the key bindings following your currently entered incomplete command (prefix) in a popup or mini-buffer.
  1377. #+NAME: emacs-which-key-package
  1378. #+BEGIN_SRC nix
  1379. epkgs.which-key
  1380. #+END_SRC
  1381. #+NAME: emacs-which-key-elisp
  1382. #+BEGIN_SRC emacs-lisp
  1383. ;; Configure `which-key' to see keyboard bindings in the
  1384. ;; mini-buffer and when using M-x.
  1385. (setq which-key-idle-delay 0.0)
  1386. (which-key-mode +1)
  1387. #+END_SRC
  1388. ** EWW
  1389. The Emacs Web Wowser[fn:42] is a Web browser written in Emacs Lisp[fn:36] based on the ~shr.el~ library. It's my primary browser when it comes to text-based browsing.
  1390. + Use ~eww~ as the default browser
  1391. + Don't use any special fonts or colours
  1392. #+NAME: emacs-eww-elisp
  1393. #+BEGIN_SRC emacs-lisp
  1394. ;; Set `eww' as the default browser.
  1395. (setq browse-url-browser-function 'eww-browse-url)
  1396. ;; Configure the `shr' rendering engine.
  1397. (setq shr-use-fonts nil
  1398. shr-use-colors nil)
  1399. #+END_SRC
  1400. ** ERC
  1401. ERC[fn:43] is a powerful, modular, and extensible IRC client for GNU/Emacs[fn:2]. It's part of the GNU project, and included in Emacs.
  1402. #+NAME: emacs-erc-elisp
  1403. #+BEGIN_SRC emacs-lisp
  1404. ;; Configure `erc'.
  1405. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#systemcrafters"))
  1406. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1407. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1408. ;; Connect to IRC via `erc'.
  1409. (defun dotfiles/erc-connect ()
  1410. "Connected to IRC via `erc'."
  1411. (interactive)
  1412. (erc-tls :server "irc.libera.chat"
  1413. :port 6697
  1414. :nick "megaphone"
  1415. :password (password-store-get "megaphone@libera.chat")
  1416. :full-name "Chris Hayward"))
  1417. ;; Configure keybindings.
  1418. (dotfiles/leader
  1419. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1420. #+END_SRC
  1421. ** Dired
  1422. #+NAME: emacs-dired-package
  1423. #+BEGIN_SRC nix
  1424. epkgs.dired-single
  1425. #+END_SRC
  1426. Dired[fn:44] shows a directory listing inside of an Emacs[fn:2] 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. Dired-Extra[fn:45] provides extra functionality for Dired[fn:44].
  1427. #+NAME: emacs-dired-elisp
  1428. #+BEGIN_SRC emacs-lisp
  1429. ;; Include `dired-x' for the `jump' method.
  1430. (require 'dired-x)
  1431. ;; Configure `dired-single' to support `evil' keys.
  1432. (evil-collection-define-key 'normal 'dired-mode-map
  1433. "h" 'dired-single-up-directory
  1434. "l" 'dired-single-buffer)
  1435. ;; Setup `all-the-icons' and the `dired' extension.
  1436. ;; Configure keybindings for `dired'.
  1437. (dotfiles/leader
  1438. "d" '(dired-jump :which-key "Dired"))
  1439. #+END_SRC
  1440. ** Icons
  1441. #+NAME: emacs-icons-package
  1442. #+BEGIN_SRC nix
  1443. epkgs.all-the-icons
  1444. epkgs.all-the-icons-dired
  1445. #+END_SRC
  1446. All The Icons[fn:46] is a utility package to collect various Icon Fonts and prioritize them within GNU/Emacs[fn:2].
  1447. #+NAME: emacs-icons-elisp
  1448. #+BEGIN_SRC emacs-lisp
  1449. ;; Setup `all-the-icons-dired'.
  1450. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1451. ;; Display default font ligatures.
  1452. (global-prettify-symbols-mode +1)
  1453. #+END_SRC
  1454. ** Emojis
  1455. #+NAME: emacs-emoji-package
  1456. #+BEGIN_SRC nix
  1457. epkgs.emojify
  1458. #+END_SRC
  1459. Emojify[fn:47] is an Emacs[fn:2] 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.
  1460. #+NAME: emacs-emoji-elisp
  1461. #+BEGIN_SRC emacs-lisp
  1462. ;; Setup `emojify'.
  1463. (add-hook 'after-init-hook 'global-emojify-mode)
  1464. #+END_SRC
  1465. ** EShell
  1466. #+NAME: emacs-eshell-package
  1467. #+BEGIN_SRC nix
  1468. epkgs.eshell-prompt-extras
  1469. #+END_SRC
  1470. EShell [fn:48] is a shell-like command interpreter for GNU/Emacs[fn:2] implemented in Emacs Lisp[fn:36]. 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[fn:2].
  1471. #+NAME: emacs-eshell-elisp
  1472. #+BEGIN_SRC emacs-lisp
  1473. ;; Configure `eshell'.
  1474. (setq eshell-highlight-prompt nil
  1475. eshell-prefer-lisp-functions nil)
  1476. ;; Configure the lambda prompt.
  1477. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1478. (setq eshell-prompt-function 'epe-theme-lambda)
  1479. ;; Configure keybindings for `eshell'.
  1480. (dotfiles/leader
  1481. "e" '(eshell :which-key "EShell"))
  1482. #+END_SRC
  1483. ** VTerm
  1484. Emacs Libvterm (VTerm)[fn:49] is a fully-fledged terminal emulator inside GNU/Emacs[fn:2] based on Libvterm[fn:50], a blazing fast C library used in Neovim[fn:37]. As a result of using compiled code (instead of Emacs Lisp[fn:36]), VTerm[fn:49] is capable, fast, and it can seamlessly handle large outputs.
  1485. #+NAME: emacs-vterm-package
  1486. #+BEGIN_SRC nix
  1487. epkgs.vterm
  1488. #+END_SRC
  1489. #+NAME: emacs-vterm-elisp
  1490. #+BEGIN_SRC emacs-lisp
  1491. ;; Add keybindings for interacting with the shell(s).
  1492. (dotfiles/leader
  1493. "v" '(vterm :which-key "VTerm"))
  1494. #+END_SRC
  1495. ** Magit
  1496. Magit[fn:51] is an interface to the Git[fn:35] version control system, implemented as a GNU/Emacs[fn:2] package written in Elisp[fn:36]. It fills the glaring gap between the Git[fn:35] command line interface and various GUIs, letting you perform trivial as well as elaborate version control tasks within a few mnemonic key presses.
  1497. #+NAME: emacs-magit-package
  1498. #+BEGIN_SRC nix
  1499. epkgs.magit
  1500. #+END_SRC
  1501. | Key | Description |
  1502. |-----+--------------------------------------|
  1503. | gg | Check the status of a repository |
  1504. | gc | Clone a remote repository |
  1505. | gf | Fetch the contents of the repository |
  1506. | gp | Pull the remotes of the repository |
  1507. #+NAME: emacs-magit-elisp
  1508. #+BEGIN_SRC emacs-lisp
  1509. ;; Add keybindings for working with `magit'.
  1510. (dotfiles/leader
  1511. "g" '(:ignore t :which-key "Git")
  1512. "gg" '(magit-status :which-key "Status")
  1513. "gc" '(magit-clone :which-key "Clone")
  1514. "gf" '(magit-fetch :which-key "Fetch")
  1515. "gp" '(magit-pull :which-key "Pull"))
  1516. #+END_SRC
  1517. ** Fonts
  1518. #+NAME: emacs-fonts-package
  1519. #+BEGIN_SRC nix
  1520. epkgs.hydra
  1521. #+END_SRC
  1522. #+NAME: emacs-fonts-elisp
  1523. #+BEGIN_SRC emacs-lisp
  1524. ;; Configure the font when running as `emacs-server'.
  1525. (custom-set-faces
  1526. '(default ((t (:inherit nil :height 96 :family "Iosevka")))))
  1527. ;; Set all three of Emacs' font faces.
  1528. ;; NOTE: This only works without `emacs-server'.
  1529. ;; (set-face-attribute 'default nil :font "Iosevka" :height 96)
  1530. ;; (set-face-attribute 'fixed-pitch nil :font "Iosevka" :height 96)
  1531. ;; (set-face-attribute 'variable-pitch nil :font "Iosevka" :height 96)
  1532. ;; Define a `hydra' function for scaling the text interactively.
  1533. (defhydra hydra-text-scale (:timeout 4)
  1534. "Scale text"
  1535. ("j" text-scale-decrease "Decrease")
  1536. ("k" text-scale-increase "Increase")
  1537. ("f" nil "Finished" :exit t))
  1538. ;; Create keybinding for calling the function.
  1539. (dotfiles/leader
  1540. "tf" '(hydra-text-scale/body :which-key "Font"))
  1541. #+END_SRC
  1542. ** Elfeed
  1543. #+NAME: emacs-elfeed-package
  1544. #+BEGIN_SRC nix
  1545. epkgs.elfeed
  1546. #+END_SRC
  1547. Elfeed[fn:52] is an extensible web feed reader for GNU/Emacs[fn:2], support both =Atom= and =RSS=. It requires =Emacs 24.3+= and is available for download from the standard repositories.
  1548. | Key | Command |
  1549. |-----+---------|
  1550. | l | Open |
  1551. | u | Update |
  1552. #+NAME: emacs-elfeed-elisp
  1553. #+BEGIN_SRC emacs-lisp
  1554. ;; Configure `elfeed'.
  1555. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1556. ;; Add custom feeds for `elfeed' to fetch.
  1557. (setq elfeed-feeds (quote
  1558. (("https://hexdsl.co.uk/rss.xml")
  1559. ("https://lukesmith.xyz/rss.xml")
  1560. ("https://friendo.monster/rss.xml")
  1561. ("https://chrishayward.xyz/index.xml")
  1562. ("https://protesilaos.com/codelog.xml"))))
  1563. ;; Add custom keybindings for `elfeed'.
  1564. (dotfiles/leader
  1565. "l" '(:ignore t :which-key "Elfeed")
  1566. "ll" '(elfeed :which-key "Open")
  1567. "lu" '(elfeed-update :which-key "Update"))
  1568. #+END_SRC
  1569. ** Org Mode
  1570. #+NAME: emacs-org-package
  1571. #+BEGIN_SRC nix
  1572. epkgs.org
  1573. #+END_SRC
  1574. Org-mode[fn:53] is a document editing and organizing mode, designed for notes, planning, and authoring within the free software text editor GNU/Emacs[fn:2]. 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.
  1575. #+NAME: emacs-org-elisp
  1576. #+BEGIN_SRC emacs-lisp
  1577. ;; Configure `org-mode' source blocks.
  1578. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1579. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1580. org-src-preserve-indentation t) ;; Stop `org-mode' from formatting blocks.
  1581. ;; Add an `org-mode-hook'.
  1582. (add-hook 'org-mode-hook
  1583. (lambda ()
  1584. (org-indent-mode)
  1585. (visual-line-mode)))
  1586. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1587. (setq org-export-html-validation-link nil
  1588. org-html-validation-link nil)
  1589. ;; TODO: Configure default structure templates.
  1590. ;; (require 'org-tempo)
  1591. ;; Apply custom keybindings.
  1592. (dotfiles/leader
  1593. "o" '(:ignore t :which-key "Org")
  1594. "oe" '(org-export-dispatch :which-key "Export")
  1595. "ot" '(org-babel-tangle :which-key "Tangle")
  1596. "oi" '(org-toggle-inline-images :which-key "Images")
  1597. "of" '(:ignore t :which-key "Footnotes")
  1598. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1599. #+END_SRC
  1600. ** Org Roam
  1601. #+NAME: emacs-org-roam-package
  1602. #+BEGIN_SRC nix
  1603. epkgs.org-roam
  1604. epkgs.org-roam-server
  1605. #+END_SRC
  1606. Org Roam[fn:54] is a plain-text knowledge management system. It borrows principles from the Zettelkasten method[fn:55], providing a solution for non-hierarchical note-taking. It should also work as a plug-and-play solution for anyone already using Org Mode[fn:53] for their personal wiki (me). Org Roam Server[fn:56] is a Web application to visualize the Org Roam[fn:54] database. Although it should automatically reload if there's a change in the database, it can be done so manually by clicking the =reload= button on the Web interface.
  1607. #+NAME: emacs-org-roam-elisp
  1608. #+BEGIN_SRC emacs-lisp
  1609. ;; Setup `org-roam' hooks.
  1610. (add-hook 'after-init-hook
  1611. (lambda ()
  1612. (org-roam-mode)
  1613. (org-roam-server-mode)))
  1614. ;; Configure `org-roam'.
  1615. (setq org-roam-encrypt-files t
  1616. org-roam-directory (expand-file-name "/etc/dotfiles")
  1617. org-roam-capture-templates '()
  1618. org-roam-dailies-capture-templates '())
  1619. ;; Encrypt files with the public key.
  1620. (setq epa-file-select-keys 2
  1621. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1622. epa-cache-passphrase-for-symmetric-encryption t)
  1623. ;; Define a new `title-to-slug' function to override the default `org-roam-title-to-slug' function.
  1624. ;; This is done to change the replacement character from "_" to "-".
  1625. (require 'cl-lib)
  1626. (defun dotfiles/title-to-slug (title)
  1627. "Convert TITLE to a filename-suitable slug."
  1628. (cl-flet* ((nonspacing-mark-p (char)
  1629. (eq 'Mn (get-char-code-property char 'general-category)))
  1630. (strip-nonspacing-marks (s)
  1631. (apply #'string (seq-remove #'nonspacing-mark-p
  1632. (ucs-normalize-NFD-string s))))
  1633. (cl-replace (title pair)
  1634. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1635. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-") ;; Convert anything not alphanumeric.
  1636. ("--*" . "-") ;; Remove sequential dashes.
  1637. ("^-" . "") ;; Remove starting dashes.
  1638. ("-$" . ""))) ;; Remove ending dashes.
  1639. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1640. (downcase slug))))
  1641. (setq org-roam-title-to-slug-function #'dotfiles/title-to-slug)
  1642. ;; Configure capture templates.
  1643. ;; Standard document.
  1644. (add-to-list 'org-roam-capture-templates
  1645. '("d" "Default" entry (function org-roam-capture--get-point)
  1646. "%?"
  1647. :file-name "docs/${slug}"
  1648. :unnarrowed t
  1649. :head
  1650. "
  1651. ,#+TITLE: ${title}
  1652. ,#+AUTHOR: Christopher James Hayward
  1653. ,#+EMAIL: chris@chrishayward.xyz
  1654. "))
  1655. ;; Course document.
  1656. (add-to-list 'org-roam-capture-templates
  1657. '("c" "Course" plain (function org-roam-capture--get-point)
  1658. "%?"
  1659. :file-name "docs/courses/${slug}"
  1660. :unnarrowed t
  1661. :head
  1662. "
  1663. ,#+TITLE: ${title}
  1664. ,#+SUBTITLE:
  1665. ,#+AUTHOR: Christopher James Hayward
  1666. ,#+EMAIL: chris@chrishayward.xyz
  1667. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  1668. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  1669. "))
  1670. ;; Daily notes.
  1671. (add-to-list 'org-roam-dailies-capture-templates
  1672. '("d" "Default" entry (function org-roam-capture--get-point)
  1673. "* %?"
  1674. :file-name "docs/daily/%<%Y-%m-%d>"
  1675. :head
  1676. "
  1677. ,#+TITLE: %<%Y-%m-%d>
  1678. ,#+AUTHOR: Christopher James Hayward
  1679. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  1680. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  1681. "))
  1682. ;; Apply custom keybindings.
  1683. (dotfiles/leader
  1684. "or" '(:ignore t :which-key "Roam")
  1685. "ori" '(org-roam-insert :which-key "Insert")
  1686. "orf" '(org-roam-find-file :which-key "Find")
  1687. "orc" '(org-roam-capture :which-key "Capture")
  1688. "orb" '(org-roam-buffer-toggle-display :which-key "Buffer"))
  1689. ;; Apply custom keybindings for dailies.
  1690. (dotfiles/leader
  1691. "ord" '(:ignore t :which-key "Dailies")
  1692. "ordd" '(org-roam-dailies-find-date :which-key "Date")
  1693. "ordt" '(org-roam-dailies-find-today :which-key "Today")
  1694. "ordm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  1695. "ordy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  1696. #+END_SRC
  1697. ** Org Drill
  1698. #+NAME: emacs-org-drill-package
  1699. #+BEGIN_SRC nix
  1700. epkgs.org-drill
  1701. #+END_SRC
  1702. Org Drill[fn:57] is an extension for Org Mode[fn:53] that uses a spaced repition algorithm to conduct interactive /Drill Sessions/ using Org files as sources of facts to be memorized.
  1703. #+NAME: emacs-org-drill-elisp
  1704. #+BEGIN_SRC emacs-lisp
  1705. ;; Configure keybindings for `org-drill'.
  1706. (dotfiles/leader
  1707. "od" '(:ignore t :which-key "Drill")
  1708. "odd" '(org-drill :which-key "Drill")
  1709. "odc" '(org-drill-cram :which-key "Cram")
  1710. "odr" '(org-drill-resume :which-key "Resume"))
  1711. #+END_SRC
  1712. ** Org Agenda
  1713. The way Org Mode[fn:53] 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.
  1714. #+NAME: emacs-org-agenda-elisp
  1715. #+BEGIN_SRC emacs-lisp
  1716. ;; Configure `org-agenda' to use the project files.
  1717. (setq org-agenda-files '("/etc/dotfiles/"
  1718. "/etc/dotfiles/docs/"
  1719. "/etc/dotfiles/docs/courses/"
  1720. "/etc/dotfiles/docs/daily/"
  1721. "/etc/dotfiles/docs/notes/"
  1722. "/etc/dotfiles/docs/posts/"
  1723. "/etc/dotfiles/docs/slides/"))
  1724. ;; Include files encrypted with `gpg'.
  1725. (require 'org)
  1726. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1727. (setq org-agenda-file-regexp
  1728. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1729. org-agenda-file-regexp)))
  1730. ;; Open an agenda buffer with SPC o a.
  1731. (dotfiles/leader
  1732. "oa" '(org-agenda :which-key "Agenda"))
  1733. #+END_SRC
  1734. ** Org Pomodoro
  1735. #+NAME: emacs-pomodoro-package
  1736. #+BEGIN_SRC nix
  1737. epkgs.org-pomodoro
  1738. #+END_SRC
  1739. Org Pomodoro[fn:58] adds basic support for the Pomodoro Technique[fn:59] in GNU/Emacs[fn:2]. 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.
  1740. #+NAME: emacs-pomodoro-elisp
  1741. #+BEGIN_SRC emacs-lisp
  1742. ;; Configure `org-pomodor' with the overtime workflow.
  1743. (setq org-pomodoro-manual-break t
  1744. org-pomodoro-keep-killed-time t)
  1745. ;; Configure keybindings.
  1746. (dotfiles/leader
  1747. "op" '(org-pomodoro :which-key "Pomodoro"))
  1748. #+END_SRC
  1749. ** Writegood Mode
  1750. #+NAME: emacs-writegood-package
  1751. #+BEGIN_SRC nix
  1752. epkgs.writegood-mode
  1753. #+END_SRC
  1754. Writegood Mode[fn:60] is an Emacs[fn:2] minor mode to aid in finding common writing problems. It highlights the text based on the following criteria:
  1755. + Weasel Words
  1756. + Passive Voice
  1757. + Duplicate Words
  1758. #+NAME: emacs-writegood-elisp
  1759. #+BEGIN_SRC emacs-lisp
  1760. ;; Configure `writegood-mode'.
  1761. (dotfiles/leader
  1762. "tg" '(writegood-mode :which-key "Grammar"))
  1763. #+END_SRC
  1764. ** Aspell
  1765. #+NAME: emacs-aspell-extras
  1766. #+BEGIN_SRC nix
  1767. pkgs.aspell
  1768. pkgs.aspellDicts.en
  1769. pkgs.aspellDicts.en-science
  1770. pkgs.aspellDicts.en-computers
  1771. #+END_SRC
  1772. GNU Aspell[fn:61] 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.
  1773. #+NAME: emacs-aspell-elisp
  1774. #+BEGIN_SRC emacs-lisp
  1775. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1776. (setq ispell-program-name "aspell"
  1777. ispell-eextra-args '("--sug-mode=fast"))
  1778. ;; Configure the built-in `flyspell-mode'.
  1779. (dotfiles/leader
  1780. "ts" '(flyspell-mode :which-key "Spelling"))
  1781. #+END_SRC
  1782. ** Hugo
  1783. #+NAME: emacs-hugo-extras
  1784. #+BEGIN_SRC nix
  1785. pkgs.hugo
  1786. #+END_SRC
  1787. Hugo[fn:62] is one of the most popular open-source static site generators.
  1788. #+NAME: emacs-hugo-package
  1789. #+BEGIN_SRC nix
  1790. epkgs.ox-hugo
  1791. #+END_SRC
  1792. Ox-Hugo[fn:63] is an Org-Mode[fn:53] exporter for Hugo[fn:62] compabile markdown. I post nonsense on my Personal Blog[fn:64], and share my notes on various textbooks, articles, and software Here[fn:65].
  1793. #+NAME: emacs-hugo-elisp
  1794. #+BEGIN_SRC emacs-lisp
  1795. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  1796. (require 'ox-hugo)
  1797. ;; Capture templates.
  1798. ;; Personal blog post.
  1799. (add-to-list 'org-roam-capture-templates
  1800. '("p" "Post" plain (function org-roam-capture--get-point)
  1801. "%?"
  1802. :file-name "docs/posts/${slug}"
  1803. :unnarrowed t
  1804. :head
  1805. "
  1806. ,#+TITLE: ${title}
  1807. ,#+AUTHOR: Christopher James Hayward
  1808. ,#+DATE: %<%Y-%m-%d>
  1809. ,#+OPTIONS: num:nil todo:nil tasks:nil
  1810. ,#+EXPORT_FILE_NAME: ${slug}
  1811. ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  1812. ,#+HUGO_BASE_DIR: ../
  1813. ,#+HUGO_AUTO_SET_LASTMOD: t
  1814. ,#+HUGO_SECTION: posts
  1815. ,#+HUGO_DRAFT: true
  1816. "))
  1817. ;; Shared notes.
  1818. (add-to-list 'org-roam-capture-templates
  1819. '("n" "Notes" plain (function org-roam-capture--get-point)
  1820. "%?"
  1821. :file-name "docs/notes/${slug}"
  1822. :unnarrowed t
  1823. :head
  1824. "
  1825. ,#+TITLE: ${title}
  1826. ,#+AUTHOR: Christopher James Hayward
  1827. ,#+OPTIONS: num:nil todo:nil tasks:nil
  1828. ,#+EXPORT_FILE_NAME: ${slug}
  1829. ,#+ROAM_KEY: https://chrishayward.xyz/notes/${slug}/
  1830. ,#+HUGO_BASE_DIR: ../
  1831. ,#+HUGO_AUTO_SET_LASTMOD: t
  1832. ,#+HUGO_SECTION: notes
  1833. ,#+HUGO_DRAFT: true
  1834. "))
  1835. #+END_SRC
  1836. ** Reveal
  1837. #+NAME: emacs-reveal-package
  1838. #+BEGIN_SRC nix
  1839. epkgs.ox-reveal
  1840. #+END_SRC
  1841. Reveal.js[fn:66] is an open source HTML presentation framework. It enables anyone with a web browser to create fully-featured and beautiful presentations for free. Presentations with Reveal.js[fn:66] are built on open web technologies. That means anything you can do on the web, you can do in your presentation. Ox Reveal[fn:67] is an Org Mode[fn:53] export backend.
  1842. #+NAME: emacs-reveal-elisp
  1843. #+BEGIN_SRC emacs-lisp
  1844. ;; Configure `ox-reveal' as an `org-mode-export' backend.
  1845. (require 'ox-reveal)
  1846. ;; Don't rely on any local software.
  1847. (setq org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js")
  1848. ;; Create a capture template.
  1849. (add-to-list 'org-roam-capture-templates
  1850. '("s" "Slides" plain (function org-roam-capture--get-point)
  1851. "%?"
  1852. :file-name "docs/slides/${slug}"
  1853. :unnarrowed t
  1854. :head
  1855. "
  1856. ,#+TITLE: ${title}
  1857. ,#+AUTHOR: Christopher James Hayward
  1858. ,#+EMAIL: chris@chrishayward.xyz
  1859. ,#+REVEAL_ROOT: https://cdn.jsdelivr.net/npm/reveal.js
  1860. ,#+REVEAL_THEME: serif
  1861. ,#+EXPORT_FILE_NAME: ${slug}
  1862. ,#+OPTIONS: reveal_title_slide:nil
  1863. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  1864. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  1865. "))
  1866. #+END_SRC
  1867. ** Passwords
  1868. #+NAME: emacs-pass-extras
  1869. #+BEGIN_SRC nix
  1870. pkgs.pass
  1871. #+END_SRC
  1872. With Pass[fn:68], each password lives inside of an encrypted =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.
  1873. #+NAME: emacs-pass-package
  1874. #+BEGIN_SRC nix
  1875. epkgs.password-store
  1876. #+END_SRC
  1877. Configure keybindings for passwords behind =SPC p=:
  1878. | Key | Description |
  1879. |-----+---------------------|
  1880. | p | Copy a password |
  1881. | r | Rename a password |
  1882. | g | Generate a password |
  1883. #+NAME: emacs-pass-elisp
  1884. #+BEGIN_SRC emacs-lisp
  1885. ;; Set the path to the password store.
  1886. (setq password-store-dir (expand-file-name "~/.password-store"))
  1887. ;; Apply custom keybindings.
  1888. (dotfiles/leader
  1889. "p" '(:ignore t :which-key "Passwords")
  1890. "pp" '(password-store-copy :which-key "Copy")
  1891. "pr" '(password-store-rename :which-key "Rename")
  1892. "pg" '(password-store-generate :which-key "Generate"))
  1893. #+END_SRC
  1894. ** MU4E
  1895. #+NAME: emacs-mu4e-extras
  1896. #+BEGIN_SRC nix
  1897. pkgs.mu
  1898. pkgs.isync
  1899. #+END_SRC
  1900. #+NAME: emacs-mu4e-package
  1901. #+BEGIN_SRC nix
  1902. epkgs.mu4e-alert
  1903. #+END_SRC
  1904. #+NAME: emacs-mu4e-config
  1905. #+BEGIN_SRC nix
  1906. home.file.".mbsyncrc" = {
  1907. text = ''
  1908. IMAPStore xyz-remote
  1909. Host mail.chrishayward.xyz
  1910. User chris@chrishayward.xyz
  1911. PassCmd "pass chrishayward.xyz/chris"
  1912. SSLType IMAPS
  1913. MaildirStore xyz-local
  1914. Path ~/.cache/mail/
  1915. Inbox ~/.cache/mail/inbox
  1916. SubFolders Verbatim
  1917. Channel xyz
  1918. Far :xyz-remote:
  1919. Near :xyz-local:
  1920. Patterns * !Archives
  1921. Create Both
  1922. Expunge Both
  1923. SyncState *
  1924. '';
  1925. };
  1926. #+END_SRC
  1927. #+BEGIN_SRC sh
  1928. mbsync -a
  1929. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  1930. mu index
  1931. #+END_SRC
  1932. #+NAME: emacs-mu4e-elisp
  1933. #+BEGIN_SRC emacs-lisp
  1934. ;; Add the `mu4e' shipped with `mu' to the load path.
  1935. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  1936. (require 'mu4e)
  1937. ;; Confiugure `mu4e'.
  1938. (setq mu4e-maildir "~/.cache/mail"
  1939. mu4e-update-interval (* 5 60)
  1940. mu4e-get-mail-command "mbsync -a"
  1941. mu4e-compose-format-flowed t
  1942. mu4e-change-filenames-when-moving t
  1943. mu4e-compose-signature (concat "Chris Hayward\n"
  1944. "chris@chrishayward.xyz"))
  1945. ;; Sign all outbound email with GPG.
  1946. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  1947. (setq message-send-mail-function 'smtpmail-send-it
  1948. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  1949. ;; Setup `mu4e' accounts.
  1950. (setq mu4e-contexts
  1951. (list
  1952. ;; Main
  1953. ;; chris@chrishayward.xyz
  1954. (make-mu4e-context
  1955. :name "Main"
  1956. :match-func
  1957. (lambda (msg)
  1958. (when msg
  1959. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  1960. :vars
  1961. '((user-full-name . "Christopher James Hayward")
  1962. (user-mail-address . "chris@chrishayward.xyz")
  1963. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  1964. (smtpmail-smtp-service . 587)
  1965. (smtpmail-stream-type . starttls)))))
  1966. ;; Setup `mu4e-alert'.
  1967. (setq mu4e-alert-set-default-style 'libnotify)
  1968. (mu4e-alert-enable-notifications)
  1969. (mu4e-alert-enable-mode-line-display)
  1970. ;; Open the `mu4e' dashboard.
  1971. (dotfiles/leader
  1972. "m" '(mu4e :which-key "Mail"))
  1973. #+END_SRC
  1974. ** Projectile
  1975. #+NAME: emacs-projectile-package
  1976. #+BEGIN_SRC nix
  1977. epkgs.projectile
  1978. #+END_SRC
  1979. Projectile[fn:69] is a project interaction library for GNU/Emacs[fn:2]. Its goal is to provide a nice set of features operating on a project level, without introducing external dependencies.
  1980. #+NAME: emacs-projectile-elisp
  1981. #+BEGIN_SRC emacs-lisp
  1982. ;; Configure the `projectile-project-search-path'.
  1983. (setq projectile-project-search-path '("~/.local/source"))
  1984. (projectile-mode +1)
  1985. #+END_SRC
  1986. ** LSP Mode
  1987. #+NAME: emacs-lsp-package
  1988. #+BEGIN_SRC nix
  1989. epkgs.lsp-mode
  1990. epkgs.lsp-ui
  1991. #+END_SRC
  1992. The Language Server Protocol (LSP)[fn:70] defines the protocol used between an Editor or IDE, and a language server that provides features like:
  1993. + Auto Complete
  1994. + Go To Defintion
  1995. + Find All References
  1996. #+NAME: emacs-lsp-elisp
  1997. #+BEGIN_SRC emacs-lisp
  1998. ;; Configure `lsp-mode'.
  1999. (setq lsp-idle-delay 0.5
  2000. lsp-prefer-flymake t)
  2001. ;; Configure `lsp-ui'.
  2002. (setq lsp-ui-doc-position 'at-point
  2003. lsp-ui-doc-delay 0.5)
  2004. #+END_SRC
  2005. ** CCLS
  2006. #+NAME: emacs-ccls-package
  2007. #+BEGIN_SRC nix
  2008. epkgs.ccls
  2009. #+END_SRC
  2010. Emacs CCLS[fn:71] is a client for CCLS, a C/C++/Objective-C language server supporting multi-million line C++ code bases, powered by libclang.
  2011. #+NAME: emacs-ccls-elisp
  2012. #+BEGIN_SRC emacs-lisp
  2013. ;; Configure `ccls' to work with `lsp-mode'.
  2014. (defun dotfiles/ccls-hook ()
  2015. (require 'ccls)
  2016. (lsp))
  2017. ;; Configure `ccls' mode hooks.
  2018. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  2019. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  2020. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  2021. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  2022. #+END_SRC
  2023. ** Company Mode
  2024. #+NAME: emacs-company-package
  2025. #+BEGIN_SRC nix
  2026. epkgs.company
  2027. #+END_SRC
  2028. Company[fn:72] is a text completion framework for GNU/Emacs[fn:2]. The name stands for =Complete Anything=. It uses pluggable back-ends and front-ends to retieve and display completion candidates.
  2029. #+NAME: emacs-company-elisp
  2030. #+BEGIN_SRC emacs-lisp
  2031. ;; Configure `company-mode'.
  2032. (setq company-backend 'company-capf
  2033. lsp-completion-provider :capf)
  2034. ;; Enable it globally.
  2035. (global-company-mode +1)
  2036. #+END_SRC
  2037. ** Go Mode
  2038. #+NAME: emacs-golang-package
  2039. #+BEGIN_SRC nix
  2040. epkgs.go-mode
  2041. #+END_SRC
  2042. Go Mode[fn:73] is a major mode for editing Golang[fn:12] source code in GNU/Emacs[fn:2].
  2043. #+NAME: emacs-golang-elisp
  2044. #+BEGIN_SRC emacs-lisp
  2045. ;; Configure `go-mode' to work with `lsp-mode'.
  2046. (defun dotfiles/go-hook ()
  2047. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  2048. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  2049. ;; Configure a custom `before-save-hook'.
  2050. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  2051. #+END_SRC
  2052. ** Rustic
  2053. #+NAME: emacs-rustic-package
  2054. #+BEGIN_SRC nix
  2055. epkgs.rustic
  2056. #+END_SRC
  2057. Rustic[fn:72] is a fork of rust-mode that integrates well with the Language Server Protocol[fn:68]. Include the rust shell before launching GNU/Emacs[fn:2] to use this!
  2058. #+NAME: emacs-rustic-elisp
  2059. #+BEGIN_SRC emacs-lisp
  2060. ;; Configure `rustic' with `lsp-mode'.
  2061. (setq rustic-format-on-save t
  2062. rustic-lsp-server 'rls)
  2063. #+END_SRC
  2064. ** Python Mode
  2065. #+NAME: emacs-python-package
  2066. #+BEGIN_SRC nix
  2067. epkgs.pretty-mode
  2068. #+END_SRC
  2069. The built in Python Mode[fn:74] has a nice feature set for working with Python[fn:18] code in GNU/Emacs[fn:2]. It is complimented with the addition of an LSP[fn:70] server. These tools are included in the Development Shell[fn:11] for Python[fn:18].
  2070. #+NAME: emacs-python-elisp
  2071. #+BEGIN_SRC emacs-lisp
  2072. ;; Configure `pretty-mode' to work with `python-mode'.
  2073. (add-hook 'python-mode-hook
  2074. (lambda ()
  2075. (turn-on-pretty-mode)))
  2076. #+END_SRC
  2077. ** PlantUML
  2078. #+NAME: emacs-plantuml-extras
  2079. #+BEGIN_SRC nix
  2080. pkgs.plantuml
  2081. #+END_SRC
  2082. PlantUML[fn:75] is an open-source tool allowing users to create diagrams from a plain-text language. Besides various UML diagrams, PlantUML[fn:75] has support for various other software developmented related formats, as well as visualizations of =JSON= and =YAML= files.
  2083. #+NAME: emacs-plantuml-package
  2084. #+BEGIN_SRC nix
  2085. epkgs.plantuml-mode
  2086. #+END_SRC
  2087. PlantUML Mode[fn:76] is a major mode for editing PlantUML[fn:75] sources in GNU/Emacs[fn:2].
  2088. #+NAME: emacs-plantuml-elisp
  2089. #+BEGIN_SRC emacs-lisp
  2090. ;; Configure `plantuml-mode'.
  2091. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  2092. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  2093. (setq plantuml-default-exec-mode 'executable
  2094. org-plantuml-exec-mode 'plantuml)
  2095. #+END_SRC
  2096. ** Swiper
  2097. #+NAME: emacs-swiper-package
  2098. #+BEGIN_SRC nix
  2099. epkgs.ivy
  2100. epkgs.counsel
  2101. epkgs.ivy-rich
  2102. epkgs.ivy-posframe
  2103. epkgs.ivy-prescient
  2104. #+END_SRC
  2105. Ivy (Swiper)[fn:77] is a generic completion mechanism for GNU/Emacs[fn:2]. 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.
  2106. #+NAME: emacs-swiper-elisp
  2107. #+BEGIN_SRC emacs-lisp
  2108. ;; Configure `ivy'.
  2109. (setq counsel-linux-app-format-function
  2110. #'counsel-linux-app-format-function-name-only)
  2111. (ivy-mode +1)
  2112. (counsel-mode +1)
  2113. ;; Configure `ivy-rich'.
  2114. (ivy-rich-mode +1)
  2115. ;; Configure `ivy-posframe'.
  2116. (setq ivy-posframe-parameters '((parent-frame nil))
  2117. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  2118. (ivy-posframe-mode +1)
  2119. ;; Configure `ivy-prescient'.
  2120. (setq ivy-prescient-enable-filtering nil)
  2121. (ivy-prescient-mode +1)
  2122. #+END_SRC
  2123. ** Transparency
  2124. It's possible to control the frame opacity in GNU/Emacs[fn:2]. Unlike other transparency hacks, it's not merely showing the desktop background image, but is true transparency -- you can se other windows behind the Emacs[fn:2] window.
  2125. #+NAME: emacs-transparency-elisp
  2126. #+BEGIN_SRC emacs-lisp
  2127. ;; Configure the default frame transparency.
  2128. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  2129. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  2130. #+END_SRC
  2131. ** Desktop Environment
  2132. #+NAME: emacs-desktop-extras
  2133. #+BEGIN_SRC nix
  2134. pkgs.brightnessctl
  2135. #+END_SRC
  2136. The Desktop Environment[fn:78] package provides commands and a global minor mode for controlling your GNU/Linux[fn:1] desktop from within GNU/Emacs[fn:2].
  2137. #+NAME: emacs-desktop-package
  2138. #+BEGIN_SRC nix
  2139. epkgs.desktop-environment
  2140. #+END_SRC
  2141. 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.
  2142. #+NAME: emacs-desktop-elisp
  2143. #+BEGIN_SRC emacs-lisp
  2144. ;; Configure `desktop-environment'.
  2145. (require 'desktop-environment)
  2146. (desktop-environment-mode +1)
  2147. #+END_SRC
  2148. ** Doom Themes
  2149. #+NAME: emacs-doom-themes-package
  2150. #+BEGIN_SRC nix
  2151. epkgs.doom-themes
  2152. #+END_SRC
  2153. Doom Themes[fn:79] is a theme megapack for GNU/Emacs[fn:2], inspired by community favourites.
  2154. #+NAME: emacs-doom-themes-elisp
  2155. #+BEGIN_SRC emacs-lisp
  2156. ;; Include modern themes from `doom-themes'.
  2157. (setq doom-themes-enable-bold t
  2158. doom-themes-enable-italic t)
  2159. ;; Load the `doom-moonlight' theme.
  2160. (load-theme 'doom-moonlight t)
  2161. (doom-modeline-mode +1)
  2162. ;; Load a new theme with <SPC> t t.
  2163. (dotfiles/leader
  2164. "tt" '(counsel-load-theme :which-key "Theme"))
  2165. #+END_SRC
  2166. ** Doom Modeline
  2167. #+NAME: emacs-doom-modeline-package
  2168. #+BEGIN_SRC nix
  2169. epkgs.doom-modeline
  2170. #+END_SRC
  2171. Doom Modeline[fn:80] is a fancy and fast modeline inspired by minimalism design. It's integrated into Centaur Emacs, Doom Emacs, and Spacemacs.
  2172. #+NAME: emacs-doom-modeline-elisp
  2173. #+BEGIN_SRC emacs-lisp
  2174. ;; Add the `doom-modeline' after initialization.
  2175. (add-hook 'after-init-hook 'doom-modeline-mode)
  2176. (setq doom-modeline-height 16
  2177. doom-modeline-icon t)
  2178. #+END_SRC
  2179. * Footnotes
  2180. [fn:1] https://gnu.org
  2181. [fn:2] https://gnu.org/software/emacs/
  2182. [fn:3] https://literateprogramming.com/knuthweb.pdf
  2183. [fn:4] https://nixos.org/manual/nixos/stable
  2184. [fn:5] https://nixos.org/manual/nix/stable
  2185. [fn:6] https://nixos.org/manual/nixpkgs/stable
  2186. [fn:7] https://github.com/nix-community/home-manager
  2187. [fn:8] https://github.com/nix-community/emacs-overlay
  2188. [fn:9] https://github.com/nixos/nixos-hardware
  2189. [fn:10] https://github.com/t184256/nix-on-droid
  2190. [fn:11] https://nixos.org/manual/nix/unstable/command-ref/nix-shell.html
  2191. [fn:12] https://golang.org
  2192. [fn:13] https://rust-lang.org
  2193. [fn:14] https://nodejs.org
  2194. [fn:15] https://grpc.io
  2195. [fn:16] https://iso.org/standard/74528.html
  2196. [fn:17] https://en.wikipedia.org/wiki/C++/
  2197. [fn:18] https://python.org
  2198. [fn:19] https://qemu.org
  2199. [fn:20] https://github.com/ch11ng/exwm
  2200. [fn:21] https://evil.readthedocs.io/en/latest/overview.html
  2201. [fn:22] https://raspberrypi.org/products/raspberry-pi-400/
  2202. [fn:23] https://www.raspberrypi.org/products/raspberry-pi-4-model-b/
  2203. [fn:24] https://samsung.com/us/mobile/galaxy-s10/buy/
  2204. [fn:25] https://x.org/wiki/
  2205. [fn:26] https://wayland.freedesktop.org
  2206. [fn:27] https://openssh.com
  2207. [fn:28] https://nixos.wiki/wiki/Flakes
  2208. [fn:29] https://nix-community.cachix.org
  2209. [fn:30] https://docker.org
  2210. [fn:31] https://en.wikipedia.org/wiki/Firefox
  2211. [fn:32] https://jellyfin.org
  2212. [fn:33] https://moonlight-stream.org
  2213. [fn:34] https://teamviewer.com
  2214. [fn:35] https://git-scm.com
  2215. [fn:36] https://emacswiki.org/emacs/LearnEmacsLisp
  2216. [fn:37] https://neovim.io
  2217. [fn:38] https://gtk.org
  2218. [fn:39] https://github.com/nixos/nix-mode
  2219. [fn:40] https://github.com/noctuid/general.el
  2220. [fn:41] https://github.com/justbur/emacs-which-key
  2221. [fn:42] https://emacswiki.org/emacs/eww
  2222. [fn:43] https://gnu.org/software/emacs/erc.html
  2223. [fn:44] https://emacswiki.org/emacs/DiredMode
  2224. [fn:45] https://emacswiki.org/emacs/DiredExtra#Dired_X
  2225. [fn:46] https://github.com/domtronn/all-the-icons.el
  2226. [fn:47] https://github.com/iqbalansari/emacs-emojify
  2227. [fn:48] https://gnu.org/software/emacs/manual/html_mono/eshell.html
  2228. [fn:49] https://github.com/akermu/emacs-libvterm
  2229. [fn:50] https://github.com/neovim/libvterm
  2230. [fn:51] https://magit.vc
  2231. [fn:52] https://github.com/skeeto/elfeed
  2232. [fn:53] https://orgmode.org
  2233. [fn:54] https://github.com/org-roam/org-roam
  2234. [fn:55] https://zettelkasten.de
  2235. [fn:56] https://github.com/org-roam/org-roam-server
  2236. [fn:57] https://orgmode.org/worg/org-contrib/org-drill.html
  2237. [fn:58] https://github.com/marcinkoziej/org-pomodoro
  2238. [fn:59] https://en.wikipedia.org/wiki/Pomodoro_Technique
  2239. [fn:60] https://github.com/bnbeckwith/writegood-mode
  2240. [fn:61] https://aspell.net
  2241. [fn:62] https://gohugo.io
  2242. [fn:63] https://oxhugo.scripter.co
  2243. [fn:64] https://chrishayward.xyz/posts/
  2244. [fn:65] https://chrishayward.xyz/notes/
  2245. [fn:66] https://revealjs.com
  2246. [fn:67] https://github.com/hexmode/ox-reveal
  2247. [fn:68] https://password-store.org
  2248. [fn:69] https://projectile.mx
  2249. [fn:70] https://microsoft.github.io/language-server-protocol
  2250. [fn:71] https://github.com/MaskRay/emacs-ccls
  2251. [fn:72] https://company-mode.github.io
  2252. [fn:73] https://emacswiki.org/emacs/GoMode
  2253. [fn:74] https://plantuml.com
  2254. [fn:75] https://github.com/skuro/plantuml-mode
  2255. [fn:76] https://github.com/abo-abo/swiper
  2256. [fn:77] https://github.com/DamienCassou/desktop-environment
  2257. [fn:78] https://github.com/hlissner/emacs-doom-themes
  2258. [fn:79] https://github.com/seagle0128/doom-modeline
  2259. [fn:80] https://laptopmedia.com/laptop-specs/acer-nitro-5-an515-53-2
  2260. [fn:81] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html