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.

3092 lines
99 KiB

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