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.

3286 lines
103 KiB

3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
1 year ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1 year ago
1 year ago
1 year 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 year 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. #+STARTUP: hideblocks
  10. #+EXPORT_FILE_NAME: dotfiles
  11. #+HUGO_BASE_DIR: docs
  12. #+HUGO_AUTO_SET_LASTMOD: t
  13. #+HUGO_SECTION:
  14. #+HUGO_DRAFT: false
  15. #+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>
  16. #+HTML: <a href="https://www.gnu.org/software/emacs/"><img src="https://img.shields.io/badge/Emacs-29.1-blueviolet.svg?style=flat-square&logo=GNU%20Emacs&logoColor=white"></a>
  17. #+HTML: <a href="https://orgmode.org"><img src="https://img.shields.io/badge/Org-9.6.12-%2377aa99?style=flat-square&logo=org&logoColor=white"></a>
  18. #+NAME: description
  19. #+BEGIN_SRC text
  20. Immutable NixOS dotfiles.
  21. #+END_SRC
  22. #+ATTR_ORG: :width 800px
  23. #+ATTR_HTML: :width 800px
  24. #+ATTR_LATEX: :width 800px
  25. [[./docs/images/desktop.png]]
  26. Built for Life, Liberty, and the Open Road.
  27. + 100% Immutable
  28. + 100% Declarative
  29. + 100% Reproducible
  30. * Introduction
  31. 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.
  32. #+NAME: file-warning
  33. #+BEGIN_SRC text
  34. This file is controlled by /etc/dotfiles/README.org
  35. #+END_SRC
  36. ** Getting Started
  37. 1) [[https://nixos.org/download.html][Download the latest version of NixOS]]
  38. 2) [[https://nixos.org/manual/nixos/stable/#sec-installation-partitioning][Partition your drives and mount the file system]]
  39. 3) Clone the project ~git clone git@git.chrishayward.xyz:chris/dotfiles /mnt/etc/dotfiles~
  40. 4) Load the default shell ~nix develop /mnt/etc/dotfiles~
  41. 5) Install the system ~sudo nixos-install --impure --flake /mnt/etc/dotfiles#nixos~
  42. 6) Reboot, login and start a graphical system ~startx~
  43. ** Making Changes
  44. 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:
  45. #+NAME: rebuild-command-table
  46. | Command | Description |
  47. |----------+---------------------------------------------------------------------------------|
  48. | boot | Build the new configuration and make it the boot default, without activation |
  49. | test | Build and activate the new configuration, without adding it to the boot menu |
  50. | switch | Build and activate the new configuration, making it the new boot default |
  51. | build | Build the new configuration, without activation, nor adding it to the boot menu |
  52. | build-vm | Build a script that starts a virtual machine with the desired configuration |
  53. After making changes to the configuration the ~switch~ command will build and activate a new configuration.
  54. #+BEGIN_SRC shell
  55. # Build and activate a new configuration.
  56. sudo nixos-rebuild switch --flake $FLAKE#$HOSTNAME
  57. #+END_SRC
  58. 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.
  59. #+BEGIN_SRC shell
  60. # Rollback to the previous generation.
  61. sudo nixos-rebuild switch --rollback
  62. #+END_SRC
  63. ** Docker Container
  64. 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.
  65. Install from the command line: ~docker pull ghcr.io/chayward1/dotfiles:main~
  66. #+BEGIN_SRC dockerfile :tangle Dockerfile :noweb yes
  67. # <<file-warning>>
  68. # Derive from the official image.
  69. FROM nixos/nix
  70. # Setup the default environment.
  71. WORKDIR /etc/dotfiles
  72. COPY . .
  73. # Load the default system shell.
  74. RUN nix-shell /etc/dotfiles/shell.nix
  75. #+END_SRC
  76. * Operating System
  77. #+ATTR_ORG: :width 400px
  78. #+ATTR_HTML: :width 400px
  79. #+ATTR_LATEX: :width 400px
  80. [[./docs/images/nixos.png]]
  81. [[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.
  82. #+BEGIN_SRC nix :noweb yes :tangle flake.nix
  83. # <<file-warning>>
  84. {
  85. description = "<<description>>";
  86. inputs = {
  87. <<os-nixpkgs>>
  88. <<os-flake-utils>>
  89. <<os-home-manager>>
  90. <<os-emacs-overlay>>
  91. <<os-nixos-hardware>>
  92. };
  93. outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, ... }: {
  94. <<host-configurations>>
  95. } //
  96. <<development-shells>>
  97. }
  98. #+END_SRC
  99. ** Nixpkgs
  100. [[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:
  101. 1) The current stable release
  102. 2) The Unstable branch following the latest development
  103. #+NAME: os-nixpkgs
  104. #+BEGIN_SRC nix
  105. nixpkgs.url = "nixpkgs/nixos-unstable";
  106. nixpkgs-unstable.url = "nixpkgs/master";
  107. #+END_SRC
  108. ** Flake Utils
  109. [[https://github.com/numtide/flake-utils][Flake Utils]] is a collection of pure Nix functions that don't depend on Nixpkgs, and that are useful in the context of writing other Nix Flakes.
  110. #+NAME: os-flake-utils
  111. #+BEGIN_SRC nix
  112. flake-utils.url = "github:numtide/flake-utils";
  113. #+END_SRC
  114. ** Home Manager
  115. [[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.
  116. #+NAME: os-home-manager
  117. #+BEGIN_SRC nix
  118. home-manager.url = "github:nix-community/home-manager";
  119. home-manager.inputs.nixpkgs.follows = "nixpkgs";
  120. #+END_SRC
  121. ** Emacs Overlay
  122. 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.
  123. #+NAME: os-emacs-overlay
  124. #+BEGIN_SRC nix
  125. emacs-overlay.url = "github:nix-community/emacs-overlay";
  126. #+END_SRC
  127. ** NixOS Hardware
  128. [[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.
  129. #+NAME: os-nixos-hardware
  130. #+BEGIN_SRC nix
  131. nixos-hardware.url = "github:nixos/nixos-hardware";
  132. #+END_SRC
  133. * Development Shells
  134. The command ~nix develop~ will run a bash shell that provides the build environment of a derivation. It's an experimental replacement for the ~nix-shell~ command that is compliant with Nix Flakes. It provides an interactive build environment nearly identical to what Nix would use to build /installable/. Inside this shell, environment variables and shell functions are set up so that you can interactively and incrementally build your package(s).
  135. #+NAME: development-shells
  136. #+BEGIN_SRC nix
  137. inputs.flake-utils.lib.eachDefaultSystem (system:
  138. let
  139. pkgs = inputs.nixpkgs.legacyPackages.${system};
  140. in
  141. rec {
  142. devShells = {
  143. default = import ./shell.nix { inherit pkgs; };
  144. cc = import ./shells/cc.nix { inherit pkgs; };
  145. go = import ./shells/go.nix { inherit pkgs; };
  146. dart = import ./shells/dart.nix { inherit pkgs; };
  147. grpc = import ./shells/grpc.nix { inherit pkgs; };
  148. java = import ./shells/java.nix { inherit pkgs; };
  149. node = import ./shells/node.nix { inherit pkgs; };
  150. python = import ./shells/python.nix { inherit pkgs; };
  151. rust = import ./shells/rust.nix { inherit pkgs; };
  152. };
  153. }
  154. );
  155. #+END_SRC
  156. ** Nix
  157. #+ATTR_ORG: :width 300px
  158. #+ATTR_HTML: :width 300px
  159. #+ATTR_LATEX: :width 300px
  160. [[./docs/images/nix.png]]
  161. This shell adds a version of the ~nix~ command that is pre-configured to support Flakes. Flakes are the unit for packaging Nix code in a reproducible and discoverable way. They can have dependencies on other flakes, making it possible to have multi-repository Nix projects. A flake is a filesystem tree that contains a file named =flake.nix=. It specifies some metadata about the flake such as dependencies (inputs), as well as the values such as packages or modules (outputs).
  162. Import this shell with ~nix develop $DOTFILES~
  163. #+BEGIN_SRC nix :noweb yes :tangle shell.nix
  164. # <<file-warning>>
  165. { pkgs ? import <nixpkgs> { } }:
  166. with pkgs;
  167. let
  168. myNix = writeShellScriptBin "nix" ''
  169. exec ${nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
  170. '';
  171. in mkShell {
  172. buildInputs = [
  173. git
  174. myNix
  175. ];
  176. shellHook = ''
  177. export DOTFILES="$(pwd)"
  178. '';
  179. }
  180. #+END_SRC
  181. ** Go
  182. #+ATTR_ORG: :width 400px
  183. #+ATTR_HTML: :width 400px
  184. #+ATTR_LATEX: :width 400px
  185. [[./docs/images/golang.png]]
  186. #+BEGIN_SRC go
  187. package main
  188. import "fmt"
  189. func main() {
  190. fmt.Println("Hello, world!")
  191. }
  192. #+END_SRC
  193. [[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.
  194. Import this shell with ~nix develop $DOTFILES#go~
  195. #+BEGIN_SRC nix :noweb yes :tangle shells/go.nix
  196. # <<file-warning>>
  197. { pkgs ? import <nixpkgs> { } }:
  198. with pkgs;
  199. mkShell {
  200. buildInputs = [
  201. go
  202. gopls
  203. protoc-gen-go
  204. protoc-gen-go-grpc
  205. ];
  206. shellHook = ''
  207. export GO111MODULE=on
  208. export GOPATH=$XDG_DATA_HOME/go
  209. export PATH=$GOPATH/bin:$PATH
  210. '';
  211. }
  212. #+END_SRC
  213. ** Dart
  214. #+ATTR_ORG: :width 400px
  215. #+ATTR_HTML: :width 400px
  216. #+ATTR_LATEX: :width 400px
  217. [[./docs/images/dart.png]]
  218. [[https://dart.dev][Dart]] is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can be used to build server and desktop applications. It is an object-oriented, class-based, garbage-collected language with C-style syntax.
  219. Import this shell with ~nix develop $DOTFILES#dart~
  220. #+BEGIN_SRC nix :noweb yes :tangle shells/dart.nix
  221. #<<file-warning>>
  222. { pkgs ? import <nixpkgs> { } }:
  223. with pkgs;
  224. mkShell {
  225. buildInputs = [
  226. dart
  227. flutter
  228. ];
  229. shellHook = ''
  230. export FLUTTER_SDK_DIR=${flutter}/bin/cache/dart-sdk/
  231. export PATH="$HOME/.pub-cache/bin":"$PATH"
  232. '';
  233. }
  234. #+END_SRC
  235. ** Rust
  236. #+ATTR_ORG: :width 400px
  237. #+ATTR_HTML: :width 400px
  238. #+ATTR_LATEX: :width 400px
  239. [[./docs/images/rust.png]]
  240. #+BEGIN_SRC rust
  241. fn main() {
  242. println!("Hello, world!");
  243. }
  244. #+END_SRC
  245. [[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
  246. counting is optional.
  247. Import this shell with ~nix develop $DOTFILES#rust~
  248. #+BEGIN_SRC nix :noweb yes :tangle shells/rust.nix
  249. # <<file-warning>>
  250. { pkgs ? import <nixpkgs> { } }:
  251. with pkgs;
  252. mkShell {
  253. buildInputs = [
  254. rustup
  255. ];
  256. shellHook = ''
  257. export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
  258. export CARGO_HOME="$XDG_DATA_HOME/cargo"
  259. export PATH="$CARGO_HOME/bin:$PATH"
  260. '';
  261. }
  262. #+END_SRC
  263. ** Node
  264. #+ATTR_ORG: :width 400px
  265. #+ATTR_HTML: :width 400px
  266. #+ATTR_LATEX: :width 400px
  267. [[./docs/images/node.png]]
  268. #+BEGIN_SRC js
  269. var http = require('http');
  270. http.createServer((req, res) => {
  271. res.WriteHead(200, { 'Content-Type': 'text/html' });
  272. res.end('Hello, world!');
  273. });
  274. #+END_SRC
  275. [[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.
  276. Import this shell with ~nix develop $DOTFILES#node~
  277. #+BEGIN_SRC nix :noweb yes :tangle shells/node.nix
  278. # <<file-warning>>
  279. { pkgs ? import <nixpkgs> { } }:
  280. with pkgs;
  281. mkShell {
  282. buildInputs = [
  283. nodejs
  284. yarn
  285. ];
  286. shellHook = ''
  287. export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
  288. export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
  289. export NPM_CACHE_PREFIX="$XDG_CACHE_HOME/npm"
  290. export PATH="$(yarn global bin):$PATH"
  291. '';
  292. }
  293. #+END_SRC
  294. ** Java
  295. #+ATTR_ORG: :width 300px
  296. #+ATTR_HTML: :width 300px
  297. #+ATTR_LATEX: :width 300px
  298. [[./docs/images/java.png]]
  299. #+BEGIN_SRC java
  300. class Program {
  301. public static void main(String[] args) {
  302. System.out.println("Hello, world!");
  303. }
  304. }
  305. #+END_SRC
  306. [[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.
  307. Import this shell with ~nix develop $DOTFILES#java~
  308. #+BEGIN_SRC nix :noweb yes :tangle shells/java.nix
  309. # <<file-warning>>
  310. { pkgs ? import <nixpkgs> { } }:
  311. with pkgs;
  312. mkShell {
  313. buildInputs = [
  314. jre8
  315. jdk8
  316. ];
  317. shellHook = ''
  318. '';
  319. }
  320. #+END_SRC
  321. ** gRPC
  322. #+ATTR_ORG: :width 300px
  323. #+ATTR_HTML: :width 300px
  324. #+ATTR_LATEX: :width 300px
  325. [[./docs/images/grpc.png]]
  326. #+BEGIN_SRC protobuf
  327. service Greeter {
  328. rpc SayHello (HelloRequest) returns (HelloResponse);
  329. }
  330. message HelloRequest { string name = 1; }
  331. message HelloResponse { string response = 1; }
  332. #+END_SRC
  333. [[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.
  334. Import this shell with ~nix develop $DOTFILES#grpc~
  335. #+BEGIN_SRC nix :noweb yes :tangle shells/grpc.nix
  336. # <<file-warning>>
  337. { pkgs ? import <nixpkgs> { } }:
  338. with pkgs;
  339. mkShell {
  340. buildInputs = [
  341. buf
  342. grpc
  343. grpcui
  344. grpcurl
  345. grpc-tools
  346. grpc-gateway
  347. ];
  348. shellHook = ''
  349. '';
  350. }
  351. #+END_SRC
  352. ** C/C++
  353. #+ATTR_ORG: :width 300px
  354. #+ATTR_HTML: :width 300px
  355. #+ATTR_LATEX: :width 300px
  356. [[./docs/images/cc.png]]
  357. #+BEGIN_SRC c++
  358. #include <iostream>
  359. int main() {
  360. std::cout << "Hello, world!\n";
  361. return 0;
  362. }
  363. #+END_SRC
  364. [[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.
  365. Import this shell with ~nix develop $DOTFILES#cc~
  366. #+BEGIN_SRC nix :noweb yes :tangle shells/cc.nix
  367. # <<file-warning>>
  368. { pkgs ? import <nixpkgs> { } }:
  369. with pkgs;
  370. mkShell {
  371. buildInputs = [
  372. gdb
  373. ccls
  374. cmake
  375. boost
  376. gnumake
  377. gcc-unwrapped
  378. ];
  379. shellHook = ''
  380. '';
  381. }
  382. #+END_SRC
  383. ** Python
  384. #+ATTR_ORG: :width 400px
  385. #+ATTR_HTML: :width 400px
  386. #+ATTR_LATEX: :width 400px
  387. [[./docs/images/python.png]]
  388. #+BEGIN_SRC python
  389. print("Hello, world!")
  390. #+END_SRC
  391. [[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.
  392. Import this shell with ~nix develop $DOTFILES#python~
  393. #+BEGIN_SRC nix :noweb yes :tangle shells/python.nix
  394. # <<file-warning>>
  395. { pkgs ? import <nixpkgs> { } }:
  396. with pkgs;
  397. mkShell {
  398. buildInputs = [
  399. python310Packages.pip
  400. python310Packages.pip-tools
  401. # python310Packages.python-lsp-black #TODO: Marked broken.
  402. # python310Packages.python-lsp-server #TODO: Marked broken.
  403. # python310Packages.python-lsp-jsonrpc #TODO: Marked broken.
  404. ];
  405. shellHook = ''
  406. '';
  407. }
  408. #+END_SRC
  409. * Host Configurations
  410. [[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.
  411. #+NAME: host-configurations
  412. #+BEGIN_SRC nix :noweb yes
  413. nixosConfigurations = {
  414. <<host-default>>
  415. };
  416. #+END_SRC
  417. ** Shared
  418. NixOS makes it easier to share common configurations amongst all of the hosts, such as with pre-configured wireless networking:
  419. #+NAME: host-config-wifi
  420. #+BEGIN_SRC nix
  421. networking.wireless.networks = {
  422. MyWiFi_5C1870 = {
  423. priority = 2;
  424. pskRaw = "409b3c85fef1c5737f284d2f82f20dc6023e41804e862d4fa26265ef8193b326";
  425. };
  426. SM-G975W3034 = {
  427. priority = 1;
  428. pskRaw = "74835d96a98ca2c56ffe4eaf92223f8a555168b59ec2bb22b1e46b2a333adc80";
  429. };
  430. };
  431. #+END_SRC
  432. 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:
  433. #+NAME: host-config-home
  434. #+BEGIN_SRC nix
  435. networking.hosts = {
  436. # "192.168.3.105" = [ "gamingpc" ];
  437. # "192.168.3.163" = [ "acernitro" ];
  438. # "192.168.3.182" = [ "raspberry" ];
  439. # "192.168.3.183" = [ "homecloud" ];
  440. };
  441. #+END_SRC
  442. 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.
  443. #+NAME: host-config-ssh
  444. #+BEGIN_SRC nix
  445. users.users.chris.openssh.authorizedKeys.keys = [
  446. "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4wka/LfG3pto15DIm9LIRbb6rWr7/ipCRiCdAKSlY4 chris@chrishayward.xyz"
  447. ];
  448. #+END_SRC
  449. ** Default
  450. 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.
  451. #+NAME: host-default
  452. #+BEGIN_SRC nix :noweb yes
  453. nixos = nixpkgs.lib.nixosSystem {
  454. system = "x86_64-linux";
  455. specialArgs = { inherit inputs; };
  456. modules = [
  457. ./hosts/nixos
  458. <<module-x11>>
  459. <<module-xdg>>
  460. <<module-ssh>>
  461. <<module-hugo>>
  462. <<module-docker>>
  463. <<module-flakes>>
  464. <<module-cachix>>
  465. <<module-firefox>>
  466. <<module-home-manager>>
  467. ];
  468. };
  469. #+END_SRC
  470. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#nixos~.
  471. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/default.nix
  472. # <<file-warning>>
  473. { config, ... }:
  474. {
  475. imports = [
  476. ./configuration.nix
  477. ./hardware.nix
  478. ];
  479. modules.x11.enable = true;
  480. modules.xdg.enable = true;
  481. modules.ssh.enable = true;
  482. modules.hugo.enable = true;
  483. modules.flakes.enable = true;
  484. modules.cachix.enable = true;
  485. modules.docker.enable = true;
  486. modules.firefox.enable = true;
  487. }
  488. #+END_SRC
  489. *** Configuration
  490. 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.
  491. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/configuration.nix
  492. # <<file-warning>>
  493. { config, pkgs, inputs, ... }:
  494. {
  495. time.timeZone = "America/Toronto";
  496. networking.hostName = "nixos";
  497. networking.useDHCP = false;
  498. networking.firewall.enable = false;
  499. networking.interfaces.ens3.useDHCP = true;
  500. <<host-config-home>>
  501. <<host-config-ssh>>
  502. programs.mtr.enable = true;
  503. programs.fish.enable = true;
  504. programs.gnupg.agent.enable = true;
  505. users.users.chris = {
  506. shell = pkgs.fish;
  507. isNormalUser = true;
  508. extraGroups = [ "wheel" ];
  509. };
  510. system.stateVersion = "23.05";
  511. }
  512. #+END_SRC
  513. *** Hardware
  514. 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.
  515. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/hardware.nix
  516. # <<file-warning>>
  517. { config, lib, pkgs, modulesPath, ... }:
  518. {
  519. imports =
  520. [ (modulesPath + "/profiles/qemu-guest.nix")
  521. ];
  522. boot.initrd.availableKernelModules = [ "ata_piix" "floppy" "sd_mod" "sr_mod" ];
  523. boot.initrd.kernelModules = [ ];
  524. boot.kernelModules = [ ];
  525. boot.extraModulePackages = [ ];
  526. boot.loader.grub.enable = true;
  527. boot.loader.grub.device = "/dev/sda";
  528. fileSystems."/" =
  529. { device = "/dev/disk/by-label/nixos";
  530. fsType = "ext4";
  531. };
  532. swapDevices =
  533. [ { device = "/dev/disk/by-label/swap"; }
  534. ];
  535. }
  536. #+END_SRC
  537. * Module Definitions
  538. 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.
  539. ** X11
  540. #+NAME: module-x11
  541. #+BEGIN_SRC nix
  542. ./modules/x11.nix
  543. #+END_SRC
  544. [[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.
  545. #+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
  546. # <<file-warning>>
  547. { config, options, lib, pkgs, ... }:
  548. with lib;
  549. with lib.types;
  550. let cfg = config.modules.x11;
  551. in {
  552. options.modules.x11 = {
  553. enable = mkOption {
  554. type = bool;
  555. default = false;
  556. };
  557. };
  558. config = mkIf cfg.enable {
  559. services.xserver.enable = true;
  560. services.xserver.layout = "us";
  561. services.xserver.libinput.enable = true;
  562. services.xserver.displayManager.startx.enable = true;
  563. environment = {
  564. systemPackages = with pkgs; [
  565. pkgs.sqlite
  566. pkgs.pfetch
  567. pkgs.cmatrix
  568. pkgs.asciiquarium
  569. ];
  570. extraInit = ''
  571. export XAUTHORITY=/tmp/Xauthority
  572. export xserverauthfile=/tmp/xserverauth
  573. [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
  574. [ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
  575. '';
  576. };
  577. services.picom.enable = true;
  578. services.printing.enable = true;
  579. fonts.packages = with pkgs; [
  580. iosevka-bin
  581. fira-code-symbols
  582. emacs-all-the-icons-fonts
  583. ];
  584. };
  585. }
  586. #+END_SRC
  587. ** XDG
  588. #+NAME: module-xdg
  589. #+BEGIN_SRC nix
  590. ./modules/x11.nix
  591. #+END_SRC
  592. The [[https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html][XDG Base Directory Specification]] is based on the following concepts:
  593. | Environment Variable | Default | Purpose |
  594. |----------------------+--------------------+---------------------------------------------------------------------------|
  595. | XDG_CONFIG_HOME | $HOME/.config | Where user-specific configurations should be written |
  596. | XDG_CACHE_HOME | $HOME/.cache | Where user-specific non essential date should be written |
  597. | XDG_DATA_HOME | $HOME/.local/share | Where user-specific data files should be written |
  598. | XDG_STATE_HOME | $HOME/.local/state | Where user-sspecific state files should be written |
  599. | XDG_RUNTIME_DIR | /run/user/$UID | Non-essential, user-specific date files such as sockets, named pipes, etc |
  600. #+BEGIN_SRC nix :noweb yes :tangle modules/xdg.nix
  601. <<file-warning>
  602. { config, options, lib, pkgs, ... }:
  603. with lib;
  604. with lib.types;
  605. let cfg = config.modules.xdg;
  606. in {
  607. options.modules.xdg = {
  608. enable = mkOption {
  609. type = bool;
  610. default = false;
  611. };
  612. };
  613. config = mkIf cfg.enable {
  614. environment.variables = {
  615. XDG_DESKTOP_DIR = "$HOME/";
  616. XDG_CACHE_HOME = "$HOME/.cache";
  617. XDG_CONFIG_HOME = "$HOME/.config";
  618. XDG_DATA_HOME = "$HOME/.local/share";
  619. XDG_BIN_HOME = "$HOME/.local/bin";
  620. };
  621. };
  622. }
  623. #+END_SRC
  624. ** SSH
  625. #+NAME: module-ssh
  626. #+BEGIN_SRC nix
  627. ./modules/ssh.nix
  628. #+END_SRC
  629. [[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.
  630. Apply some configuration to the default settings:
  631. + Disable logging in as =root=
  632. + Disable password authentication
  633. #+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
  634. # <<file-warning>>
  635. { config, options, lib, pkgs, ... }:
  636. with lib;
  637. with lib.types;
  638. let cfg = config.modules.ssh;
  639. in {
  640. options.modules.ssh = {
  641. enable = mkOption {
  642. type = bool;
  643. default = false;
  644. };
  645. };
  646. config = mkIf cfg.enable {
  647. services.openssh = {
  648. enable = true;
  649. settings = {
  650. PermitRootLogin = "no";
  651. PasswordAuthentication = false;
  652. };
  653. };
  654. };
  655. }
  656. #+END_SRC
  657. ** Hugo
  658. #+NAME: module-hugo
  659. #+BEGIN_SRC nix
  660. ./modules/hugo.nix
  661. #+END_SRC
  662. [[https://gohugo.io][Hugo]] is one of the most popular open-source static site generators. I use it to build https://chrishayward.xyz which is included in a later section of this configuration. This module adds a custom package to push the site to the server.
  663. #+BEGIN_SRC nix :noweb yes :tangle modules/hugo.nix
  664. # <<file-warning>>
  665. { config, options, lib, pkgs, ... }:
  666. with lib;
  667. with lib.types;
  668. let
  669. cfg = config.modules.hugo;
  670. mySiteDir = "/etc/dotfiles/docs/public/";
  671. mySiteTgt = "ubuntu@chrishayward.xyz:/var/www/chrishayward";
  672. mySiteBuild = pkgs.writeShellScriptBin "site-build" ''
  673. pushd ${mySiteDir}../ > /dev/null &&
  674. ${pkgs.hugo}/bin/hugo -v ;
  675. popd > /dev/null
  676. '';
  677. mySiteUpdate = pkgs.writeShellScriptBin "site-update" ''
  678. ${pkgs.rsync}/bin/rsync -aP ${mySiteDir} ${mySiteTgt}
  679. '';
  680. in {
  681. options.modules.hugo = {
  682. enable = mkOption {
  683. type = bool;
  684. default = false;
  685. };
  686. };
  687. config = mkIf cfg.enable {
  688. environment.systemPackages = [
  689. pkgs.hugo
  690. mySiteBuild
  691. mySiteUpdate
  692. ];
  693. };
  694. }
  695. #+END_SRC
  696. ** Flakes
  697. #+NAME: module-flakes
  698. #+BEGIN_SRC nix
  699. ./modules/flakes.nix
  700. #+END_SRC
  701. [[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.
  702. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  703. # <<file-warning>>
  704. { config, options, lib, pkgs, inputs, ... }:
  705. with lib;
  706. with lib.types;
  707. let cfg = config.modules.flakes;
  708. in {
  709. options.modules.flakes = {
  710. enable = mkOption {
  711. type = bool;
  712. default = false;
  713. };
  714. };
  715. config = mkIf cfg.enable {
  716. nix = {
  717. package = pkgs.nixUnstable;
  718. extraOptions = ''
  719. experimental-features = nix-command flakes
  720. '';
  721. };
  722. nixpkgs = {
  723. config = { allowUnfree = true; };
  724. overlays = [ inputs.emacs-overlay.overlay ];
  725. };
  726. };
  727. }
  728. #+END_SRC
  729. ** Cachix
  730. #+NAME: module-cachix
  731. #+BEGIN_SRC nix
  732. ./modules/cachix.nix
  733. #+END_SRC
  734. [[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.
  735. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  736. # <<file-warning>>
  737. { config, options, lib, pkgs, ... }:
  738. with lib;
  739. with lib.types;
  740. let
  741. cfg = config.modules.cachix;
  742. in {
  743. options.modules.cachix = {
  744. enable = mkOption {
  745. type = bool;
  746. default = false;
  747. };
  748. };
  749. config = mkIf cfg.enable {
  750. nix = {
  751. settings = {
  752. substituters = [
  753. "https://nix-community.cachix.org"
  754. ];
  755. trusted-public-keys = [
  756. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  757. ];
  758. };
  759. };
  760. };
  761. }
  762. #+END_SRC
  763. ** Docker
  764. #+NAME: module-docker
  765. #+BEGIN_SRC nix
  766. ./modules/docker.nix
  767. #+END_SRC
  768. [[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.
  769. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  770. # <<file-warning>>
  771. { config, options, lib, pkgs, ... }:
  772. with lib;
  773. with lib.types;
  774. let cfg = config.modules.docker;
  775. myDockerNuke = pkgs.writeShellScriptBin "docker-nuke" ''
  776. docker stop $(docker ps -aq)
  777. docker rm $(docker ps -aq)
  778. docker network prune -f
  779. docker rmi -f $(docker images --filter dangling=true -qa)
  780. docker volume rm $(docker volume ls --filter dangling=true -q)
  781. docker rmi -f $(docker images -qa)
  782. '';
  783. in {
  784. options.modules.docker = {
  785. enable = mkOption {
  786. type = bool;
  787. default = false;
  788. };
  789. };
  790. config = mkIf cfg.enable {
  791. # Enable the docker virutalization platform.
  792. virtualisation.docker = {
  793. enable = true;
  794. enableOnBoot = true;
  795. autoPrune.enable = true;
  796. };
  797. # Required for the `docker' command.
  798. users.users.chris.extraGroups = [ "docker" ];
  799. # Add docker extensions.
  800. environment.systemPackages = [
  801. myDockerNuke
  802. pkgs.docker-compose
  803. pkgs.docker-machine
  804. ];
  805. };
  806. }
  807. #+END_SRC
  808. ** Firefox
  809. #+NAME: module-firefox
  810. #+BEGIN_SRC nix
  811. ./modules/firefox.nix
  812. #+END_SRC
  813. [[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.
  814. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  815. # <<file-warning>>
  816. { config, options, lib, pkgs, ... }:
  817. with lib;
  818. with lib.types;
  819. let
  820. cfg = config.modules.firefox;
  821. myFirefox = pkgs.writeShellScriptBin "firefox" ''
  822. HOME=~/.local/share/mozilla ${pkgs.firefox-bin}/bin/firefox
  823. '';
  824. in {
  825. options.modules.firefox = {
  826. enable = mkOption {
  827. type = bool;
  828. default = false;
  829. };
  830. };
  831. config = mkIf cfg.enable {
  832. # NOTE: Use the binary until module is developed.
  833. environment.systemPackages = [
  834. myFirefox
  835. ];
  836. };
  837. }
  838. #+END_SRC
  839. ** Home Manager
  840. [[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.
  841. #+NAME: module-home-manager
  842. #+BEGIN_SRC nix :noweb yes
  843. inputs.home-manager.nixosModules.home-manager {
  844. home-manager.useGlobalPkgs = true;
  845. home-manager.useUserPackages = true;
  846. home-manager.users.chris = {
  847. home.stateVersion = "23.05";
  848. imports = [
  849. <<module-git>>
  850. <<module-gpg>>
  851. <<module-vim>>
  852. <<module-gtk>>
  853. <<module-emacs>>
  854. ];
  855. modules.git = {
  856. enable = true;
  857. name = "Christopher James Hayward";
  858. email = "chris@chrishayward.xyz";
  859. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  860. };
  861. modules.gpg.enable = true;
  862. modules.vim.enable = true;
  863. modules.gtk.enable = true;
  864. modules.emacs.enable = true;
  865. };
  866. }
  867. #+END_SRC
  868. Certain modules have to be included within home manager or they will not function correctly.
  869. #+NAME: home-manager-warning
  870. #+BEGIN_SRC text
  871. This module MUST be included within home manager
  872. #+END_SRC
  873. *** Git
  874. #+NAME: module-git
  875. #+BEGIN_SRC nix
  876. ./modules/git.nix
  877. #+END_SRC
  878. [[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.
  879. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  880. # <<file-warning>>
  881. # <<home-manager-warning>>
  882. { config, options, lib, pkgs, ... }:
  883. with lib;
  884. with lib.types;
  885. let
  886. cfg = config.modules.git;
  887. # Fix any corruptions in the local copy.
  888. myGitFix = pkgs.writeShellScriptBin "git-fix" ''
  889. if [ -d .git/objects/ ]; then
  890. find .git/objects/ -type f -empty | xargs rm -f
  891. git fetch -p
  892. git fsck --full
  893. fi
  894. exit 1
  895. '';
  896. in {
  897. options.modules.git = {
  898. enable = mkOption {
  899. type = bool;
  900. default = false;
  901. };
  902. name = mkOption {
  903. type = str;
  904. default = "Anon";
  905. };
  906. email = mkOption {
  907. type = str;
  908. default = "anon@devnull.com";
  909. };
  910. key = mkOption {
  911. type = str;
  912. default = "ABCD1234";
  913. };
  914. };
  915. config = mkIf cfg.enable {
  916. home.packages = [ myGitFix ];
  917. programs.git = {
  918. enable = true;
  919. userName = cfg.name;
  920. userEmail = cfg.email;
  921. signing = {
  922. key = cfg.key;
  923. signByDefault = true;
  924. };
  925. };
  926. };
  927. }
  928. #+END_SRC
  929. *** Gpg
  930. #+NAME: module-gpg
  931. #+BEGIN_SRC nix
  932. ./modules/gpg.nix
  933. #+END_SRC
  934. [[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.
  935. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  936. # <<file-warning>>
  937. # <<home-manager-warning>>
  938. { config, options, lib, pkgs, ... }:
  939. with lib;
  940. with lib.types;
  941. let
  942. cfg = config.modules.gpg;
  943. in {
  944. options.modules.gpg = {
  945. enable = mkOption {
  946. type = bool;
  947. default = false;
  948. };
  949. };
  950. config = mkIf cfg.enable {
  951. services.gpg-agent = {
  952. enable = true;
  953. defaultCacheTtl = 1800;
  954. enableSshSupport = true;
  955. pinentryFlavor = "gtk2";
  956. };
  957. };
  958. }
  959. #+END_SRC
  960. *** Vim
  961. #+NAME: module-vim
  962. #+BEGIN_SRC nix
  963. ./modules/vim.nix
  964. #+END_SRC
  965. [[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
  966. + Simplify maintenance and encourage contributions
  967. + Split the work between multiple developers
  968. + Enable advanced UIs without core modification
  969. + Maximize extensibility
  970. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  971. # <<file-warning>>
  972. # <<home-manager-warning>>
  973. { config, options, lib, pkgs, ... }:
  974. with lib;
  975. with lib.types;
  976. let cfg = config.modules.vim;
  977. in {
  978. options.modules.vim = {
  979. enable = mkOption {
  980. type = bool;
  981. default = false;
  982. };
  983. };
  984. config = mkIf cfg.enable {
  985. programs.neovim = {
  986. enable = true;
  987. viAlias = true;
  988. vimAlias = true;
  989. vimdiffAlias = true;
  990. extraConfig = ''
  991. set number relativenumber
  992. set nobackup
  993. '';
  994. extraPackages = [
  995. pkgs.nixfmt
  996. ];
  997. plugins = with pkgs.vimPlugins; [
  998. vim-nix
  999. vim-airline
  1000. vim-polyglot
  1001. ];
  1002. };
  1003. };
  1004. }
  1005. #+END_SRC
  1006. *** GTK
  1007. #+NAME: module-gtk
  1008. #+BEGIN_SRC nix
  1009. ./modules/gtk.nix
  1010. #+END_SRC
  1011. [[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.
  1012. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  1013. # <<file-warning>>
  1014. # <<home-manager-warning>>
  1015. { config, options, lib, pkgs, ... }:
  1016. with lib;
  1017. with lib.types;
  1018. let cfg = config.modules.gtk;
  1019. in {
  1020. options.modules.gtk = {
  1021. enable = mkOption {
  1022. type = bool;
  1023. default = false;
  1024. };
  1025. };
  1026. config = mkIf cfg.enable {
  1027. home.packages = [
  1028. pkgs.nordic
  1029. pkgs.arc-icon-theme
  1030. pkgs.lxappearance
  1031. ];
  1032. home.file.".gtkrc-2.0" = {
  1033. text = ''
  1034. gtk-theme-name="Nordic-darker"
  1035. gtk-icon-theme-name="Arc"
  1036. gtk-font-name="Iosevka 11"
  1037. gtk-cursor-theme-size=0
  1038. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  1039. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  1040. gtk-button-images=0
  1041. gtk-menu-images=0
  1042. gtk-enable-event-sounds=1
  1043. gtk-enable-input-feedback-sounds=1
  1044. gtk-xft-antialias=1
  1045. gtk-xft-hinting=1
  1046. gtk-xft-hintstyle="hintmedium"
  1047. '';
  1048. };
  1049. home.file.".config/gtk-2.0/gtkfilechooser.ini" = {
  1050. text = ''
  1051. [Filechooser Settings]
  1052. LocationMode=path-bar
  1053. ShowHidden=false
  1054. ShowSizeColumn=true
  1055. GeometryX=442
  1056. GeometryY=212
  1057. GeometryWidth=1036
  1058. GeometryHeight=609
  1059. SortColumn=name
  1060. SortOrder=ascending
  1061. StartupMode=recent
  1062. '';
  1063. };
  1064. home.file.".config/gtk-3.0/settings.ini" = {
  1065. text = ''
  1066. [Settings]
  1067. gtk-theme-name=Nordic-darker
  1068. gtk-icon-theme-name=Arc
  1069. gtk-font-name=Iosevka 11
  1070. gtk-cursor-theme-size=0
  1071. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  1072. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  1073. gtk-button-images=0
  1074. gtk-menu-images=0
  1075. gtk-enable-event-sounds=1
  1076. gtk-enable-input-feedback-sounds=1
  1077. gtk-xft-antialias=1
  1078. gtk-xft-hinting=1
  1079. gtk-xft-hintstyle=hintmedium
  1080. '';
  1081. };
  1082. };
  1083. }
  1084. #+END_SRC
  1085. ** Emacs Configuration
  1086. #+ATTR_ORG: :width 300px
  1087. #+ATTR_HTML: :width 300px
  1088. #+ATTR_LATEX: :width 300px
  1089. [[./docs/images/emacs.png]]
  1090. #+NAME: module-emacs
  1091. #+BEGIN_SRC nix
  1092. ./modules/emacs.nix
  1093. #+END_SRC
  1094. [[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:
  1095. + Highly customizable
  1096. + Full Unicopde support
  1097. + Content-aware editing modes
  1098. + Complete built-in documentation
  1099. + Wide range of functionality beyond text editing
  1100. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  1101. # <<file-warning>>
  1102. # <<home-manager-warning>>
  1103. { config, options, lib, pkgs, ... }:
  1104. with lib;
  1105. with lib.types;
  1106. let
  1107. cfg = config.modules.emacs;
  1108. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  1109. config = ../README.org;
  1110. package = <<emacs-native-comp-package>>
  1111. alwaysEnsure = true;
  1112. alwaysTangle = true;
  1113. extraEmacsPackages = epkgs: [
  1114. # Required packages...
  1115. <<emacs-exwm-package>>
  1116. <<emacs-evil-package>>
  1117. <<emacs-general-package>>
  1118. <<emacs-which-key-package>>
  1119. # Optional packages.
  1120. <<emacs-org-package>>
  1121. <<emacs-org-roam-package>>
  1122. <<emacs-org-roam-ui-package>>
  1123. <<emacs-org-drill-package>>
  1124. <<emacs-pomodoro-package>>
  1125. <<emacs-writegood-package>>
  1126. <<emacs-http-package>>
  1127. <<emacs-hugo-package>>
  1128. <<emacs-pass-package>>
  1129. <<emacs-docker-package>>
  1130. <<emacs-mu4e-package>>
  1131. <<emacs-dired-package>>
  1132. <<emacs-icons-package>>
  1133. <<emacs-emoji-package>>
  1134. <<emacs-eshell-package>>
  1135. <<emacs-vterm-package>>
  1136. <<emacs-magit-package>>
  1137. <<emacs-hydra-package>>
  1138. <<emacs-ligatures-package>>
  1139. <<emacs-elfeed-package>>
  1140. <<emacs-nix-mode-package>>
  1141. <<emacs-projectile-package>>
  1142. <<emacs-lsp-package>>
  1143. <<emacs-company-package>>
  1144. <<emacs-ccls-package>>
  1145. <<emacs-golang-package>>
  1146. <<emacs-dart-package>>
  1147. <<emacs-python-package>>
  1148. <<emacs-rustic-package>>
  1149. <<emacs-protobuf-package>>
  1150. <<emacs-typescript-package>>
  1151. <<emacs-yaml-mode-package>>
  1152. <<emacs-plantuml-package>>
  1153. # User interface packages.
  1154. <<emacs-neotree-package>>
  1155. <<emacs-swiper-package>>
  1156. <<emacs-desktop-package>>
  1157. <<emacs-doom-themes-package>>
  1158. <<emacs-doom-modeline-package>>
  1159. ];
  1160. };
  1161. in {
  1162. options.modules.emacs = {
  1163. enable = mkOption {
  1164. type = bool;
  1165. default = false;
  1166. };
  1167. };
  1168. config = mkIf cfg.enable {
  1169. home.packages = [
  1170. <<emacs-exwm-extras>>
  1171. <<emacs-pass-extras>>
  1172. <<emacs-mu4e-extras>>
  1173. <<emacs-aspell-extras>>
  1174. <<emacs-texlive-extras>>
  1175. <<emacs-desktop-extras>>
  1176. <<emacs-plantuml-extras>>
  1177. <<emacs-nix-mode-extras>>
  1178. <<emacs-doom-themes-extras>>
  1179. ];
  1180. programs.emacs = {
  1181. enable = true;
  1182. package = myEmacs;
  1183. };
  1184. <<emacs-exwm-config>>
  1185. <<emacs-exwm-xinitrc>>
  1186. <<emacs-mu4e-config>>
  1187. };
  1188. }
  1189. #+END_SRC
  1190. 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.
  1191. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.config/emacs/init.el
  1192. ;; <<file-warning>>
  1193. ;; Required inputs.
  1194. <<emacs-exwm-elisp>>
  1195. <<emacs-evil-elisp>>
  1196. <<emacs-general-elisp>>
  1197. <<emacs-which-key-elisp>>
  1198. ;; Optional inputs.
  1199. <<emacs-org-elisp>>
  1200. <<emacs-org-roam-elisp>>
  1201. <<emacs-org-roam-ui-elisp>>
  1202. <<emacs-org-drill-elisp>>
  1203. <<emacs-org-agenda-elisp>>
  1204. <<emacs-pomodoro-elisp>>
  1205. <<emacs-writegood-elisp>>
  1206. <<emacs-aspell-elisp>>
  1207. <<emacs-eww-elisp>>
  1208. <<emacs-http-elisp>>
  1209. <<emacs-hugo-elisp>>
  1210. <<emacs-pass-elisp>>
  1211. <<emacs-docker-elisp>>
  1212. <<emacs-erc-elisp>>
  1213. <<emacs-mu4e-elisp>>
  1214. <<emacs-dired-elisp>>
  1215. <<emacs-icons-elisp>>
  1216. <<emacs-emoji-elisp>>
  1217. <<emacs-eshell-elisp>>
  1218. <<emacs-vterm-elisp>>
  1219. <<emacs-magit-elisp>>
  1220. <<emacs-fonts-elisp>>
  1221. <<emacs-line-numbers-elisp>>
  1222. <<emacs-frames-elisp>>
  1223. <<emacs-ligatures-elisp>>
  1224. <<emacs-elfeed-elisp>>
  1225. <<emacs-projectile-elisp>>
  1226. <<emacs-electric-pair-elisp>>
  1227. <<emacs-lsp-elisp>>
  1228. <<emacs-company-elisp>>
  1229. <<emacs-golang-elisp>>
  1230. <<emacs-typescript-elisp>>
  1231. <<emacs-dart-elisp>>
  1232. <<emacs-python-elisp>>
  1233. <<emacs-rustic-elisp>>
  1234. <<emacs-plantuml-elisp>>
  1235. <<emacs-desktop-elisp>>
  1236. ;; User interface.
  1237. <<emacs-neotree-elisp>>
  1238. <<emacs-swiper-elisp>>
  1239. <<emacs-transparency-elisp>>
  1240. <<emacs-doom-themes-elisp>>
  1241. <<emacs-doom-modeline-elisp>>
  1242. #+END_SRC
  1243. 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=.
  1244. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.config/emacs/early-init.el
  1245. ;; <<file-warning>>
  1246. <<emacs-disable-ui-elisp>>
  1247. <<emacs-native-comp-elisp>>
  1248. <<emacs-backup-files-elisp>>
  1249. <<emacs-shell-commands-elisp>>
  1250. <<emacs-improved-prompts>>
  1251. #+END_SRC
  1252. *** Native Comp
  1253. #+NAME: emacs-native-comp-package
  1254. #+BEGIN_SRC nix
  1255. pkgs.emacs-unstable;
  1256. #+END_SRC
  1257. 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.
  1258. #+NAME: emacs-native-comp-elisp
  1259. #+BEGIN_SRC emacs-lisp
  1260. ;; Silence warnings from packages that don't support `native-comp'.
  1261. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  1262. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  1263. #+END_SRC
  1264. *** Disable UI
  1265. [[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.
  1266. #+NAME: emacs-disable-ui-elisp
  1267. #+BEGIN_SRC emacs-lisp
  1268. ;; Disable unwanted UI elements.
  1269. (tooltip-mode -1)
  1270. (menu-bar-mode -1)
  1271. (tool-bar-mode -1)
  1272. (scroll-bar-mode -1)
  1273. ;; Fix the scrolling behaviour.
  1274. (setq scroll-conservatively 101)
  1275. ;; Fix mouse-wheel scrolling behaviour.
  1276. (setq mouse-wheel-follow-mouse t
  1277. mouse-wheel-progressive-speed t
  1278. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  1279. ;; Start in fullscreen/maximized.
  1280. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  1281. #+END_SRC
  1282. *** Backup Files
  1283. [[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.
  1284. #+NAME: emacs-backup-files-elisp
  1285. #+BEGIN_SRC emacs-lisp
  1286. ;; Disable unwanted features.
  1287. (setq make-backup-files nil
  1288. create-lockfiles nil)
  1289. #+END_SRC
  1290. *** Shell Commands
  1291. Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
  1292. 1) Method to run an external process, launching any application on a new process without interference
  1293. 2) Method to apply commands to the current call process, effecting the running instance
  1294. #+NAME: emacs-shell-commands-elisp
  1295. #+BEGIN_SRC emacs-lisp
  1296. ;; Define a method to run an external process.
  1297. (defun dotfiles/run (cmd)
  1298. "Run an external process."
  1299. (interactive (list (read-shell-command "λ ")))
  1300. (start-process-shell-command cmd nil cmd))
  1301. ;; Define a method to run a background process.
  1302. (defun dotfiles/run-in-background (cmd)
  1303. (let ((command-parts (split-string cmd "[ ]+")))
  1304. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  1305. #+END_SRC
  1306. *** Improved prompts
  1307. By default Emacs will ask you to enter 'Yes' or 'No' instead of 'Y' or 'N'. This is a relatively conservative design decision, based on the fact that certain prompts may be important enough to warrant typing three characters.
  1308. #+NAME: emacs-improved-prompts
  1309. #+BEGIN_SRC emacs-lisp
  1310. ;; Use 'y' and 'n' instead of 'yes' and 'no'.
  1311. (defalias 'yes-or-no-p 'y-or-n-p)
  1312. #+END_SRC
  1313. *** Nix Mode
  1314. #+NAME: emacs-nix-mode-extras
  1315. #+BEGIN_SRC nix
  1316. pkgs.nixfmt
  1317. pkgs.rnix-lsp
  1318. #+END_SRC
  1319. [[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. [[https:github.com/nix-community/rnix-lsp][rnix-lsp]] is a work-in-progress language server for Nix with syntax checking and basic completion.
  1320. #+NAME: emacs-nix-mode-package
  1321. #+BEGIN_SRC nix
  1322. epkgs.nix-mode
  1323. #+END_SRC
  1324. *** Evil Mode
  1325. [[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.
  1326. #+NAME: emacs-evil-package
  1327. #+BEGIN_SRC nix
  1328. epkgs.evil
  1329. epkgs.evil-collection
  1330. epkgs.evil-surround
  1331. epkgs.evil-nerd-commenter
  1332. #+END_SRC
  1333. 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]].
  1334. #+NAME: emacs-evil-elisp
  1335. #+BEGIN_SRC emacs-lisp
  1336. ;; Enable the Extensible VI Layer for Emacs.
  1337. (setq evil-want-integration t ;; Required for `evil-collection.'
  1338. evil-want-keybinding nil ;; Same as above.
  1339. evil-want-C-i-jump nil) ;; Disable jumping in terminal.
  1340. (evil-mode +1)
  1341. ;; Configure `evil-collection'.
  1342. (evil-collection-init)
  1343. ;; Configure `evil-surround'.
  1344. (global-evil-surround-mode +1)
  1345. ;; Configure `evil-nerd-commenter'.
  1346. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1347. ;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
  1348. (evil-define-key 'normal 'org-mode-map (kbd "<tab>") #'org-cycle)
  1349. #+END_SRC
  1350. *** EXWM
  1351. #+NAME: emacs-exwm-package
  1352. #+BEGIN_SRC nix
  1353. epkgs.exwm
  1354. #+END_SRC
  1355. [[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:
  1356. + Fully keyboard-driven operations
  1357. + Hybrid layout modes (tiling & stacking)
  1358. + Dynamic workspace support
  1359. + ICCM/EWMH compliance
  1360. #+NAME: emacs-exwm-extras
  1361. #+BEGIN_SRC nix
  1362. pkgs.arandr
  1363. pkgs.nitrogen
  1364. pkgs.autorandr
  1365. (pkgs.writeShellScriptBin "g" ''
  1366. pushd $HOME
  1367. startx
  1368. popd /dev/null
  1369. '')
  1370. #+END_SRC
  1371. 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]].
  1372. #+NAME: emacs-exwm-config
  1373. #+BEGIN_SRC nix
  1374. xsession = {
  1375. enable = true;
  1376. windowManager.command = ''
  1377. ${pkgs.nitrogen}/bin/nitrogen --restore
  1378. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1379. ${myEmacs}/bin/emacsclient -c
  1380. '';
  1381. };
  1382. #+END_SRC
  1383. [[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=.
  1384. #+NAME: emacs-exwm-xinitrc
  1385. #+BEGIN_SRC nix
  1386. home.file.".xinitrc" = {
  1387. text = ''
  1388. exec ./.xsession
  1389. '';
  1390. };
  1391. #+END_SRC
  1392. #+NAME: emacs-exwm-elisp
  1393. #+BEGIN_SRC emacs-lisp
  1394. ;; Configure `exwm'.
  1395. (setq exwm-workspace-number 5
  1396. exwm-layout-show-all-buffers t
  1397. exwm-worspace-show-all-buffers t)
  1398. ;; Configure input keys.
  1399. (setq exwm-input-prefix-keys
  1400. '(?\M-x
  1401. ?\C-g
  1402. ?\C-\ ))
  1403. (setq exwm-input-global-keys
  1404. `(([?\s-r] . exwm-reset)
  1405. ,@(mapcar (lambda (i)
  1406. `(,(kbd (format "s-%d" i)) .
  1407. (lambda ()
  1408. (interactive)
  1409. (exwm-workspace-switch-create ,i))))
  1410. (number-sequence 0 9))))
  1411. ;; Configure `exwm-randr'.
  1412. (require 'exwm-randr)
  1413. (exwm-randr-enable)
  1414. ;; Configure custom hooks.
  1415. (setq display-time-day-and-date t)
  1416. (add-hook 'exwm-init-hook
  1417. (lambda ()
  1418. (display-battery-mode +1) ;; Display battery info (if available).
  1419. (display-time-mode +1))) ;; Display the time in the modeline.
  1420. ;; Setup buffer display names.
  1421. (add-hook 'exwm-update-class-hook
  1422. (lambda ()
  1423. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1424. ;; Configure monitor hot-swapping.
  1425. (add-hook 'exwm-randr-screen-change-hook
  1426. (lambda ()
  1427. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1428. #+END_SRC
  1429. *** Which Key
  1430. [[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.
  1431. #+NAME: emacs-which-key-package
  1432. #+BEGIN_SRC nix
  1433. epkgs.which-key
  1434. #+END_SRC
  1435. #+NAME: emacs-which-key-elisp
  1436. #+BEGIN_SRC emacs-lisp
  1437. ;; Configure `which-key' to see keyboard bindings in the
  1438. ;; mini-buffer and when using M-x.
  1439. (setq which-key-idle-delay 0.0)
  1440. (which-key-mode +1)
  1441. #+END_SRC
  1442. *** General
  1443. #+NAME: emacs-general-package
  1444. #+BEGIN_SRC nix
  1445. epkgs.general
  1446. #+END_SRC
  1447. [[https://github.com/noctuid/general.el][General.el]] provides a more conven1ent 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.
  1448. #+NAME: emacs-general-elisp
  1449. #+BEGIN_SRC emacs-lisp
  1450. ;; Use <SPC> as a leader key via `general.el'.
  1451. (general-create-definer dotfiles/leader
  1452. :keymaps '(normal insert visual emacs)
  1453. :prefix "SPC"
  1454. :global-prefix "C-SPC")
  1455. ;; Setup general to work with `evil-mode'.
  1456. (setq general-evil-setup t)
  1457. ;; Find files with <SPC> <period> ...
  1458. ;; Switch buffers with <SPC> <comma> ...
  1459. (dotfiles/leader
  1460. "." '(find-file :which-key "File")
  1461. "," '(switch-to-buffer :which-key "Buffer")
  1462. "k" '(kill-buffer :which-key "Kill")
  1463. "c" '(kill-buffer-and-window :which-key "Close"))
  1464. ;; Add keybindings for executing shell commands.
  1465. (dotfiles/leader
  1466. "r" '(:ignore t :which-key "Run")
  1467. "rr" '(dotfiles/run :which-key "Run")
  1468. "ra" '(async-shell-command :which-key "Async"))
  1469. ;; Add keybindings for quitting Emacs.
  1470. (dotfiles/leader
  1471. "q" '(:ignore t :which-key "Quit")
  1472. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1473. "qw" '(kill-emacs :which-key "Now")
  1474. "qf" '(delete-frame :which-key "Frame"))
  1475. ;; Add keybindings for toggles / tweaks.
  1476. (dotfiles/leader
  1477. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1478. ;; Add keybinding to navigate to scratch buffer.
  1479. (dotfiles/leader
  1480. "s" '((lambda () (interactive) (switch-to-buffer "*scratch*")) :which-key "Scratch"))
  1481. #+END_SRC
  1482. *** EWW
  1483. [[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.
  1484. + Use ~eww~ as the default browser
  1485. + Don't use any special fonts or colours
  1486. #+NAME: emacs-eww-elisp
  1487. #+BEGIN_SRC emacs-lisp
  1488. ;; Set `eww' as the default browser.
  1489. (setq browse-url-browser-function 'eww-browse-url)
  1490. ;; Configure the `shr' rendering engine.
  1491. (setq shr-use-fonts nil
  1492. shr-use-colors nil)
  1493. #+END_SRC
  1494. *** ERC
  1495. [[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.
  1496. #+NAME: emacs-erc-elisp
  1497. #+BEGIN_SRC emacs-lisp
  1498. ;; Configure `erc'.
  1499. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
  1500. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1501. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1502. ;; Configure `erc-fill-column'.
  1503. (add-hook 'window-configuration-change-hook
  1504. '(lambda ()
  1505. (setq erc-fill-column (- (window-width) 12))))
  1506. ;; Connect to IRC via `erc'.
  1507. (defun dotfiles/erc-connect ()
  1508. "Connected to IRC via `erc'."
  1509. (interactive)
  1510. (erc-tls :server "irc.libera.chat"
  1511. :port 6697
  1512. :nick "megaphone"
  1513. :password (password-store-get "libera.chat/megaphone")
  1514. :full-name "Chris Hayward"))
  1515. ;; Configure keybindings.
  1516. (dotfiles/leader
  1517. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1518. #+END_SRC
  1519. *** Dired
  1520. #+NAME: emacs-dired-package
  1521. #+BEGIN_SRC nix
  1522. epkgs.dired-single
  1523. #+END_SRC
  1524. [[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.
  1525. #+NAME: emacs-dired-elisp
  1526. #+BEGIN_SRC emacs-lisp
  1527. ;; Include `dired-x' for the `jump' method.
  1528. (require 'dired-x)
  1529. ;; Configure `dired-single' to support `evil' keys.
  1530. (evil-collection-define-key 'normal 'dired-mode-map
  1531. "h" 'dired-single-up-directory
  1532. "l" 'dired-single-buffer)
  1533. ;; Configure keybindings for `dired'.
  1534. (dotfiles/leader
  1535. "d" '(dired-jump :which-key "Dired"))
  1536. #+END_SRC
  1537. *** Icons
  1538. #+NAME: emacs-icons-package
  1539. #+BEGIN_SRC nix
  1540. epkgs.nerd-icons
  1541. epkgs.all-the-icons
  1542. epkgs.all-the-icons-dired
  1543. epkgs.all-the-icons-ivy-rich
  1544. #+END_SRC
  1545. [[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]].
  1546. #+NAME: emacs-icons-elisp
  1547. #+BEGIN_SRC emacs-lisp
  1548. ;; Setup `all-the-icons-dired'.
  1549. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1550. ;; Disable monochrome icons.
  1551. (setq all-the-icons-dired-monochrome nil)
  1552. ;; Display default font ligatures.
  1553. (global-prettify-symbols-mode +1)
  1554. #+END_SRC
  1555. *** Emojis
  1556. #+NAME: emacs-emoji-package
  1557. #+BEGIN_SRC nix
  1558. epkgs.emojify
  1559. #+END_SRC
  1560. [[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.
  1561. #+NAME: emacs-emoji-elisp
  1562. #+BEGIN_SRC emacs-lisp
  1563. ;; Setup `emojify'.
  1564. ;; TODO: Causes an exception.
  1565. (add-hook 'after-init-hook 'global-emojify-mode)
  1566. #+END_SRC
  1567. *** EShell
  1568. #+NAME: emacs-eshell-package
  1569. #+BEGIN_SRC nix
  1570. epkgs.eshell-prompt-extras
  1571. #+END_SRC
  1572. [[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.
  1573. #+NAME: emacs-eshell-elisp
  1574. #+BEGIN_SRC emacs-lisp
  1575. ;; Configure `eshell'.
  1576. (setq eshell-highlight-prompt nil
  1577. eshell-prefer-lisp-functions nil)
  1578. ;; Configure the lambda prompt.
  1579. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1580. (setq eshell-prompt-function 'epe-theme-lambda)
  1581. ;; Configure keybindings for `eshell'.
  1582. (dotfiles/leader
  1583. "e" '(eshell :which-key "EShell"))
  1584. #+END_SRC
  1585. *** VTerm
  1586. [[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.
  1587. #+NAME: emacs-vterm-package
  1588. #+BEGIN_SRC nix
  1589. epkgs.vterm
  1590. epkgs.multi-vterm
  1591. #+END_SRC
  1592. #+NAME: emacs-vterm-elisp
  1593. #+BEGIN_SRC emacs-lisp
  1594. ;; Set the dedicated terminal height.
  1595. (setq multi-vterm-dedicated-window-height-percent 30)
  1596. ;; Add keybindings for interacting with the shell(s).
  1597. (dotfiles/leader
  1598. "v" '(:ignore t :which-key "VTerm")
  1599. "vj" '(multi-vterm :which-key "New")
  1600. "vl" '(multi-vterm-next :which-key "Next")
  1601. "vh" '(multi-vterm-prev :which-key "Previous")
  1602. "vk" '(multi-vterm-project :which-key "Project")
  1603. "vv" '(multi-vterm-dedicated-toggle :which-key "Dedicated"))
  1604. #+END_SRC
  1605. *** Magit
  1606. [[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.
  1607. #+NAME: emacs-magit-package
  1608. #+BEGIN_SRC nix
  1609. epkgs.magit
  1610. #+END_SRC
  1611. #+NAME: emacs-magit-elisp
  1612. #+BEGIN_SRC emacs-lisp
  1613. ;; Add keybindings for working with `magit'.
  1614. (dotfiles/leader
  1615. "g" '(:ignore t :which-key "Git")
  1616. "gg" '(magit-status :which-key "Status")
  1617. "gc" '(magit-clone :which-key "Clone")
  1618. "gf" '(magit-fetch :which-key "Fetch")
  1619. "gp" '(magit-pull :which-key "Pull"))
  1620. #+END_SRC
  1621. *** Hydra
  1622. #+NAME: emacs-hydra-package
  1623. #+BEGIN_SRC nix
  1624. epkgs.hydra
  1625. #+END_SRC
  1626. [[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.
  1627. *** Fonts
  1628. [[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.
  1629. #+NAME: emacs-fonts-elisp
  1630. #+BEGIN_SRC emacs-lisp
  1631. ;; Configure the font when running as `emacs-server'.
  1632. (custom-set-faces
  1633. '(default ((t (:inherit nil :height 120 :family "Iosevka Term")))))
  1634. ;; Define a `hydra' function for scaling the text interactively.
  1635. (defhydra hydra-text-scale (:timeout 4)
  1636. "Scale the text in the current buffer."
  1637. ("k" text-scale-decrease "Decrease")
  1638. ("j" text-scale-increase "Increase")
  1639. ("f" nil "Finished" :exit t))
  1640. ;; Create keybinding for calling the function.
  1641. (dotfiles/leader
  1642. "tf" '(hydra-text-scale/body :which-key "Font"))
  1643. #+END_SRC
  1644. *** Line Numbers
  1645. With relative line numbers, each line in a file is numbered relative to the cursor's current position to show the distance to that line. The current line is marked 0, the ones above and below are marked 1, and so on.
  1646. #+NAME: emacs-line-numbers-elisp
  1647. #+BEGIN_SRC emacs-lisp
  1648. ;; Enable relative line numbers.
  1649. ;; (global-display-line-numbers-mode +1)
  1650. (setq display-line-numbers-type 'relative)
  1651. ;; Enable line numbering for all programming modes.
  1652. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  1653. ;; Add a shortcut to toggle line numbers.
  1654. (dotfiles/leader
  1655. "tl" '(display-line-numbers-mode :which-key "Line Numbers"))
  1656. #+END_SRC
  1657. *** Ligatures
  1658. #+NAME: emacs-ligatures-package
  1659. #+BEGIN_SRC nix
  1660. epkgs.ligature
  1661. #+END_SRC
  1662. Ligature.el maps ordinary graphmemes (characters) to fancy ligatures, if both the version of [[https://gnu.org/software/emacs/][Emacs]] and the font supports it. It can control where [[https://gnu.org/software/emacs/][Emacs]] must display ligatures, useful if only a subset of the ligatures in certain major modes is required.
  1663. #+NAME: emacs-ligatures-elisp
  1664. #+BEGIN_SRC emacs-lisp
  1665. (ligature-set-ligatures 't '("www"))
  1666. ;; Enable traditional ligature support in eww-mode, if the
  1667. ;; `variable-pitch' face supports it
  1668. (ligature-set-ligatures 'eww-mode '("ff" "fi" "ffi"))
  1669. ;; Enable all Cascadia Code ligatures in programming modes
  1670. (ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
  1671. ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
  1672. "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
  1673. "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
  1674. "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
  1675. "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
  1676. "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
  1677. "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
  1678. ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
  1679. "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
  1680. "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
  1681. "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
  1682. "\\\\" "://"))
  1683. ;; Enables ligature checks globally in all buffers. You can also do it
  1684. ;; per mode with `ligature-mode'.
  1685. (global-ligature-mode t)
  1686. #+END_SRC
  1687. *** Frames
  1688. 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:
  1689. #+NAME: emacs-frames-elisp
  1690. #+BEGIN_SRC emacs-lisp
  1691. ;; Define a `hydra' function for resizing the current frame.
  1692. (defhydra hydra-resize-frame (:timeout 4)
  1693. "Scale the current frame."
  1694. ("h" shrink-window-horizontally "Left")
  1695. ("j" enlarge-window "Down")
  1696. ("k" shrink-window "Up")
  1697. ("l" enlarge-window-horizontally "Right")
  1698. ("f" nil "Finished" :exit t))
  1699. ;; Add keybindings for working with frames to replace
  1700. ;; the C-x <num> <num> method of bindings, which is awful.
  1701. (dotfiles/leader
  1702. "w" '(:ignore t :which-key "Windows")
  1703. "ww" '(window-swap-states :which-key "Swap")
  1704. "wc" '(delete-window :which-key "Close")
  1705. "wh" '(windmove-left :which-key "Left")
  1706. "wj" '(windmove-down :which-key "Down")
  1707. "wk" '(windmove-up :which-key "Up")
  1708. "wl" '(windmove-right :which-key "Right")
  1709. "ws" '(:ignore t :which-key "Split")
  1710. "wsj" '(split-window-below :which-key "Below")
  1711. "wsl" '(split-window-right :which-key "Right")
  1712. "wr" '(hydra-resize-frame/body :which-key "Resize"))
  1713. #+END_SRC
  1714. *** Elfeed
  1715. #+NAME: emacs-elfeed-package
  1716. #+BEGIN_SRC nix
  1717. epkgs.elfeed
  1718. #+END_SRC
  1719. [[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.
  1720. #+NAME: emacs-elfeed-elisp
  1721. #+BEGIN_SRC emacs-lisp
  1722. ;; Configure `elfeed'.
  1723. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1724. ;; Add custom feeds for `elfeed' to fetch.
  1725. (setq elfeed-feeds (quote
  1726. (("https://hexdsl.co.uk/rss.xml")
  1727. ("https://lukesmith.xyz/rss.xml")
  1728. ("https://friendo.monster/rss.xml")
  1729. ("https://chrishayward.xyz/index.xml")
  1730. ("https://protesilaos.com/master.xml"))))
  1731. ;; Add custom keybindings for `elfeed'.
  1732. (dotfiles/leader
  1733. "f" '(:ignore t :which-key "Elfeed")
  1734. "fl" '(elfeed :which-key "Open")
  1735. "fu" '(elfeed-update :which-key "Update"))
  1736. #+END_SRC
  1737. *** Org Mode
  1738. #+NAME: emacs-org-package
  1739. #+BEGIN_SRC nix
  1740. epkgs.org
  1741. #+END_SRC
  1742. [[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.
  1743. #+NAME: emacs-org-elisp
  1744. #+BEGIN_SRC emacs-lisp
  1745. ;; Configure `org-mode' source blocks.
  1746. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1747. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1748. org-hide-emphasis-markers t ;; Don't show emphasis markup.
  1749. org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
  1750. org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
  1751. ;; Add an `org-mode-hook'.
  1752. (add-hook 'org-mode-hook
  1753. (lambda ()
  1754. (org-indent-mode)
  1755. (visual-line-mode)))
  1756. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1757. (setq org-export-html-validation-link nil
  1758. org-html-validation-link nil)
  1759. ;; Configure the keywords in the TODO -> DONE sequence.
  1760. (setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  1761. ;; Track ids globally.
  1762. (setq org-id-track-globally t)
  1763. ;; Configure `org-babel' languages.
  1764. (org-babel-do-load-languages
  1765. 'org-babel-load-languages
  1766. '((C . t)))
  1767. ;; Log / Clock into property drawers.
  1768. (setq org-log-into-drawer t
  1769. org-clock-into-drawer t)
  1770. ;; Encrypt files with the public key.
  1771. (setq epa-file-select-keys 2
  1772. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1773. epa-cache-passphrase-for-symmetric-encryption t)
  1774. ;; TODO: Configure default structure templates.
  1775. ;; (require 'org-tempo)
  1776. ;; Don't use native image sizes in previews.
  1777. (setq org-image-actual-width nil)
  1778. ;; Apply custom keybindings.
  1779. (dotfiles/leader
  1780. "o" '(:ignore t :which-key "Org")
  1781. "oe" '(org-export-dispatch :which-key "Export")
  1782. "ot" '(org-babel-tangle :which-key "Tangle")
  1783. "oi" '(org-toggle-inline-images :which-key "Images")
  1784. "of" '(:ignore t :which-key "Footnotes")
  1785. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1786. #+END_SRC
  1787. *** Org Roam
  1788. #+NAME: emacs-org-roam-package
  1789. #+BEGIN_SRC nix
  1790. epkgs.org-roam
  1791. #+END_SRC
  1792. [[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.
  1793. #+NAME: emacs-org-roam-elisp
  1794. #+BEGIN_SRC emacs-lisp
  1795. ;; Setup `org-roam'.
  1796. (require 'org-roam)
  1797. ;; Silence the migration warnings.
  1798. (setq org-roam-v2-ack t)
  1799. ;; Enable `visual-line-mode' in `org-roam' buffer.
  1800. (add-hook 'org-roam-mode-hook
  1801. (lambda ()
  1802. (visual-line-mode +1)))
  1803. ;; Enable completion everywhere.
  1804. (setq org-roam-completion-everywhere t)
  1805. ;; Set the roam directories.
  1806. (setq org-roam-directory (expand-file-name "/etc/dotfiles")
  1807. org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
  1808. ;; Clear the deafult capture templates.
  1809. (setq org-roam-capture-templates '()
  1810. org-roam-dailies-capture-templates '())
  1811. ;; Override the default slug method.
  1812. (cl-defmethod org-roam-node-slug ((node org-roam-node))
  1813. (let ((title (org-roam-node-title node))
  1814. (slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
  1815. 769 ; U+0301 COMBINING ACUTE ACCENT
  1816. 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
  1817. 771 ; U+0303 COMBINING TILDE
  1818. 772 ; U+0304 COMBINING MACRON
  1819. 774 ; U+0306 COMBINING BREVE
  1820. 775 ; U+0307 COMBINING DOT ABOVE
  1821. 776 ; U+0308 COMBINING DIAERESIS
  1822. 777 ; U+0309 COMBINING HOOK ABOVE
  1823. 778 ; U+030A COMBINING RING ABOVE
  1824. 780 ; U+030C COMBINING CARON
  1825. 795 ; U+031B COMBINING HORN
  1826. 803 ; U+0323 COMBINING DOT BELOW
  1827. 804 ; U+0324 COMBINING DIAERESIS BELOW
  1828. 805 ; U+0325 COMBINING RING BELOW
  1829. 807 ; U+0327 COMBINING CEDILLA
  1830. 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
  1831. 814 ; U+032E COMBINING BREVE BELOW
  1832. 816 ; U+0330 COMBINING TILDE BELOW
  1833. 817 ; U+0331 COMBINING MACRON BELOW
  1834. )))
  1835. (cl-flet* ((nonspacing-mark-p (char)
  1836. (memq char slug-trim-chars))
  1837. (strip-nonspacing-marks (s)
  1838. (ucs-normalize-NFC-string
  1839. (apply #'string (seq-remove #'nonspacing-mark-p
  1840. (ucs-normalize-NFD-string s)))))
  1841. (cl-replace (title pair)
  1842. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1843. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
  1844. ("--*" . "-")
  1845. ("^-" . "")
  1846. ("-$" . "")))
  1847. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1848. (downcase slug)))))
  1849. ;; Configure capture templates.
  1850. ;; Standard document.
  1851. (add-to-list 'org-roam-capture-templates
  1852. '("d" "Default" plain "%?"
  1853. :target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
  1854. "
  1855. ,#+TITLE: ${title}
  1856. ,#+AUTHOR: Christopher James Hayward
  1857. ,#+EMAIL: chris@chrishayward.xyz
  1858. "
  1859. )
  1860. :unnarrowed t))
  1861. ;; Daily notes.
  1862. (add-to-list 'org-roam-dailies-capture-templates
  1863. '("d" "Default" entry "* %?"
  1864. :target (file+head "%<%Y-%m-%d>.org.gpg"
  1865. "
  1866. ,#+TITLE: %<%Y-%m-%d>
  1867. ,#+AUTHOR: Christopher James Hayward
  1868. ,#+EMAIL: chris@chrishayward.xyz
  1869. ")))
  1870. ;; Apply custom keybindings.
  1871. (dotfiles/leader
  1872. "or" '(:ignore t :which-key "Roam")
  1873. "ori" '(org-roam-node-insert :which-key "Insert")
  1874. "orf" '(org-roam-node-find :which-key "Find")
  1875. "orc" '(org-roam-capture :which-key "Capture")
  1876. "org" '(org-id-get-create :which-key "Get/Create")
  1877. "orb" '(org-roam-buffer-toggle :which-key "Buffer"))
  1878. ;; Apply custom keybindings for dailies.
  1879. (dotfiles/leader
  1880. "ord" '(:ignore t :which-key "Dailies")
  1881. "ordd" '(org-roam-dailies-goto-date :which-key "Date")
  1882. "ordt" '(org-roam-dailies-goto-today :which-key "Today")
  1883. "ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
  1884. "ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
  1885. ;; Run the setup command.
  1886. (org-roam-setup)
  1887. #+END_SRC
  1888. *** Org Roam UI
  1889. #+NAME: emacs-org-roam-ui-package
  1890. #+BEGIN_SRC nix
  1891. epkgs.org-roam-ui
  1892. epkgs.websocket
  1893. epkgs.simple-httpd
  1894. #+END_SRC
  1895. [[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]].
  1896. #+NAME: emacs-org-roam-ui-elisp
  1897. #+BEGIN_SRC emacs-lisp
  1898. ;; HACK: Set up `org-roam-ui'.
  1899. ;; (add-to-list 'load-path "~/.local/source/org-roam-ui")
  1900. (load-library "org-roam-ui")
  1901. ;; Configure `org-roam-ui'.
  1902. (setq org-roam-ui-follow t
  1903. org-roam-ui-sync-theme t
  1904. org-roam-ui-open-on-start t
  1905. org-roam-ui-update-on-save t
  1906. org-roam-ui-browser-function #'browse-url-firefox)
  1907. ;; Configure keybindings.
  1908. (dotfiles/leader
  1909. "oru" '(:ignore t :which-key "UI")
  1910. "oruu" '(org-roam-ui-mode :which-key "Toggle UI")
  1911. "orut" '(org-roam-ui-sync-theme :which-key "Sync Theme"))
  1912. #+END_SRC
  1913. *** Org Drill
  1914. #+NAME: emacs-org-drill-package
  1915. #+BEGIN_SRC nix
  1916. epkgs.org-drill
  1917. #+END_SRC
  1918. [[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.
  1919. #+NAME: emacs-org-drill-elisp
  1920. #+BEGIN_SRC emacs-lisp
  1921. ;; Exclude :drill: items from `org-roam'.
  1922. (setq org-roam-db-node-include-function
  1923. (defun dotfiles/org-roam-include ()
  1924. (not (member "drill" (org-get-tags)))))
  1925. ;; Configure keybindings for `org-drill'.
  1926. (dotfiles/leader
  1927. "od" '(:ignore t :which-key "Drill")
  1928. "odd" '(org-drill :which-key "Drill")
  1929. "odc" '(org-drill-cram :which-key "Cram")
  1930. "odr" '(org-drill-resume :which-key "Resume"))
  1931. #+END_SRC
  1932. *** Org Agenda
  1933. 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.
  1934. #+NAME: emacs-org-agenda-elisp
  1935. #+BEGIN_SRC emacs-lisp
  1936. ;; Configure `org-agenda' to use the project files.
  1937. (setq org-agenda-files '("/etc/dotfiles/"
  1938. "/etc/dotfiles/docs/"
  1939. "/etc/dotfiles/docs/daily/"))
  1940. ;; Include files encrypted with `gpg'.
  1941. (require 'org)
  1942. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1943. (setq org-agenda-file-regexp
  1944. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1945. org-agenda-file-regexp)))
  1946. ;; Open an agenda buffer with SPC o a.
  1947. (dotfiles/leader
  1948. "oa" '(org-agenda :which-key "Agenda"))
  1949. #+END_SRC
  1950. *** Org Pomodoro
  1951. #+NAME: emacs-pomodoro-package
  1952. #+BEGIN_SRC nix
  1953. epkgs.org-pomodoro
  1954. #+END_SRC
  1955. [[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.
  1956. #+NAME: emacs-pomodoro-elisp
  1957. #+BEGIN_SRC emacs-lisp
  1958. ;; Configure `org-pomodor' with the overtime workflow.
  1959. (setq org-pomodoro-manual-break t
  1960. org-pomodoro-keep-killed-time t)
  1961. ;; Configure keybindings.
  1962. (dotfiles/leader
  1963. "op" '(org-pomodoro :which-key "Pomodoro"))
  1964. #+END_SRC
  1965. *** Writegood Mode
  1966. #+NAME: emacs-writegood-package
  1967. #+BEGIN_SRC nix
  1968. epkgs.writegood-mode
  1969. #+END_SRC
  1970. [[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:
  1971. + Weasel Words
  1972. + Passive Voice
  1973. + Duplicate Words
  1974. #+NAME: emacs-writegood-elisp
  1975. #+BEGIN_SRC emacs-lisp
  1976. ;; Configure `writegood-mode'.
  1977. (dotfiles/leader
  1978. "tg" '(writegood-mode :which-key "Grammar"))
  1979. #+END_SRC
  1980. *** Aspell
  1981. #+NAME: emacs-aspell-extras
  1982. #+BEGIN_SRC nix
  1983. pkgs.aspell
  1984. pkgs.aspellDicts.en
  1985. pkgs.aspellDicts.en-science
  1986. pkgs.aspellDicts.en-computers
  1987. #+END_SRC
  1988. [[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.
  1989. #+NAME: emacs-aspell-elisp
  1990. #+BEGIN_SRC emacs-lisp
  1991. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1992. (setq ispell-program-name "aspell"
  1993. ispell-eextra-args '("--sug-mode=fast"))
  1994. ;; Configure the built-in `flyspell-mode'.
  1995. (dotfiles/leader
  1996. "ts" '(flyspell-mode :which-key "Spelling"))
  1997. #+END_SRC
  1998. *** TexLive
  1999. [[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/:
  2000. | Name | Derivation | Comment |
  2001. |---------+---------------------------------+------------------------------------------------------------|
  2002. | Full | texlive.combined.scheme-full | Contains every TeX Live package |
  2003. | Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
  2004. | Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
  2005. | Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
  2006. | Minimal | texlive.combined.scheme-minimal | Contains plain only |
  2007. #+NAME: emacs-texlive-extras
  2008. #+BEGIN_SRC nix
  2009. # pkgs.texlive.combined.scheme-full
  2010. #+END_SRC
  2011. *** Http
  2012. #+NAME: emacs-http-package
  2013. #+BEGIN_SRC nix
  2014. epkgs.ob-http
  2015. #+END_SRC
  2016. 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.
  2017. #+NAME: emacs-http-elisp
  2018. #+BEGIN_SRC emacs-lisp
  2019. ;; Required to setup `ob-http'.
  2020. (org-babel-do-load-languages
  2021. 'org-babel-load-languages
  2022. '((http . t)))
  2023. #+END_SRC
  2024. *** Hugo
  2025. #+NAME: emacs-hugo-package
  2026. #+BEGIN_SRC nix
  2027. epkgs.ox-hugo
  2028. #+END_SRC
  2029. [[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/.
  2030. #+NAME: emacs-hugo-elisp
  2031. #+BEGIN_SRC emacs-lisp
  2032. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  2033. (require 'ox-hugo)
  2034. ;; Set up the base directory.
  2035. (setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
  2036. ;; Capture templates.
  2037. ;; Shared content
  2038. ;; (add-to-list 'org-roam-capture-templates
  2039. ;; '("p" "Post" plain "%?"
  2040. ;; :target (file+head "docs/posts/${slug}.org.gpg"
  2041. ;; "
  2042. ;; ,#+TITLE: ${title}
  2043. ;; ,#+AUTHOR: Christopher James Hayward
  2044. ;; ,#+DATE: %<%Y-%m-%d>
  2045. ;; ,#+EXPORT_FILE_NAME: ${slug}
  2046. ;; ,#+OPTIONS: num:nil todo:nil tasks:nil
  2047. ;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  2048. ;; ,#+HUGO_BASE_DIR: ../
  2049. ;; ,#+HUGO_AUTO_SET_LASTMOD: t
  2050. ;; ,#+HUGO_SECTION: posts
  2051. ;; ,#+HUGO_DRAFT: true
  2052. ;; "
  2053. ;; )
  2054. ;; :unnarrowed t))
  2055. #+END_SRC
  2056. *** Passwords
  2057. #+NAME: emacs-pass-extras
  2058. #+BEGIN_SRC nix
  2059. pkgs.pass
  2060. (pkgs.writeShellScriptBin "pass-init" ''
  2061. ${pkgs.git}/bin/git clone git@git.chrishayward.xyz:chris/passwords /home/chris/.password-store
  2062. ${pkgs.pass}/bin/pass init
  2063. '')
  2064. #+END_SRC
  2065. 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.
  2066. #+NAME: emacs-pass-package
  2067. #+BEGIN_SRC nix
  2068. epkgs.password-store
  2069. #+END_SRC
  2070. Configure keybindings for passwords behind =SPC p=:
  2071. #+NAME: emacs-pass-elisp
  2072. #+BEGIN_SRC emacs-lisp
  2073. ;; Set the path to the password store.
  2074. (setq password-store-dir (expand-file-name "~/.password-store"))
  2075. ;; Apply custom keybindings.
  2076. (dotfiles/leader
  2077. "p" '(:ignore t :which-key "Passwords")
  2078. "pp" '(password-store-copy :which-key "Copy")
  2079. "pe" '(password-store-edit :which-key "Edit")
  2080. "pi" '(password-store-insert :which-key "Insert")
  2081. "pr" '(password-store-rename :which-key "Rename")
  2082. "pg" '(password-store-generate :which-key "Generate"))
  2083. #+END_SRC
  2084. *** Docker
  2085. #+NAME: emacs-docker-package
  2086. #+BEGIN_SRC nix
  2087. epkgs.docker
  2088. epkgs.dockerfile-mode
  2089. #+END_SRC
  2090. 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.
  2091. #+NAME: emacs-docker-elisp
  2092. #+BEGIN_SRC emacs-lisp
  2093. ;; Apply custom keybindings.
  2094. (dotfiles/leader
  2095. "n" '(:ignore t :which-key "Containers")
  2096. "nd" '(docker :which-key "Docker"))
  2097. #+END_SRC
  2098. *** MU4E
  2099. #+NAME: emacs-mu4e-extras
  2100. #+BEGIN_SRC nix
  2101. pkgs.mu
  2102. pkgs.isync
  2103. (pkgs.writeShellScriptBin "mail-init" ''
  2104. ${pkgs.mu}/bin/mu init --maildir="/home/chris/.cache/mail" --my-address="chris@chrishayward.xyz"
  2105. ${pkgs.mu}/bin/mu index
  2106. '')
  2107. (pkgs.writeShellScriptBin "mail-sync" ''
  2108. ${pkgs.isync}/bin/mbsync -a
  2109. '')
  2110. #+END_SRC
  2111. [[https://github.com/djcb/mu][MU]] is a tool for dealing with email messages stored in the Maildir-format. Its purpose is to help quickly find the messages needed, and allows users to view messages, extract attachments, create new maildirs, and much more. It's written in C and C++, and includes extensions for Emacs (MU4E) and guile scheme.
  2112. #+NAME: emacs-mu4e-package
  2113. #+BEGIN_SRC nix
  2114. epkgs.mu4e
  2115. epkgs.mu4e-alert
  2116. #+END_SRC
  2117. [[https://emacswiki.org/emacs/mu4e][MU4E]] is an email client for Emacs. It's based on the mu email indexer / searcher.
  2118. + Fully search based: no folders, only queries
  2119. + Fully documented, with example configurations
  2120. + User-interface optimized for speed, with quick keystrokes for common actions
  2121. + Asynchronous; heavy actions do not block Emacs
  2122. + Support for non-English languages
  2123. + Support for signing and encryption
  2124. + Address auto-completion based on existing messages
  2125. + Extensibile with existing code and snippets
  2126. #+NAME: emacs-mu4e-config
  2127. #+BEGIN_SRC nix
  2128. # Deploy the authinfo file.
  2129. home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
  2130. # Deploy the isync configuration file.
  2131. home.file.".mbsyncrc" = {
  2132. text = ''
  2133. IMAPStore xyz-remote
  2134. Host mail.chrishayward.xyz
  2135. User chris@chrishayward.xyz
  2136. PassCmd "pass chrishayward.xyz/chris"
  2137. SSLType IMAPS
  2138. MaildirStore xyz-local
  2139. Path ~/.cache/mail/
  2140. Inbox ~/.cache/mail/inbox
  2141. SubFolders Verbatim
  2142. Channel xyz
  2143. Far :xyz-remote:
  2144. Near :xyz-local:
  2145. Patterns * !Archives
  2146. Create Both
  2147. Expunge Both
  2148. SyncState *
  2149. '';
  2150. };
  2151. #+END_SRC
  2152. Before using the software inside of Emacs, the maildir must be created in the local filesystem, and indexed. This is done with a single custom shell script binary ~mail-init~ which wraps the underlying mu commands. The emacs extension is shipped with the mu mail indexer. To utilize it, it must be added to the load path inside of Emacs.
  2153. #+NAME: emacs-mu4e-elisp
  2154. #+BEGIN_SRC emacs-lisp
  2155. ;; Add the `mu4e' shipped with `mu' to the load path.
  2156. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  2157. (require 'mu4e)
  2158. ;; Confiugure `mu4e'.
  2159. (setq mu4e-maildir "~/.cache/mail"
  2160. mu4e-update-interval (* 5 60)
  2161. mu4e-get-mail-command "mail-sync"
  2162. mu4e-compose-format-flowed t
  2163. mu4e-change-filenames-when-moving t
  2164. mu4e-compose-signature (concat "Chris Hayward\n"
  2165. "chris@chrishayward.xyz"))
  2166. ;; Sign all outbound email with GPG.
  2167. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  2168. (setq message-send-mail-function 'smtpmail-send-it
  2169. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  2170. ;; Setup `mu4e' accounts.
  2171. (setq mu4e-contexts
  2172. (list
  2173. ;; Main
  2174. ;; chris@chrishayward.xyz
  2175. (make-mu4e-context
  2176. :name "Main"
  2177. :match-func
  2178. (lambda (msg)
  2179. (when msg
  2180. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  2181. :vars
  2182. '((user-full-name . "Christopher James Hayward")
  2183. (user-mail-address . "chris@chrishayward.xyz")
  2184. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  2185. (smtpmail-smtp-service . 587)
  2186. (smtpmail-stream-type . starttls)))))
  2187. ;; Setup `mu4e-alert'.
  2188. (setq mu4e-alert-set-default-style 'libnotify)
  2189. (mu4e-alert-enable-notifications)
  2190. (mu4e-alert-enable-mode-line-display)
  2191. ;; Open the `mu4e' dashboard.
  2192. (dotfiles/leader
  2193. "m" '(mu4e :which-key "Mail"))
  2194. #+END_SRC
  2195. *** Projectile
  2196. #+NAME: emacs-projectile-package
  2197. #+BEGIN_SRC nix
  2198. epkgs.projectile
  2199. #+END_SRC
  2200. [[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.
  2201. #+NAME: emacs-projectile-elisp
  2202. #+BEGIN_SRC emacs-lisp
  2203. ;; Configure the `projectile-project-search-path'.
  2204. (setq projectile-project-search-path '("~/.local/source"))
  2205. (projectile-mode +1)
  2206. #+END_SRC
  2207. *** Electric Pair
  2208. #+NAME: emacs-electric-pair-elisp
  2209. #+BEGIN_SRC emacs-lisp
  2210. ;; Enable smart parenthesis.
  2211. (electric-pair-mode 1)
  2212. (setq electric-pair-preserve-balance nil)
  2213. #+END_SRC
  2214. *** LSP Mode
  2215. #+NAME: emacs-lsp-package
  2216. #+BEGIN_SRC nix
  2217. epkgs.lsp-mode
  2218. epkgs.lsp-ui
  2219. #+END_SRC
  2220. 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:
  2221. + Auto Complete
  2222. + Go To Defintion
  2223. + Find All References
  2224. #+NAME: emacs-lsp-elisp
  2225. #+BEGIN_SRC emacs-lisp
  2226. ;; Configure `lsp-mode'.
  2227. (setq lsp-idle-delay 0.5
  2228. lsp-prefer-flymake t)
  2229. ;; Configure `lsp-ui'.
  2230. (setq lsp-ui-doc-position 'at-point
  2231. lsp-ui-doc-delay 0.5)
  2232. ;; Add custom keybindings for `lsp'.
  2233. (dotfiles/leader
  2234. "l" '(:ignore t :which-key "LSP")
  2235. "ll" '(lsp :which-key "LSP")
  2236. "lr" '(lsp-rename :which-key "Rename")
  2237. "lf" '(lsp-format-buffer :which-key "Format")
  2238. "lo" '(lsp-organize-imports :which-key "Organize"))
  2239. #+END_SRC
  2240. *** CCLS
  2241. #+NAME: emacs-ccls-package
  2242. #+BEGIN_SRC nix
  2243. epkgs.ccls
  2244. #+END_SRC
  2245. [[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.
  2246. #+NAME: emacs-ccls-elisp
  2247. #+BEGIN_SRC emacs-lisp
  2248. ;; Configure `ccls' to work with `lsp-mode'.
  2249. (defun dotfiles/ccls-hook ()
  2250. (require 'ccls)
  2251. (lsp))
  2252. ;; Configure `ccls' mode hooks.
  2253. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  2254. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  2255. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  2256. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  2257. #+END_SRC
  2258. *** Company Mode
  2259. #+NAME: emacs-company-package
  2260. #+BEGIN_SRC nix
  2261. epkgs.company
  2262. #+END_SRC
  2263. [[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.
  2264. #+NAME: emacs-company-elisp
  2265. #+BEGIN_SRC emacs-lisp
  2266. ;; Configure `company-mode'.
  2267. (setq company-backend 'company-capf
  2268. lsp-completion-provider :capf)
  2269. ;; Enable it globally.
  2270. (global-company-mode +1)
  2271. #+END_SRC
  2272. *** Go Mode
  2273. #+NAME: emacs-golang-package
  2274. #+BEGIN_SRC nix
  2275. epkgs.go-mode
  2276. #+END_SRC
  2277. [[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.
  2278. #+NAME: emacs-golang-elisp
  2279. #+BEGIN_SRC emacs-lisp
  2280. ;; Configure `go-mode' to work with `lsp-mode'.
  2281. (defun dotfiles/go-hook ()
  2282. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  2283. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  2284. ;; Configure a custom `before-save-hook'.
  2285. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  2286. #+END_SRC
  2287. *** Dart Mode
  2288. #+NAME: emacs-dart-package
  2289. #+BEGIN_SRC nix
  2290. epkgs.dart-mode
  2291. epkgs.lsp-dart
  2292. epkgs.hover
  2293. #+END_SRC
  2294. [[https://github.com/emacs-lsp/lsp-dart][Emacs Dart IDE]] using LSP Mode to connect to Dart Analysis Server.
  2295. #+NAME: emacs-dart-elisp
  2296. #+BEGIN_SRC emacs-lisp
  2297. ;; Configure `dart-mode' to work with `lsp-mode'.
  2298. (add-hook 'dart-mode-hook 'lsp)
  2299. ;; Help Emacs find Flutter packages.
  2300. (setq lsp-dart-sdk-dir (getenv "$FLUTTER_SDK_DIR"))
  2301. #+END_SRC
  2302. *** Rustic
  2303. #+NAME: emacs-rustic-package
  2304. #+BEGIN_SRC nix
  2305. epkgs.rustic
  2306. #+END_SRC
  2307. 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!
  2308. #+NAME: emacs-rustic-elisp
  2309. #+BEGIN_SRC emacs-lisp
  2310. ;; Configure `rustic' with `lsp-mode'.
  2311. (setq rustic-format-on-save t
  2312. rustic-lsp-server 'rls)
  2313. #+END_SRC
  2314. *** Python Mode
  2315. #+NAME: emacs-python-package
  2316. #+BEGIN_SRC nix
  2317. epkgs.pretty-mode
  2318. #+END_SRC
  2319. 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.
  2320. #+NAME: emacs-python-elisp
  2321. #+BEGIN_SRC emacs-lisp
  2322. ;; Configure `pretty-mode' to work with `python-mode'.
  2323. (add-hook 'python-mode-hook
  2324. (lambda ()
  2325. (turn-on-pretty-mode)))
  2326. #+END_SRC
  2327. *** Protobuf Mode
  2328. #+NAME: emacs-protobuf-package
  2329. #+BEGIN_SRC nix
  2330. epkgs.protobuf-mode
  2331. #+END_SRC
  2332. Protobuf mode is an Emacs major mode for editing protocol buffers.
  2333. *** Typescript Mode
  2334. #+NAME: emacs-typescript-package
  2335. #+BEGIN_SRC nix
  2336. epkgs.typescript-mode
  2337. #+END_SRC
  2338. Typescript.el is a self-contained, lightweight and minimalist major-mode focused on providing basic font-lock/syntax-highlighting and indentation for Typescript syntax, without any external dependencies.
  2339. #+NAME: emacs-typescript-elisp
  2340. #+BEGIN_SRC emacs-lisp
  2341. ;; Use spaces instead of tabs.
  2342. (setq-default tab-width 4)
  2343. (setq-default indent-tabs-mode nil)
  2344. ;; Create a custom hook for typescript mode.
  2345. (defun dotfiles/typescript-hook ()
  2346. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  2347. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  2348. ;; Apply the hook.
  2349. (add-hook 'typescript-mode-hook #'dotfilers/typescript-hook)
  2350. #+END_SRC
  2351. *** YAML Mode
  2352. #+NAME: emacs-yaml-mode-package
  2353. #+BEGIN_SRC nix
  2354. epkgs.yaml-mode
  2355. #+END_SRC
  2356. YAML Mode helps you edit =YAML= ~.yml~ and ~.yaml~ files. It features font locking for data forms and comments, and some electric keys to help with block literals.
  2357. *** PlantUML
  2358. #+NAME: emacs-plantuml-extras
  2359. #+BEGIN_SRC nix
  2360. pkgs.plantuml
  2361. #+END_SRC
  2362. [[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.
  2363. #+NAME: emacs-plantuml-package
  2364. #+BEGIN_SRC nix
  2365. epkgs.plantuml-mode
  2366. #+END_SRC
  2367. [[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]].
  2368. #+NAME: emacs-plantuml-elisp
  2369. #+BEGIN_SRC emacs-lisp
  2370. ;; Configure `plantuml-mode'.
  2371. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  2372. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  2373. (setq plantuml-default-exec-mode 'executable
  2374. org-plantuml-exec-mode 'plantuml)
  2375. #+END_SRC
  2376. *** Neotree
  2377. #+NAME: emacs-neotree-package
  2378. #+BEGIN_SRC nix
  2379. epkgs.neotree
  2380. #+END_SRC
  2381. [[https://github.com/jaypei/emacs-neotree][Emacs Neotree]] is an Emacs tree plugin similar to NerdTree for Vim.
  2382. #+NAME: emacs-neotree-elisp
  2383. #+BEGIN_SRC emacs-lisp
  2384. ;; Enable all-the-icons font support.
  2385. (setq neo-theme (if (daemonp) 'icons 'arrow))
  2386. ;; Add a key to toggle the window.
  2387. (dotfiles/leader
  2388. "tr" '(neotree-toggle :which-key "Neotree"))
  2389. #+END_SRC
  2390. *** Swiper
  2391. #+NAME: emacs-swiper-package
  2392. #+BEGIN_SRC nix
  2393. epkgs.ivy
  2394. epkgs.counsel
  2395. epkgs.ivy-rich
  2396. epkgs.ivy-posframe
  2397. epkgs.ivy-prescient
  2398. #+END_SRC
  2399. [[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.
  2400. #+NAME: emacs-swiper-elisp
  2401. #+BEGIN_SRC emacs-lisp
  2402. ;; Configure `ivy'.
  2403. (setq counsel-linux-app-format-function
  2404. #'counsel-linux-app-format-function-name-only)
  2405. (ivy-mode +1)
  2406. (counsel-mode +1)
  2407. ;; Configure `ivy-rich'.
  2408. (ivy-rich-mode +1)
  2409. ;; Configure `ivy-posframe'.
  2410. (setq ivy-posframe-parameters '((parent-frame nil))
  2411. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  2412. (ivy-posframe-mode +1)
  2413. ;; Configure `ivy-prescient'.
  2414. (setq ivy-prescient-enable-filtering nil)
  2415. (ivy-prescient-mode +1)
  2416. #+END_SRC
  2417. *** Transparency
  2418. 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.
  2419. #+NAME: emacs-transparency-elisp
  2420. #+BEGIN_SRC emacs-lisp
  2421. ;; Configure the default frame transparency.
  2422. (set-frame-parameter (selected-frame) 'alpha '(85 . 85))
  2423. (add-to-list 'default-frame-alist '(alpha . (85 . 85)))
  2424. #+END_SRC
  2425. *** Desktop Environment
  2426. #+NAME: emacs-desktop-extras
  2427. #+BEGIN_SRC nix
  2428. pkgs.brightnessctl
  2429. #+END_SRC
  2430. 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]].
  2431. #+NAME: emacs-desktop-package
  2432. #+BEGIN_SRC nix
  2433. epkgs.desktop-environment
  2434. #+END_SRC
  2435. 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.
  2436. #+NAME: emacs-desktop-elisp
  2437. #+BEGIN_SRC emacs-lisp
  2438. ;; Configure `desktop-environment'.
  2439. (require 'desktop-environment)
  2440. (desktop-environment-mode +1)
  2441. #+END_SRC
  2442. *** Doom Themes
  2443. #+NAME: emacs-doom-themes-package
  2444. #+BEGIN_SRC nix
  2445. epkgs.doom-themes
  2446. #+END_SRC
  2447. [[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.
  2448. #+NAME: emacs-doom-themes-elisp
  2449. #+BEGIN_SRC emacs-lisp
  2450. ;; Include modern themes from `doom-themes'.
  2451. (setq doom-themes-enable-bold t
  2452. doom-themes-enable-italic t)
  2453. ;; Load the `doom-nord' and `doom-nord-light' themes.
  2454. (load-theme 'doom-nord-aurora t)
  2455. ;; (load-theme 'doom-nord-light t)
  2456. ;; (load-theme 'doom-nord t)
  2457. ;; Define a method for returning information about the current theme.
  2458. ;; This is based off the function `org-roam-ui-get-theme'.
  2459. (defun dotfiles/theme ()
  2460. "Return information about the current theme."
  2461. (list `(bg . ,(face-background hl-line-face))
  2462. `(bg-alt . ,(face-background 'default))
  2463. `(fg . ,(face-foreground 'default))
  2464. `(fg-alt . ,(face-foreground font-lock-comment-face))
  2465. `(red . ,(face-foreground 'error))
  2466. `(orange . ,(face-foreground 'warning))
  2467. `(yellow . ,(face-foreground font-lock-builtin-face))
  2468. `(green . ,(face-foreground 'success))
  2469. `(cyan . ,(face-foreground font-lock-constant-face))
  2470. `(blue . ,(face-foreground font-lock-keyword-face))
  2471. `(violet . ,(face-foreground font-lock-constant-face))
  2472. `(magenta . ,(face-foreground font-lock-preprocessor-face))))
  2473. ;; Load a new theme with <SPC> t t.
  2474. (dotfiles/leader
  2475. "tt" '(counsel-load-theme :which-key "Theme"))
  2476. #+END_SRC
  2477. Create a shell command that returns a JSON string of the current theme in the following format:
  2478. #+BEGIN_SRC json
  2479. {
  2480. "bg": "#272C36",
  2481. "bg-alt": "#2E3440",
  2482. "fg": "#ECEFF4",
  2483. "fg-alt": "#6f7787",
  2484. "red": "#BF616A",
  2485. "orange": "#EBCB8B",
  2486. "yellow": "#81A1C1",
  2487. "green": "#A3BE8C",
  2488. "cyan": "#81A1C1",
  2489. "blue": "#81A1C1",
  2490. "violet": "#81A1C1",
  2491. "magenta": "#81A1C1"
  2492. }
  2493. #+END_SRC
  2494. #+NAME: emacs-doom-themes-extras
  2495. #+BEGIN_SRC nix
  2496. (pkgs.writeShellScriptBin "dotfiles-theme" ''
  2497. ${myEmacs}/bin/emacsclient --no-wait --eval '(json-encode (dotfiles/theme))' | sed "s/\\\\//g" | sed -e 's/^"//' -e 's/"$//'
  2498. '')
  2499. #+END_SRC
  2500. *** Doom Modeline
  2501. #+NAME: emacs-doom-modeline-package
  2502. #+BEGIN_SRC nix
  2503. epkgs.doom-modeline
  2504. #+END_SRC
  2505. [[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.
  2506. #+NAME: emacs-doom-modeline-elisp
  2507. #+BEGIN_SRC emacs-lisp
  2508. ;; Configure `doom-modeline'.
  2509. (require 'doom-modeline)
  2510. (setq doom-modeline-height 16
  2511. doom-modeline-icon t)
  2512. ;; Launch after initialization.
  2513. (add-hook 'after-init-hook 'doom-modeline-mode)
  2514. ;; Define a modeline segment to show the workspace information.
  2515. (doom-modeline-def-segment dotfiles/workspaces
  2516. (exwm-workspace--update-switch-history)
  2517. (concat
  2518. (doom-modeline-spc)
  2519. (elt (let* ((num (exwm-workspace--count))
  2520. (sequence (number-sequence 0 (1- num)))
  2521. (not-empty (make-vector num nil)))
  2522. (dolist (i exwm--id-buffer-alist)
  2523. (with-current-buffer (cdr i)
  2524. (when exwm--frame
  2525. (setf (aref not-empty
  2526. (exwm-workspace--position exwm--frame))
  2527. t))))
  2528. (mapcar
  2529. (lambda (i)
  2530. (mapconcat
  2531. (lambda (j)
  2532. (format (if (= i j) "[%s]" " %s ")
  2533. (propertize
  2534. (apply exwm-workspace-index-map (list j))
  2535. 'face
  2536. (cond ((frame-parameter (elt exwm-workspace--list j)
  2537. 'exwm-urgency)
  2538. '(:inherit warning :weight bold))
  2539. ((= i j) '(:inherit underline :weight bold))
  2540. ((aref not-empty j) '(:inherit success :weight bold))
  2541. (t `((:foreground ,(face-foreground 'mode-line-inactive))))))))
  2542. sequence ""))
  2543. sequence))
  2544. (exwm-workspace--position (selected-frame)))))
  2545. ;; Define a custom modeline to override the default.
  2546. (doom-modeline-def-modeline 'dotfiles/modeline
  2547. '(bar workspace-name dotfiles/workspaces window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info)
  2548. '(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))
  2549. ;; Define a method to load the modeline.
  2550. (defun dotfiles/load-modeline ()
  2551. "Load the default modeline."
  2552. (doom-modeline-set-modeline 'dotfiles/modeline 'default))
  2553. ;; Enable `doom-modeline'.
  2554. (add-hook 'doom-modeline-mode-hook 'dotfiles/load-modeline)
  2555. (doom-modeline-mode +1)
  2556. (doom-modeline-set-modeline 'dotfiles/modeline 'default)
  2557. #+END_SRC
  2558. ** Website Configuration
  2559. #+ATTR_ORG: :width 800px
  2560. #+ATTR_HTML: :width 800px
  2561. #+ATTR_LATEX: :width 800px
  2562. [[./docs/images/website.png]]
  2563. My [[https://chrishayward.xyz][personal website]] is a static HTML page written with [[https://gohugo.io][Hugo]], and is fully integrated into this configuration. It uses the ~config.toml~, ~config.yaml~, or ~config.json~ file (found in the sites root directory) as the default site config. Working with this requires the module to be enabled.
  2564. #+BEGIN_SRC conf :noweb yes :tangle docs/config.toml
  2565. # <<file-warning>>
  2566. title = "Chris Hayward"
  2567. copyright = "Licensed under Attribution 4.0 International (CC BY 4.0)"
  2568. baseURL = "https://chrishayward.xyz/"
  2569. theme = "hello-friend-ng"
  2570. languageCode = "en-us"
  2571. defaultContentLanguage = "en"
  2572. pygmentsCodefences = true
  2573. pygmentsUseClasses = false
  2574. pygmentsStyle = "dracula"
  2575. <<website-params>>
  2576. <<website-privacy>>
  2577. <<website-layout>>
  2578. #+END_SRC
  2579. *** Params
  2580. Dates are important in [[https://gohugo.io][Hugo]], and they configure how dates are assigned and displayed in your content pages. Themes are also able to extract information from the configuration to display, including social media icons, subtitles, and footer sections.
  2581. #+NAME: website-params
  2582. #+BEGIN_SRC conf
  2583. [params]
  2584. dateform = "Jan 2, 2006"
  2585. dateformShort = "Jan 2"
  2586. dateformNum = "2006-01-02"
  2587. dateformNumTime = "2006-01-02 15:04 -0700"
  2588. authorName = "Christopher James Hayward"
  2589. homeSubtitle = "Airplanes, Linux, and Metalcore"
  2590. footerCopyright = ' &#183; <a href="http://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC BY 4.0</a>'
  2591. enableThemeToggle = true
  2592. [[params.social]]
  2593. name = "paypal"
  2594. url = "https://paypal.me/chrishaywardxyz"
  2595. [[params.social]]
  2596. name = "github"
  2597. url = "https://github.com/chayward1/"
  2598. [[params.social]]
  2599. name = "gitlab"
  2600. url = "https://gitlab.com/chayward1/"
  2601. [[params.social]]
  2602. name = "email"
  2603. url = "mailto:chris@chrishayward.xyz"
  2604. #+END_SRC
  2605. *** Privacy
  2606. I do not use any analytics or tracking in my website. Depending on the theme selected, some of these features may be enabled. I opt to override those settings here to make sure no unwanted trackers are loaded.
  2607. #+NAME: website-privacy
  2608. #+BEGIN_SRC conf
  2609. [privacy]
  2610. [privacy.disqus]
  2611. disable = true
  2612. [privacy.googleAnalytics]
  2613. disable = true
  2614. [privacy.instagram]
  2615. disable = true
  2616. [privacy.twitter]
  2617. disable = true
  2618. [privacy.vimeo]
  2619. disable = true
  2620. [privacy.youtube]
  2621. disable = true
  2622. #+END_SRC
  2623. *** Layout
  2624. Individual pages can be configured here to define the layout of the page. This is where quick links can be configured, and other sections such as blog posts, an about section, or a contact page can be added.
  2625. #+NAME: website-layout
  2626. #+BEGIN_SRC conf
  2627. [menu]
  2628. [[menu.main]]
  2629. identifier = "cloud"
  2630. name = "Cloud"
  2631. url = "https://cloud.chrishayward.xyz"
  2632. [[menu.main]]
  2633. identifier = "dotfiles"
  2634. name = "Dotfiles"
  2635. url = "/dotfiles"
  2636. [[menu.main]]
  2637. identifier = "projects"
  2638. name = "Projects"
  2639. url = "https://git.chrishayward.xyz"
  2640. #+END_SRC
  2641. * Footnotes