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.

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