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.

2920 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 800px
  15. #+ATTR_HTML: :width 800px
  16. #+ATTR_LATEX: :width 800px
  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. "192.168.3.136" = [ "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.xserver.libinput.touchpad.tapping = false;
  423. services.printing.enable = true;
  424. programs.mtr.enable = true;
  425. programs.fish.enable = true;
  426. programs.gnupg.agent.enable = true;
  427. users.users.chris = {
  428. shell = pkgs.fish;
  429. isNormalUser = true;
  430. extraGroups = [ "wheel" ];
  431. };
  432. }
  433. #+END_SRC
  434. *** Hardware
  435. + Enables sound via PulseAudio
  436. + Adds support for the NVIDIA Hybrid GPU
  437. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/hardware.nix
  438. # <<file-warning>>
  439. { config, lib, pkgs, modulesPath, ... }:
  440. {
  441. imports =
  442. [ (modulesPath + "/installer/scan/not-detected.nix")
  443. ];
  444. boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ];
  445. boot.initrd.kernelModules = [ ];
  446. boot.kernelModules = [ "kvm-intel" ];
  447. boot.extraModulePackages = [ ];
  448. boot.loader.systemd-boot.enable = true;
  449. boot.loader.efi.canTouchEfiVariables = true;
  450. sound.enable = true;
  451. hardware.pulseaudio.enable = true;
  452. hardware.pulseaudio.support32Bit = true;
  453. fileSystems."/" =
  454. { device = "/dev/disk/by-uuid/2f548eb9-47ce-4280-950f-9c6d1d162852";
  455. fsType = "ext4";
  456. };
  457. fileSystems."/boot" =
  458. { device = "/dev/disk/by-uuid/5BC3-73F3";
  459. fsType = "vfat";
  460. };
  461. swapDevices =
  462. [ { device = "/dev/disk/by-uuid/bef7bf62-d26f-45b1-a1f8-1227c2f8b26a"; }
  463. ];
  464. powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  465. }
  466. #+END_SRC
  467. ** Raspberry
  468. 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.
  469. #+NAME: host-raspberry
  470. #+BEGIN_SRC nix :noweb yes
  471. raspberry = nixpkgs.lib.nixosSystem {
  472. system = "aarch64-linux";
  473. specialArgs = { inherit inputs; };
  474. modules = [
  475. ./hosts/raspberry
  476. <<module-x11>>
  477. <<module-ssh>>
  478. <<module-flakes>>
  479. <<module-cachix>>
  480. <<module-home-manager>>
  481. ];
  482. };
  483. #+END_SRC
  484. Deploy this configuration with ~sudo nixos-rebuild switch --flake /etc/dotfiles/#raspberry~.
  485. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/default.nix
  486. # <<file-warning>>
  487. { ... }:
  488. {
  489. imports = [
  490. ./configuration.nix
  491. ./hardware.nix
  492. ];
  493. }
  494. #+END_SRC
  495. *** Configuration
  496. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/configuration.nix
  497. # <<file-warning>>
  498. { config, pkgs, ... }:
  499. {
  500. time.timeZone = "America/Toronto";
  501. networking.hostName = "raspberry";
  502. networking.firewall.enable = false;
  503. networking.networkmanager.enable = true;
  504. networking.interfaces.eth0.useDHCP = true;
  505. networking.interfaces.wlan0.useDHCP = true;
  506. <<host-config-home>>
  507. environment.systemPackages = [
  508. pkgs.libraspberrypi
  509. pkgs.raspberrypi-eeprom
  510. ];
  511. programs.fish.enable = true;
  512. programs.gnupg.agent.enable = true;
  513. users.users.chris = {
  514. shell = pkgs.fish;
  515. isNormalUser = true;
  516. extraGroups = [ "wheel" "networkmanager" ];
  517. };
  518. }
  519. #+END_SRC
  520. *** Hardware
  521. 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.
  522. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/hardware.nix
  523. # <<file-warning>>
  524. { config, pkgs, lib, inputs, ... }:
  525. {
  526. # imports = [
  527. # inputs.nixos-hardware.nixosModules.raspberry-pi-4
  528. # ];
  529. # boot.kernelPackages = pkgs.linuxPackages_rpi4;
  530. boot.tmpOnTmpfs = true;
  531. boot.initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
  532. boot.kernelParams = [
  533. "8250.nr_uarts=1"
  534. "console=ttyAMA0,115200"
  535. "console=tty1"
  536. "cma=128M"
  537. ];
  538. boot.loader.grub.enable = false;
  539. boot.loader.generic-extlinux-compatible.enable = true;
  540. boot.loader.raspberryPi = {
  541. enable = true;
  542. version = 4;
  543. firmwareConfig = ''
  544. hdmi_drive=2
  545. hdmi_force_hotplug=1
  546. dtparam=sd_poll_once=on
  547. dtparam=audio=on
  548. '';
  549. };
  550. # FIXME: Requires GPU support.
  551. services.xserver.videoDrivers = [ "fbdev" ];
  552. sound.enable = true;
  553. hardware.pulseaudio.enable = true;
  554. hardware.enableRedistributableFirmware = true;
  555. # hardware.raspberry-pi."4".fkms-3d.enable = true;
  556. fileSystems = {
  557. "/" = {
  558. device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
  559. fsType = "ext4";
  560. options = [ "noatime" ];
  561. };
  562. };
  563. powerManagement.cpuFreqGovernor = "ondemand";
  564. }
  565. #+END_SRC
  566. ** Homecloud
  567. 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=.
  568. #+NAME: host-homecloud
  569. #+BEGIN_SRC nix :noweb yes
  570. homecloud = nixpkgs.lib.nixosSystem {
  571. system = "aarch64-linux";
  572. specialArgs = { inherit inputs; };
  573. modules = [
  574. ./hosts/homecloud
  575. <<module-ssh>>
  576. <<module-flakes>>
  577. <<module-cachix>>
  578. ];
  579. };
  580. #+END_SRC
  581. Deploy this configuration with ~sudo nixos-rebuild switch --flake /etc/dotfiles/#homecloud~.
  582. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/default.nix
  583. # <<file-warning>
  584. { ... }:
  585. {
  586. imports = [
  587. ./configuration.nix
  588. ./hardware.nix
  589. ];
  590. }
  591. #+END_SRC
  592. *** Configuration
  593. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/configuration.nix
  594. # <<file-warning>>
  595. { config, pkgs, ... }:
  596. {
  597. time.timeZone = "America/Toronto";
  598. networking.hostName = "homecloud";
  599. networking.firewall.enable = false;
  600. networking.networkmanager.enable = true;
  601. networking.interfaces.eth0.useDHCP = true;
  602. networking.interfaces.wlan0.useDHCP = true;
  603. <<host-config-wifi>>
  604. <<host-config-home>>
  605. environment.systemPackages = [
  606. pkgs.libraspberrypi
  607. pkgs.raspberrypi-eeprom
  608. ];
  609. programs.fish.enable = true;
  610. programs.mtr.enable = true;
  611. users.users.chris = {
  612. shell = pkgs.fish;
  613. isNormalUser = true;
  614. extraGroups = [ "wheel" "networkmanager" ];
  615. };
  616. }
  617. #+END_SRC
  618. *** Hardware
  619. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/hardware.nix
  620. # <<file-warning>>
  621. { config, pkgs, lib, inputs, ... }:
  622. {
  623. # imports = [
  624. # inputs.nixos-hardware.nixosModules.raspberry-pi-4
  625. # ];
  626. # boot.kernelPackages = pkgs.linuxPackages_rpi4;
  627. boot.tmpOnTmpfs = true;
  628. boot.initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
  629. boot.kernelParams = [
  630. "8250.nr_uarts=1"
  631. "console=ttyAMA0,115200"
  632. "console=tty1"
  633. "cma=128M"
  634. ];
  635. boot.loader.grub.enable = false;
  636. boot.loader.generic-extlinux-compatible.enable = true;
  637. boot.loader.raspberryPi = {
  638. enable = true;
  639. version = 4;
  640. firmwareConfig = ''
  641. hdmi_drive=2
  642. hdmi_force_hotplug=1
  643. dtparam=sd_poll_once=on
  644. dtparam=audio=on
  645. '';
  646. };
  647. # hardware.raspberry-pi."4".fkms-3d.enable = true;
  648. fileSystems = {
  649. "/" = {
  650. device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
  651. fsType = "ext4";
  652. options = [ "noatime" ];
  653. };
  654. };
  655. powerManagement.cpuFreqGovernor = "ondemand";
  656. }
  657. #+END_SRC
  658. ** TODO Zero-One
  659. TODO: Raspberry Pi Zero/Zero WH
  660. #+NAME: host-zero-one
  661. #+BEGIN_SRC nix
  662. zero-one = nixpkgs.lib.nixosSystem {
  663. system = "armv7l-linux";
  664. specialArgs = { inherit inputs; };
  665. modules = [
  666. ./hosts/zero-one
  667. ./modules/ssh.nix
  668. ./modules/flakes.nix
  669. ./modules/cachix.nix
  670. ];
  671. };
  672. #+END_SRC
  673. ** TODO Zero-Two
  674. #+NAME: host-zero-two
  675. #+BEGIN_SRC nix
  676. zero-two = nixpkgs.lib.nixosSystem {
  677. system = "armv7l-linux";
  678. specialArgs = { inherit inputs; };
  679. modules = [
  680. ./hosts/zero-two
  681. ./modules/ssh.nix
  682. ./modules/flakes.nix
  683. ./modules/cachix.nix
  684. ];
  685. };
  686. #+END_SRC
  687. ** TODO Android
  688. 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.
  689. #+NAME: host-android
  690. #+BEGIN_SRC nix
  691. android = (inputs.nix-on-droid.lib.aarch64-linux.nix-on-droid {
  692. config = ./hosts/android/nix-on-droid.nix;
  693. }).activationPackage;
  694. #+END_SRC
  695. Build the activation package with ~nix build .#android --impure~, and activate it with =result/activate=.
  696. #+BEGIN_SRC nix :noweb yes :tangle hosts/android/nix-on-droid.nix
  697. # <<file-warning>>
  698. { pkgs, ... }:
  699. {
  700. environment.packages = [
  701. pkgs.git
  702. pkgs.vim
  703. pkgs.pass
  704. pkgs.gnupg
  705. pkgs.openssh
  706. ];
  707. }
  708. #+END_SRC
  709. * Module Definitions
  710. 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.
  711. ** X11
  712. #+NAME: module-x11
  713. #+BEGIN_SRC nix
  714. ./modules/x11.nix
  715. #+END_SRC
  716. 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.
  717. #+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
  718. # <<file-warning>>
  719. { config, pkgs, ... }:
  720. {
  721. services.xserver.enable = true;
  722. services.xserver.layout = "us";
  723. services.xserver.libinput.enable = true;
  724. services.xserver.displayManager.startx.enable = true;
  725. environment = {
  726. variables = {
  727. XDG_CACHE_HOME = "$HOME/.cache";
  728. XDG_CONFIG_HOME = "$HOME/.config";
  729. XDG_DATA_HOME = "$HOME/.local/share";
  730. XDG_BIN_HOME = "$HOME/.local/bin";
  731. };
  732. systemPackages = with pkgs; [
  733. pkgs.sqlite
  734. pkgs.pfetch
  735. pkgs.cmatrix
  736. pkgs.asciiquarium
  737. ];
  738. extraInit = ''
  739. export XAUTHORITY=/tmp/Xauthority
  740. export xserverauthfile=/tmp/xserverauth
  741. [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
  742. [ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
  743. '';
  744. };
  745. services.picom.enable = true;
  746. services.printing.enable = true;
  747. fonts.fonts = with pkgs; [
  748. iosevka-bin
  749. emacs-all-the-icons-fonts
  750. ];
  751. }
  752. #+END_SRC
  753. ** SSH
  754. #+NAME: module-ssh
  755. #+BEGIN_SRC nix
  756. ./modules/ssh.nix
  757. #+END_SRC
  758. 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.
  759. Apply some configuration to the default settings:
  760. + Disable logging in as =root=
  761. + Disable password authentication
  762. #+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
  763. # <<file-warning>>
  764. { config, pkgs, ... }:
  765. {
  766. services.openssh = {
  767. enable = true;
  768. permitRootLogin = "no";
  769. passwordAuthentication = false;
  770. };
  771. }
  772. #+END_SRC
  773. ** Flakes
  774. #+NAME: module-flakes
  775. #+BEGIN_SRC nix
  776. ./modules/flakes.nix
  777. #+END_SRC
  778. 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.
  779. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  780. # <<file-warning>>
  781. { config, pkgs, inputs, ... }:
  782. {
  783. nix = {
  784. package = pkgs.nixUnstable;
  785. extraOptions = ''
  786. experimental-features = nix-command flakes
  787. '';
  788. };
  789. nixpkgs = {
  790. config = { allowUnfree = true; };
  791. overlays = [ inputs.emacs-overlay.overlay ];
  792. };
  793. }
  794. #+END_SRC
  795. ** Cachix
  796. #+NAME: module-cachix
  797. #+BEGIN_SRC nix
  798. ./modules/cachix.nix
  799. #+END_SRC
  800. 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.
  801. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  802. # <<file-warning>>
  803. { config, ... }:
  804. {
  805. nix = {
  806. binaryCaches = [
  807. "https://nix-community.cachix.org"
  808. ];
  809. binaryCachePublicKeys = [
  810. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  811. ];
  812. };
  813. }
  814. #+END_SRC
  815. ** Docker
  816. #+NAME: module-docker
  817. #+BEGIN_SRC nix
  818. ./modules/docker.nix
  819. #+END_SRC
  820. 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.
  821. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  822. { config, pkgs, ... }:
  823. {
  824. virtualisation.docker = {
  825. enable = true;
  826. enableOnBoot = true;
  827. autoPrune.enable = true;
  828. };
  829. }
  830. #+END_SRC
  831. ** NVIDIA
  832. #+NAME: module-nvidia
  833. #+BEGIN_SRC nix
  834. ./modules/nvidia.nix
  835. #+END_SRC
  836. #+BEGIN_SRC nix :noweb yes :tangle modules/nvidia.nix
  837. { config, pkgs, ... }:
  838. let
  839. myIntelBusId = "PCI:0:2:0";
  840. myNvidiaBusId = "PCI:1:0:0";
  841. myNvidiaOffload = pkgs.writeShellScriptBin "nvidia-offload" ''
  842. export __NV_PRIME_RENDER_OFFLOAD=1
  843. export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
  844. export __GLX_VENDOR_LIBRARY_NAME=nvidia
  845. export __VK_LAYER_NV_optimus=NVIDIA_only
  846. exec -a "$0" "$@"
  847. '';
  848. in {
  849. # Add the offload script to the $PATH.
  850. environment.systemPackages = [ myNvidiaOffload ];
  851. # Configure XDG compliance.
  852. environment.variables = {
  853. __GL_SHADER_DISK_CACHE_PATH = "$XDG_CACHE_HOME/nv";
  854. CUDA_CACHE_PATH = "$XDG_CACHE_HOME/nv";
  855. };
  856. # Enable the NVIDIA drivers.
  857. # NOTE: You may need to use either of the commands below:
  858. services.xserver.videoDrivers = [ "nvidia" ];
  859. # services.xserver.videoDrivers = [ "modesetting" "nvidia" ];
  860. # Configure `offload-mode'.
  861. hardware.nvidia.prime = {
  862. offload.enable = true;
  863. intelBusId = myIntelBusId;
  864. nvidiaBusId = myNvidiaBusId;
  865. };
  866. }
  867. #+END_SRC
  868. ** Firefox
  869. #+NAME: module-firefox
  870. #+BEGIN_SRC nix
  871. ./modules/firefox.nix
  872. #+END_SRC
  873. 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.
  874. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  875. # <<file-warning>>
  876. { pkgs, ... }:
  877. {
  878. # NOTE: Use the binary until module is developed.
  879. environment.systemPackages = [
  880. pkgs.firefox-bin
  881. ];
  882. }
  883. #+END_SRC
  884. ** Jellyfin
  885. #+NAME: module-jellyfin
  886. #+BEGIN_SRC nix
  887. ./modules/jellyfin.nix
  888. #+END_SRC
  889. 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.
  890. #+BEGIN_SRC nix :noweb yes :tangle modules/jellyfin.nix
  891. # <<file-warning>>
  892. { config, pkgs, ... }:
  893. {
  894. services.jellyfin = {
  895. enable = true;
  896. };
  897. }
  898. #+END_SRC
  899. ** Moonlight
  900. #+NAME: module-moonlight
  901. #+BEGIN_SRC nix
  902. ./modules/moonlight.nix
  903. #+END_SRC
  904. 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.
  905. #+BEGIN_SRC nix :noweb yes :tangle modules/moonlight.nix
  906. # <<file-warning>>
  907. { pkgs, ... }:
  908. {
  909. environment.systemPackages = [
  910. pkgs.moonlight-qt
  911. ];
  912. }
  913. #+END_SRC
  914. ** Teamviewer
  915. #+NAME: module-teamviewer
  916. #+BEGIN_SRC nix
  917. ./modules/teamviewer.nix
  918. #+END_SRC
  919. 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.
  920. #+BEGIN_SRC nix :noweb yes :tangle modules/teamviewer.nix
  921. # <<file-warning>>
  922. { pkgs, ... }:
  923. {
  924. # NOTE: Neither of these are working!
  925. # services.teamviewer.enable = true;
  926. # environment.systemPackages = [
  927. # pkgs.teamviewer
  928. # ];
  929. }
  930. #+END_SRC
  931. ** Home Manager
  932. 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.
  933. #+NAME: module-home-manager
  934. #+BEGIN_SRC nix :noweb yes
  935. inputs.home-manager.nixosModules.home-manager {
  936. home-manager.useGlobalPkgs = true;
  937. home-manager.useUserPackages = true;
  938. home-manager.users.chris = {
  939. imports = [
  940. <<module-git>>
  941. <<module-gpg>>
  942. <<module-vim>>
  943. <<module-gtk>>
  944. <<module-emacs>>
  945. ];
  946. };
  947. }
  948. #+END_SRC
  949. *** Git
  950. #+NAME: module-git
  951. #+BEGIN_SRC nix
  952. ./modules/git.nix
  953. #+END_SRC
  954. 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.
  955. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  956. # <<file-warning>>
  957. { pkgs, ... }:
  958. {
  959. programs.git = {
  960. enable = true;
  961. userName = "Christopher James Hayward";
  962. userEmail = "chris@chrishayward.xyz";
  963. signing = {
  964. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  965. signByDefault = true;
  966. };
  967. };
  968. }
  969. #+END_SRC
  970. *** Gpg
  971. #+NAME: module-gpg
  972. #+BEGIN_SRC nix
  973. ./modules/gpg.nix
  974. #+END_SRC
  975. 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.
  976. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  977. # <<file-warning>>
  978. { pkgs, ... }:
  979. {
  980. services.gpg-agent = {
  981. enable = true;
  982. defaultCacheTtl = 1800;
  983. enableSshSupport = true;
  984. pinentryFlavor = "gtk2";
  985. };
  986. }
  987. #+END_SRC
  988. *** Vim
  989. #+NAME: module-vim
  990. #+BEGIN_SRC nix
  991. ./modules/vim.nix
  992. #+END_SRC
  993. Neovim[fn:37] is a project that seeks to aggressively refactor Vim in order to:
  994. + Simplify maintenance and encourage contributions
  995. + Split the work between multiple developers
  996. + Enable advanced UIs without core modification
  997. + Maximize extensibility
  998. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  999. # <<file-warning>>
  1000. { pkgs, ... }:
  1001. {
  1002. programs.neovim = {
  1003. enable = true;
  1004. viAlias = true;
  1005. vimAlias = true;
  1006. vimdiffAlias = true;
  1007. extraConfig = ''
  1008. set number relativenumber
  1009. set nobackup
  1010. '';
  1011. extraPackages = [
  1012. pkgs.nixfmt
  1013. ];
  1014. plugins = with pkgs.vimPlugins; [
  1015. vim-nix
  1016. vim-airline
  1017. vim-polyglot
  1018. ];
  1019. };
  1020. }
  1021. #+END_SRC
  1022. *** GTK
  1023. #+NAME: module-gtk
  1024. #+BEGIN_SRC nix
  1025. ./modules/gtk.nix
  1026. #+END_SRC
  1027. 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.
  1028. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  1029. # <<file-warning>>
  1030. { pkgs, ... }:
  1031. {
  1032. home.packages = [
  1033. pkgs.arc-theme
  1034. pkgs.arc-icon-theme
  1035. pkgs.lxappearance
  1036. ];
  1037. home.file.".gtkrc-2.0" = {
  1038. text = ''
  1039. gtk-theme-name="Arc-Dark"
  1040. gtk-icon-theme-name="Arc"
  1041. gtk-font-name="Sans 10"
  1042. gtk-cursor-theme-size=0
  1043. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  1044. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  1045. gtk-button-images=0
  1046. gtk-menu-images=0
  1047. gtk-enable-event-sounds=1
  1048. gtk-enable-input-feedback-sounds=1
  1049. gtk-xft-antialias=1
  1050. gtk-xft-hinting=1
  1051. gtk-xft-hintstyle="hintmedium"
  1052. '';
  1053. };
  1054. }
  1055. #+END_SRC
  1056. * Emacs Configuration
  1057. #+NAME: module-emacs
  1058. #+BEGIN_SRC nix
  1059. ./modules/emacs.nix
  1060. #+END_SRC
  1061. 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:
  1062. + Highly customizable
  1063. + Full Unicopde support
  1064. + Content-aware editing modes
  1065. + Complete built-in documentation
  1066. + Wide range of functionality beyond text editing
  1067. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  1068. # <<file-warning>>
  1069. { pkgs, ... }:
  1070. let
  1071. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  1072. config = ../README.org;
  1073. package = <<emacs-native-comp-package>>
  1074. alwaysEnsure = true;
  1075. alwaysTangle = true;
  1076. extraEmacsPackages = epkgs: [
  1077. # Required packages...
  1078. <<emacs-exwm-package>>
  1079. <<emacs-evil-package>>
  1080. <<emacs-general-package>>
  1081. <<emacs-which-key-package>>
  1082. # Optional packages.
  1083. <<emacs-org-package>>
  1084. <<emacs-org-roam-package>>
  1085. <<emacs-org-drill-package>>
  1086. <<emacs-pomodoro-package>>
  1087. <<emacs-writegood-package>>
  1088. <<emacs-hugo-package>>
  1089. <<emacs-reveal-package>>
  1090. <<emacs-pass-package>>
  1091. <<emacs-mu4e-package>>
  1092. <<emacs-dired-package>>
  1093. <<emacs-icons-package>>
  1094. <<emacs-emoji-package>>
  1095. <<emacs-eshell-package>>
  1096. <<emacs-vterm-package>>
  1097. <<emacs-magit-package>>
  1098. <<emacs-fonts-package>>
  1099. <<emacs-elfeed-package>>
  1100. <<emacs-nix-mode-package>>
  1101. <<emacs-projectile-package>>
  1102. <<emacs-lsp-package>>
  1103. <<emacs-company-package>>
  1104. <<emacs-golang-package>>
  1105. <<emacs-python-package>>
  1106. <<emacs-rustic-package>>
  1107. <<emacs-plantuml-package>>
  1108. <<emacs-swiper-package>>
  1109. <<emacs-desktop-package>>
  1110. <<emacs-doom-themes-package>>
  1111. <<emacs-doom-modeline-package>>
  1112. ];
  1113. };
  1114. in {
  1115. home.packages = [
  1116. <<emacs-exwm-extras>>
  1117. <<emacs-hugo-extras>>
  1118. <<emacs-pass-extras>>
  1119. <<emacs-mu4e-extras>>
  1120. <<emacs-aspell-extras>>
  1121. <<emacs-desktop-extras>>
  1122. <<emacs-plantuml-extras>>
  1123. <<emacs-nix-mode-extras>>
  1124. ];
  1125. programs.emacs = {
  1126. enable = true;
  1127. package = myEmacs;
  1128. };
  1129. <<emacs-exwm-config>>
  1130. <<emacs-exwm-xinitrc>>
  1131. <<emacs-mu4e-config>>
  1132. }
  1133. #+END_SRC
  1134. 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.
  1135. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  1136. ;; <<file-warning>>
  1137. ;; Required inputs.
  1138. <<emacs-exwm-elisp>>
  1139. <<emacs-evil-elisp>>
  1140. <<emacs-general-elisp>>
  1141. <<emacs-which-key-elisp>>
  1142. ;; Optional inputs.
  1143. <<emacs-org-elisp>>
  1144. <<emacs-org-roam-elisp>>
  1145. <<emacs-org-drill-elisp>>
  1146. <<emacs-org-agenda-elisp>>
  1147. <<emacs-pomodoro-elisp>>
  1148. <<emacs-writegood-elisp>>
  1149. <<emacs-aspell-elisp>>
  1150. <<emacs-eww-elisp>>
  1151. <<emacs-hugo-elisp>>
  1152. <<emacs-reveal-elisp>>
  1153. <<emacs-pass-elisp>>
  1154. <<emacs-erc-elisp>>
  1155. <<emacs-mu4e-elisp>>
  1156. <<emacs-dired-elisp>>
  1157. <<emacs-icons-elisp>>
  1158. <<emacs-emoji-elisp>>
  1159. <<emacs-eshell-elisp>>
  1160. <<emacs-vterm-elisp>>
  1161. <<emacs-magit-elisp>>
  1162. <<emacs-fonts-elisp>>
  1163. <<emacs-elfeed-elisp>>
  1164. <<emacs-projectile-elisp>>
  1165. <<emacs-lsp-elisp>>
  1166. <<emacs-company-elisp>>
  1167. <<emacs-golang-elisp>>
  1168. <<emacs-python-elisp>>
  1169. <<emacs-rustic-elisp>>
  1170. <<emacs-plantuml-elisp>>
  1171. <<emacs-desktop-elisp>>
  1172. ;; User interface.
  1173. <<emacs-swiper-elisp>>
  1174. <<emacs-transparency-elisp>>
  1175. <<emacs-doom-themes-elisp>>
  1176. <<emacs-doom-modeline-elisp>>
  1177. #+END_SRC
  1178. 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=.
  1179. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  1180. ;; <<file-warning>>
  1181. <<emacs-disable-ui-elisp>>
  1182. <<emacs-native-comp-elisp>>
  1183. <<emacs-backup-files-elisp>>
  1184. <<emacs-shell-commands-elisp>>
  1185. #+END_SRC
  1186. ** Disable UI
  1187. 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.
  1188. #+NAME: emacs-disable-ui-elisp
  1189. #+BEGIN_SRC emacs-lisp
  1190. ;; Disable unwanted UI elements.
  1191. (tooltip-mode -1)
  1192. (menu-bar-mode -1)
  1193. (tool-bar-mode -1)
  1194. (scroll-bar-mode -1)
  1195. ;; Fix the scrolling behaviour.
  1196. (setq scroll-conservatively 101)
  1197. ;; Fix mouse-wheel scrolling behaviour.
  1198. (setq mouse-wheel-follow-mouse t
  1199. mouse-wheel-progressive-speed t
  1200. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  1201. #+END_SRC
  1202. ** Native Comp
  1203. #+NAME: emacs-native-comp-package
  1204. #+BEGIN_SRC nix
  1205. pkgs.emacsGcc;
  1206. #+END_SRC
  1207. 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.
  1208. #+NAME: emacs-native-comp-elisp
  1209. #+BEGIN_SRC emacs-lisp
  1210. ;; Silence warnings from packages that don't support `native-comp'.
  1211. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  1212. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  1213. #+END_SRC
  1214. ** Backup Files
  1215. 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.
  1216. #+NAME: emacs-backup-files-elisp
  1217. #+BEGIN_SRC emacs-lisp
  1218. ;; Disable unwanted features.
  1219. (setq make-backup-files nil
  1220. create-lockfiles nil)
  1221. #+END_SRC
  1222. ** Shell Commands
  1223. Define some methods for interaction between GNU/Emacs[fn:2], and the systems underyling shell:
  1224. 1) Method to run an external process, launching any application on a new process without interferring with Emacs[fn:2]
  1225. 2) Method to apply commands to the curren call process, effecting the running instance of Emacs[fn:2]
  1226. #+NAME: emacs-shell-commands-elisp
  1227. #+BEGIN_SRC emacs-lisp
  1228. ;; Define a method to run an external process.
  1229. (defun dotfiles/run (cmd)
  1230. "Run an external process."
  1231. (interactive (list (read-shell-command "λ ")))
  1232. (start-process-shell-command cmd nil cmd))
  1233. ;; Define a method to run a background process.
  1234. (defun dotfiles/run-in-background (cmd)
  1235. (let ((command-parts (split-string cmd "[ ]+")))
  1236. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  1237. #+END_SRC
  1238. ** Nix Mode
  1239. #+NAME: emacs-nix-mode-extras
  1240. #+BEGIN_SRC nix
  1241. pkgs.nixfmt
  1242. #+END_SRC
  1243. 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.
  1244. #+NAME: emacs-nix-mode-package
  1245. #+BEGIN_SRC nix
  1246. epkgs.nix-mode
  1247. #+END_SRC
  1248. ** Evil Mode
  1249. 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.
  1250. #+NAME: emacs-evil-package
  1251. #+BEGIN_SRC nix
  1252. epkgs.evil
  1253. epkgs.evil-collection
  1254. epkgs.evil-surround
  1255. epkgs.evil-nerd-commenter
  1256. #+END_SRC
  1257. 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].
  1258. #+NAME: emacs-evil-elisp
  1259. #+BEGIN_SRC emacs-lisp
  1260. ;; Enable the Extensible VI Layer for Emacs.
  1261. (setq evil-want-integration t ;; Required for `evil-collection.'
  1262. evil-want-keybinding nil) ;; Same as above.
  1263. (evil-mode +1)
  1264. ;; Configure `evil-collection'.
  1265. (evil-collection-init)
  1266. ;; Configure `evil-surround'.
  1267. (global-evil-surround-mode +1)
  1268. ;; Configure `evil-nerd-commenter'.
  1269. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1270. #+END_SRC
  1271. ** EXWM
  1272. #+NAME: emacs-exwm-package
  1273. #+BEGIN_SRC nix
  1274. epkgs.exwm
  1275. #+END_SRC
  1276. 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:
  1277. + Fully keyboard-driven operations
  1278. + Hybrid layout modes (tiling & stacking)
  1279. + Dynamic workspace support
  1280. + ICCM/EWMH compliance
  1281. #+NAME: emacs-exwm-extras
  1282. #+BEGIN_SRC nix
  1283. pkgs.nitrogen
  1284. pkgs.autorandr
  1285. #+END_SRC
  1286. 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].
  1287. #+NAME: emacs-exwm-config
  1288. #+BEGIN_SRC nix
  1289. xsession = {
  1290. enable = true;
  1291. windowManager.command = ''
  1292. ${pkgs.nitrogen}/bin/nitrogen --restore
  1293. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1294. ${myEmacs}/bin/emacsclient -c
  1295. '';
  1296. };
  1297. #+END_SRC
  1298. 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=.
  1299. #+NAME: emacs-exwm-xinitrc
  1300. #+BEGIN_SRC nix
  1301. home.file.".xinitrc" = {
  1302. text = ''
  1303. exec ./.xsession
  1304. '';
  1305. };
  1306. #+END_SRC
  1307. #+NAME: emacs-exwm-elisp
  1308. #+BEGIN_SRC emacs-lisp
  1309. ;; Configure `exwm'.
  1310. (setq exwm-worspace-show-all-buffers t)
  1311. (setq exwm-input-prefix-keys
  1312. '(?\M-x
  1313. ?\C-g
  1314. ?\C-\ ))
  1315. (setq exwm-input-global-keys
  1316. `(([?\s-r] . exwm-reset)
  1317. ,@(mapcar (lambda (i)
  1318. `(,(kbd (format "s-%d" i)) .
  1319. (lambda ()
  1320. (interactive)
  1321. (exwm-workspace-switch-create ,i))))
  1322. (number-sequence 1 9))))
  1323. ;; Configure `exwm-randr'.
  1324. (require 'exwm-randr)
  1325. (exwm-randr-enable)
  1326. ;; Configure custom hooks.
  1327. (setq display-time-and-date t)
  1328. (add-hook 'exwm-init-hook
  1329. (lambda ()
  1330. (display-battery-mode +1) ;; Display battery info (if available).
  1331. (display-time-mode +1))) ;; Display the time in the modeline.
  1332. ;; Setup buffer display names.
  1333. (add-hook 'exwm-update-class-hook
  1334. (lambda ()
  1335. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1336. ;; Configure monitor hot-swapping.
  1337. (add-hook 'exwm-randr-screen-change-hook
  1338. (lambda ()
  1339. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1340. #+END_SRC
  1341. ** General
  1342. #+NAME: emacs-general-package
  1343. #+BEGIN_SRC nix
  1344. epkgs.general
  1345. #+END_SRC
  1346. 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.
  1347. #+NAME: emacs-general-elisp
  1348. #+BEGIN_SRC emacs-lisp
  1349. ;; Use <SPC> as a leader key via `general.el'.
  1350. (general-create-definer dotfiles/leader
  1351. :states '(normal motion)
  1352. :keymaps 'override
  1353. :prefix "SPC"
  1354. :global-prefix "C-SPC")
  1355. ;; Find files with <SPC> <period> ...
  1356. ;; Switch buffers with <SPC> <comma> ...
  1357. (dotfiles/leader
  1358. "." '(find-file :which-key "File")
  1359. "," '(switch-to-buffer :which-key "Buffer")
  1360. "k" '(kill-buffer :which-key "Kill")
  1361. "c" '(kill-buffer-and-window :which-key "Close"))
  1362. ;; Add keybindings for executing shell commands.
  1363. (dotfiles/leader
  1364. "r" '(:ignore t :which-key "Run")
  1365. "rr" '(dotfiles/run :which-key "Run")
  1366. "ra" '(async-shell-command :which-key "Async"))
  1367. ;; Add keybindings for quitting Emacs.
  1368. (dotfiles/leader
  1369. "q" '(:ignore t :which-key "Quit")
  1370. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1371. "qw" '(kill-emacs :which-key "Now")
  1372. "qf" '(delete-frame :which-key "Frame"))
  1373. ;; Add keybindings for toggles / tweaks.
  1374. (dotfiles/leader
  1375. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1376. ;; Add keybindings for working with frames to replace
  1377. ;; the C-x <num> <num> method of bindings, which is awful.
  1378. (dotfiles/leader
  1379. "w" '(:ignore t :which-key "Windows")
  1380. "ww" '(window-swap-states :which-key "Swap")
  1381. "wc" '(delete-window :which-key "Close")
  1382. "wh" '(windmove-left :which-key "Left")
  1383. "wj" '(windmove-down :which-key "Down")
  1384. "wk" '(windmove-up :which-key "Up")
  1385. "wl" '(windmove-right :which-key "Right")
  1386. "ws" '(:ignore t :which-key "Split")
  1387. "wsj" '(split-window-below :which-key "Below")
  1388. "wsl" '(split-window-right :which-key "Right"))
  1389. #+END_SRC
  1390. ** Which Key
  1391. 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.
  1392. #+NAME: emacs-which-key-package
  1393. #+BEGIN_SRC nix
  1394. epkgs.which-key
  1395. #+END_SRC
  1396. #+NAME: emacs-which-key-elisp
  1397. #+BEGIN_SRC emacs-lisp
  1398. ;; Configure `which-key' to see keyboard bindings in the
  1399. ;; mini-buffer and when using M-x.
  1400. (setq which-key-idle-delay 0.0)
  1401. (which-key-mode +1)
  1402. #+END_SRC
  1403. ** EWW
  1404. 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.
  1405. + Use ~eww~ as the default browser
  1406. + Don't use any special fonts or colours
  1407. #+NAME: emacs-eww-elisp
  1408. #+BEGIN_SRC emacs-lisp
  1409. ;; Set `eww' as the default browser.
  1410. (setq browse-url-browser-function 'eww-browse-url)
  1411. ;; Configure the `shr' rendering engine.
  1412. (setq shr-use-fonts nil
  1413. shr-use-colors nil)
  1414. #+END_SRC
  1415. ** ERC
  1416. 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.
  1417. #+NAME: emacs-erc-elisp
  1418. #+BEGIN_SRC emacs-lisp
  1419. ;; Configure `erc'.
  1420. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#systemcrafters"))
  1421. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1422. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1423. ;; Connect to IRC via `erc'.
  1424. (defun dotfiles/erc-connect ()
  1425. "Connected to IRC via `erc'."
  1426. (interactive)
  1427. (erc-tls :server "irc.libera.chat"
  1428. :port 6697
  1429. :nick "megaphone"
  1430. :password (password-store-get "megaphone@libera.chat")
  1431. :full-name "Chris Hayward"))
  1432. ;; Configure keybindings.
  1433. (dotfiles/leader
  1434. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1435. #+END_SRC
  1436. ** Dired
  1437. #+NAME: emacs-dired-package
  1438. #+BEGIN_SRC nix
  1439. epkgs.dired-single
  1440. #+END_SRC
  1441. 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].
  1442. #+NAME: emacs-dired-elisp
  1443. #+BEGIN_SRC emacs-lisp
  1444. ;; Include `dired-x' for the `jump' method.
  1445. (require 'dired-x)
  1446. ;; Configure `dired-single' to support `evil' keys.
  1447. (evil-collection-define-key 'normal 'dired-mode-map
  1448. "h" 'dired-single-up-directory
  1449. "l" 'dired-single-buffer)
  1450. ;; Setup `all-the-icons' and the `dired' extension.
  1451. ;; Configure keybindings for `dired'.
  1452. (dotfiles/leader
  1453. "d" '(dired-jump :which-key "Dired"))
  1454. #+END_SRC
  1455. ** Icons
  1456. #+NAME: emacs-icons-package
  1457. #+BEGIN_SRC nix
  1458. epkgs.all-the-icons
  1459. epkgs.all-the-icons-dired
  1460. #+END_SRC
  1461. All The Icons[fn:46] is a utility package to collect various Icon Fonts and prioritize them within GNU/Emacs[fn:2].
  1462. #+NAME: emacs-icons-elisp
  1463. #+BEGIN_SRC emacs-lisp
  1464. ;; Setup `all-the-icons-dired'.
  1465. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1466. ;; Display default font ligatures.
  1467. (global-prettify-symbols-mode +1)
  1468. #+END_SRC
  1469. ** Emojis
  1470. #+NAME: emacs-emoji-package
  1471. #+BEGIN_SRC nix
  1472. epkgs.emojify
  1473. #+END_SRC
  1474. 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.
  1475. #+NAME: emacs-emoji-elisp
  1476. #+BEGIN_SRC emacs-lisp
  1477. ;; Setup `emojify'.
  1478. (add-hook 'after-init-hook 'global-emojify-mode)
  1479. #+END_SRC
  1480. ** EShell
  1481. #+NAME: emacs-eshell-package
  1482. #+BEGIN_SRC nix
  1483. epkgs.eshell-prompt-extras
  1484. #+END_SRC
  1485. 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].
  1486. #+NAME: emacs-eshell-elisp
  1487. #+BEGIN_SRC emacs-lisp
  1488. ;; Configure `eshell'.
  1489. (setq eshell-highlight-prompt nil
  1490. eshell-prefer-lisp-functions nil)
  1491. ;; Configure the lambda prompt.
  1492. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1493. (setq eshell-prompt-function 'epe-theme-lambda)
  1494. ;; Configure keybindings for `eshell'.
  1495. (dotfiles/leader
  1496. "e" '(eshell :which-key "EShell"))
  1497. #+END_SRC
  1498. ** VTerm
  1499. 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.
  1500. #+NAME: emacs-vterm-package
  1501. #+BEGIN_SRC nix
  1502. epkgs.vterm
  1503. #+END_SRC
  1504. #+NAME: emacs-vterm-elisp
  1505. #+BEGIN_SRC emacs-lisp
  1506. ;; Add keybindings for interacting with the shell(s).
  1507. (dotfiles/leader
  1508. "v" '(vterm :which-key "VTerm"))
  1509. #+END_SRC
  1510. ** Magit
  1511. 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.
  1512. #+NAME: emacs-magit-package
  1513. #+BEGIN_SRC nix
  1514. epkgs.magit
  1515. #+END_SRC
  1516. | Key | Description |
  1517. |-----+--------------------------------------|
  1518. | gg | Check the status of a repository |
  1519. | gc | Clone a remote repository |
  1520. | gf | Fetch the contents of the repository |
  1521. | gp | Pull the remotes of the repository |
  1522. #+NAME: emacs-magit-elisp
  1523. #+BEGIN_SRC emacs-lisp
  1524. ;; Add keybindings for working with `magit'.
  1525. (dotfiles/leader
  1526. "g" '(:ignore t :which-key "Git")
  1527. "gg" '(magit-status :which-key "Status")
  1528. "gc" '(magit-clone :which-key "Clone")
  1529. "gf" '(magit-fetch :which-key "Fetch")
  1530. "gp" '(magit-pull :which-key "Pull"))
  1531. #+END_SRC
  1532. ** Fonts
  1533. #+NAME: emacs-fonts-package
  1534. #+BEGIN_SRC nix
  1535. epkgs.hydra
  1536. #+END_SRC
  1537. #+NAME: emacs-fonts-elisp
  1538. #+BEGIN_SRC emacs-lisp
  1539. ;; Configure the font when running as `emacs-server'.
  1540. (custom-set-faces
  1541. '(default ((t (:inherit nil :height 96 :family "Iosevka")))))
  1542. ;; Set all three of Emacs' font faces.
  1543. ;; NOTE: This only works without `emacs-server'.
  1544. ;; (set-face-attribute 'default nil :font "Iosevka" :height 96)
  1545. ;; (set-face-attribute 'fixed-pitch nil :font "Iosevka" :height 96)
  1546. ;; (set-face-attribute 'variable-pitch nil :font "Iosevka" :height 96)
  1547. ;; Define a `hydra' function for scaling the text interactively.
  1548. (defhydra hydra-text-scale (:timeout 4)
  1549. "Scale text"
  1550. ("j" text-scale-decrease "Decrease")
  1551. ("k" text-scale-increase "Increase")
  1552. ("f" nil "Finished" :exit t))
  1553. ;; Create keybinding for calling the function.
  1554. (dotfiles/leader
  1555. "tf" '(hydra-text-scale/body :which-key "Font"))
  1556. #+END_SRC
  1557. ** Elfeed
  1558. #+NAME: emacs-elfeed-package
  1559. #+BEGIN_SRC nix
  1560. epkgs.elfeed
  1561. #+END_SRC
  1562. 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.
  1563. | Key | Command |
  1564. |-----+---------|
  1565. | l | Open |
  1566. | u | Update |
  1567. #+NAME: emacs-elfeed-elisp
  1568. #+BEGIN_SRC emacs-lisp
  1569. ;; Configure `elfeed'.
  1570. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1571. ;; Add custom feeds for `elfeed' to fetch.
  1572. (setq elfeed-feeds (quote
  1573. (("https://hexdsl.co.uk/rss.xml")
  1574. ("https://lukesmith.xyz/rss.xml")
  1575. ("https://friendo.monster/rss.xml")
  1576. ("https://chrishayward.xyz/index.xml")
  1577. ("https://protesilaos.com/codelog.xml"))))
  1578. ;; Add custom keybindings for `elfeed'.
  1579. (dotfiles/leader
  1580. "l" '(:ignore t :which-key "Elfeed")
  1581. "ll" '(elfeed :which-key "Open")
  1582. "lu" '(elfeed-update :which-key "Update"))
  1583. #+END_SRC
  1584. ** Org Mode
  1585. #+NAME: emacs-org-package
  1586. #+BEGIN_SRC nix
  1587. epkgs.org
  1588. #+END_SRC
  1589. 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.
  1590. #+NAME: emacs-org-elisp
  1591. #+BEGIN_SRC emacs-lisp
  1592. ;; Configure `org-mode' source blocks.
  1593. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1594. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1595. org-src-preserve-indentation t) ;; Stop `org-mode' from formatting blocks.
  1596. ;; Add an `org-mode-hook'.
  1597. (add-hook 'org-mode-hook
  1598. (lambda ()
  1599. (org-indent-mode)
  1600. (visual-line-mode)))
  1601. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1602. (setq org-export-html-validation-link nil
  1603. org-html-validation-link nil)
  1604. ;; TODO: Configure default structure templates.
  1605. ;; (require 'org-tempo)
  1606. ;; Apply custom keybindings.
  1607. (dotfiles/leader
  1608. "o" '(:ignore t :which-key "Org")
  1609. "oe" '(org-export-dispatch :which-key "Export")
  1610. "ot" '(org-babel-tangle :which-key "Tangle")
  1611. "oi" '(org-toggle-inline-images :which-key "Images")
  1612. "of" '(:ignore t :which-key "Footnotes")
  1613. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1614. #+END_SRC
  1615. ** Org Roam
  1616. #+NAME: emacs-org-roam-package
  1617. #+BEGIN_SRC nix
  1618. epkgs.org-roam
  1619. epkgs.org-roam-server
  1620. #+END_SRC
  1621. 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.
  1622. #+NAME: emacs-org-roam-elisp
  1623. #+BEGIN_SRC emacs-lisp
  1624. ;; Setup `org-roam' hooks.
  1625. (add-hook 'after-init-hook
  1626. (lambda ()
  1627. (org-roam-mode)
  1628. (org-roam-server-mode)))
  1629. ;; Configure `org-roam'.
  1630. (setq org-roam-encrypt-files t
  1631. org-roam-directory (expand-file-name "/etc/dotfiles")
  1632. org-roam-capture-templates '()
  1633. org-roam-dailies-capture-templates '())
  1634. ;; Encrypt files with the public key.
  1635. (setq epa-file-select-keys 2
  1636. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1637. epa-cache-passphrase-for-symmetric-encryption t)
  1638. ;; Define a new `title-to-slug' function to override the default `org-roam-title-to-slug' function.
  1639. ;; This is done to change the replacement character from "_" to "-".
  1640. (require 'cl-lib)
  1641. (defun dotfiles/title-to-slug (title)
  1642. "Convert TITLE to a filename-suitable slug."
  1643. (cl-flet* ((nonspacing-mark-p (char)
  1644. (eq 'Mn (get-char-code-property char 'general-category)))
  1645. (strip-nonspacing-marks (s)
  1646. (apply #'string (seq-remove #'nonspacing-mark-p
  1647. (ucs-normalize-NFD-string s))))
  1648. (cl-replace (title pair)
  1649. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1650. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-") ;; Convert anything not alphanumeric.
  1651. ("--*" . "-") ;; Remove sequential dashes.
  1652. ("^-" . "") ;; Remove starting dashes.
  1653. ("-$" . ""))) ;; Remove ending dashes.
  1654. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1655. (downcase slug))))
  1656. (setq org-roam-title-to-slug-function #'dotfiles/title-to-slug)
  1657. ;; Configure capture templates.
  1658. ;; Standard document.
  1659. (add-to-list 'org-roam-capture-templates
  1660. '("d" "Default" entry (function org-roam-capture--get-point)
  1661. "%?"
  1662. :file-name "docs/${slug}"
  1663. :unnarrowed t
  1664. :head
  1665. "
  1666. ,#+TITLE: ${title}
  1667. ,#+AUTHOR: Christopher James Hayward
  1668. ,#+EMAIL: chris@chrishayward.xyz
  1669. "))
  1670. ;; Course document.
  1671. (add-to-list 'org-roam-capture-templates
  1672. '("c" "Course" plain (function org-roam-capture--get-point)
  1673. "%?"
  1674. :file-name "docs/courses/${slug}"
  1675. :unnarrowed t
  1676. :head
  1677. "
  1678. ,#+TITLE: ${title}
  1679. ,#+SUBTITLE:
  1680. ,#+AUTHOR: Christopher James Hayward
  1681. ,#+EMAIL: chris@chrishayward.xyz
  1682. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  1683. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  1684. "))
  1685. ;; Daily notes.
  1686. (add-to-list 'org-roam-dailies-capture-templates
  1687. '("d" "Default" entry (function org-roam-capture--get-point)
  1688. "* %?"
  1689. :file-name "docs/daily/%<%Y-%m-%d>"
  1690. :head
  1691. "
  1692. ,#+TITLE: %<%Y-%m-%d>
  1693. ,#+AUTHOR: Christopher James Hayward
  1694. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  1695. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  1696. "))
  1697. ;; Apply custom keybindings.
  1698. (dotfiles/leader
  1699. "or" '(:ignore t :which-key "Roam")
  1700. "ori" '(org-roam-insert :which-key "Insert")
  1701. "orf" '(org-roam-find-file :which-key "Find")
  1702. "orc" '(org-roam-capture :which-key "Capture")
  1703. "orb" '(org-roam-buffer-toggle-display :which-key "Buffer"))
  1704. ;; Apply custom keybindings for dailies.
  1705. (dotfiles/leader
  1706. "ord" '(:ignore t :which-key "Dailies")
  1707. "ordd" '(org-roam-dailies-find-date :which-key "Date")
  1708. "ordt" '(org-roam-dailies-find-today :which-key "Today")
  1709. "ordm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  1710. "ordy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  1711. #+END_SRC
  1712. ** Org Drill
  1713. #+NAME: emacs-org-drill-package
  1714. #+BEGIN_SRC nix
  1715. epkgs.org-drill
  1716. #+END_SRC
  1717. 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.
  1718. #+NAME: emacs-org-drill-elisp
  1719. #+BEGIN_SRC emacs-lisp
  1720. ;; Configure keybindings for `org-drill'.
  1721. (dotfiles/leader
  1722. "od" '(:ignore t :which-key "Drill")
  1723. "odd" '(org-drill :which-key "Drill")
  1724. "odc" '(org-drill-cram :which-key "Cram")
  1725. "odr" '(org-drill-resume :which-key "Resume"))
  1726. #+END_SRC
  1727. ** Org Agenda
  1728. 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.
  1729. #+NAME: emacs-org-agenda-elisp
  1730. #+BEGIN_SRC emacs-lisp
  1731. ;; Configure `org-agenda' to use the project files.
  1732. (setq org-agenda-files '("/etc/dotfiles/"
  1733. "/etc/dotfiles/docs/"
  1734. "/etc/dotfiles/docs/courses/"
  1735. "/etc/dotfiles/docs/daily/"
  1736. "/etc/dotfiles/docs/notes/"
  1737. "/etc/dotfiles/docs/posts/"
  1738. "/etc/dotfiles/docs/slides/"))
  1739. ;; Include files encrypted with `gpg'.
  1740. (require 'org)
  1741. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1742. (setq org-agenda-file-regexp
  1743. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1744. org-agenda-file-regexp)))
  1745. ;; Open an agenda buffer with SPC o a.
  1746. (dotfiles/leader
  1747. "oa" '(org-agenda :which-key "Agenda"))
  1748. #+END_SRC
  1749. ** Org Pomodoro
  1750. #+NAME: emacs-pomodoro-package
  1751. #+BEGIN_SRC nix
  1752. epkgs.org-pomodoro
  1753. #+END_SRC
  1754. 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.
  1755. #+NAME: emacs-pomodoro-elisp
  1756. #+BEGIN_SRC emacs-lisp
  1757. ;; Configure `org-pomodor' with the overtime workflow.
  1758. (setq org-pomodoro-manual-break t
  1759. org-pomodoro-keep-killed-time t)
  1760. ;; Configure keybindings.
  1761. (dotfiles/leader
  1762. "op" '(org-pomodoro :which-key "Pomodoro"))
  1763. #+END_SRC
  1764. ** Writegood Mode
  1765. #+NAME: emacs-writegood-package
  1766. #+BEGIN_SRC nix
  1767. epkgs.writegood-mode
  1768. #+END_SRC
  1769. 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:
  1770. + Weasel Words
  1771. + Passive Voice
  1772. + Duplicate Words
  1773. #+NAME: emacs-writegood-elisp
  1774. #+BEGIN_SRC emacs-lisp
  1775. ;; Configure `writegood-mode'.
  1776. (dotfiles/leader
  1777. "tg" '(writegood-mode :which-key "Grammar"))
  1778. #+END_SRC
  1779. ** Aspell
  1780. #+NAME: emacs-aspell-extras
  1781. #+BEGIN_SRC nix
  1782. pkgs.aspell
  1783. pkgs.aspellDicts.en
  1784. pkgs.aspellDicts.en-science
  1785. pkgs.aspellDicts.en-computers
  1786. #+END_SRC
  1787. 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.
  1788. #+NAME: emacs-aspell-elisp
  1789. #+BEGIN_SRC emacs-lisp
  1790. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1791. (setq ispell-program-name "aspell"
  1792. ispell-eextra-args '("--sug-mode=fast"))
  1793. ;; Configure the built-in `flyspell-mode'.
  1794. (dotfiles/leader
  1795. "ts" '(flyspell-mode :which-key "Spelling"))
  1796. #+END_SRC
  1797. ** Hugo
  1798. #+NAME: emacs-hugo-extras
  1799. #+BEGIN_SRC nix
  1800. pkgs.hugo
  1801. #+END_SRC
  1802. Hugo[fn:62] is one of the most popular open-source static site generators.
  1803. #+NAME: emacs-hugo-package
  1804. #+BEGIN_SRC nix
  1805. epkgs.ox-hugo
  1806. #+END_SRC
  1807. 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].
  1808. #+NAME: emacs-hugo-elisp
  1809. #+BEGIN_SRC emacs-lisp
  1810. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  1811. (require 'ox-hugo)
  1812. ;; Capture templates.
  1813. ;; Personal blog post.
  1814. (add-to-list 'org-roam-capture-templates
  1815. '("p" "Post" plain (function org-roam-capture--get-point)
  1816. "%?"
  1817. :file-name "docs/posts/${slug}"
  1818. :unnarrowed t
  1819. :head
  1820. "
  1821. ,#+TITLE: ${title}
  1822. ,#+AUTHOR: Christopher James Hayward
  1823. ,#+DATE: %<%Y-%m-%d>
  1824. ,#+OPTIONS: num:nil todo:nil tasks:nil
  1825. ,#+EXPORT_FILE_NAME: ${slug}
  1826. ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  1827. ,#+HUGO_BASE_DIR: ../
  1828. ,#+HUGO_AUTO_SET_LASTMOD: t
  1829. ,#+HUGO_SECTION: posts
  1830. ,#+HUGO_DRAFT: true
  1831. "))
  1832. ;; Shared notes.
  1833. (add-to-list 'org-roam-capture-templates
  1834. '("n" "Notes" plain (function org-roam-capture--get-point)
  1835. "%?"
  1836. :file-name "docs/notes/${slug}"
  1837. :unnarrowed t
  1838. :head
  1839. "
  1840. ,#+TITLE: ${title}
  1841. ,#+AUTHOR: Christopher James Hayward
  1842. ,#+OPTIONS: num:nil todo:nil tasks:nil
  1843. ,#+EXPORT_FILE_NAME: ${slug}
  1844. ,#+ROAM_KEY: https://chrishayward.xyz/notes/${slug}/
  1845. ,#+HUGO_BASE_DIR: ../
  1846. ,#+HUGO_AUTO_SET_LASTMOD: t
  1847. ,#+HUGO_SECTION: notes
  1848. ,#+HUGO_DRAFT: true
  1849. "))
  1850. #+END_SRC
  1851. ** Reveal
  1852. #+NAME: emacs-reveal-package
  1853. #+BEGIN_SRC nix
  1854. epkgs.ox-reveal
  1855. #+END_SRC
  1856. 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.
  1857. #+NAME: emacs-reveal-elisp
  1858. #+BEGIN_SRC emacs-lisp
  1859. ;; Configure `ox-reveal' as an `org-mode-export' backend.
  1860. (require 'ox-reveal)
  1861. ;; Don't rely on any local software.
  1862. (setq org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js")
  1863. ;; Create a capture template.
  1864. (add-to-list 'org-roam-capture-templates
  1865. '("s" "Slides" plain (function org-roam-capture--get-point)
  1866. "%?"
  1867. :file-name "docs/slides/${slug}"
  1868. :unnarrowed t
  1869. :head
  1870. "
  1871. ,#+TITLE: ${title}
  1872. ,#+AUTHOR: Christopher James Hayward
  1873. ,#+EMAIL: chris@chrishayward.xyz
  1874. ,#+REVEAL_ROOT: https://cdn.jsdelivr.net/npm/reveal.js
  1875. ,#+REVEAL_THEME: serif
  1876. ,#+EXPORT_FILE_NAME: ${slug}
  1877. ,#+OPTIONS: reveal_title_slide:nil
  1878. ,#+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  1879. ,#+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  1880. "))
  1881. #+END_SRC
  1882. ** Passwords
  1883. #+NAME: emacs-pass-extras
  1884. #+BEGIN_SRC nix
  1885. pkgs.pass
  1886. #+END_SRC
  1887. 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.
  1888. #+NAME: emacs-pass-package
  1889. #+BEGIN_SRC nix
  1890. epkgs.password-store
  1891. #+END_SRC
  1892. Configure keybindings for passwords behind =SPC p=:
  1893. | Key | Description |
  1894. |-----+---------------------|
  1895. | p | Copy a password |
  1896. | r | Rename a password |
  1897. | g | Generate a password |
  1898. #+NAME: emacs-pass-elisp
  1899. #+BEGIN_SRC emacs-lisp
  1900. ;; Set the path to the password store.
  1901. (setq password-store-dir (expand-file-name "~/.password-store"))
  1902. ;; Apply custom keybindings.
  1903. (dotfiles/leader
  1904. "p" '(:ignore t :which-key "Passwords")
  1905. "pp" '(password-store-copy :which-key "Copy")
  1906. "pr" '(password-store-rename :which-key "Rename")
  1907. "pg" '(password-store-generate :which-key "Generate"))
  1908. #+END_SRC
  1909. ** MU4E
  1910. #+NAME: emacs-mu4e-extras
  1911. #+BEGIN_SRC nix
  1912. pkgs.mu
  1913. pkgs.isync
  1914. #+END_SRC
  1915. #+NAME: emacs-mu4e-package
  1916. #+BEGIN_SRC nix
  1917. epkgs.mu4e-alert
  1918. #+END_SRC
  1919. #+NAME: emacs-mu4e-config
  1920. #+BEGIN_SRC nix
  1921. home.file.".mbsyncrc" = {
  1922. text = ''
  1923. IMAPStore xyz-remote
  1924. Host mail.chrishayward.xyz
  1925. User chris@chrishayward.xyz
  1926. PassCmd "pass chrishayward.xyz/chris"
  1927. SSLType IMAPS
  1928. MaildirStore xyz-local
  1929. Path ~/.cache/mail/
  1930. Inbox ~/.cache/mail/inbox
  1931. SubFolders Verbatim
  1932. Channel xyz
  1933. Far :xyz-remote:
  1934. Near :xyz-local:
  1935. Patterns * !Archives
  1936. Create Both
  1937. Expunge Both
  1938. SyncState *
  1939. '';
  1940. };
  1941. #+END_SRC
  1942. #+BEGIN_SRC sh
  1943. mbsync -a
  1944. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  1945. mu index
  1946. #+END_SRC
  1947. #+NAME: emacs-mu4e-elisp
  1948. #+BEGIN_SRC emacs-lisp
  1949. ;; Add the `mu4e' shipped with `mu' to the load path.
  1950. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  1951. (require 'mu4e)
  1952. ;; Confiugure `mu4e'.
  1953. (setq mu4e-maildir "~/.cache/mail"
  1954. mu4e-update-interval (* 5 60)
  1955. mu4e-get-mail-command "mbsync -a"
  1956. mu4e-compose-format-flowed t
  1957. mu4e-change-filenames-when-moving t
  1958. mu4e-compose-signature (concat "Chris Hayward\n"
  1959. "chris@chrishayward.xyz"))
  1960. ;; Sign all outbound email with GPG.
  1961. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  1962. (setq message-send-mail-function 'smtpmail-send-it
  1963. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  1964. ;; Setup `mu4e' accounts.
  1965. (setq mu4e-contexts
  1966. (list
  1967. ;; Main
  1968. ;; chris@chrishayward.xyz
  1969. (make-mu4e-context
  1970. :name "Main"
  1971. :match-func
  1972. (lambda (msg)
  1973. (when msg
  1974. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  1975. :vars
  1976. '((user-full-name . "Christopher James Hayward")
  1977. (user-mail-address . "chris@chrishayward.xyz")
  1978. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  1979. (smtpmail-smtp-service . 587)
  1980. (smtpmail-stream-type . starttls)))))
  1981. ;; Setup `mu4e-alert'.
  1982. (setq mu4e-alert-set-default-style 'libnotify)
  1983. (mu4e-alert-enable-notifications)
  1984. (mu4e-alert-enable-mode-line-display)
  1985. ;; Open the `mu4e' dashboard.
  1986. (dotfiles/leader
  1987. "m" '(mu4e :which-key "Mail"))
  1988. #+END_SRC
  1989. ** Projectile
  1990. #+NAME: emacs-projectile-package
  1991. #+BEGIN_SRC nix
  1992. epkgs.projectile
  1993. #+END_SRC
  1994. 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.
  1995. #+NAME: emacs-projectile-elisp
  1996. #+BEGIN_SRC emacs-lisp
  1997. ;; Configure the `projectile-project-search-path'.
  1998. (setq projectile-project-search-path '("~/.local/source"))
  1999. (projectile-mode +1)
  2000. #+END_SRC
  2001. ** LSP Mode
  2002. #+NAME: emacs-lsp-package
  2003. #+BEGIN_SRC nix
  2004. epkgs.lsp-mode
  2005. epkgs.lsp-ui
  2006. #+END_SRC
  2007. The Language Server Protocol (LSP)[fn:70] defines the protocol used between an Editor or IDE, and a language server that provides features like:
  2008. + Auto Complete
  2009. + Go To Defintion
  2010. + Find All References
  2011. #+NAME: emacs-lsp-elisp
  2012. #+BEGIN_SRC emacs-lisp
  2013. ;; Configure `lsp-mode'.
  2014. (setq lsp-idle-delay 0.5
  2015. lsp-prefer-flymake t)
  2016. ;; Configure `lsp-ui'.
  2017. (setq lsp-ui-doc-position 'at-point
  2018. lsp-ui-doc-delay 0.5)
  2019. #+END_SRC
  2020. ** CCLS
  2021. #+NAME: emacs-ccls-package
  2022. #+BEGIN_SRC nix
  2023. epkgs.ccls
  2024. #+END_SRC
  2025. 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.
  2026. #+NAME: emacs-ccls-elisp
  2027. #+BEGIN_SRC emacs-lisp
  2028. ;; Configure `ccls' to work with `lsp-mode'.
  2029. (defun dotfiles/ccls-hook ()
  2030. (require 'ccls)
  2031. (lsp))
  2032. ;; Configure `ccls' mode hooks.
  2033. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  2034. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  2035. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  2036. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  2037. #+END_SRC
  2038. ** Company Mode
  2039. #+NAME: emacs-company-package
  2040. #+BEGIN_SRC nix
  2041. epkgs.company
  2042. #+END_SRC
  2043. 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.
  2044. #+NAME: emacs-company-elisp
  2045. #+BEGIN_SRC emacs-lisp
  2046. ;; Configure `company-mode'.
  2047. (setq company-backend 'company-capf
  2048. lsp-completion-provider :capf)
  2049. ;; Enable it globally.
  2050. (global-company-mode +1)
  2051. #+END_SRC
  2052. ** Go Mode
  2053. #+NAME: emacs-golang-package
  2054. #+BEGIN_SRC nix
  2055. epkgs.go-mode
  2056. #+END_SRC
  2057. Go Mode[fn:73] is a major mode for editing Golang[fn:12] source code in GNU/Emacs[fn:2].
  2058. #+NAME: emacs-golang-elisp
  2059. #+BEGIN_SRC emacs-lisp
  2060. ;; Configure `go-mode' to work with `lsp-mode'.
  2061. (defun dotfiles/go-hook ()
  2062. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  2063. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  2064. ;; Configure a custom `before-save-hook'.
  2065. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  2066. #+END_SRC
  2067. ** Rustic
  2068. #+NAME: emacs-rustic-package
  2069. #+BEGIN_SRC nix
  2070. epkgs.rustic
  2071. #+END_SRC
  2072. 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!
  2073. #+NAME: emacs-rustic-elisp
  2074. #+BEGIN_SRC emacs-lisp
  2075. ;; Configure `rustic' with `lsp-mode'.
  2076. (setq rustic-format-on-save t
  2077. rustic-lsp-server 'rls)
  2078. #+END_SRC
  2079. ** Python Mode
  2080. #+NAME: emacs-python-package
  2081. #+BEGIN_SRC nix
  2082. epkgs.pretty-mode
  2083. #+END_SRC
  2084. 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].
  2085. #+NAME: emacs-python-elisp
  2086. #+BEGIN_SRC emacs-lisp
  2087. ;; Configure `pretty-mode' to work with `python-mode'.
  2088. (add-hook 'python-mode-hook
  2089. (lambda ()
  2090. (turn-on-pretty-mode)))
  2091. #+END_SRC
  2092. ** PlantUML
  2093. #+NAME: emacs-plantuml-extras
  2094. #+BEGIN_SRC nix
  2095. pkgs.plantuml
  2096. #+END_SRC
  2097. 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.
  2098. #+NAME: emacs-plantuml-package
  2099. #+BEGIN_SRC nix
  2100. epkgs.plantuml-mode
  2101. #+END_SRC
  2102. PlantUML Mode[fn:76] is a major mode for editing PlantUML[fn:75] sources in GNU/Emacs[fn:2].
  2103. #+NAME: emacs-plantuml-elisp
  2104. #+BEGIN_SRC emacs-lisp
  2105. ;; Configure `plantuml-mode'.
  2106. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  2107. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  2108. (setq plantuml-default-exec-mode 'executable
  2109. org-plantuml-exec-mode 'plantuml)
  2110. #+END_SRC
  2111. ** Swiper
  2112. #+NAME: emacs-swiper-package
  2113. #+BEGIN_SRC nix
  2114. epkgs.ivy
  2115. epkgs.counsel
  2116. epkgs.ivy-rich
  2117. epkgs.ivy-posframe
  2118. epkgs.ivy-prescient
  2119. #+END_SRC
  2120. 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.
  2121. #+NAME: emacs-swiper-elisp
  2122. #+BEGIN_SRC emacs-lisp
  2123. ;; Configure `ivy'.
  2124. (setq counsel-linux-app-format-function
  2125. #'counsel-linux-app-format-function-name-only)
  2126. (ivy-mode +1)
  2127. (counsel-mode +1)
  2128. ;; Configure `ivy-rich'.
  2129. (ivy-rich-mode +1)
  2130. ;; Configure `ivy-posframe'.
  2131. (setq ivy-posframe-parameters '((parent-frame nil))
  2132. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  2133. (ivy-posframe-mode +1)
  2134. ;; Configure `ivy-prescient'.
  2135. (setq ivy-prescient-enable-filtering nil)
  2136. (ivy-prescient-mode +1)
  2137. #+END_SRC
  2138. ** Transparency
  2139. 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.
  2140. #+NAME: emacs-transparency-elisp
  2141. #+BEGIN_SRC emacs-lisp
  2142. ;; Configure the default frame transparency.
  2143. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  2144. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  2145. #+END_SRC
  2146. ** Desktop Environment
  2147. #+NAME: emacs-desktop-extras
  2148. #+BEGIN_SRC nix
  2149. pkgs.brightnessctl
  2150. #+END_SRC
  2151. 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].
  2152. #+NAME: emacs-desktop-package
  2153. #+BEGIN_SRC nix
  2154. epkgs.desktop-environment
  2155. #+END_SRC
  2156. 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.
  2157. #+NAME: emacs-desktop-elisp
  2158. #+BEGIN_SRC emacs-lisp
  2159. ;; Configure `desktop-environment'.
  2160. (require 'desktop-environment)
  2161. (desktop-environment-mode +1)
  2162. #+END_SRC
  2163. ** Doom Themes
  2164. #+NAME: emacs-doom-themes-package
  2165. #+BEGIN_SRC nix
  2166. epkgs.doom-themes
  2167. #+END_SRC
  2168. Doom Themes[fn:79] is a theme megapack for GNU/Emacs[fn:2], inspired by community favourites.
  2169. #+NAME: emacs-doom-themes-elisp
  2170. #+BEGIN_SRC emacs-lisp
  2171. ;; Include modern themes from `doom-themes'.
  2172. (setq doom-themes-enable-bold t
  2173. doom-themes-enable-italic t)
  2174. ;; Load the `doom-moonlight' theme.
  2175. (load-theme 'doom-moonlight t)
  2176. (doom-modeline-mode +1)
  2177. ;; Load a new theme with <SPC> t t.
  2178. (dotfiles/leader
  2179. "tt" '(counsel-load-theme :which-key "Theme"))
  2180. #+END_SRC
  2181. ** Doom Modeline
  2182. #+NAME: emacs-doom-modeline-package
  2183. #+BEGIN_SRC nix
  2184. epkgs.doom-modeline
  2185. #+END_SRC
  2186. Doom Modeline[fn:80] is a fancy and fast modeline inspired by minimalism design. It's integrated into Centaur Emacs, Doom Emacs, and Spacemacs.
  2187. #+NAME: emacs-doom-modeline-elisp
  2188. #+BEGIN_SRC emacs-lisp
  2189. ;; Add the `doom-modeline' after initialization.
  2190. (add-hook 'after-init-hook 'doom-modeline-mode)
  2191. (setq doom-modeline-height 16
  2192. doom-modeline-icon t)
  2193. #+END_SRC
  2194. * Footnotes
  2195. [fn:1] https://gnu.org
  2196. [fn:2] https://gnu.org/software/emacs/
  2197. [fn:3] https://literateprogramming.com/knuthweb.pdf
  2198. [fn:4] https://nixos.org/manual/nixos/stable
  2199. [fn:5] https://nixos.org/manual/nix/stable
  2200. [fn:6] https://nixos.org/manual/nixpkgs/stable
  2201. [fn:7] https://github.com/nix-community/home-manager
  2202. [fn:8] https://github.com/nix-community/emacs-overlay
  2203. [fn:9] https://github.com/nixos/nixos-hardware
  2204. [fn:10] https://github.com/t184256/nix-on-droid
  2205. [fn:11] https://nixos.org/manual/nix/unstable/command-ref/nix-shell.html
  2206. [fn:12] https://golang.org
  2207. [fn:13] https://rust-lang.org
  2208. [fn:14] https://nodejs.org
  2209. [fn:15] https://grpc.io
  2210. [fn:16] https://iso.org/standard/74528.html
  2211. [fn:17] https://en.wikipedia.org/wiki/C++/
  2212. [fn:18] https://python.org
  2213. [fn:19] https://qemu.org
  2214. [fn:20] https://github.com/ch11ng/exwm
  2215. [fn:21] https://evil.readthedocs.io/en/latest/overview.html
  2216. [fn:22] https://raspberrypi.org/products/raspberry-pi-400/
  2217. [fn:23] https://www.raspberrypi.org/products/raspberry-pi-4-model-b/
  2218. [fn:24] https://samsung.com/us/mobile/galaxy-s10/buy/
  2219. [fn:25] https://x.org/wiki/
  2220. [fn:26] https://wayland.freedesktop.org
  2221. [fn:27] https://openssh.com
  2222. [fn:28] https://nixos.wiki/wiki/Flakes
  2223. [fn:29] https://nix-community.cachix.org
  2224. [fn:30] https://docker.org
  2225. [fn:31] https://en.wikipedia.org/wiki/Firefox
  2226. [fn:32] https://jellyfin.org
  2227. [fn:33] https://moonlight-stream.org
  2228. [fn:34] https://teamviewer.com
  2229. [fn:35] https://git-scm.com
  2230. [fn:36] https://emacswiki.org/emacs/LearnEmacsLisp
  2231. [fn:37] https://neovim.io
  2232. [fn:38] https://gtk.org
  2233. [fn:39] https://github.com/nixos/nix-mode
  2234. [fn:40] https://github.com/noctuid/general.el
  2235. [fn:41] https://github.com/justbur/emacs-which-key
  2236. [fn:42] https://emacswiki.org/emacs/eww
  2237. [fn:43] https://gnu.org/software/emacs/erc.html
  2238. [fn:44] https://emacswiki.org/emacs/DiredMode
  2239. [fn:45] https://emacswiki.org/emacs/DiredExtra#Dired_X
  2240. [fn:46] https://github.com/domtronn/all-the-icons.el
  2241. [fn:47] https://github.com/iqbalansari/emacs-emojify
  2242. [fn:48] https://gnu.org/software/emacs/manual/html_mono/eshell.html
  2243. [fn:49] https://github.com/akermu/emacs-libvterm
  2244. [fn:50] https://github.com/neovim/libvterm
  2245. [fn:51] https://magit.vc
  2246. [fn:52] https://github.com/skeeto/elfeed
  2247. [fn:53] https://orgmode.org
  2248. [fn:54] https://github.com/org-roam/org-roam
  2249. [fn:55] https://zettelkasten.de
  2250. [fn:56] https://github.com/org-roam/org-roam-server
  2251. [fn:57] https://orgmode.org/worg/org-contrib/org-drill.html
  2252. [fn:58] https://github.com/marcinkoziej/org-pomodoro
  2253. [fn:59] https://en.wikipedia.org/wiki/Pomodoro_Technique
  2254. [fn:60] https://github.com/bnbeckwith/writegood-mode
  2255. [fn:61] https://aspell.net
  2256. [fn:62] https://gohugo.io
  2257. [fn:63] https://oxhugo.scripter.co
  2258. [fn:64] https://chrishayward.xyz/posts/
  2259. [fn:65] https://chrishayward.xyz/notes/
  2260. [fn:66] https://revealjs.com
  2261. [fn:67] https://github.com/hexmode/ox-reveal
  2262. [fn:68] https://password-store.org
  2263. [fn:69] https://projectile.mx
  2264. [fn:70] https://microsoft.github.io/language-server-protocol
  2265. [fn:71] https://github.com/MaskRay/emacs-ccls
  2266. [fn:72] https://company-mode.github.io
  2267. [fn:73] https://emacswiki.org/emacs/GoMode
  2268. [fn:74] https://plantuml.com
  2269. [fn:75] https://github.com/skuro/plantuml-mode
  2270. [fn:76] https://github.com/abo-abo/swiper
  2271. [fn:77] https://github.com/DamienCassou/desktop-environment
  2272. [fn:78] https://github.com/hlissner/emacs-doom-themes
  2273. [fn:79] https://github.com/seagle0128/doom-modeline
  2274. [fn:80] https://laptopmedia.com/laptop-specs/acer-nitro-5-an515-53-2
  2275. [fn:81] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html