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.

2973 lines
95 KiB

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