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.

3056 lines
98 KiB

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