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.

2992 lines
86 KiB

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