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.

2605 lines
85 KiB

3 years ago
4 years ago
3 years ago
3 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
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
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
  1. :PROPERTIES:
  2. :ID: e4ad3dd5-0996-45bc-92ab-6bdbf16e4310
  3. :ROAM_REFS: https://chrishayward.xyz/dotfiles/
  4. :END:
  5. #+TITLE: Dotfiles
  6. #+AUTHOR: Christopher James Hayward
  7. #+EMAIL: chris@chrishayward.xyz
  8. #+STARTUP: overview
  9. #+EXPORT_FILE_NAME: dotfiles
  10. #+HUGO_BASE_DIR: docs
  11. #+HUGO_AUTO_SET_LASTMOD: t
  12. #+HUGO_SECTION:
  13. #+HUGO_DRAFT: false
  14. #+HTML: <a href="https://nixos.org"><img src="https://img.shields.io/badge/NixOS-unstable-blue.svg?style=flat-square&logo=NixOS&logoColor=white"></a>
  15. #+HTML: <a href="https://www.gnu.org/software/emacs/"><img src="https://img.shields.io/badge/Emacs-28.0.91-blueviolet.svg?style=flat-square&logo=GNU%20Emacs&logoColor=white"></a>
  16. #+HTML: <a href="https://orgmode.org"><img src="https://img.shields.io/badge/Org-9.5.2-%2377aa99?style=flat-square&logo=org&logoColor=white"></a>
  17. #+NAME: description
  18. #+BEGIN_SRC text
  19. Immutable NixOS dotfiles.
  20. #+END_SRC
  21. #+ATTR_ORG: :width 800px
  22. #+ATTR_HTML: :width 800px
  23. #+ATTR_LATEX: :width 800px
  24. [[./docs/images/desktop-example.png]]
  25. Built for Life, Liberty, and the Open Road.
  26. + 100% Immutable
  27. + 100% Declarative
  28. + 100% Reproducible
  29. * Introduction
  30. This is my personal configuration for [[https://linux.org][GNU/Linux]] systems. It enables a consistent experience and computing environment across all of my machines. This project is written with [[https://gnu.org/software/emacs/][GNU/Emacs]], leveraging its capabilities for [[https://doi.org/10.1093/comjnl/27.2.97][Literate Programming]], a technique where programs are written in a natural language, such as English, interspersed with snippets of code to describe a software project.
  31. #+NAME: file-warning
  32. #+BEGIN_SRC text
  33. This file is controlled by /etc/dotfiles/README.org
  34. #+END_SRC
  35. ** Getting Started
  36. 1) [[https://nixos.org/download.html][Download the latest version of NixOS]]
  37. 2) [[https://nixos.org/manual/nixos/stable/#sec-installation-partitioning][Partition your drives and mount the file system]]
  38. 3) Clone the project ~git clone git@git.chrishayward.xyz:chris/dotfiles /mnt/etc/dotfiles~
  39. 4) Load the default shell ~nix-shell /mnt/etc/dotfiles~
  40. 5) Install the system ~sudo nixos-install --impure --flake /mnt/etc/dotfiles#nixos~
  41. 6) Reboot, login and start a graphical system ~startx~
  42. ** Making Changes
  43. 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:
  44. #+NAME: rebuild-command-table
  45. | Command | Description |
  46. |----------+---------------------------------------------------------------------------------|
  47. | boot | Build the new configuration and make it the boot default, without activation |
  48. | test | Build and activate the new configuration, without adding it to the boot menu |
  49. | switch | Build and activate the new configuration, making it the new boot default |
  50. | build | Build the new configuration, without activation, nor adding it to the boot menu |
  51. | build-vm | Build a script that starts a virtual machine with the desired configuration |
  52. After making changes to the configuration the ~switch~ command will build and activate a new configuration.
  53. #+BEGIN_SRC shell
  54. # Build and activate a new configuration.
  55. sudo nixos-rebuild switch --flake $FLAKE#$HOSTNAME
  56. #+END_SRC
  57. 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.
  58. #+BEGIN_SRC shell
  59. # Rollback to the previous generation.
  60. sudo nixos-rebuild switch --rollback
  61. #+END_SRC
  62. ** Docker Container
  63. It's possible to use parts of this configuration using a [[https://docker.org][Docker]] 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.
  64. Install from the command line: ~docker pull ghcr.io/chayward1/dotfiles:main~
  65. #+BEGIN_SRC dockerfile :tangle Dockerfile :noweb yes
  66. # <<file-warning>>
  67. # Derive from the official image.
  68. FROM nixos/nix
  69. # Setup the default environment.
  70. WORKDIR /etc/dotfiles
  71. COPY . .
  72. # Load the default system shell.
  73. RUN nix-shell /etc/dotfiles/shell.nix
  74. #+END_SRC
  75. * Operating System
  76. [[https://nixos.org][NixOS]] is a purely functional Linux distribution built on top of the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]]. It uses a declarative configuration language to define entire computer systems, and allows reliable system upgrades and rollbacks. [[https://nixos.org][NixOS]] also has tool dedicated to DevOps and deployment tasks, and makes it trivial to share development environments.
  77. #+BEGIN_SRC nix :noweb yes :tangle flake.nix
  78. # <<file-warning>>
  79. {
  80. description = "<<description>>";
  81. inputs = {
  82. <<os-nixpkgs>>
  83. <<os-home-manager>>
  84. <<os-emacs-overlay>>
  85. <<os-nixos-hardware>>
  86. <<os-nix-on-droid>>
  87. };
  88. outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, ... }: {
  89. nixosConfigurations = {
  90. <<host-default>>
  91. <<host-android>>
  92. };
  93. };
  94. }
  95. #+END_SRC
  96. ** Nixpkgs
  97. [[https://nixos.org/manual/nixpkgs/stable][Nixpkgs]] is a collection of over 60,000 software packages that can be installed with the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]]. Two main branches are offered:
  98. 1) The current stable release
  99. 2) The Unstable branch following the latest development
  100. #+NAME: os-nixpkgs
  101. #+BEGIN_SRC nix
  102. nixpkgs.url = "nixpkgs/nixos-unstable";
  103. nixpkgs-unstable.url = "nixpkgs/master";
  104. #+END_SRC
  105. ** Home Manager
  106. [[https://nixos.wiki/wiki/Home_Manager][Home Manager]] provides a basic system for managing user environments using the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]] together with the Nix libraries found in [[https://nixos.org/manual/nixpkgs/stable][Nixpkgs]]. It allows declarative configuration of user specific (non-global) packages and files.
  107. #+NAME: os-home-manager
  108. #+BEGIN_SRC nix
  109. home-manager.url = "github:nix-community/home-manager";
  110. home-manager.inputs.nixpkgs.follows = "nixpkgs";
  111. #+END_SRC
  112. ** Emacs Overlay
  113. Adding the [[https://github.com/nix-community/emacs-overlay][Emacs Overlay]] extends the [[https://gnu.org/software/emacs/][GNU/Emacs]] package set to contain the latest versions, and daily generations from popular package sources, including the needed dependencies to run Emacs as a Window Manager.
  114. #+NAME: os-emacs-overlay
  115. #+BEGIN_SRC nix
  116. emacs-overlay.url = "github:nix-community/emacs-overlay";
  117. #+END_SRC
  118. ** NixOS Hardware
  119. [[https://github.com/nixos/nixos-hardware][NixOS Hardware]] is a collection of [[https://nixos.org][NixOS]] 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.
  120. #+NAME: os-nixos-hardware
  121. #+BEGIN_SRC nix
  122. nixos-hardware.url = "github:nixos/nixos-hardware";
  123. #+END_SRC
  124. ** Nix On Droid
  125. [[https://github.com/t184256/nix-on-droid][Nix On Droid]] is a deployment of the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]] on [[https://android.com][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.
  126. #+NAME: os-nix-on-droid
  127. #+BEGIN_SRC nix
  128. nix-on-droid.url = "github:t184256/nix-on-droid/master";
  129. nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
  130. #+END_SRC
  131. * Development Shells
  132. The command ~nix-shell~ 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.
  133. Import this shell with ~nix-shell /etc/dotfiles/shell.nix~.
  134. #+BEGIN_SRC nix :noweb yes :tangle shell.nix
  135. # <<file-warning>>
  136. { pkgs ? import <nixpkgs> { } }:
  137. with pkgs;
  138. let
  139. nixBin = writeShellScriptBin "nix" ''
  140. exec ${nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
  141. '';
  142. in mkShell {
  143. buildInputs = [
  144. git
  145. ];
  146. shellHook = ''
  147. export FLAKE="$(pwd)"
  148. export PATH="$FLAKE/bin:${nixBin}/bin:$PATH"
  149. '';
  150. }
  151. #+END_SRC
  152. ** Go
  153. [[https://golang.org][Go]] 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.
  154. Import this shell with ~nix-shell /etc/dotfiles/shells/go.nix~
  155. #+BEGIN_SRC nix :noweb yes :tangle shells/go.nix
  156. # <<file-warning>>
  157. { pkgs ? import <nixpkgs> { } }:
  158. with pkgs;
  159. mkShell {
  160. buildInputs = [
  161. go
  162. gopls
  163. # FIXME: Broken on nixpkgs/unstable.
  164. # protoc-gen-go
  165. # protoc-gen-go-grpc
  166. ];
  167. shellHook = ''
  168. export GO111MODULE=on
  169. export GOPATH=$XDG_DATA_HOME/go
  170. export PATH=$GOPATH/bin:$PATH
  171. '';
  172. }
  173. #+END_SRC
  174. ** Rust
  175. [[https://rust-lang.org/][Rust]] 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 achieves memory safety /without/ garbage collection, and reference counting is optional.
  176. Import this shell with ~nix-shell /etc/dotfiles/shells/rust.nix~.
  177. #+BEGIN_SRC nix :noweb yes :tangle shells/rust.nix
  178. # <<file-warning>>
  179. { pkgs ? import <nixpkgs> { } }:
  180. with pkgs;
  181. mkShell {
  182. buildInputs = [
  183. rustup
  184. ];
  185. shellHook = ''
  186. export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
  187. export CARGO_HOME="$XDG_DATA_HOME/cargo"
  188. export PATH="$CARGO_HOME/bin:$PATH"
  189. '';
  190. }
  191. #+END_SRC
  192. ** Node
  193. [[https://nodejs.org][NodeJS]] 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. NodeJS lets developers user JavaScript to write command line tools, and for server-side scripting to produce dynamic web page content.
  194. Import this shell with ~nix-shell /etc/dotfiles/shells/node.nix~.
  195. #+BEGIN_SRC nix :noweb yes :tangle shells/node.nix
  196. # <<file-warning>>
  197. { pkgs ? import <nixpkgs> { } }:
  198. with pkgs;
  199. mkShell {
  200. buildInputs = [
  201. nodejs
  202. yarn
  203. ];
  204. shellHook = ''
  205. export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
  206. export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
  207. export NPM_CACHE_PREFIX="$XDG_CACHE_HOME/npm"
  208. export PATH="$(yarn global bin):$PATH"
  209. '';
  210. }
  211. #+END_SRC
  212. ** Java
  213. [[https://openjdk.java.net][OpenJDK]] is a free and open-source implementation of the [[https://en.wikipedia.org/wiki/Java_(software_platform)][Java]] Platform, Standard Edition. It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GNU General Public License Version 2 with a linking exception.
  214. Import this shell with ~nix-shell /etc/dotfiles/shells/java.nix~.
  215. #+BEGIN_SRC nix :noweb yes :tangle shells/java.nix
  216. # <<file-warning>>
  217. { pkgs ? import <nixpkgs> { } }:
  218. with pkgs;
  219. mkShell {
  220. buildInputs = [
  221. # openjdk8 # Legacy Java 8 VM.
  222. # openjdk11 # Current LTS version of OpenJDK.
  223. openjdk14 # Current version of OpenJDK.
  224. ];
  225. shellHook = ''
  226. '';
  227. }
  228. #+END_SRC
  229. ** gRPC
  230. [[https://grpc.io][gRPC]] 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.
  231. Import this shell with ~nix-shell /etc/dotfiles/shells/grpc.nix~.
  232. #+BEGIN_SRC nix :noweb yes :tangle shells/grpc.nix
  233. # <<file-warning>>
  234. { pkgs ? import <nixpkgs> { } }:
  235. with pkgs;
  236. mkShell {
  237. buildInputs = [
  238. grpc
  239. grpcui
  240. grpcurl
  241. # FIXME: Broken on nixpkgs/unstable.
  242. # grpc-tools
  243. ];
  244. shellHook = ''
  245. '';
  246. }
  247. #+END_SRC
  248. ** C/C++
  249. [[https://iso.org/standard/74528.html][C]] 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. [[https://en.wikipedia.org/wiki/C++/][C++]] is a general-purpose programming language created as an extension of the C programming language.
  250. Import this shell with ~nix-shell /etc/dotfiles/shells/cc.nix~.
  251. #+BEGIN_SRC nix :noweb yes :tangle shells/cc.nix
  252. # <<file-warning>>
  253. { pkgs ? import <nixpkgs> { } }:
  254. with pkgs;
  255. mkShell {
  256. buildInputs = [
  257. gdb
  258. ccls
  259. cmake
  260. gnumake
  261. gcc-unwrapped
  262. ];
  263. shellHook = ''
  264. '';
  265. }
  266. #+END_SRC
  267. ** Python
  268. [[https://python.org][Python]] 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.
  269. Import this shell with ~nix-shell /etc/dotfiles/shells/python.nix~
  270. #+BEGIN_SRC nix :noweb yes :tangle shells/python.nix
  271. # <<file-warning>>
  272. { pkgs ? import <nixpkgs> { } }:
  273. with pkgs;
  274. mkShell {
  275. buildInputs = [
  276. python38Packages.pip
  277. python38Packages.pip-tools
  278. python38Packages.pyls-mypy
  279. python38Packages.pyls-isort
  280. python38Packages.pyls-black
  281. ];
  282. shellHook = ''
  283. '';
  284. }
  285. #+END_SRC
  286. ** Docker
  287. [[https://docker.org][Docker]] is a set of platform as a service tools that use OS level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuratuion files.
  288. [[https://docs.docker.com/compose/][Compose]] is a tool for defining and running multi-container Docker applications. With Compose, 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.
  289. [[https://docs.docker.com/machine/][Machine]] is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with ~docker-machine~ commands. You can use Machine to create hosts on your local box, company network, data center, or on any cloud provider.
  290. Import this shell with ~nix-shell /etc/dotfiles/shells/docker.nix~
  291. #+BEGIN_SRC nix :noweb yes :tangle shells/docker.nix
  292. # <<file-warning>>
  293. { pkgs ? import <nixpkgs> { } }:
  294. with pkgs;
  295. mkShell {
  296. buildInputs = [
  297. docker-compose
  298. docker-machine
  299. ];
  300. shellHook = ''
  301. '';
  302. }
  303. #+END_SRC
  304. ** Heroku
  305. [[https://heroku.com][Heroku]] is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language. It now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.
  306. Import this shell with ~nix-shell /etc/dotfiles/shells/heroku.nix~
  307. #+BEGIN_SRC nix :noweb yes :tangle shells/heroku.nix
  308. # <<file-warning>>
  309. { pkgs ? import <nixpkgs> { } }:
  310. with pkgs;
  311. mkShell {
  312. buildInputs = [
  313. heroku
  314. ];
  315. shellHook = ''
  316. '';
  317. }
  318. #+END_SRC
  319. * Host Configurations
  320. [[https://nixos.org/][NixOS]] 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:
  321. #+NAME: host-config-wifi
  322. #+BEGIN_SRC nix
  323. networking.wireless.networks = {
  324. MyWiFi_5C1870 = {
  325. priority = 3;
  326. pskRaw = "409b3c85fef1c5737f284d2f82f20dc6023e41804e862d4fa26265ef8193b326";
  327. };
  328. BELL182 = {
  329. priority = 2;
  330. pskRaw = "8b3c114c695c5013bbcf5fc0af781c7872f95c34e2cceb31afa7bfc1adf66245";
  331. };
  332. SM-G975W3034 = {
  333. priority = 1;
  334. pskRaw = "74835d96a98ca2c56ffe4eaf92223f8a555168b59ec2bb22b1e46b2a333adc80";
  335. };
  336. };
  337. #+END_SRC
  338. 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:
  339. #+NAME: host-config-home
  340. #+BEGIN_SRC nix
  341. networking.hosts = {
  342. # "192.168.3.105" = [ "gamingpc" ];
  343. # "192.168.3.163" = [ "acernitro" ];
  344. # "192.168.3.182" = [ "raspberry" ];
  345. # "192.168.3.183" = [ "homecloud" ];
  346. };
  347. #+END_SRC
  348. 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.
  349. #+NAME: host-config-ssh
  350. #+BEGIN_SRC nix
  351. users.users.chris.openssh.authorizedKeys.keys = [
  352. "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4wka/LfG3pto15DIm9LIRbb6rWr7/ipCRiCdAKSlY4 chris@chrishayward.xyz"
  353. ];
  354. #+END_SRC
  355. ** Default
  356. The default host, built using [[https://qemu.org][QEMU]], a free and open-source emulator that can perform hardware virtualization. It features a lightweight system optimized for development, running [[https://gnu.org/software/emacs/][GNU/Emacs]] + [[https://github.com/ch11ng/exwm][EXWM]] as the graphical environment.
  357. #+NAME: host-default
  358. #+BEGIN_SRC nix :noweb yes
  359. nixos = nixpkgs.lib.nixosSystem {
  360. system = "x86_64-linux";
  361. specialArgs = { inherit inputs; };
  362. modules = [
  363. ./hosts/nixos
  364. <<module-x11>>
  365. <<module-ssh>>
  366. <<module-hugo>>
  367. <<module-flakes>>
  368. <<module-cachix>>
  369. <<module-home-manager>>
  370. ];
  371. };
  372. #+END_SRC
  373. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#nixos~.
  374. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/default.nix
  375. # <<file-warning>>
  376. { ... }:
  377. {
  378. imports = [
  379. ./configuration.nix
  380. ./hardware.nix
  381. ];
  382. }
  383. #+END_SRC
  384. *** Configuration
  385. This is a basic default configuration that specified the indended default configuration of the system. Because [[https://nixos.org/][NixOS]] has a declarative configuration model, you can create or edit a description of the desired configuration, and update it from one file.
  386. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/configuration.nix
  387. # <<file-warning>>
  388. { config, pkgs, inputs, ... }:
  389. {
  390. time.timeZone = "America/Toronto";
  391. networking.hostName = "nixos";
  392. networking.useDHCP = false;
  393. networking.firewall.enable = false;
  394. networking.interfaces.ens3.useDHCP = true;
  395. <<host-config-home>>
  396. <<host-config-ssh>>
  397. programs.mtr.enable = true;
  398. programs.fish.enable = true;
  399. programs.gnupg.agent.enable = true;
  400. users.users.chris = {
  401. shell = pkgs.fish;
  402. isNormalUser = true;
  403. extraGroups = [ "wheel" ];
  404. };
  405. }
  406. #+END_SRC
  407. *** Hardware
  408. The file system for this host is a single 24GB =QCOW= file, a format for disk images used by [[https://qemu.org][QEMU]]. The file can be recreated easily by following the steps listed in the [[https://nixos.org/][NixOS]] installation manual, specifically the section on disk formatting.
  409. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/hardware.nix
  410. # <<file-warning>>
  411. { config, lib, pkgs, modulesPath, ... }:
  412. {
  413. imports =
  414. [ (modulesPath + "/profiles/qemu-guest.nix")
  415. ];
  416. boot.initrd.availableKernelModules = [ "ata_piix" "floppy" "sd_mod" "sr_mod" ];
  417. boot.initrd.kernelModules = [ ];
  418. boot.kernelModules = [ ];
  419. boot.extraModulePackages = [ ];
  420. boot.loader.grub.enable = true;
  421. boot.loader.grub.version = 2;
  422. boot.loader.grub.device = "/dev/sda";
  423. fileSystems."/" =
  424. { device = "/dev/disk/by-label/nixos";
  425. fsType = "ext4";
  426. };
  427. swapDevices =
  428. [ { device = "/dev/disk/by-label/swap"; }
  429. ];
  430. }
  431. #+END_SRC
  432. ** Android
  433. This is my [[https://samsung.com/us/mobile/galaxy-s10/buy/][Samsung Galaxy S10+]] running [[https://github.com/t184256/nix-on-droid][Nix On Droid]] with the experimental support for [[https://nixos.wiki/wiki/Flakes][Flakes]] being used to manage the configuration.
  434. #+NAME: host-android
  435. #+BEGIN_SRC nix
  436. android = {
  437. device = inputs.nix-on-droid.lib.nixOnDroidConfiguration {
  438. config = ./hosts/android/nix-on-droid.nix;
  439. system = "aarch64-linux";
  440. specialArgs = { inherit inputs; };
  441. };
  442. };
  443. #+END_SRC
  444. Build and activate the configuration with ~nix-on-droid switch --flake .#android~. Currently this cannot be built with a pure flake because of hardcoded store paths for =proot=. Every evaluation will be executed with the =--impure= flag.
  445. #+BEGIN_SRC nix :noweb yes :tangle hosts/android/nix-on-droid.nix
  446. # <<file-warning>>
  447. { pkgs, ... }:
  448. {
  449. environment.packages = [
  450. pkgs.git
  451. pkgs.vim
  452. pkgs.pass
  453. pkgs.gnupg
  454. pkgs.openssh
  455. ];
  456. }
  457. #+END_SRC
  458. * Module Definitions
  459. Modules are files combined by [[https://nixos.org/][NixOS]] to produce the full system configuration. Modules wre introduced to allow extending NixOS without modifying its source code. They also allow splitting up =configuration.nix=, making the system configuration easier to maintain and use.
  460. ** X11
  461. #+NAME: module-x11
  462. #+BEGIN_SRC nix
  463. ./modules/x11.nix
  464. #+END_SRC
  465. [[https://x.org/wiki/][X11]], or X is the generic name for the X Window System Display Server. All graphical [[https://linux.org][GNU/Linux]] applications connect to an X-Window (or Wayland) 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.
  466. #+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
  467. # <<file-warning>>
  468. { config, pkgs, ... }:
  469. {
  470. services.xserver.enable = true;
  471. services.xserver.layout = "us";
  472. services.xserver.libinput.enable = true;
  473. services.xserver.displayManager.startx.enable = true;
  474. environment = {
  475. variables = {
  476. XDG_DESKTOP_DIR = "$HOME/";
  477. XDG_CACHE_HOME = "$HOME/.cache";
  478. XDG_CONFIG_HOME = "$HOME/.config";
  479. XDG_DATA_HOME = "$HOME/.local/share";
  480. XDG_BIN_HOME = "$HOME/.local/bin";
  481. };
  482. systemPackages = with pkgs; [
  483. pkgs.sqlite
  484. pkgs.pfetch
  485. pkgs.cmatrix
  486. pkgs.asciiquarium
  487. ];
  488. extraInit = ''
  489. export XAUTHORITY=/tmp/Xauthority
  490. export xserverauthfile=/tmp/xserverauth
  491. [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
  492. [ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
  493. '';
  494. };
  495. services.picom.enable = true;
  496. services.printing.enable = true;
  497. fonts.fonts = with pkgs; [
  498. iosevka-bin
  499. emacs-all-the-icons-fonts
  500. ];
  501. }
  502. #+END_SRC
  503. ** SSH
  504. #+NAME: module-ssh
  505. #+BEGIN_SRC nix
  506. ./modules/ssh.nix
  507. #+END_SRC
  508. [[https://openssh.com][OpenSSH]] is a suite of secure networking utilities based on the [[https://en.wikipedia.org/wiki/Secure_Shell][Secure Shell Protocol]], which provides a secure channel over an unsecured network in a client-server architecture. OpenSSH started as a fork of the free SSH program; later versions were proprietary software.
  509. Apply some configuration to the default settings:
  510. + Disable logging in as =root=
  511. + Disable password authentication
  512. #+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
  513. # <<file-warning>>
  514. { config, pkgs, ... }:
  515. {
  516. services.openssh = {
  517. enable = true;
  518. permitRootLogin = "no";
  519. passwordAuthentication = false;
  520. };
  521. }
  522. #+END_SRC
  523. ** Hugo
  524. #+NAME: module-hugo
  525. #+BEGIN_SRC nix
  526. ./modules/hugo.nix
  527. #+END_SRC
  528. [[https://gohugo.io][Hugo]] is one of the most popular open-source static site generators.
  529. #+BEGIN_SRC nix :noweb yes :tangle modules/hugo.nix
  530. # <<file-warning>>
  531. { config, pkgs, ... }:
  532. let
  533. myUpdateSite = pkgs.writeShellScriptBin "update-site" ''
  534. rsync -aP /etc/dotfiles/docs/public/ ubuntu@chrishayward.xyz:/var/www/chrishayward
  535. '';
  536. in {
  537. environment.systemPackages = [
  538. pkgs.hugo
  539. myUpdateSite
  540. ];
  541. }
  542. #+END_SRC
  543. ** Flakes
  544. #+NAME: module-flakes
  545. #+BEGIN_SRC nix
  546. ./modules/flakes.nix
  547. #+END_SRC
  548. [[https://nixos.wiki/wiki/Flakes][Nix Flakes]] are an upcoming feature of the [[https://nixos.org/manual/nix/stable/][Nix Package Manager]]. 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 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 are not available unless explicitly enabled.
  549. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  550. # <<file-warning>>
  551. { config, pkgs, inputs, ... }:
  552. {
  553. nix = {
  554. package = pkgs.nixUnstable;
  555. extraOptions = ''
  556. experimental-features = nix-command flakes
  557. '';
  558. };
  559. nixpkgs = {
  560. config = { allowUnfree = true; };
  561. overlays = [ inputs.emacs-overlay.overlay ];
  562. };
  563. }
  564. #+END_SRC
  565. ** Cachix
  566. #+NAME: module-cachix
  567. #+BEGIN_SRC nix
  568. ./modules/cachix.nix
  569. #+END_SRC
  570. [[https://nix-community.cachix.org][Cachix]] is a Command line client for [[https://nixos.org/manual/nix/stable/][Nix]] 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.
  571. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  572. # <<file-warning>>
  573. { config, ... }:
  574. {
  575. nix = {
  576. settings = {
  577. substituters = [
  578. "https://nix-community.cachix.org"
  579. ];
  580. trusted-public-keys = [
  581. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  582. ];
  583. };
  584. };
  585. }
  586. #+END_SRC
  587. ** Docker
  588. #+NAME: module-docker
  589. #+BEGIN_SRC nix
  590. ./modules/docker.nix
  591. #+END_SRC
  592. [[https://docker.org][Docker]] is a set of platform as a service tools that use 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.
  593. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  594. { config, pkgs, ... }:
  595. {
  596. # Enable the docker virutalization platform.
  597. virtualisation.docker = {
  598. enable = true;
  599. enableOnBoot = true;
  600. autoPrune.enable = true;
  601. };
  602. # Required for the `docker' command.
  603. users.users.chris.extraGroups = [ "docker" ];
  604. }
  605. #+END_SRC
  606. ** Firefox
  607. #+NAME: module-firefox
  608. #+BEGIN_SRC nix
  609. ./modules/firefox.nix
  610. #+END_SRC
  611. [[https://firefox.com][Firefox Browser]], 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.
  612. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  613. # <<file-warning>>
  614. { pkgs, ... }:
  615. {
  616. # NOTE: Use the binary until module is developed.
  617. environment.systemPackages = [
  618. pkgs.firefox-bin
  619. ];
  620. }
  621. #+END_SRC
  622. ** Home Manager
  623. [[https://nixos.wiki/wiki/Home_Manager][Home Manager]] 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.
  624. #+NAME: module-home-manager
  625. #+BEGIN_SRC nix :noweb yes
  626. inputs.home-manager.nixosModules.home-manager {
  627. home-manager.useGlobalPkgs = true;
  628. home-manager.useUserPackages = true;
  629. home-manager.users.chris = {
  630. imports = [
  631. <<module-git>>
  632. <<module-gpg>>
  633. <<module-vim>>
  634. <<module-gtk>>
  635. <<module-emacs>>
  636. ];
  637. };
  638. }
  639. #+END_SRC
  640. *** Git
  641. #+NAME: module-git
  642. #+BEGIN_SRC nix
  643. ./modules/git.nix
  644. #+END_SRC
  645. [[https://git.scm.com][Git]] 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.
  646. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  647. # <<file-warning>>
  648. { pkgs, ... }:
  649. let
  650. # Fix any corruptions in the local copy.
  651. myGitFix = pkgs.writeShellScriptBin "git-fix" ''
  652. if [ -d .git/objects/ ]; then
  653. find .git/objects/ -type f -empty | xargs rm -f
  654. git fetch -p
  655. git fsck --full
  656. fi
  657. exit 1
  658. '';
  659. in {
  660. home.packages = [ myGitFix ];
  661. programs.git = {
  662. enable = true;
  663. userName = "Christopher James Hayward";
  664. userEmail = "chris@chrishayward.xyz";
  665. signing = {
  666. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  667. signByDefault = true;
  668. };
  669. };
  670. }
  671. #+END_SRC
  672. *** Gpg
  673. #+NAME: module-gpg
  674. #+BEGIN_SRC nix
  675. ./modules/gpg.nix
  676. #+END_SRC
  677. [[https://gnupg.org][GNU Privacy Guard]] 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.
  678. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  679. # <<file-warning>>
  680. { pkgs, ... }:
  681. {
  682. services.gpg-agent = {
  683. enable = true;
  684. defaultCacheTtl = 1800;
  685. enableSshSupport = true;
  686. pinentryFlavor = "gtk2";
  687. };
  688. }
  689. #+END_SRC
  690. *** Vim
  691. #+NAME: module-vim
  692. #+BEGIN_SRC nix
  693. ./modules/vim.nix
  694. #+END_SRC
  695. [[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
  696. + Simplify maintenance and encourage contributions
  697. + Split the work between multiple developers
  698. + Enable advanced UIs without core modification
  699. + Maximize extensibility
  700. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  701. # <<file-warning>>
  702. { pkgs, ... }:
  703. {
  704. programs.neovim = {
  705. enable = true;
  706. viAlias = true;
  707. vimAlias = true;
  708. vimdiffAlias = true;
  709. extraConfig = ''
  710. set number relativenumber
  711. set nobackup
  712. '';
  713. extraPackages = [
  714. pkgs.nixfmt
  715. ];
  716. plugins = with pkgs.vimPlugins; [
  717. vim-nix
  718. vim-airline
  719. vim-polyglot
  720. ];
  721. };
  722. }
  723. #+END_SRC
  724. *** GTK
  725. #+NAME: module-gtk
  726. #+BEGIN_SRC nix
  727. ./modules/gtk.nix
  728. #+END_SRC
  729. [[https://gtk.org][GTK]] is a free and open-source, cross-platform widget toolkit for graphical user interfaces. It's one of the most popular toolkits for the [[https://wayland.freedesktop.org][Wayland]] and [[https://x.org/wiki/][X11]] windowing systems.
  730. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  731. # <<file-warning>>
  732. { pkgs, ... }:
  733. {
  734. home.packages = [
  735. pkgs.nordic
  736. pkgs.arc-icon-theme
  737. pkgs.lxappearance
  738. ];
  739. home.file.".gtkrc-2.0" = {
  740. text = ''
  741. gtk-theme-name="Nordic-darker"
  742. gtk-icon-theme-name="Arc"
  743. gtk-font-name="Iosevka 11"
  744. gtk-cursor-theme-size=0
  745. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  746. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  747. gtk-button-images=0
  748. gtk-menu-images=0
  749. gtk-enable-event-sounds=1
  750. gtk-enable-input-feedback-sounds=1
  751. gtk-xft-antialias=1
  752. gtk-xft-hinting=1
  753. gtk-xft-hintstyle="hintmedium"
  754. '';
  755. };
  756. home.file.".config/gtk-2.0/gtkfilechooser.ini" = {
  757. text = ''
  758. [Filechooser Settings]
  759. LocationMode=path-bar
  760. ShowHidden=false
  761. ShowSizeColumn=true
  762. GeometryX=442
  763. GeometryY=212
  764. GeometryWidth=1036
  765. GeometryHeight=609
  766. SortColumn=name
  767. SortOrder=ascending
  768. StartupMode=recent
  769. '';
  770. };
  771. home.file.".config/gtk-3.0/settings.ini" = {
  772. text = ''
  773. [Settings]
  774. gtk-theme-name=Nordic-darker
  775. gtk-icon-theme-name=Arc
  776. gtk-font-name=Iosevka 11
  777. gtk-cursor-theme-size=0
  778. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  779. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  780. gtk-button-images=0
  781. gtk-menu-images=0
  782. gtk-enable-event-sounds=1
  783. gtk-enable-input-feedback-sounds=1
  784. gtk-xft-antialias=1
  785. gtk-xft-hinting=1
  786. gtk-xft-hintstyle=hintmedium
  787. '';
  788. };
  789. }
  790. #+END_SRC
  791. * Emacs Configuration
  792. #+NAME: module-emacs
  793. #+BEGIN_SRC nix
  794. ./modules/emacs.nix
  795. #+END_SRC
  796. [[https://gnu.org/software/emacs/][GNU/Emacs]] is an extensible, customizable, free/libre text editor -- and more. At its core is an interpreter for [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]], a dialect of the Lisp programming language with extensions to support text editing. Other features include:
  797. + Highly customizable
  798. + Full Unicopde support
  799. + Content-aware editing modes
  800. + Complete built-in documentation
  801. + Wide range of functionality beyond text editing
  802. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  803. # <<file-warning>>
  804. { pkgs, ... }:
  805. let
  806. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  807. config = ../README.org;
  808. package = <<emacs-native-comp-package>>
  809. alwaysEnsure = true;
  810. alwaysTangle = true;
  811. extraEmacsPackages = epkgs: [
  812. # Required packages...
  813. <<emacs-exwm-package>>
  814. <<emacs-evil-package>>
  815. <<emacs-general-package>>
  816. <<emacs-which-key-package>>
  817. # Optional packages.
  818. <<emacs-org-package>>
  819. <<emacs-org-roam-package>>
  820. <<emacs-org-roam-ui-package>>
  821. <<emacs-org-drill-package>>
  822. <<emacs-pomodoro-package>>
  823. <<emacs-writegood-package>>
  824. <<emacs-http-package>>
  825. <<emacs-hugo-package>>
  826. <<emacs-reveal-package>>
  827. <<emacs-pass-package>>
  828. <<emacs-docker-package>>
  829. <<emacs-mu4e-package>>
  830. <<emacs-dired-package>>
  831. <<emacs-icons-package>>
  832. <<emacs-emoji-package>>
  833. <<emacs-eshell-package>>
  834. <<emacs-vterm-package>>
  835. <<emacs-magit-package>>
  836. <<emacs-hydra-package>>
  837. <<emacs-elfeed-package>>
  838. <<emacs-nix-mode-package>>
  839. <<emacs-projectile-package>>
  840. <<emacs-lsp-package>>
  841. <<emacs-company-package>>
  842. <<emacs-ccls-package>>
  843. <<emacs-golang-package>>
  844. <<emacs-python-package>>
  845. <<emacs-rustic-package>>
  846. <<emacs-plantuml-package>>
  847. <<emacs-protobuf-package>>
  848. <<emacs-swiper-package>>
  849. <<emacs-desktop-package>>
  850. <<emacs-doom-themes-package>>
  851. <<emacs-doom-modeline-package>>
  852. ];
  853. };
  854. in {
  855. home.packages = [
  856. <<emacs-exwm-extras>>
  857. <<emacs-pass-extras>>
  858. <<emacs-mu4e-extras>>
  859. <<emacs-aspell-extras>>
  860. <<emacs-texlive-extras>>
  861. <<emacs-desktop-extras>>
  862. <<emacs-plantuml-extras>>
  863. <<emacs-nix-mode-extras>>
  864. <<emacs-doom-themes-extras>>
  865. ];
  866. programs.emacs = {
  867. enable = true;
  868. package = myEmacs;
  869. };
  870. <<emacs-exwm-config>>
  871. <<emacs-exwm-xinitrc>>
  872. <<emacs-mu4e-config>>
  873. }
  874. #+END_SRC
  875. 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.
  876. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  877. ;; <<file-warning>>
  878. ;; Required inputs.
  879. <<emacs-exwm-elisp>>
  880. <<emacs-evil-elisp>>
  881. <<emacs-general-elisp>>
  882. <<emacs-which-key-elisp>>
  883. ;; Optional inputs.
  884. <<emacs-org-elisp>>
  885. <<emacs-org-roam-elisp>>
  886. <<emacs-org-roam-ui-elisp>>
  887. <<emacs-org-drill-elisp>>
  888. <<emacs-org-agenda-elisp>>
  889. <<emacs-pomodoro-elisp>>
  890. <<emacs-writegood-elisp>>
  891. <<emacs-aspell-elisp>>
  892. <<emacs-eww-elisp>>
  893. <<emacs-http-elisp>>
  894. <<emacs-hugo-elisp>>
  895. <<emacs-reveal-elisp>>
  896. <<emacs-pass-elisp>>
  897. <<emacs-docker-elisp>>
  898. <<emacs-erc-elisp>>
  899. <<emacs-mu4e-elisp>>
  900. <<emacs-dired-elisp>>
  901. <<emacs-icons-elisp>>
  902. <<emacs-emoji-elisp>>
  903. <<emacs-eshell-elisp>>
  904. <<emacs-vterm-elisp>>
  905. <<emacs-magit-elisp>>
  906. <<emacs-fonts-elisp>>
  907. <<emacs-frames-elisp>>
  908. <<emacs-elfeed-elisp>>
  909. <<emacs-projectile-elisp>>
  910. <<emacs-lsp-elisp>>
  911. <<emacs-company-elisp>>
  912. <<emacs-golang-elisp>>
  913. <<emacs-python-elisp>>
  914. <<emacs-rustic-elisp>>
  915. <<emacs-plantuml-elisp>>
  916. <<emacs-desktop-elisp>>
  917. ;; User interface.
  918. <<emacs-swiper-elisp>>
  919. <<emacs-transparency-elisp>>
  920. <<emacs-doom-themes-elisp>>
  921. <<emacs-doom-modeline-elisp>>
  922. #+END_SRC
  923. 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=.
  924. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  925. ;; <<file-warning>>
  926. <<emacs-disable-ui-elisp>>
  927. <<emacs-native-comp-elisp>>
  928. <<emacs-backup-files-elisp>>
  929. <<emacs-shell-commands-elisp>>
  930. #+END_SRC
  931. ** Native Comp
  932. #+NAME: emacs-native-comp-package
  933. #+BEGIN_SRC nix
  934. pkgs.emacsGcc;
  935. #+END_SRC
  936. Native Comp, also known as GccEmacs, refers to the ~--with-native-compilation~ configuration option when building [[https://gnu.org/software/emacs/][GNU/Emacs]]. It adds support for compiling [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][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.
  937. #+NAME: emacs-native-comp-elisp
  938. #+BEGIN_SRC emacs-lisp
  939. ;; Silence warnings from packages that don't support `native-comp'.
  940. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  941. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  942. #+END_SRC
  943. ** Disable UI
  944. [[https://gnu.org/software/emacs/][Emacs]] 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.
  945. #+NAME: emacs-disable-ui-elisp
  946. #+BEGIN_SRC emacs-lisp
  947. ;; Disable unwanted UI elements.
  948. (tooltip-mode -1)
  949. (menu-bar-mode -1)
  950. (tool-bar-mode -1)
  951. (scroll-bar-mode -1)
  952. ;; Fix the scrolling behaviour.
  953. (setq scroll-conservatively 101)
  954. ;; Fix mouse-wheel scrolling behaviour.
  955. (setq mouse-wheel-follow-mouse t
  956. mouse-wheel-progressive-speed t
  957. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  958. ;; Start in fullscreen/maximized.
  959. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  960. #+END_SRC
  961. ** Backup Files
  962. [[https://gnu.org/software/emacs/][Emacs]] 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.
  963. #+NAME: emacs-backup-files-elisp
  964. #+BEGIN_SRC emacs-lisp
  965. ;; Disable unwanted features.
  966. (setq make-backup-files nil
  967. create-lockfiles nil)
  968. #+END_SRC
  969. ** Shell Commands
  970. Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
  971. 1) Method to run an external process, launching any application on a new process without interference
  972. 2) Method to apply commands to the current call process, effecting the running instance
  973. #+NAME: emacs-shell-commands-elisp
  974. #+BEGIN_SRC emacs-lisp
  975. ;; Define a method to run an external process.
  976. (defun dotfiles/run (cmd)
  977. "Run an external process."
  978. (interactive (list (read-shell-command "λ ")))
  979. (start-process-shell-command cmd nil cmd))
  980. ;; Define a method to run a background process.
  981. (defun dotfiles/run-in-background (cmd)
  982. (let ((command-parts (split-string cmd "[ ]+")))
  983. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  984. #+END_SRC
  985. ** Nix Mode
  986. #+NAME: emacs-nix-mode-extras
  987. #+BEGIN_SRC nix
  988. pkgs.nixfmt
  989. #+END_SRC
  990. [[https://github.com/nixos/nix-mode][Nix Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] major mode for editing [[https://nixos.org/manual/nix/stable/][Nix]] expressions. This provides basic handling of =.nix= files. Syntax highlighting and indentation support using =SMIE= are provided.
  991. #+NAME: emacs-nix-mode-package
  992. #+BEGIN_SRC nix
  993. epkgs.nix-mode
  994. #+END_SRC
  995. ** Evil Mode
  996. [[https://evil.readthedocs.io/en/latest/overview.html][Evil Mode]] is an extensible VI layer for [[https://gnu.org/software/emacs/][GNU/Emacs]]. It emulates the main features of [[https://neovim.io][Vim]], transforming GNU/Emacs into a modal editor.
  997. #+NAME: emacs-evil-package
  998. #+BEGIN_SRC nix
  999. epkgs.evil
  1000. epkgs.evil-collection
  1001. epkgs.evil-surround
  1002. epkgs.evil-nerd-commenter
  1003. #+END_SRC
  1004. The next time [[https://gnu.org/software/emacs/][Emacs]] 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 in general, [[https://evil.readthedocs.io/en/latest/overview.html][Evil Mode]] is extensible in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]].
  1005. #+NAME: emacs-evil-elisp
  1006. #+BEGIN_SRC emacs-lisp
  1007. ;; Enable the Extensible VI Layer for Emacs.
  1008. (setq evil-want-integration t ;; Required for `evil-collection.'
  1009. evil-want-keybinding nil ;; Same as above.
  1010. evil-want-C-i-jump nil) ;; Disable jumping in terminal.
  1011. (evil-mode +1)
  1012. ;; Configure `evil-collection'.
  1013. (evil-collection-init)
  1014. ;; Configure `evil-surround'.
  1015. (global-evil-surround-mode +1)
  1016. ;; Configure `evil-nerd-commenter'.
  1017. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1018. ;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
  1019. (evil-define-key 'normal 'org-mode-map (kbd "<tab>") #'org-cycle)
  1020. #+END_SRC
  1021. ** EXWM
  1022. #+NAME: emacs-exwm-package
  1023. #+BEGIN_SRC nix
  1024. epkgs.exwm
  1025. #+END_SRC
  1026. [[https://github.com/ch11ng/exwm][EXWM]] (Emacs X Window Manager) is a full-featured tiling [[https://x.org/wiki/][X11]] window manager for [[https://gnu.org/software/emacs/][GNU/Emacs]] built on-top of XELB. It features:
  1027. + Fully keyboard-driven operations
  1028. + Hybrid layout modes (tiling & stacking)
  1029. + Dynamic workspace support
  1030. + ICCM/EWMH compliance
  1031. #+NAME: emacs-exwm-extras
  1032. #+BEGIN_SRC nix
  1033. pkgs.nitrogen
  1034. pkgs.autorandr
  1035. #+END_SRC
  1036. 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 [[https://github.com/ch11ng/exwm][EXWM]].
  1037. #+NAME: emacs-exwm-config
  1038. #+BEGIN_SRC nix
  1039. xsession = {
  1040. enable = true;
  1041. windowManager.command = ''
  1042. ${pkgs.nitrogen}/bin/nitrogen --restore
  1043. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1044. ${myEmacs}/bin/emacsclient -c
  1045. '';
  1046. };
  1047. #+END_SRC
  1048. [[https://github.com/ch11ng/exwm][EXWM]] cannot make an [[https://x.org/wiki/][X]] window manager by itself, this is by design; You must tell X to do it. Override the =~/.xinitrc= file to start the =xsession=.
  1049. #+NAME: emacs-exwm-xinitrc
  1050. #+BEGIN_SRC nix
  1051. home.file.".xinitrc" = {
  1052. text = ''
  1053. exec ./.xsession
  1054. '';
  1055. };
  1056. #+END_SRC
  1057. #+NAME: emacs-exwm-elisp
  1058. #+BEGIN_SRC emacs-lisp
  1059. ;; Configure `exwm'.
  1060. (setq exwm-workspace-number 5
  1061. exwm-layout-show-all-buffers t
  1062. exwm-worspace-show-all-buffers t)
  1063. ;; Configure input keys.
  1064. (setq exwm-input-prefix-keys
  1065. '(?\M-x
  1066. ?\C-g
  1067. ?\C-\ ))
  1068. (setq exwm-input-global-keys
  1069. `(([?\s-r] . exwm-reset)
  1070. ,@(mapcar (lambda (i)
  1071. `(,(kbd (format "s-%d" i)) .
  1072. (lambda ()
  1073. (interactive)
  1074. (exwm-workspace-switch-create ,i))))
  1075. (number-sequence 0 9))))
  1076. ;; Configure `exwm-randr'.
  1077. (require 'exwm-randr)
  1078. (exwm-randr-enable)
  1079. ;; Configure custom hooks.
  1080. (setq display-time-day-and-date t)
  1081. (add-hook 'exwm-init-hook
  1082. (lambda ()
  1083. (display-battery-mode +1) ;; Display battery info (if available).
  1084. (display-time-mode +1))) ;; Display the time in the modeline.
  1085. ;; Setup buffer display names.
  1086. (add-hook 'exwm-update-class-hook
  1087. (lambda ()
  1088. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1089. ;; Configure monitor hot-swapping.
  1090. (add-hook 'exwm-randr-screen-change-hook
  1091. (lambda ()
  1092. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1093. #+END_SRC
  1094. ** General
  1095. #+NAME: emacs-general-package
  1096. #+BEGIN_SRC nix
  1097. epkgs.general
  1098. #+END_SRC
  1099. [[https://github.com/noctuid/general.el][General.el]] provides a more convenient method for binding keys in [[https://gnu.org/software/emacs/][Emacs]], providing a unified interface for key definitions. Its primary purpose is to build on /existing/ functionality to make key definitions more clear and concise.
  1100. #+NAME: emacs-general-elisp
  1101. #+BEGIN_SRC emacs-lisp
  1102. ;; Use <SPC> as a leader key via `general.el'.
  1103. (general-create-definer dotfiles/leader
  1104. :keymaps '(normal insert visual emacs)
  1105. :prefix "SPC"
  1106. :global-prefix "C-SPC")
  1107. ;; Setup general to work with `evil-mode'.
  1108. (setq general-evil-setup t)
  1109. ;; Find files with <SPC> <period> ...
  1110. ;; Switch buffers with <SPC> <comma> ...
  1111. (dotfiles/leader
  1112. "." '(find-file :which-key "File")
  1113. "," '(switch-to-buffer :which-key "Buffer")
  1114. "k" '(kill-buffer :which-key "Kill")
  1115. "c" '(kill-buffer-and-window :which-key "Close"))
  1116. ;; Add keybindings for executing shell commands.
  1117. (dotfiles/leader
  1118. "r" '(:ignore t :which-key "Run")
  1119. "rr" '(dotfiles/run :which-key "Run")
  1120. "ra" '(async-shell-command :which-key "Async"))
  1121. ;; Add keybindings for quitting Emacs.
  1122. (dotfiles/leader
  1123. "q" '(:ignore t :which-key "Quit")
  1124. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1125. "qw" '(kill-emacs :which-key "Now")
  1126. "qf" '(delete-frame :which-key "Frame"))
  1127. ;; Add keybindings for toggles / tweaks.
  1128. (dotfiles/leader
  1129. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1130. #+END_SRC
  1131. ** Which Key
  1132. [[https://github.com/justbur/emacs-which-key][Which Key]] is an [[https://gnu.org/software/emacs/][Emacs]] minor mode that displays the key bindings following your currently entered incomplete command (prefix) in a popup or mini-buffer.
  1133. #+NAME: emacs-which-key-package
  1134. #+BEGIN_SRC nix
  1135. epkgs.which-key
  1136. #+END_SRC
  1137. #+NAME: emacs-which-key-elisp
  1138. #+BEGIN_SRC emacs-lisp
  1139. ;; Configure `which-key' to see keyboard bindings in the
  1140. ;; mini-buffer and when using M-x.
  1141. (setq which-key-idle-delay 0.0)
  1142. (which-key-mode +1)
  1143. #+END_SRC
  1144. ** EWW
  1145. [[https://emacswiki.org/emacs/eww][Emacs Web Wowser (EWW)]] is a Web browser written in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]] based on the ~shr.el~ library. It's my primary browser when it comes to text-based browsing.
  1146. + Use ~eww~ as the default browser
  1147. + Don't use any special fonts or colours
  1148. #+NAME: emacs-eww-elisp
  1149. #+BEGIN_SRC emacs-lisp
  1150. ;; Set `eww' as the default browser.
  1151. (setq browse-url-browser-function 'eww-browse-url)
  1152. ;; Configure the `shr' rendering engine.
  1153. (setq shr-use-fonts nil
  1154. shr-use-colors nil)
  1155. #+END_SRC
  1156. ** ERC
  1157. [[https://gnu.org/software/emacs/erc.html][ERC]] is a powerful, modular, and extensible IRC client for [[https://gnu.org/software/emacs/][GNU/Emacs]]. It's part of the GNU project, and included in Emacs.
  1158. #+NAME: emacs-erc-elisp
  1159. #+BEGIN_SRC emacs-lisp
  1160. ;; Configure `erc'.
  1161. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
  1162. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1163. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1164. ;; Configure `erc-fill-column'.
  1165. (add-hook 'window-configuration-change-hook
  1166. '(lambda ()
  1167. (setq erc-fill-column (- (window-width) 12))))
  1168. ;; Connect to IRC via `erc'.
  1169. (defun dotfiles/erc-connect ()
  1170. "Connected to IRC via `erc'."
  1171. (interactive)
  1172. (erc-tls :server "irc.libera.chat"
  1173. :port 6697
  1174. :nick "megaphone"
  1175. :password (password-store-get "megaphone@libera.chat")
  1176. :full-name "Chris Hayward"))
  1177. ;; Configure keybindings.
  1178. (dotfiles/leader
  1179. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1180. #+END_SRC
  1181. ** Dired
  1182. #+NAME: emacs-dired-package
  1183. #+BEGIN_SRC nix
  1184. epkgs.dired-single
  1185. #+END_SRC
  1186. [[https://emacswiki.org/emacs/DiredMode][Dired Mode]] shows a directory listing inside of an [[https://gnu.org/software/emacs/][Emacs]] 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. [[https://emacswiki.org/emacs/DiredExtra#Dired_X][Dired Extra]] provides extra functionality.
  1187. #+NAME: emacs-dired-elisp
  1188. #+BEGIN_SRC emacs-lisp
  1189. ;; Include `dired-x' for the `jump' method.
  1190. (require 'dired-x)
  1191. ;; Configure `dired-single' to support `evil' keys.
  1192. (evil-collection-define-key 'normal 'dired-mode-map
  1193. "h" 'dired-single-up-directory
  1194. "l" 'dired-single-buffer)
  1195. ;; Setup `all-the-icons' and the `dired' extension.
  1196. ;; Configure keybindings for `dired'.
  1197. (dotfiles/leader
  1198. "d" '(dired-jump :which-key "Dired"))
  1199. #+END_SRC
  1200. ** Icons
  1201. #+NAME: emacs-icons-package
  1202. #+BEGIN_SRC nix
  1203. epkgs.all-the-icons
  1204. epkgs.all-the-icons-dired
  1205. epkgs.all-the-icons-ivy-rich
  1206. #+END_SRC
  1207. [[https://github.com/domtronn/all-the-icons.el][All The Icons]] is a utility package to collect various Icon Fonts and prioritize them within [[https://gnu.org/software/emacs/][GNU/Emacs]].
  1208. #+NAME: emacs-icons-elisp
  1209. #+BEGIN_SRC emacs-lisp
  1210. ;; Setup `all-the-icons-dired'.
  1211. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1212. ;; Disable monochrome icons.
  1213. (setq all-the-icons-dired-monochrome nil)
  1214. ;; Display default font ligatures.
  1215. (global-prettify-symbols-mode +1)
  1216. #+END_SRC
  1217. ** Emojis
  1218. #+NAME: emacs-emoji-package
  1219. #+BEGIN_SRC nix
  1220. epkgs.emojify
  1221. #+END_SRC
  1222. [[https://github.com/iqbalansari/emacs-emojify][Emojify]] is an [[https://gnu.org/software/emacs/][Emacs]] 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.
  1223. #+NAME: emacs-emoji-elisp
  1224. #+BEGIN_SRC emacs-lisp
  1225. ;; Setup `emojify'.
  1226. (add-hook 'after-init-hook 'global-emojify-mode)
  1227. #+END_SRC
  1228. ** EShell
  1229. #+NAME: emacs-eshell-package
  1230. #+BEGIN_SRC nix
  1231. epkgs.eshell-prompt-extras
  1232. #+END_SRC
  1233. [[https://gnu.org/software/emacs/manual/html_mono/eshell.html][EShell]] is a shell-like command interpreter for [[https://gnu.org/software/emacs/][GNU/Emacs]] implemented in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]]. 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.
  1234. #+NAME: emacs-eshell-elisp
  1235. #+BEGIN_SRC emacs-lisp
  1236. ;; Configure `eshell'.
  1237. (setq eshell-highlight-prompt nil
  1238. eshell-prefer-lisp-functions nil)
  1239. ;; Configure the lambda prompt.
  1240. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1241. (setq eshell-prompt-function 'epe-theme-lambda)
  1242. ;; Configure keybindings for `eshell'.
  1243. (dotfiles/leader
  1244. "e" '(eshell :which-key "EShell"))
  1245. #+END_SRC
  1246. ** VTerm
  1247. [[https://github.com/akermu/emacs-libvterm][Emacs Libvterm (VTerm)]] is a fully-fledged terminal emulator inside [[https://gnu.org/software/emacs/][GNU/Emacs]] based on [[https://github.com/neovim/libvterm][Libvterm]], a blazing fast C library used in [[https://neovim.io][Neovim]]. As a result of using compiled code (instead of [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]]), VTerm is capable, fast, and it can seamlessly handle large outputs.
  1248. #+NAME: emacs-vterm-package
  1249. #+BEGIN_SRC nix
  1250. epkgs.vterm
  1251. #+END_SRC
  1252. #+NAME: emacs-vterm-elisp
  1253. #+BEGIN_SRC emacs-lisp
  1254. ;; Add keybindings for interacting with the shell(s).
  1255. (dotfiles/leader
  1256. "v" '(vterm :which-key "VTerm"))
  1257. #+END_SRC
  1258. ** Magit
  1259. [[https://magit.vc][Magit]] is an interface to the [[https://git-scm.com][Git]] version control system, implemented as a [[https://gnu.org/software/emacs/][GNU/Emacs]] package written in [[https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html][Emacs Lisp]]. It fills the glaring gap between the Git command line interface and various GUIs, letting you perform trivial as well as elaborate version control tasks within a few mnemonic key presses.
  1260. #+NAME: emacs-magit-package
  1261. #+BEGIN_SRC nix
  1262. epkgs.magit
  1263. #+END_SRC
  1264. #+NAME: emacs-magit-elisp
  1265. #+BEGIN_SRC emacs-lisp
  1266. ;; Add keybindings for working with `magit'.
  1267. (dotfiles/leader
  1268. "g" '(:ignore t :which-key "Git")
  1269. "gg" '(magit-status :which-key "Status")
  1270. "gc" '(magit-clone :which-key "Clone")
  1271. "gf" '(magit-fetch :which-key "Fetch")
  1272. "gp" '(magit-pull :which-key "Pull"))
  1273. #+END_SRC
  1274. ** Hydra
  1275. #+NAME: emacs-hydra-package
  1276. #+BEGIN_SRC nix
  1277. epkgs.hydra
  1278. #+END_SRC
  1279. [[https://github.com/abo-abo/hydra][Hydra]] allows you to create keymaps for related commands, with the ability to easily repeat commands using a single keystroke.
  1280. ** Fonts
  1281. [[https://typeof.net/Iosevka][Iosevka]] is an open-source, sans-serif + slab-serif, monospace + quasi-proportional typeface family, designed for writing code, using in terminals, and preparing technical documents. Configure it as the default font face inside of [[https://gnu.org/software/emacs/][Emacs]] and define a [[https://github.com/abo-abo/hydra][Hydra]] command for quickly scaling text.
  1282. #+NAME: emacs-fonts-elisp
  1283. #+BEGIN_SRC emacs-lisp
  1284. ;; Configure the font when running as `emacs-server'.
  1285. (custom-set-faces
  1286. '(default ((t (:inherit nil :height 120 :family "Iosevka")))))
  1287. ;; Define a `hydra' function for scaling the text interactively.
  1288. (defhydra hydra-text-scale (:timeout 4)
  1289. "Scale the text in the current buffer."
  1290. ("k" text-scale-decrease "Decrease")
  1291. ("j" text-scale-increase "Increase")
  1292. ("f" nil "Finished" :exit t))
  1293. ;; Create keybinding for calling the function.
  1294. (dotfiles/leader
  1295. "tf" '(hydra-text-scale/body :which-key "Font"))
  1296. #+END_SRC
  1297. ** Frames
  1298. Sometimes it's useful to resize the current frame without using the mouse (always). The default behaviour when calling ~shrink-window~ and ~enlarge-window~ only changes the size by a small margin. I solved this problem with the same method used for scaling text:
  1299. #+NAME: emacs-frames-elisp
  1300. #+BEGIN_SRC emacs-lisp
  1301. ;; Define a `hydra' function for resizing the current frame.
  1302. (defhydra hydra-resize-frame (:timeout 4)
  1303. "Scale the current frame."
  1304. ("h" shrink-window-horizontally "Left")
  1305. ("j" enlarge-window "Down")
  1306. ("k" shrink-window "Up")
  1307. ("l" enlarge-window-horizontally "Right")
  1308. ("f" nil "Finished" :exit t))
  1309. ;; Add keybindings for working with frames to replace
  1310. ;; the C-x <num> <num> method of bindings, which is awful.
  1311. (dotfiles/leader
  1312. "w" '(:ignore t :which-key "Windows")
  1313. "ww" '(window-swap-states :which-key "Swap")
  1314. "wc" '(delete-window :which-key "Close")
  1315. "wh" '(windmove-left :which-key "Left")
  1316. "wj" '(windmove-down :which-key "Down")
  1317. "wk" '(windmove-up :which-key "Up")
  1318. "wl" '(windmove-right :which-key "Right")
  1319. "ws" '(:ignore t :which-key "Split")
  1320. "wsj" '(split-window-below :which-key "Below")
  1321. "wsl" '(split-window-right :which-key "Right")
  1322. "wr" '(hydra-resize-frame/body :which-key "Resize"))
  1323. #+END_SRC
  1324. ** Elfeed
  1325. #+NAME: emacs-elfeed-package
  1326. #+BEGIN_SRC nix
  1327. epkgs.elfeed
  1328. #+END_SRC
  1329. [[https://github.com/skeeto/elfeed][Elfeed]] is an extensible web feed reader for [[https://gnu.org/software/emacs/][GNU/Emacs]], support both =Atom= and =RSS=. It requires =Emacs 24.3+= and is available for download from the standard repositories.
  1330. #+NAME: emacs-elfeed-elisp
  1331. #+BEGIN_SRC emacs-lisp
  1332. ;; Configure `elfeed'.
  1333. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1334. ;; Add custom feeds for `elfeed' to fetch.
  1335. (setq elfeed-feeds (quote
  1336. (("https://hexdsl.co.uk/rss.xml")
  1337. ("https://lukesmith.xyz/rss.xml")
  1338. ("https://friendo.monster/rss.xml")
  1339. ("https://chrishayward.xyz/index.xml")
  1340. ("https://protesilaos.com/master.xml"))))
  1341. ;; Add custom keybindings for `elfeed'.
  1342. (dotfiles/leader
  1343. "l" '(:ignore t :which-key "Elfeed")
  1344. "ll" '(elfeed :which-key "Open")
  1345. "lu" '(elfeed-update :which-key "Update"))
  1346. #+END_SRC
  1347. ** Org Mode
  1348. #+NAME: emacs-org-package
  1349. #+BEGIN_SRC nix
  1350. epkgs.org
  1351. #+END_SRC
  1352. [[https://orgmode.org][Org Mode]] is a document editing and organizing mode, designed for notes, planning, and authoring within the free software text editor [[https://gnu.org/software/emacs/][GNU/Emacs]]. 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.
  1353. #+NAME: emacs-org-elisp
  1354. #+BEGIN_SRC emacs-lisp
  1355. ;; Configure `org-mode' source blocks.
  1356. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1357. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1358. org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
  1359. org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
  1360. ;; Add an `org-mode-hook'.
  1361. (add-hook 'org-mode-hook
  1362. (lambda ()
  1363. (org-indent-mode)
  1364. (visual-line-mode)))
  1365. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1366. (setq org-export-html-validation-link nil
  1367. org-html-validation-link nil)
  1368. ;; Configure the keywords in the TODO -> DONE sequence.
  1369. (setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  1370. ;; Track ids globally.
  1371. (setq org-id-track-globally t)
  1372. ;; Configure `org-babel' languages.
  1373. (org-babel-do-load-languages
  1374. 'org-babel-load-languages
  1375. '((C . t)))
  1376. ;; Log / Clock into property drawers.
  1377. (setq org-log-into-drawer t
  1378. org-clock-into-drawer t)
  1379. ;; Encrypt files with the public key.
  1380. (setq epa-file-select-keys 2
  1381. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1382. epa-cache-passphrase-for-symmetric-encryption t)
  1383. ;; TODO: Configure default structure templates.
  1384. ;; (require 'org-tempo)
  1385. ;; Apply custom keybindings.
  1386. (dotfiles/leader
  1387. "o" '(:ignore t :which-key "Org")
  1388. "oe" '(org-export-dispatch :which-key "Export")
  1389. "ot" '(org-babel-tangle :which-key "Tangle")
  1390. "oi" '(org-toggle-inline-images :which-key "Images")
  1391. "of" '(:ignore t :which-key "Footnotes")
  1392. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1393. #+END_SRC
  1394. ** Org Roam
  1395. #+NAME: emacs-org-roam-package
  1396. #+BEGIN_SRC nix
  1397. epkgs.org-roam
  1398. #+END_SRC
  1399. [[https://github.com/org-roam/org-roam][Org Roam]] is a plain-text knowledge management system. It borrows principles from the [[https://zettelkasten.de][Zettelkasten]] method, providing a solution for non-hierarchical note-taking. It should also work as a plug-and-play solution for anyone already using [[https://orgmode.org][Org Mode]] for their personal wiki.
  1400. #+NAME: emacs-org-roam-elisp
  1401. #+BEGIN_SRC emacs-lisp
  1402. ;; Setup `org-roam'.
  1403. (require 'org-roam)
  1404. ;; Silence the migration warnings.
  1405. (setq org-roam-v2-ack t)
  1406. ;; Enable `visual-line-mode' in `org-roam' buffer.
  1407. (add-hook 'org-roam-mode-hook
  1408. (lambda ()
  1409. (visual-line-mode +1)))
  1410. ;; Enable completion everywhere.
  1411. (setq org-roam-completion-everywhere t)
  1412. ;; Set the roam directories.
  1413. (setq org-roam-directory (expand-file-name "/etc/dotfiles")
  1414. org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
  1415. ;; Clear the deafult capture templates.
  1416. (setq org-roam-capture-templates '()
  1417. org-roam-dailies-capture-templates '())
  1418. ;; Override the default slug method.
  1419. (cl-defmethod org-roam-node-slug ((node org-roam-node))
  1420. (let ((title (org-roam-node-title node))
  1421. (slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
  1422. 769 ; U+0301 COMBINING ACUTE ACCENT
  1423. 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
  1424. 771 ; U+0303 COMBINING TILDE
  1425. 772 ; U+0304 COMBINING MACRON
  1426. 774 ; U+0306 COMBINING BREVE
  1427. 775 ; U+0307 COMBINING DOT ABOVE
  1428. 776 ; U+0308 COMBINING DIAERESIS
  1429. 777 ; U+0309 COMBINING HOOK ABOVE
  1430. 778 ; U+030A COMBINING RING ABOVE
  1431. 780 ; U+030C COMBINING CARON
  1432. 795 ; U+031B COMBINING HORN
  1433. 803 ; U+0323 COMBINING DOT BELOW
  1434. 804 ; U+0324 COMBINING DIAERESIS BELOW
  1435. 805 ; U+0325 COMBINING RING BELOW
  1436. 807 ; U+0327 COMBINING CEDILLA
  1437. 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
  1438. 814 ; U+032E COMBINING BREVE BELOW
  1439. 816 ; U+0330 COMBINING TILDE BELOW
  1440. 817 ; U+0331 COMBINING MACRON BELOW
  1441. )))
  1442. (cl-flet* ((nonspacing-mark-p (char)
  1443. (memq char slug-trim-chars))
  1444. (strip-nonspacing-marks (s)
  1445. (ucs-normalize-NFC-string
  1446. (apply #'string (seq-remove #'nonspacing-mark-p
  1447. (ucs-normalize-NFD-string s)))))
  1448. (cl-replace (title pair)
  1449. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1450. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
  1451. ("--*" . "-")
  1452. ("^-" . "")
  1453. ("-$" . "")))
  1454. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1455. (downcase slug)))))
  1456. ;; Configure capture templates.
  1457. ;; Standard document.
  1458. (add-to-list 'org-roam-capture-templates
  1459. '("d" "Default" plain "%?"
  1460. :target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
  1461. "
  1462. ,#+TITLE: ${title}
  1463. ,#+AUTHOR: Christopher James Hayward
  1464. ,#+EMAIL: chris@chrishayward.xyz
  1465. "
  1466. )
  1467. :unnarrowed t))
  1468. ;; Daily notes.
  1469. (add-to-list 'org-roam-dailies-capture-templates
  1470. '("d" "Default" entry "* %?"
  1471. :target (file+head "%<%Y-%m-%d>.org.gpg"
  1472. "
  1473. ,#+TITLE: %<%Y-%m-%d>
  1474. ,#+AUTHOR: Christopher James Hayward
  1475. ,#+EMAIL: chris@chrishayward.xyz
  1476. ")))
  1477. ;; Apply custom keybindings.
  1478. (dotfiles/leader
  1479. "or" '(:ignore t :which-key "Roam")
  1480. "ori" '(org-roam-node-insert :which-key "Insert")
  1481. "orf" '(org-roam-node-find :which-key "Find")
  1482. "orc" '(org-roam-capture :which-key "Capture")
  1483. "orb" '(org-roam-buffer-toggle :which-key "Buffer"))
  1484. ;; Apply custom keybindings for dailies.
  1485. (dotfiles/leader
  1486. "ord" '(:ignore t :which-key "Dailies")
  1487. "ordd" '(org-roam-dailies-goto-date :which-key "Date")
  1488. "ordt" '(org-roam-dailies-goto-today :which-key "Today")
  1489. "ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
  1490. "ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
  1491. ;; Run the setup command.
  1492. (org-roam-setup)
  1493. #+END_SRC
  1494. ** Org Roam UI
  1495. #+NAME: emacs-org-roam-ui-package
  1496. #+BEGIN_SRC nix
  1497. epkgs.org-roam-ui
  1498. epkgs.websocket
  1499. epkgs.simple-httpd
  1500. #+END_SRC
  1501. [[https://github.com/org-roam/org-roam-ui][Org Roam UI]] is a graphical frontend for exploring your [[https://github.com/org-roam/org-roam][Org Roam]] [[https://zettelkasten.de][Zettelkasten]]. It's meant as a successor to [[https://github.com/org-roam/org-roam-server][Org Roam Server]] that extends functionality of Org Roam with a web application that runs side-by-side with [[https://gnu.org/software/emacs/][Emacs]].
  1502. #+NAME: emacs-org-roam-ui-elisp
  1503. #+BEGIN_SRC emacs-lisp
  1504. ;; HACK: Set up `org-roam-ui'.
  1505. ;; (add-to-list 'load-path "~/.local/source/org-roam-ui")
  1506. (load-library "org-roam-ui")
  1507. ;; Configure `org-roam-ui'.
  1508. (setq org-roam-ui-follow t
  1509. org-roam-ui-sync-theme t
  1510. org-roam-ui-open-on-start t
  1511. org-roam-ui-update-on-save t
  1512. org-roam-ui-browser-function #'browse-url-firefox)
  1513. ;; Configure keybindings.
  1514. (dotfiles/leader
  1515. "oru" '(:ignore t :which-key "UI")
  1516. "oruu" '(org-roam-ui-mode :which-key "Toggle UI")
  1517. "orut" '(orui-sync-theme :which-key "Sync Theme"))
  1518. #+END_SRC
  1519. ** Org Drill
  1520. #+NAME: emacs-org-drill-package
  1521. #+BEGIN_SRC nix
  1522. epkgs.org-drill
  1523. #+END_SRC
  1524. [[https://orgmode.org/worg/org-contrib/org-drill.html][Org Drill]] is an extension for [[https://orgmode.org][Org Mode]] that uses a spaced repition algorithm to conduct interactive /Drill Sessions/ using Org files as sources of facts to be memorized.
  1525. #+NAME: emacs-org-drill-elisp
  1526. #+BEGIN_SRC emacs-lisp
  1527. ;; Exclude :drill: items from `org-roam'.
  1528. (setq org-roam-db-node-include-function
  1529. (defun dotfiles/org-roam-include ()
  1530. (not (member "drill" (org-get-tags)))))
  1531. ;; Configure keybindings for `org-drill'.
  1532. (dotfiles/leader
  1533. "od" '(:ignore t :which-key "Drill")
  1534. "odd" '(org-drill :which-key "Drill")
  1535. "odc" '(org-drill-cram :which-key "Cram")
  1536. "odr" '(org-drill-resume :which-key "Resume"))
  1537. #+END_SRC
  1538. ** Org Agenda
  1539. The way [[https://orgmode.org][Org Mode]] 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.
  1540. #+NAME: emacs-org-agenda-elisp
  1541. #+BEGIN_SRC emacs-lisp
  1542. ;; Configure `org-agenda' to use the project files.
  1543. (setq org-agenda-files '("/etc/dotfiles/"
  1544. "/etc/dotfiles/docs/"
  1545. "/etc/dotfiles/docs/daily/"))
  1546. ;; Include files encrypted with `gpg'.
  1547. (require 'org)
  1548. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1549. (setq org-agenda-file-regexp
  1550. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1551. org-agenda-file-regexp)))
  1552. ;; Open an agenda buffer with SPC o a.
  1553. (dotfiles/leader
  1554. "oa" '(org-agenda :which-key "Agenda"))
  1555. #+END_SRC
  1556. ** Org Pomodoro
  1557. #+NAME: emacs-pomodoro-package
  1558. #+BEGIN_SRC nix
  1559. epkgs.org-pomodoro
  1560. #+END_SRC
  1561. [[https://github.com/marcinkoziej/org-pomodoro][Org Pomodoro]] adds basic support for the [[https://en.wikipedia.org/wiki/Pomodoro_Technique][Pomodoro Technique]] in [[https://gnu.org/software/emacs/][GNU/Emacs]]. 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.
  1562. #+NAME: emacs-pomodoro-elisp
  1563. #+BEGIN_SRC emacs-lisp
  1564. ;; Configure `org-pomodor' with the overtime workflow.
  1565. (setq org-pomodoro-manual-break t
  1566. org-pomodoro-keep-killed-time t)
  1567. ;; Configure keybindings.
  1568. (dotfiles/leader
  1569. "op" '(org-pomodoro :which-key "Pomodoro"))
  1570. #+END_SRC
  1571. ** Writegood Mode
  1572. #+NAME: emacs-writegood-package
  1573. #+BEGIN_SRC nix
  1574. epkgs.writegood-mode
  1575. #+END_SRC
  1576. [[https://github.com/bnbeckwith/writegood-mode][Writegood Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] minor mode to aid in finding common writing problems. It highlights the text based on the following criteria:
  1577. + Weasel Words
  1578. + Passive Voice
  1579. + Duplicate Words
  1580. #+NAME: emacs-writegood-elisp
  1581. #+BEGIN_SRC emacs-lisp
  1582. ;; Configure `writegood-mode'.
  1583. (dotfiles/leader
  1584. "tg" '(writegood-mode :which-key "Grammar"))
  1585. #+END_SRC
  1586. ** Aspell
  1587. #+NAME: emacs-aspell-extras
  1588. #+BEGIN_SRC nix
  1589. pkgs.aspell
  1590. pkgs.aspellDicts.en
  1591. pkgs.aspellDicts.en-science
  1592. pkgs.aspellDicts.en-computers
  1593. #+END_SRC
  1594. [[https://aspell.net][GNU Aspell]] 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.
  1595. #+NAME: emacs-aspell-elisp
  1596. #+BEGIN_SRC emacs-lisp
  1597. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1598. (setq ispell-program-name "aspell"
  1599. ispell-eextra-args '("--sug-mode=fast"))
  1600. ;; Configure the built-in `flyspell-mode'.
  1601. (dotfiles/leader
  1602. "ts" '(flyspell-mode :which-key "Spelling"))
  1603. #+END_SRC
  1604. ** TexLive
  1605. [[https://wikipedia.org/wiki/Tex_Live][TeX Live]] is a free software distributution for the TeX typesetting system that includes major TeX-related programs, macro packages, and fonts. Since TeX Live consists of /thousands/ of packages, to make managing it easier, NixOS replicates the organization of Tex Live into /schemes/ and /collections/:
  1606. | Name | Derivation | Comment |
  1607. |---------+---------------------------------+------------------------------------------------------------|
  1608. | Full | texlive.combined.scheme-full | Contains every TeX Live package |
  1609. | Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
  1610. | Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
  1611. | Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
  1612. | Minimal | texlive.combined.scheme-minimal | Contains plain only |
  1613. #+NAME: emacs-texlive-extras
  1614. #+BEGIN_SRC nix
  1615. # pkgs.texlive.combined.scheme-full
  1616. #+END_SRC
  1617. ** Http
  1618. #+NAME: emacs-http-package
  1619. #+BEGIN_SRC nix
  1620. epkgs.ob-http
  1621. #+END_SRC
  1622. It's possible to make HTTP requests from Org Mode buffers using [[https://github.com/zweifisch/ob-http][ob-http]], this relies on Org Babel (included with [[https://orgmode.org][Org Mode]]) being present and configured properly.
  1623. #+NAME: emacs-http-elisp
  1624. #+BEGIN_SRC emacs-lisp
  1625. ;; Required to setup `ob-http'.
  1626. (org-babel-do-load-languages
  1627. 'org-babel-load-languages
  1628. '((http . t)))
  1629. #+END_SRC
  1630. ** Hugo
  1631. #+NAME: emacs-hugo-package
  1632. #+BEGIN_SRC nix
  1633. epkgs.ox-hugo
  1634. #+END_SRC
  1635. [[https://oxhugo.scripter.co][Ox Hugo]] is an [[https://orgmode.org][Org Mode]] exporter for [[https://gohugo.io][Hugo]] compabile markdown. My dotfiles are a result of this, and are available to view here https://chrishayward.xyz/dotfiles/.
  1636. #+NAME: emacs-hugo-elisp
  1637. #+BEGIN_SRC emacs-lisp
  1638. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  1639. (require 'ox-hugo)
  1640. ;; Set up the base directory.
  1641. (setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
  1642. ;; Capture templates.
  1643. ;; Shared content
  1644. ;; (add-to-list 'org-roam-capture-templates
  1645. ;; '("p" "Post" plain "%?"
  1646. ;; :target (file+head "docs/posts/${slug}.org.gpg"
  1647. ;; "
  1648. ;; ,#+TITLE: ${title}
  1649. ;; ,#+AUTHOR: Christopher James Hayward
  1650. ;; ,#+DATE: %<%Y-%m-%d>
  1651. ;; ,#+EXPORT_FILE_NAME: ${slug}
  1652. ;; ,#+OPTIONS: num:nil todo:nil tasks:nil
  1653. ;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  1654. ;; ,#+HUGO_BASE_DIR: ../
  1655. ;; ,#+HUGO_AUTO_SET_LASTMOD: t
  1656. ;; ,#+HUGO_SECTION: posts
  1657. ;; ,#+HUGO_DRAFT: true
  1658. ;; "
  1659. ;; )
  1660. ;; :unnarrowed t))
  1661. #+END_SRC
  1662. ** Passwords
  1663. #+NAME: emacs-pass-extras
  1664. #+BEGIN_SRC nix
  1665. pkgs.pass
  1666. #+END_SRC
  1667. With [[https://password-store.org][Pass]], each password lives inside of an encrypted [[https://gnupg.org][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.
  1668. #+NAME: emacs-pass-package
  1669. #+BEGIN_SRC nix
  1670. epkgs.password-store
  1671. #+END_SRC
  1672. Configure keybindings for passwords behind =SPC p=:
  1673. #+NAME: emacs-pass-elisp
  1674. #+BEGIN_SRC emacs-lisp
  1675. ;; Set the path to the password store.
  1676. (setq password-store-dir (expand-file-name "~/.password-store"))
  1677. ;; Apply custom keybindings.
  1678. (dotfiles/leader
  1679. "p" '(:ignore t :which-key "Passwords")
  1680. "pp" '(password-store-copy :which-key "Copy")
  1681. "pe" '(password-store-edit :which-key "Edit")
  1682. "pi" '(password-store-insert :which-key "Insert")
  1683. "pr" '(password-store-rename :which-key "Rename")
  1684. "pg" '(password-store-generate :which-key "Generate"))
  1685. #+END_SRC
  1686. ** Docker
  1687. #+NAME: emacs-docker-package
  1688. #+BEGIN_SRC nix
  1689. epkgs.docker
  1690. epkgs.dockerfile-mode
  1691. #+END_SRC
  1692. Manage Docker from inside of Emacs using [[https://github.com/Silex/docker.el][Docker.el]]. This is a full docker porcelain similar to Magit, allowing complete control of a Docker system. Add syntax highlighting to Dockerfiles using [[https://github.com/spotify/dockerfile-mode][dockerfile-mode]] from Spotify.
  1693. #+NAME: emacs-docker-elisp
  1694. #+BEGIN_SRC emacs-lisp
  1695. ;; Apply custom keybindings.
  1696. (dotfiles/leader
  1697. "n" '(:ignore t :which-key "Containers")
  1698. "nd" '(docker :which-key "Docker"))
  1699. #+END_SRC
  1700. ** MU4E
  1701. #+NAME: emacs-mu4e-extras
  1702. #+BEGIN_SRC nix
  1703. pkgs.mu
  1704. pkgs.isync
  1705. #+END_SRC
  1706. #+NAME: emacs-mu4e-package
  1707. #+BEGIN_SRC nix
  1708. epkgs.mu4e-alert
  1709. #+END_SRC
  1710. #+NAME: emacs-mu4e-config
  1711. #+BEGIN_SRC nix
  1712. # Deploy the authinfo file.
  1713. home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
  1714. # Deploy the isync configuration file.
  1715. home.file.".mbsyncrc" = {
  1716. text = ''
  1717. IMAPStore xyz-remote
  1718. Host mail.chrishayward.xyz
  1719. User chris@chrishayward.xyz
  1720. PassCmd "pass chrishayward.xyz/chris"
  1721. SSLType IMAPS
  1722. MaildirStore xyz-local
  1723. Path ~/.cache/mail/
  1724. Inbox ~/.cache/mail/inbox
  1725. SubFolders Verbatim
  1726. Channel xyz
  1727. Far :xyz-remote:
  1728. Near :xyz-local:
  1729. Patterns * !Archives
  1730. Create Both
  1731. Expunge Both
  1732. SyncState *
  1733. '';
  1734. };
  1735. #+END_SRC
  1736. #+BEGIN_SRC sh
  1737. mbsync -a
  1738. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  1739. mu index
  1740. #+END_SRC
  1741. #+NAME: emacs-mu4e-elisp
  1742. #+BEGIN_SRC emacs-lisp
  1743. ;; Add the `mu4e' shipped with `mu' to the load path.
  1744. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  1745. (require 'mu4e)
  1746. ;; Confiugure `mu4e'.
  1747. (setq mu4e-maildir "~/.cache/mail"
  1748. mu4e-update-interval (* 5 60)
  1749. mu4e-get-mail-command "mbsync -a"
  1750. mu4e-compose-format-flowed t
  1751. mu4e-change-filenames-when-moving t
  1752. mu4e-compose-signature (concat "Chris Hayward\n"
  1753. "chris@chrishayward.xyz"))
  1754. ;; Sign all outbound email with GPG.
  1755. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  1756. (setq message-send-mail-function 'smtpmail-send-it
  1757. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  1758. ;; Setup `mu4e' accounts.
  1759. (setq mu4e-contexts
  1760. (list
  1761. ;; Main
  1762. ;; chris@chrishayward.xyz
  1763. (make-mu4e-context
  1764. :name "Main"
  1765. :match-func
  1766. (lambda (msg)
  1767. (when msg
  1768. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  1769. :vars
  1770. '((user-full-name . "Christopher James Hayward")
  1771. (user-mail-address . "chris@chrishayward.xyz")
  1772. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  1773. (smtpmail-smtp-service . 587)
  1774. (smtpmail-stream-type . starttls)))))
  1775. ;; Setup `mu4e-alert'.
  1776. (setq mu4e-alert-set-default-style 'libnotify)
  1777. (mu4e-alert-enable-notifications)
  1778. (mu4e-alert-enable-mode-line-display)
  1779. ;; Open the `mu4e' dashboard.
  1780. (dotfiles/leader
  1781. "m" '(mu4e :which-key "Mail"))
  1782. #+END_SRC
  1783. ** Projectile
  1784. #+NAME: emacs-projectile-package
  1785. #+BEGIN_SRC nix
  1786. epkgs.projectile
  1787. #+END_SRC
  1788. [[https://projectile.mx][Projectile]] is a project interaction library for [[https://gnu.org/software/emacs/][GNU/Emacs]]. Its goal is to provide a nice set of features operating on a project level, without introducing external dependencies.
  1789. #+NAME: emacs-projectile-elisp
  1790. #+BEGIN_SRC emacs-lisp
  1791. ;; Configure the `projectile-project-search-path'.
  1792. (setq projectile-project-search-path '("~/.local/source"))
  1793. (projectile-mode +1)
  1794. #+END_SRC
  1795. ** LSP Mode
  1796. #+NAME: emacs-lsp-package
  1797. #+BEGIN_SRC nix
  1798. epkgs.lsp-mode
  1799. epkgs.lsp-ui
  1800. #+END_SRC
  1801. The [[https://microsoft.github.io/language-server-protocol][Language Server Protocol (LSP)]] defines the protocol used between an Editor or IDE, and a language server that provides features like:
  1802. + Auto Complete
  1803. + Go To Defintion
  1804. + Find All References
  1805. #+NAME: emacs-lsp-elisp
  1806. #+BEGIN_SRC emacs-lisp
  1807. ;; Configure `lsp-mode'.
  1808. (setq lsp-idle-delay 0.5
  1809. lsp-prefer-flymake t)
  1810. ;; Configure `lsp-ui'.
  1811. (setq lsp-ui-doc-position 'at-point
  1812. lsp-ui-doc-delay 0.5)
  1813. #+END_SRC
  1814. ** CCLS
  1815. #+NAME: emacs-ccls-package
  1816. #+BEGIN_SRC nix
  1817. epkgs.ccls
  1818. #+END_SRC
  1819. [[https://github.com/MaskRay/emacs-ccls][Emacs CCLS]] is a client for CCLS, a C/C++/Objective-C language server supporting multi-million line C++ code bases, powered by libclang.
  1820. #+NAME: emacs-ccls-elisp
  1821. #+BEGIN_SRC emacs-lisp
  1822. ;; Configure `ccls' to work with `lsp-mode'.
  1823. (defun dotfiles/ccls-hook ()
  1824. (require 'ccls)
  1825. (lsp))
  1826. ;; Configure `ccls' mode hooks.
  1827. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  1828. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  1829. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  1830. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  1831. #+END_SRC
  1832. ** Company Mode
  1833. #+NAME: emacs-company-package
  1834. #+BEGIN_SRC nix
  1835. epkgs.company
  1836. #+END_SRC
  1837. [[https://company-mode.github.io][Company Mode]] is a text completion framework for [[https://gnu.org/software/emacs/][GNU/Emacs]]. The name stands for =Complete Anything=. It uses pluggable back-ends and front-ends to retieve and display completion candidates.
  1838. #+NAME: emacs-company-elisp
  1839. #+BEGIN_SRC emacs-lisp
  1840. ;; Configure `company-mode'.
  1841. (setq company-backend 'company-capf
  1842. lsp-completion-provider :capf)
  1843. ;; Enable it globally.
  1844. (global-company-mode +1)
  1845. #+END_SRC
  1846. ** Go Mode
  1847. #+NAME: emacs-golang-package
  1848. #+BEGIN_SRC nix
  1849. epkgs.go-mode
  1850. #+END_SRC
  1851. [[https://emacswiki.org/emacs/GoMode][Go Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] major mode for editing [[https://golang.org][Golang]] source code.
  1852. #+NAME: emacs-golang-elisp
  1853. #+BEGIN_SRC emacs-lisp
  1854. ;; Configure `go-mode' to work with `lsp-mode'.
  1855. (defun dotfiles/go-hook ()
  1856. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  1857. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  1858. ;; Configure a custom `before-save-hook'.
  1859. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  1860. #+END_SRC
  1861. ** Rustic
  1862. #+NAME: emacs-rustic-package
  1863. #+BEGIN_SRC nix
  1864. epkgs.rustic
  1865. #+END_SRC
  1866. Rustic is a fork of Rust Mode that integrates well with the [[https://microsoft.github.io/language-server-protocol][Language Server Protocol (LSP)]]. Include the rust shell before launching [[https://gnu.org/software/emacs/][GNU/Emacs]] to use this!
  1867. #+NAME: emacs-rustic-elisp
  1868. #+BEGIN_SRC emacs-lisp
  1869. ;; Configure `rustic' with `lsp-mode'.
  1870. (setq rustic-format-on-save t
  1871. rustic-lsp-server 'rls)
  1872. #+END_SRC
  1873. ** Python Mode
  1874. #+NAME: emacs-python-package
  1875. #+BEGIN_SRC nix
  1876. epkgs.pretty-mode
  1877. #+END_SRC
  1878. The built in [[https://emacswiki.org/emacs/PythonProgrammingInEmacs][Python Mode]] has a nice feature set for working with [[https://python.org][Python]] code in [[https://gnu.org/software/emacs/][GNU/Emacs]]. It is complimented with the addition of a [[https://microsoft.github.io/language-server-protocol][Language Server Protocol (LSP)]] server. These tools are included in the Development Shell for Python.
  1879. #+NAME: emacs-python-elisp
  1880. #+BEGIN_SRC emacs-lisp
  1881. ;; Configure `pretty-mode' to work with `python-mode'.
  1882. (add-hook 'python-mode-hook
  1883. (lambda ()
  1884. (turn-on-pretty-mode)))
  1885. #+END_SRC
  1886. ** Protobuf Mode
  1887. #+NAME: emacs-protobuf-package
  1888. #+BEGIN_SRC nix
  1889. epkgs.protobuf-mode
  1890. #+END_SRC
  1891. ** PlantUML
  1892. #+NAME: emacs-plantuml-extras
  1893. #+BEGIN_SRC nix
  1894. pkgs.plantuml
  1895. #+END_SRC
  1896. [[https://plantuml.com][PlantUML]] is an open-source tool allowing users to create diagrams from a plain-text language. Besides various UML diagrams, PlantUML has support for various other software developmented related formats, as well as visualizations of =JSON= and =YAML= files.
  1897. #+NAME: emacs-plantuml-package
  1898. #+BEGIN_SRC nix
  1899. epkgs.plantuml-mode
  1900. #+END_SRC
  1901. [[https://github.com/skuro/plantuml-mode][PlantUML Mode]] is a major mode for editing [[https://plantuml.com][PlantUML]] sources in [[https://gnu.org/software/emacs/][GNU/Emacs]].
  1902. #+NAME: emacs-plantuml-elisp
  1903. #+BEGIN_SRC emacs-lisp
  1904. ;; Configure `plantuml-mode'.
  1905. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  1906. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  1907. (setq plantuml-default-exec-mode 'executable
  1908. org-plantuml-exec-mode 'plantuml)
  1909. #+END_SRC
  1910. ** Swiper
  1911. #+NAME: emacs-swiper-package
  1912. #+BEGIN_SRC nix
  1913. epkgs.ivy
  1914. epkgs.counsel
  1915. epkgs.ivy-rich
  1916. epkgs.ivy-posframe
  1917. epkgs.ivy-prescient
  1918. #+END_SRC
  1919. [[https://github.com/abo-abo/swiper][Ivy (Swiper)]] is a generic completion mechanism for [[https://gnu.org/software/emacs/][GNU/Emacs]]. 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.
  1920. #+NAME: emacs-swiper-elisp
  1921. #+BEGIN_SRC emacs-lisp
  1922. ;; Configure `ivy'.
  1923. (setq counsel-linux-app-format-function
  1924. #'counsel-linux-app-format-function-name-only)
  1925. (ivy-mode +1)
  1926. (counsel-mode +1)
  1927. ;; Configure `ivy-rich'.
  1928. (ivy-rich-mode +1)
  1929. ;; Configure `ivy-posframe'.
  1930. (setq ivy-posframe-parameters '((parent-frame nil))
  1931. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  1932. (ivy-posframe-mode +1)
  1933. ;; Configure `ivy-prescient'.
  1934. (setq ivy-prescient-enable-filtering nil)
  1935. (ivy-prescient-mode +1)
  1936. #+END_SRC
  1937. ** Transparency
  1938. It's possible to control the frame opacity in [[https://gnu.org/software/emacs/][GNU/Emacs]]. Unlike other transparency hacks, it's not merely showing the desktop background image, but is true transparency -- you can see other windows behind the Emacs window.
  1939. #+NAME: emacs-transparency-elisp
  1940. #+BEGIN_SRC emacs-lisp
  1941. ;; Configure the default frame transparency.
  1942. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  1943. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  1944. #+END_SRC
  1945. ** Desktop Environment
  1946. #+NAME: emacs-desktop-extras
  1947. #+BEGIN_SRC nix
  1948. pkgs.brightnessctl
  1949. #+END_SRC
  1950. The [[https://github.com/DamienCassou/desktop-environment][Desktop Environment]] package provides commands and a global minor mode for controlling your [[https://linux.org][GNU/Linux]] desktop from within [[https://gnu.org/software/emacs/][GNU/Emacs]].
  1951. #+NAME: emacs-desktop-package
  1952. #+BEGIN_SRC nix
  1953. epkgs.desktop-environment
  1954. #+END_SRC
  1955. 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.
  1956. #+NAME: emacs-desktop-elisp
  1957. #+BEGIN_SRC emacs-lisp
  1958. ;; Configure `desktop-environment'.
  1959. (require 'desktop-environment)
  1960. (desktop-environment-mode +1)
  1961. #+END_SRC
  1962. ** Doom Themes
  1963. #+NAME: emacs-doom-themes-package
  1964. #+BEGIN_SRC nix
  1965. epkgs.doom-themes
  1966. #+END_SRC
  1967. [[https://github.com/hlissner/emacs-doom-themes][Doom Themes]] is a theme megapack for [[https://gnu.org/software/emacs/][GNU/Emacs]], inspired by community favourites.
  1968. #+NAME: emacs-doom-themes-elisp
  1969. #+BEGIN_SRC emacs-lisp
  1970. ;; Include modern themes from `doom-themes'.
  1971. (setq doom-themes-enable-bold t
  1972. doom-themes-enable-italic t)
  1973. ;; Load the `doom-nord' and `doom-nord-light' themes.
  1974. ;; (load-theme 'doom-nord-light t)
  1975. (load-theme 'doom-nord t)
  1976. ;; Define a method for returning information about the current theme.
  1977. ;; This is based off the function `org-roam-ui-get-theme'.
  1978. (defun dotfiles/theme ()
  1979. "Return information about the current theme."
  1980. (list `(bg . ,(face-background hl-line-face))
  1981. `(bg-alt . ,(face-background 'default))
  1982. `(fg . ,(face-foreground 'default))
  1983. `(fg-alt . ,(face-foreground font-lock-comment-face))
  1984. `(red . ,(face-foreground 'error))
  1985. `(orange . ,(face-foreground 'warning))
  1986. `(yellow . ,(face-foreground font-lock-builtin-face))
  1987. `(green . ,(face-foreground 'success))
  1988. `(cyan . ,(face-foreground font-lock-constant-face))
  1989. `(blue . ,(face-foreground font-lock-keyword-face))
  1990. `(violet . ,(face-foreground font-lock-constant-face))
  1991. `(magenta . ,(face-foreground font-lock-preprocessor-face))))
  1992. ;; Load a new theme with <SPC> t t.
  1993. (dotfiles/leader
  1994. "tt" '(counsel-load-theme :which-key "Theme"))
  1995. #+END_SRC
  1996. Create a shell command that returns a JSON string of the current theme in the following format:
  1997. #+BEGIN_SRC json
  1998. {
  1999. "bg": "#272C36",
  2000. "bg-alt": "#2E3440",
  2001. "fg": "#ECEFF4",
  2002. "fg-alt": "#6f7787",
  2003. "red": "#BF616A",
  2004. "orange": "#EBCB8B",
  2005. "yellow": "#81A1C1",
  2006. "green": "#A3BE8C",
  2007. "cyan": "#81A1C1",
  2008. "blue": "#81A1C1",
  2009. "violet": "#81A1C1",
  2010. "magenta": "#81A1C1"
  2011. }
  2012. #+END_SRC
  2013. #+NAME: emacs-doom-themes-extras
  2014. #+BEGIN_SRC nix
  2015. (pkgs.writeShellScriptBin "dotfiles-theme" ''
  2016. ${myEmacs}/bin/emacsclient --no-wait --eval '(json-encode (dotfiles/theme))' | sed "s/\\\\//g" | sed -e 's/^"//' -e 's/"$//'
  2017. '')
  2018. #+END_SRC
  2019. ** Doom Modeline
  2020. #+NAME: emacs-doom-modeline-package
  2021. #+BEGIN_SRC nix
  2022. epkgs.doom-modeline
  2023. #+END_SRC
  2024. [[https://github.com/seagle0128/doom-modeline][Doom Modeline]] is a fancy and fast modeline inspired by minimalism design. It's integrated into Centaur Emacs, Doom Emacs, and Spacemacs.
  2025. #+NAME: emacs-doom-modeline-elisp
  2026. #+BEGIN_SRC emacs-lisp
  2027. ;; Configure `doom-modeline'.
  2028. (require 'doom-modeline)
  2029. (setq doom-modeline-height 16
  2030. doom-modeline-icon t)
  2031. ;; Launch after initialization.
  2032. (add-hook 'after-init-hook 'doom-modeline-mode)
  2033. ;; Define a modeline segment to show the workspace information.
  2034. (doom-modeline-def-segment dotfiles/workspaces
  2035. (exwm-workspace--update-switch-history)
  2036. (concat
  2037. (doom-modeline-spc)
  2038. (elt (let* ((num (exwm-workspace--count))
  2039. (sequence (number-sequence 0 (1- num)))
  2040. (not-empty (make-vector num nil)))
  2041. (dolist (i exwm--id-buffer-alist)
  2042. (with-current-buffer (cdr i)
  2043. (when exwm--frame
  2044. (setf (aref not-empty
  2045. (exwm-workspace--position exwm--frame))
  2046. t))))
  2047. (mapcar
  2048. (lambda (i)
  2049. (mapconcat
  2050. (lambda (j)
  2051. (format (if (= i j) "[%s]" " %s ")
  2052. (propertize
  2053. (apply exwm-workspace-index-map (list j))
  2054. 'face
  2055. (cond ((frame-parameter (elt exwm-workspace--list j)
  2056. 'exwm-urgency)
  2057. '(:inherit warning :weight bold))
  2058. ((= i j) '(:inherit underline :weight bold))
  2059. ((aref not-empty j) '(:inherit success :weight bold))
  2060. (t `((:foreground ,(face-foreground 'mode-line-inactive))))))))
  2061. sequence ""))
  2062. sequence))
  2063. (exwm-workspace--position (selected-frame)))))
  2064. ;; Define a custom modeline to override the default.
  2065. (doom-modeline-def-modeline 'dotfiles/modeline
  2066. '(bar workspace-name dotfiles/workspaces window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info)
  2067. '(objed-state misc-info persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
  2068. ;; Define a method to load the modeline.
  2069. (defun dotfiles/load-modeline ()
  2070. "Load the default modeline."
  2071. (doom-modeline-set-modeline 'dotfiles/modeline 'default))
  2072. ;; Enable `doom-modeline'.
  2073. (add-hook 'doom-modeline-mode-hook 'dotfiles/load-modeline)
  2074. (doom-modeline-mode +1)
  2075. (doom-modeline-set-modeline 'dotfiles/modeline 'default)
  2076. #+END_SRC
  2077. * Footnotes