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.

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