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.

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