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.

2993 lines
95 KiB

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