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.

2995 lines
93 KiB

3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 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
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
  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. #+EXPORT_FILE_NAME: dotfiles
  9. #+HUGO_BASE_DIR: docs
  10. #+HUGO_AUTO_SET_LASTMOD: t
  11. #+HUGO_SECTION:
  12. #+HUGO_DRAFT: false
  13. #+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>
  14. #+HTML: <a href="https://www.gnu.org/software/emacs/"><img src="https://img.shields.io/badge/Emacs-28.0.50-blueviolet.svg?style=flat-square&logo=GNU%20Emacs&logoColor=white"></a>
  15. #+HTML: <a href="https://orgmode.org"><img src="https://img.shields.io/badge/Org-9.4.6-%2377aa99?style=flat-square&logo=org&logoColor=white"></a>
  16. #+NAME: description
  17. #+BEGIN_SRC text
  18. Immutable NixOS dotfiles.
  19. #+END_SRC
  20. #+ATTR_ORG: :width 800px
  21. #+ATTR_HTML: :width 800px
  22. #+ATTR_LATEX: :width 800px
  23. [[./docs/images/desktop-example.png]]
  24. Built for Life, Liberty, and the Open Road.
  25. + 100% Immutable
  26. + 100% Declarative
  27. + 100% Reproducible
  28. * Introduction
  29. 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.
  30. #+NAME: file-warning
  31. #+BEGIN_SRC text
  32. This file is controlled by /etc/dotfiles/README.org
  33. #+END_SRC
  34. ** Getting Started
  35. 1) [[https://nixos.org/download.html][Download the latest version of NixOS]]
  36. 2) [[https://nixos.org/manual/nixos/stable/#sec-installation-partitioning][Partition your drives and mount the file system]]
  37. 3) Clone the project ~git clone git@git.chrishayward.xyz:chris/dotfiles /mnt/etc/dotfiles~
  38. 4) Load the default shell ~nix-shell /mnt/etc/dotfiles~
  39. 5) Install the system ~sudo nixos-install --flake /mnt/etc/dotfiles#nixos~
  40. 6) Reboot, login and start a graphical system ~startx~
  41. ** Making Changes
  42. 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:
  43. #+NAME: rebuild-command-table
  44. | Command | Description |
  45. |----------+---------------------------------------------------------------------------------|
  46. | boot | Build the new configuration and make it the boot default, without activation |
  47. | test | Build and activate the new configuration, without adding it to the boot menu |
  48. | switch | Build and activate the new configuration, making it the new boot default |
  49. | build | Build the new configuration, without activation, nor adding it to the boot menu |
  50. | build-vm | Build a script that starts a virtual machine with the desired configuration |
  51. After making changes to the configuration the ~switch~ command will build and activate a new configuration.
  52. #+BEGIN_SRC shell
  53. # Build and activate a new configuration.
  54. sudo nixos-rebuild switch --flake $FLAKE#$HOSTNAME
  55. #+END_SRC
  56. 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.
  57. #+BEGIN_SRC shell
  58. # Rollback to the previous generation.
  59. sudo nixos-rebuild switch --rollback
  60. #+END_SRC
  61. ** Docker Container
  62. 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.
  63. Install from the command line: ~docker pull ghcr.io/chayward1/dotfiles:main~
  64. #+BEGIN_SRC dockerfile :tangle Dockerfile :noweb yes
  65. # <<file-warning>>
  66. # Derive from the official image.
  67. FROM nixos/nix
  68. # Setup the default environment.
  69. WORKDIR /etc/dotfiles
  70. COPY . .
  71. # Load the default system shell.
  72. RUN nix-shell /etc/dotfiles/shell.nix
  73. #+END_SRC
  74. * Operating System
  75. [[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.
  76. #+BEGIN_SRC nix :noweb yes :tangle flake.nix
  77. # <<file-warning>>
  78. {
  79. description = "<<description>>";
  80. inputs = {
  81. <<os-nixpkgs>>
  82. <<os-home-manager>>
  83. <<os-emacs-overlay>>
  84. <<os-nixos-hardware>>
  85. <<os-nix-on-droid>>
  86. };
  87. outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, ... }: {
  88. nixosConfigurations = {
  89. <<host-default>>
  90. <<host-acernitro>>
  91. <<host-raspberry>>
  92. <<host-homecloud>>
  93. <<host-android>>
  94. };
  95. };
  96. }
  97. #+END_SRC
  98. ** Nixpkgs
  99. [[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:
  100. 1) The current stable release
  101. 2) The Unstable branch following the latest development
  102. #+NAME: os-nixpkgs
  103. #+BEGIN_SRC nix
  104. nixpkgs.url = "nixpkgs/nixos-unstable";
  105. nixpkgs-unstable.url = "nixpkgs/master";
  106. #+END_SRC
  107. ** Home Manager
  108. [[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.
  109. #+NAME: os-home-manager
  110. #+BEGIN_SRC nix
  111. home-manager.url = "github:nix-community/home-manager";
  112. home-manager.inputs.nixpkgs.follows = "nixpkgs";
  113. #+END_SRC
  114. ** Emacs Overlay
  115. 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.
  116. #+NAME: os-emacs-overlay
  117. #+BEGIN_SRC nix
  118. emacs-overlay.url = "github:nix-community/emacs-overlay";
  119. #+END_SRC
  120. ** NixOS Hardware
  121. [[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.
  122. #+NAME: os-nixos-hardware
  123. #+BEGIN_SRC nix
  124. nixos-hardware.url = "github:nixos/nixos-hardware";
  125. #+END_SRC
  126. ** Nix On Droid
  127. [[https://github.com/t184256/nix-on-droid][Nix On Droid]] is a deployment of the [[https://nixos.org/manual/nix/stable/Nix][Nix Package Manager]] on [[https://android.com][Android]], in a single-click installable package. It does not require =root=, user namespace support, or disabling SELinux, but relies on =proot=. It has no relation to the Termux distribution.
  128. #+NAME: os-nix-on-droid
  129. #+BEGIN_SRC nix
  130. nix-on-droid.url = "github:t184256/nix-on-droid/master";
  131. nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
  132. #+END_SRC
  133. * Development Shells
  134. The command ~nix-shell~ will build the dependencies of the specified derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation /path/ have been set to their corresponding values.
  135. Import this shell with ~nix-shell /etc/dotfiles/shell.nix~.
  136. #+BEGIN_SRC nix :noweb yes :tangle shell.nix
  137. # <<file-warning>>
  138. { pkgs ? import <nixpkgs> { } }:
  139. with pkgs;
  140. let
  141. nixBin = writeShellScriptBin "nix" ''
  142. exec ${nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
  143. '';
  144. in mkShell {
  145. buildInputs = [
  146. git
  147. ];
  148. shellHook = ''
  149. export FLAKE="$(pwd)"
  150. export PATH="$FLAKE/bin:${nixBin}/bin:$PATH"
  151. '';
  152. }
  153. #+END_SRC
  154. ** Go
  155. [[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.
  156. Import this shell with ~nix-shell /etc/dotfiles/shells/go.nix~
  157. #+BEGIN_SRC nix :noweb yes :tangle shells/go.nix
  158. # <<file-warning>>
  159. { pkgs ? import <nixpkgs> { } }:
  160. with pkgs;
  161. mkShell {
  162. buildInputs = [
  163. go
  164. gopls
  165. # FIXME: Broken on nixpkgs/unstable.
  166. # protoc-gen-go
  167. # protoc-gen-go-grpc
  168. ];
  169. shellHook = ''
  170. export GO111MODULE=on
  171. export GOPATH=$XDG_DATA_HOME/go
  172. export PATH=$GOPATH/bin:$PATH
  173. '';
  174. }
  175. #+END_SRC
  176. ** Rust
  177. [[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 counting is optional.
  178. Import this shell with ~nix-shell /etc/dotfiles/shells/rust.nix~.
  179. #+BEGIN_SRC nix :noweb yes :tangle shells/rust.nix
  180. # <<file-warning>>
  181. { pkgs ? import <nixpkgs> { } }:
  182. with pkgs;
  183. mkShell {
  184. buildInputs = [
  185. rustup
  186. ];
  187. shellHook = ''
  188. export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
  189. export CARGO_HOME="$XDG_DATA_HOME/cargo"
  190. export PATH="$CARGO_HOME/bin:$PATH"
  191. '';
  192. }
  193. #+END_SRC
  194. ** Node
  195. [[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.
  196. Import this shell with ~nix-shell /etc/dotfiles/shells/node.nix~.
  197. #+BEGIN_SRC nix :noweb yes :tangle shells/node.nix
  198. # <<file-warning>>
  199. { pkgs ? import <nixpkgs> { } }:
  200. with pkgs;
  201. mkShell {
  202. buildInputs = [
  203. nodejs
  204. yarn
  205. ];
  206. shellHook = ''
  207. export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
  208. export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
  209. export NPM_CACHE_PREFIX="$XDG_CACHE_HOME/npm"
  210. export PATH="$(yarn global bin):$PATH"
  211. '';
  212. }
  213. #+END_SRC
  214. ** Java
  215. [[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.
  216. Import this shell with ~nix-shell /etc/dotfiles/shells/java.nix~.
  217. #+BEGIN_SRC nix :noweb yes :tangle shells/java.nix
  218. # <<file-warning>>
  219. { pkgs ? import <nixpkgs> { } }:
  220. with pkgs;
  221. mkShell {
  222. buildInputs = [
  223. # openjdk8 # Legacy Java 8 VM.
  224. # openjdk11 # Current LTS version of OpenJDK.
  225. openjdk14 # Current version of OpenJDK.
  226. ];
  227. shellHook = ''
  228. '';
  229. }
  230. #+END_SRC
  231. ** gRPC
  232. [[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.
  233. Import this shell with ~nix-shell /etc/dotfiles/shells/grpc.nix~.
  234. #+BEGIN_SRC nix :noweb yes :tangle shells/grpc.nix
  235. # <<file-warning>>
  236. { pkgs ? import <nixpkgs> { } }:
  237. with pkgs;
  238. mkShell {
  239. buildInputs = [
  240. grpc
  241. grpcui
  242. grpcurl
  243. # FIXME: Broken on nixpkgs/unstable.
  244. # grpc-tools
  245. ];
  246. shellHook = ''
  247. '';
  248. }
  249. #+END_SRC
  250. ** C/C++
  251. [[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.
  252. Import this shell with ~nix-shell /etc/dotfiles/shells/cc.nix~.
  253. #+BEGIN_SRC nix :noweb yes :tangle shells/cc.nix
  254. # <<file-warning>>
  255. { pkgs ? import <nixpkgs> { } }:
  256. with pkgs;
  257. mkShell {
  258. buildInputs = [
  259. gdb
  260. ccls
  261. cmake
  262. gnumake
  263. gcc-unwrapped
  264. ];
  265. shellHook = ''
  266. '';
  267. }
  268. #+END_SRC
  269. ** Python
  270. [[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.
  271. Import this shell with ~nix-shell /etc/dotfiles/shells/python.nix~
  272. #+BEGIN_SRC nix :noweb yes :tangle shells/python.nix
  273. # <<file-warning>>
  274. { pkgs ? import <nixpkgs> { } }:
  275. with pkgs;
  276. mkShell {
  277. buildInputs = [
  278. python38Packages.pip
  279. python38Packages.pip-tools
  280. python38Packages.pyls-mypy
  281. python38Packages.pyls-isort
  282. python38Packages.pyls-black
  283. ];
  284. shellHook = ''
  285. '';
  286. }
  287. #+END_SRC
  288. ** Docker
  289. [[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 configuratuion files.
  290. [[https://docs.docker.com/compose/][Compose]] is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application services. Then, with a single command, you create and start all of the services from your configuration.
  291. [[https://docs.docker.com/machine/][Machine]] is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with ~docker-machine~ commands. You can use Machine to create hosts on your local box, company network, data center, or on any cloud provider.
  292. Import this shell with ~nix-shell /etc/dotfiles/shells/docker.nix~
  293. #+BEGIN_SRC nix :noweb yes :tangle shells/docker.nix
  294. # <<file-warning>>
  295. { pkgs ? import <nixpkgs> { } }:
  296. with pkgs;
  297. mkShell {
  298. buildInputs = [
  299. docker-compose
  300. docker-machine
  301. ];
  302. shellHook = ''
  303. '';
  304. }
  305. #+END_SRC
  306. ** Heroku
  307. [[https://heroku.com][Heroku]] is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language. It now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.
  308. Import this shell with ~nix-shell /etc/dotfiles/shells/heroku.nix~
  309. #+BEGIN_SRC nix :noweb yes :tangle shells/heroku.nix
  310. # <<file-warning>>
  311. { pkgs ? import <nixpkgs> { } }:
  312. with pkgs;
  313. mkShell {
  314. buildInputs = [
  315. heroku
  316. ];
  317. shellHook = ''
  318. '';
  319. }
  320. #+END_SRC
  321. * Host Configurations
  322. [[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. It also makes it easier to share common configurations amongst all of the hosts, such as with pre-configured wireless networking:
  323. #+NAME: host-config-wifi
  324. #+BEGIN_SRC nix
  325. networking.wireless.networks = {
  326. MyWiFi_5C1870 = {
  327. priority = 3;
  328. pskRaw = "409b3c85fef1c5737f284d2f82f20dc6023e41804e862d4fa26265ef8193b326";
  329. };
  330. BELL182 = {
  331. priority = 2;
  332. pskRaw = "8b3c114c695c5013bbcf5fc0af781c7872f95c34e2cceb31afa7bfc1adf66245";
  333. };
  334. SM-G975W3034 = {
  335. priority = 1;
  336. pskRaw = "74835d96a98ca2c56ffe4eaf92223f8a555168b59ec2bb22b1e46b2a333adc80";
  337. };
  338. };
  339. #+END_SRC
  340. 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:
  341. #+NAME: host-config-home
  342. #+BEGIN_SRC nix
  343. networking.hosts = {
  344. "192.168.3.105" = [ "gamingpc" ];
  345. "192.168.3.163" = [ "acernitro" ];
  346. "192.168.3.182" = [ "raspberry" ];
  347. "192.168.3.183" = [ "homecloud" ];
  348. };
  349. #+END_SRC
  350. 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.
  351. #+NAME: host-config-ssh
  352. #+BEGIN_SRC nix
  353. users.users.chris.openssh.authorizedKeys.keys = [
  354. "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4wka/LfG3pto15DIm9LIRbb6rWr7/ipCRiCdAKSlY4 chris@chrishayward.xyz"
  355. ];
  356. #+END_SRC
  357. ** Default
  358. 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.
  359. #+NAME: host-default
  360. #+BEGIN_SRC nix :noweb yes
  361. nixos = nixpkgs.lib.nixosSystem {
  362. system = "x86_64-linux";
  363. specialArgs = { inherit inputs; };
  364. modules = [
  365. ./hosts/nixos
  366. <<module-x11>>
  367. <<module-ssh>>
  368. <<module-flakes>>
  369. <<module-cachix>>
  370. <<module-home-manager>>
  371. ];
  372. };
  373. #+END_SRC
  374. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#nixos~.
  375. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/default.nix
  376. # <<file-warning>>
  377. { ... }:
  378. {
  379. imports = [
  380. ./configuration.nix
  381. ./hardware.nix
  382. ];
  383. }
  384. #+END_SRC
  385. *** Configuration
  386. 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.
  387. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/configuration.nix
  388. # <<file-warning>>
  389. { config, pkgs, inputs, ... }:
  390. {
  391. time.timeZone = "America/Toronto";
  392. networking.hostName = "nixos";
  393. networking.useDHCP = false;
  394. networking.firewall.enable = false;
  395. networking.interfaces.ens3.useDHCP = true;
  396. <<host-config-home>>
  397. <<host-config-ssh>>
  398. programs.mtr.enable = true;
  399. programs.fish.enable = true;
  400. programs.gnupg.agent.enable = true;
  401. users.users.chris = {
  402. shell = pkgs.fish;
  403. isNormalUser = true;
  404. extraGroups = [ "wheel" ];
  405. };
  406. }
  407. #+END_SRC
  408. *** Hardware
  409. 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.
  410. #+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/hardware.nix
  411. # <<file-warning>>
  412. { config, lib, pkgs, modulesPath, ... }:
  413. {
  414. imports =
  415. [ (modulesPath + "/profiles/qemu-guest.nix")
  416. ];
  417. boot.initrd.availableKernelModules = [ "ata_piix" "floppy" "sd_mod" "sr_mod" ];
  418. boot.initrd.kernelModules = [ ];
  419. boot.kernelModules = [ ];
  420. boot.extraModulePackages = [ ];
  421. boot.loader.grub.enable = true;
  422. boot.loader.grub.version = 2;
  423. boot.loader.grub.device = "/dev/sda";
  424. fileSystems."/" =
  425. { device = "/dev/disk/by-uuid/fddc37ff-a442-41fa-afc4-abf878be7c5a";
  426. fsType = "ext4";
  427. };
  428. swapDevices =
  429. [ { device = "/dev/disk/by-uuid/5fc0e3df-e796-4fe2-8482-c6acaed9d36f"; }
  430. ];
  431. }
  432. #+END_SRC
  433. ** Acernitro
  434. My gaming laptop, the model is an [[https://laptopmedia.com/laptop-specs/acer-nitro-5-an515-53-2][Acer Nitro AN-515-53]]. The Nitro 5 has more in common with the mid-range notebooks rather than the gaming models due to its cooling design, chassis, and overall construction.
  435. Here are the specs:
  436. | Slot | Component |
  437. |---------+---------------------------------------|
  438. | CPU | Intel Core i5-8300H |
  439. | GPU | NVIDIA GeForce GTX 1050Ti (4GB GDDR5) |
  440. | RAM | 16GB DDR4 |
  441. | Display | 15.6" Full HD (1920 x 1080), IPS |
  442. | Storage | 1000GB HDD |
  443. | Weight | 2.48kg (5.5 lbs) |
  444. #+NAME: host-acernitro
  445. #+BEGIN_SRC nix :noweb yes
  446. acernitro = nixpkgs.lib.nixosSystem {
  447. system = "x86_64-linux";
  448. specialArgs = { inherit inputs; };
  449. modules = [
  450. ./hosts/acernitro
  451. <<module-x11>>
  452. <<module-ssh>>
  453. <<module-hugo>>
  454. <<module-docker>>
  455. <<module-flakes>>
  456. <<module-cachix>>
  457. <<module-nvidia>>
  458. <<module-firefox>>
  459. <<module-moonlight>>
  460. <<module-teamviewer>>
  461. <<module-home-manager>>
  462. ];
  463. };
  464. #+END_SRC
  465. Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#acernitro~.
  466. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/default.nix
  467. # <<file-warning>>
  468. { ... }:
  469. {
  470. imports = [
  471. ./configuration.nix
  472. ./hardware.nix
  473. ];
  474. }
  475. #+END_SRC
  476. *** Configuration
  477. This configuration is nearly identical to the default, except for a few key differences:
  478. + Enables sound
  479. + Applies the desired hostname
  480. + Enables power management daemon
  481. + It adds support for =UEFI= systems
  482. + Enables support for wireless networking
  483. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/configuration.nix
  484. # <<file-warning>>
  485. { config, pkgs, inputs, ... }:
  486. {
  487. time.timeZone = "America/Toronto";
  488. networking.hostName = "acernitro";
  489. networking.firewall.enable = false;
  490. networking.wireless.enable = true;
  491. networking.wireless.userControlled.enable = true;
  492. networking.useDHCP = false;
  493. networking.interfaces.enp6s0f1.useDHCP = true;
  494. networking.interfaces.wlp0s20f3.useDHCP = true;
  495. <<host-config-wifi>>
  496. <<host-config-home>>
  497. <<host-config-ssh>>
  498. services.tlp.enable = true;
  499. services.xserver.dpi = 96;
  500. services.xserver.libinput.touchpad.tapping = false;
  501. services.printing.enable = true;
  502. programs.mtr.enable = true;
  503. programs.fish.enable = true;
  504. programs.gnupg.agent.enable = true;
  505. users.users.chris = {
  506. shell = pkgs.fish;
  507. isNormalUser = true;
  508. extraGroups = [ "wheel" ];
  509. };
  510. }
  511. #+END_SRC
  512. *** Hardware
  513. + Enables sound via PulseAudio
  514. + Enables powertop via power management
  515. + Adds support for the NVIDIA Hybrid GPU
  516. #+BEGIN_SRC nix :noweb yes :tangle hosts/acernitro/hardware.nix
  517. # <<file-warning>>
  518. { config, lib, pkgs, modulesPath, ... }:
  519. {
  520. imports =
  521. [ (modulesPath + "/installer/scan/not-detected.nix")
  522. ];
  523. boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ];
  524. boot.initrd.kernelModules = [ ];
  525. boot.kernelModules = [ "kvm-intel" ];
  526. boot.extraModulePackages = [ ];
  527. boot.loader.systemd-boot.enable = true;
  528. boot.loader.efi.canTouchEfiVariables = true;
  529. sound.enable = true;
  530. hardware.pulseaudio.enable = true;
  531. hardware.pulseaudio.support32Bit = true;
  532. fileSystems."/" =
  533. { device = "/dev/disk/by-uuid/2f548eb9-47ce-4280-950f-9c6d1d162852";
  534. fsType = "ext4";
  535. };
  536. fileSystems."/boot" =
  537. { device = "/dev/disk/by-uuid/5BC3-73F3";
  538. fsType = "vfat";
  539. };
  540. swapDevices =
  541. [ { device = "/dev/disk/by-uuid/bef7bf62-d26f-45b1-a1f8-1227c2f8b26a"; }
  542. ];
  543. powerManagement.powertop.enable = true;
  544. powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  545. }
  546. #+END_SRC
  547. ** Raspberry
  548. The [[https://raspberrypi.org/products/raspberry-pi-400/][Raspberry Pi 400]] is your complete personal computer, built into a compact keyboard. It features a quad-core, 64-bit processor, 4GB of RAM, wireless networking, dual-display output, 4k video playback, as well as a 40-pin GPIO header. It's the most powerful Raspberry Pi computer yet.
  549. #+NAME: host-raspberry
  550. #+BEGIN_SRC nix :noweb yes
  551. raspberry = nixpkgs.lib.nixosSystem {
  552. system = "aarch64-linux";
  553. specialArgs = { inherit inputs; };
  554. modules = [
  555. ./hosts/raspberry
  556. <<module-x11>>
  557. <<module-ssh>>
  558. <<module-flakes>>
  559. <<module-cachix>>
  560. <<module-home-manager>>
  561. ];
  562. };
  563. #+END_SRC
  564. Deploy this configuration with ~sudo nixos-rebuild switch --flake /etc/dotfiles/#raspberry~.
  565. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/default.nix
  566. # <<file-warning>>
  567. { ... }:
  568. {
  569. imports = [
  570. ./configuration.nix
  571. ./hardware.nix
  572. ];
  573. }
  574. #+END_SRC
  575. *** Configuration
  576. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/configuration.nix
  577. # <<file-warning>>
  578. { config, pkgs, ... }:
  579. {
  580. time.timeZone = "America/Toronto";
  581. networking.hostName = "raspberry";
  582. networking.firewall.enable = false;
  583. networking.networkmanager.enable = true;
  584. networking.interfaces.eth0.useDHCP = true;
  585. networking.interfaces.wlan0.useDHCP = true;
  586. <<host-config-home>>
  587. <<host-config-ssh>>
  588. environment.systemPackages = [
  589. pkgs.libraspberrypi
  590. pkgs.raspberrypi-eeprom
  591. ];
  592. programs.fish.enable = true;
  593. programs.gnupg.agent.enable = true;
  594. users.users.chris = {
  595. shell = pkgs.fish;
  596. isNormalUser = true;
  597. extraGroups = [ "wheel" "networkmanager" ];
  598. };
  599. }
  600. #+END_SRC
  601. *** Hardware
  602. This section is very much a work in progress. I have struggled to get this device to boot according to the NixOS documentation / wiki on the subject. It seems that when running with the vendored kernel there's an issue booting from the SD card. Nevertheless, the issue is avoided by using the standard kernel.
  603. #+BEGIN_SRC nix :noweb yes :tangle hosts/raspberry/hardware.nix
  604. # <<file-warning>>
  605. { config, pkgs, lib, inputs, ... }:
  606. {
  607. # imports = [
  608. # inputs.nixos-hardware.nixosModules.raspberry-pi-4
  609. # ];
  610. # boot.kernelPackages = pkgs.linuxPackages_rpi4;
  611. boot.tmpOnTmpfs = true;
  612. boot.initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
  613. boot.kernelParams = [
  614. "8250.nr_uarts=1"
  615. "console=ttyAMA0,115200"
  616. "console=tty1"
  617. "cma=128M"
  618. ];
  619. boot.loader.grub.enable = false;
  620. boot.loader.generic-extlinux-compatible.enable = true;
  621. boot.loader.raspberryPi = {
  622. enable = true;
  623. version = 4;
  624. firmwareConfig = ''
  625. hdmi_drive=2
  626. hdmi_force_hotplug=1
  627. dtparam=sd_poll_once=on
  628. dtparam=audio=on
  629. '';
  630. };
  631. # FIXME: Requires GPU support.
  632. services.xserver.videoDrivers = [ "fbdev" ];
  633. sound.enable = true;
  634. hardware.pulseaudio.enable = true;
  635. hardware.enableRedistributableFirmware = true;
  636. # hardware.raspberry-pi."4".fkms-3d.enable = true;
  637. fileSystems = {
  638. "/" = {
  639. device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
  640. fsType = "ext4";
  641. options = [ "noatime" ];
  642. };
  643. };
  644. powerManagement.cpuFreqGovernor = "ondemand";
  645. }
  646. #+END_SRC
  647. ** Homecloud
  648. The [[https://www.raspberrypi.org/products/raspberry-pi-4-model-b/][Raspberry Pi Model B-8GB]] is the latest product in the popular Raspberry Pi range of computers. It offers groundbreaking increases in processor speed, multimedia performance, memory, and connectivity compared to the prior generation. On [[https://nixos.org/][NixOS]], the Raspberry Pi family is /only/ supported on the =AArch64= platform, although there is community support for =armv6l= and =armv7l=.
  649. #+NAME: host-homecloud
  650. #+BEGIN_SRC nix :noweb yes
  651. homecloud = nixpkgs.lib.nixosSystem {
  652. system = "aarch64-linux";
  653. specialArgs = { inherit inputs; };
  654. modules = [
  655. ./hosts/homecloud
  656. <<module-ssh>>
  657. <<module-flakes>>
  658. <<module-cachix>>
  659. <<module-jellyfin>>
  660. ];
  661. };
  662. #+END_SRC
  663. Deploy this configuration with ~sudo nixos-rebuild switch --flake /etc/dotfiles/#homecloud~.
  664. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/default.nix
  665. # <<file-warning>
  666. { ... }:
  667. {
  668. imports = [
  669. ./configuration.nix
  670. ./hardware.nix
  671. ];
  672. }
  673. #+END_SRC
  674. *** Configuration
  675. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/configuration.nix
  676. # <<file-warning>>
  677. { config, pkgs, ... }:
  678. {
  679. time.timeZone = "America/Toronto";
  680. networking.hostName = "homecloud";
  681. networking.firewall.enable = false;
  682. networking.networkmanager.enable = true;
  683. networking.interfaces.eth0.useDHCP = true;
  684. networking.interfaces.wlan0.useDHCP = true;
  685. <<host-config-wifi>>
  686. <<host-config-home>>
  687. <<host-config-ssh>>
  688. environment.systemPackages = [
  689. pkgs.libraspberrypi
  690. pkgs.raspberrypi-eeprom
  691. ];
  692. programs.fish.enable = true;
  693. programs.mtr.enable = true;
  694. users.users.chris = {
  695. shell = pkgs.fish;
  696. isNormalUser = true;
  697. extraGroups = [ "wheel" "networkmanager" ];
  698. };
  699. }
  700. #+END_SRC
  701. *** Hardware
  702. #+BEGIN_SRC nix :noweb yes :tangle hosts/homecloud/hardware.nix
  703. # <<file-warning>>
  704. { config, pkgs, lib, inputs, ... }:
  705. {
  706. # imports = [
  707. # inputs.nixos-hardware.nixosModules.raspberry-pi-4
  708. # ];
  709. # boot.kernelPackages = pkgs.linuxPackages_rpi4;
  710. boot.tmpOnTmpfs = true;
  711. boot.initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
  712. boot.kernelParams = [
  713. "8250.nr_uarts=1"
  714. "console=ttyAMA0,115200"
  715. "console=tty1"
  716. "cma=128M"
  717. ];
  718. boot.loader.grub.enable = false;
  719. boot.loader.generic-extlinux-compatible.enable = true;
  720. boot.loader.raspberryPi = {
  721. enable = true;
  722. version = 4;
  723. firmwareConfig = ''
  724. hdmi_drive=2
  725. hdmi_force_hotplug=1
  726. dtparam=sd_poll_once=on
  727. dtparam=audio=on
  728. '';
  729. };
  730. # hardware.raspberry-pi."4".fkms-3d.enable = true;
  731. fileSystems = {
  732. "/" = {
  733. device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888";
  734. fsType = "ext4";
  735. options = [ "noatime" ];
  736. };
  737. };
  738. powerManagement.cpuFreqGovernor = "ondemand";
  739. }
  740. #+END_SRC
  741. ** Android
  742. This is my [[https://samsung.com/us/mobile/galaxy-s10/buy/][Samsung Galaxy S10+]] running [[https://github.com/t184256/nix-on-droid][Nix On Droid]] with the experimental support for [[https://nixos.wiki/wiki/Flakes][Flakes]] being used to manage the configuration.
  743. #+NAME: host-android
  744. #+BEGIN_SRC nix
  745. android = (inputs.nix-on-droid.lib.aarch64-linux.nix-on-droid {
  746. config = ./hosts/android/nix-on-droid.nix;
  747. }).activationPackage;
  748. #+END_SRC
  749. Build the activation package with ~nix build .#android --impure~, and activate it with =result/activate=.
  750. #+BEGIN_SRC nix :noweb yes :tangle hosts/android/nix-on-droid.nix
  751. # <<file-warning>>
  752. { pkgs, ... }:
  753. {
  754. environment.packages = [
  755. pkgs.git
  756. pkgs.vim
  757. pkgs.pass
  758. pkgs.gnupg
  759. pkgs.openssh
  760. ];
  761. }
  762. #+END_SRC
  763. * Module Definitions
  764. 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.
  765. ** X11
  766. #+NAME: module-x11
  767. #+BEGIN_SRC nix
  768. ./modules/x11.nix
  769. #+END_SRC
  770. [[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.
  771. #+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
  772. # <<file-warning>>
  773. { config, pkgs, ... }:
  774. {
  775. services.xserver.enable = true;
  776. services.xserver.layout = "us";
  777. services.xserver.libinput.enable = true;
  778. services.xserver.displayManager.startx.enable = true;
  779. environment = {
  780. variables = {
  781. XDG_DESKTOP_DIR = "$HOME/";
  782. XDG_CACHE_HOME = "$HOME/.cache";
  783. XDG_CONFIG_HOME = "$HOME/.config";
  784. XDG_DATA_HOME = "$HOME/.local/share";
  785. XDG_BIN_HOME = "$HOME/.local/bin";
  786. };
  787. systemPackages = with pkgs; [
  788. pkgs.sqlite
  789. pkgs.pfetch
  790. pkgs.cmatrix
  791. pkgs.asciiquarium
  792. ];
  793. extraInit = ''
  794. export XAUTHORITY=/tmp/Xauthority
  795. export xserverauthfile=/tmp/xserverauth
  796. [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
  797. [ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
  798. '';
  799. };
  800. services.picom.enable = true;
  801. services.printing.enable = true;
  802. fonts.fonts = with pkgs; [
  803. iosevka-bin
  804. emacs-all-the-icons-fonts
  805. ];
  806. }
  807. #+END_SRC
  808. ** SSH
  809. #+NAME: module-ssh
  810. #+BEGIN_SRC nix
  811. ./modules/ssh.nix
  812. #+END_SRC
  813. [[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.
  814. Apply some configuration to the default settings:
  815. + Disable logging in as =root=
  816. + Disable password authentication
  817. #+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
  818. # <<file-warning>>
  819. { config, pkgs, ... }:
  820. {
  821. services.openssh = {
  822. enable = true;
  823. permitRootLogin = "no";
  824. passwordAuthentication = false;
  825. };
  826. }
  827. #+END_SRC
  828. ** Hugo
  829. #+NAME: module-hugo
  830. #+BEGIN_SRC nix
  831. ./modules/hugo.nix
  832. #+END_SRC
  833. [[https://gohugo.io][Hugo]] is one of the most popular open-source static site generators.
  834. #+BEGIN_SRC nix :noweb yes :tangle modules/hugo.nix
  835. # <<file-warning>>
  836. { config, pkgs, ... }:
  837. let
  838. myUpdateSite = pkgs.writeShellScriptBin "update-site" ''
  839. rsync -aP /etc/dotfiles/docs/public/ ubuntu@chrishayward.xyz:/var/www/chrishayward
  840. '';
  841. in {
  842. environment.systemPackages = [
  843. pkgs.hugo
  844. myUpdateSite
  845. ];
  846. }
  847. #+END_SRC
  848. ** Flakes
  849. #+NAME: module-flakes
  850. #+BEGIN_SRC nix
  851. ./modules/flakes.nix
  852. #+END_SRC
  853. [[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.
  854. #+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
  855. # <<file-warning>>
  856. { config, pkgs, inputs, ... }:
  857. {
  858. nix = {
  859. package = pkgs.nixUnstable;
  860. extraOptions = ''
  861. experimental-features = nix-command flakes
  862. '';
  863. };
  864. nixpkgs = {
  865. config = { allowUnfree = true; };
  866. overlays = [ inputs.emacs-overlay.overlay ];
  867. };
  868. }
  869. #+END_SRC
  870. ** Cachix
  871. #+NAME: module-cachix
  872. #+BEGIN_SRC nix
  873. ./modules/cachix.nix
  874. #+END_SRC
  875. [[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.
  876. #+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
  877. # <<file-warning>>
  878. { config, ... }:
  879. {
  880. nix = {
  881. binaryCaches = [
  882. "https://nix-community.cachix.org"
  883. ];
  884. binaryCachePublicKeys = [
  885. "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  886. ];
  887. };
  888. }
  889. #+END_SRC
  890. ** Docker
  891. #+NAME: module-docker
  892. #+BEGIN_SRC nix
  893. ./modules/docker.nix
  894. #+END_SRC
  895. [[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.
  896. #+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
  897. { config, pkgs, ... }:
  898. {
  899. # Enable the docker virutalization platform.
  900. virtualisation.docker = {
  901. enable = true;
  902. enableOnBoot = true;
  903. autoPrune.enable = true;
  904. };
  905. # Required for the `docker' command.
  906. users.users.chris.extraGroups = [ "docker" ];
  907. }
  908. #+END_SRC
  909. ** NVIDIA
  910. #+NAME: module-nvidia
  911. #+BEGIN_SRC nix
  912. ./modules/nvidia.nix
  913. #+END_SRC
  914. Use the ~lspci~ command to determine the type of graphics card you have, following the guide on NVIDIA at the [[https://nixos.wiki/wiki/Nvidia][NixOS Wiki]].
  915. #+BEGIN_QUOTE
  916. + MXM / output-providing card (shows as VGA Controller in lspci), i.e. graphics card in desktop computer or in some laptops
  917. + muxless/non-MXM Optimus cards have no display outputs and show as 3D Controller in lspci output, seen in most modern consumer laptops
  918. MXM cards allow you to use the Nvidia card standalone, in Non-Optimus mode. Non-MXM cards require Optimus, Nvidia's integrated-vs-discrete GPU switching technology.
  919. #+END_QUOTE
  920. Your output should look something like this:
  921. #+BEGIN_EXAMPLE
  922. ...
  923. 00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630 (Mobile)
  924. Subsystem: Acer Incorporated [ALI] Device 1264
  925. Kernel driver in use: i915
  926. Kernel modules: i915
  927. ...
  928. 01:00.0 VGA compatible controller: NVIDIA Corporation GP107M [GeForce GTX 1050 Mobile] (rev a1)
  929. Subsystem: Acer Incorporated [ALI] Device 1265
  930. Kernel driver in use: nouveau
  931. Kernel modules: nvidiafb, nouveau
  932. 01:00.1 Audio device: NVIDIA Corporation GP107GL High Definition Audio Controller (rev a1)
  933. Kernel driver in use: snd_hda_intel
  934. Kernel modules: snd_hda_intel
  935. ...
  936. #+END_EXAMPLE
  937. This reveals the information needed, which is the information about the two display cards in the laptop:
  938. + Intel UHD :: This is the dedicated graphics on the CPU
  939. + NVIDIA GP107M :: This is the /mobile/ version of the GTX 1050ti
  940. #+BEGIN_SRC nix :noweb yes :tangle modules/nvidia.nix
  941. { config, pkgs, ... }:
  942. let
  943. myIntelBusId = "PCI:0:2:0";
  944. myNvidiaBusId = "PCI:1:0:0";
  945. myNvidiaOffload = pkgs.writeShellScriptBin "nvidia-offload" ''
  946. export __NV_PRIME_RENDER_OFFLOAD=1
  947. export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
  948. export __GLX_VENDOR_LIBRARY_NAME=nvidia
  949. export __VK_LAYER_NV_optimus=NVIDIA_only
  950. exec -a "$0" "$@"
  951. '';
  952. in {
  953. # Add the offload script to the $PATH.
  954. environment.systemPackages = [ myNvidiaOffload ];
  955. # Configure XDG compliance.
  956. environment.variables = {
  957. __GL_SHADER_DISK_CACHE_PATH = "$XDG_CACHE_HOME/nv";
  958. CUDA_CACHE_PATH = "$XDG_CACHE_HOME/nv";
  959. };
  960. # Enable the NVIDIA drivers.
  961. services.xserver.videoDrivers = [ "nvidia" ];
  962. # Fix screen tearing.
  963. services.xserver.screenSection = ''
  964. Option "metamodes" "nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}"
  965. Option "AllowIndirectGLXProtocol" "off"
  966. Option "TripleBuffer" "on"
  967. '';
  968. # Configure `offload-mode'.
  969. hardware.nvidia.prime = {
  970. offload.enable = true;
  971. intelBusId = myIntelBusId;
  972. nvidiaBusId = myNvidiaBusId;
  973. };
  974. # Add OpenGL support.
  975. hardware.opengl = {
  976. enable = true;
  977. driSupport = true;
  978. driSupport32Bit = true;
  979. extraPackages32 = with pkgs; [
  980. pkgsi686Linux.libva
  981. intel-media-driver
  982. vaapiIntel
  983. ];
  984. };
  985. # Add user to video group.
  986. users.users.chris = {
  987. extraGroups = [ "video" ];
  988. };
  989. }
  990. #+END_SRC
  991. ** Firefox
  992. #+NAME: module-firefox
  993. #+BEGIN_SRC nix
  994. ./modules/firefox.nix
  995. #+END_SRC
  996. [[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.
  997. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  998. # <<file-warning>>
  999. { pkgs, ... }:
  1000. {
  1001. # NOTE: Use the binary until module is developed.
  1002. environment.systemPackages = [
  1003. pkgs.firefox-bin
  1004. ];
  1005. }
  1006. #+END_SRC
  1007. ** Jellyfin
  1008. #+NAME: module-jellyfin
  1009. #+BEGIN_SRC nix
  1010. ./modules/jellyfin.nix
  1011. #+END_SRC
  1012. [[https://jellyfin.org][Jellyfin]] is a suite of multimedia applications designed to organize, manage, and share digital media files to networked devices. It consists of a server application installed on a machine, and another application running as a client on devices such as Smartphones, Tablets, SmartTVs, Streaming Media Players, Game Consoles, or in a Web Browser. It can also serve media to DLNA and Chromecast enabled devices. It's free and open-source software fork of Emby.
  1013. #+BEGIN_SRC nix :noweb yes :tangle modules/jellyfin.nix
  1014. # <<file-warning>>
  1015. { config, pkgs, ... }:
  1016. {
  1017. services.jellyfin = {
  1018. enable = true;
  1019. };
  1020. }
  1021. #+END_SRC
  1022. ** Moonlight
  1023. #+NAME: module-moonlight
  1024. #+BEGIN_SRC nix
  1025. ./modules/moonlight.nix
  1026. #+END_SRC
  1027. [[https://moonlight-stream.org][Moonlight]] is an open-source implementation of NVIDIA's GameStream Protocol. You can stream your collection of PC games from your GameStream-compatible PC to any supported device and play them remotely. Moonlight is perfect for gaming on the go (or on [[https://linux.org][GNU/Linux]]) without sacrificing the graphics and game selection available for the PC.
  1028. #+BEGIN_SRC nix :noweb yes :tangle modules/moonlight.nix
  1029. # <<file-warning>>
  1030. { pkgs, ... }:
  1031. {
  1032. environment.systemPackages = [
  1033. pkgs.moonlight-qt
  1034. ];
  1035. }
  1036. #+END_SRC
  1037. ** Teamviewer
  1038. #+NAME: module-teamviewer
  1039. #+BEGIN_SRC nix
  1040. ./modules/teamviewer.nix
  1041. #+END_SRC
  1042. The [[https://teamviewer.com][Teamviewer]] remote connectivity cloud platform enables secure remote access to any device, across platforms, from anywhere, anytime. Teamviewer connects computers, smartphones, servers, IoT devices, robots -- anything -- with fast, high performance connections through their global access network. It has been used in outer-space low-bandwidth environments.
  1043. #+BEGIN_SRC nix :noweb yes :tangle modules/teamviewer.nix
  1044. # <<file-warning>>
  1045. { pkgs, ... }:
  1046. {
  1047. # NOTE: Neither of these are working!
  1048. # services.teamviewer.enable = true;
  1049. # environment.systemPackages = [
  1050. # pkgs.teamviewer
  1051. # ];
  1052. }
  1053. #+END_SRC
  1054. ** Home Manager
  1055. [[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.
  1056. #+NAME: module-home-manager
  1057. #+BEGIN_SRC nix :noweb yes
  1058. inputs.home-manager.nixosModules.home-manager {
  1059. home-manager.useGlobalPkgs = true;
  1060. home-manager.useUserPackages = true;
  1061. home-manager.users.chris = {
  1062. imports = [
  1063. <<module-git>>
  1064. <<module-gpg>>
  1065. <<module-vim>>
  1066. <<module-gtk>>
  1067. <<module-emacs>>
  1068. ];
  1069. };
  1070. }
  1071. #+END_SRC
  1072. *** Git
  1073. #+NAME: module-git
  1074. #+BEGIN_SRC nix
  1075. ./modules/git.nix
  1076. #+END_SRC
  1077. [[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.
  1078. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  1079. # <<file-warning>>
  1080. { pkgs, ... }:
  1081. let
  1082. # Fix any corruptions in the local copy.
  1083. myGitFix = pkgs.writeShellScriptBin "git-fix" ''
  1084. if [ -d .git/objects/ ]; then
  1085. find .git/objects/ -type f -empty | xargs rm -f
  1086. git fetch -p
  1087. git fsck --full
  1088. fi
  1089. exit 1
  1090. '';
  1091. in {
  1092. home.packages = [ myGitFix ];
  1093. programs.git = {
  1094. enable = true;
  1095. userName = "Christopher James Hayward";
  1096. userEmail = "chris@chrishayward.xyz";
  1097. signing = {
  1098. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  1099. signByDefault = true;
  1100. };
  1101. };
  1102. }
  1103. #+END_SRC
  1104. *** Gpg
  1105. #+NAME: module-gpg
  1106. #+BEGIN_SRC nix
  1107. ./modules/gpg.nix
  1108. #+END_SRC
  1109. [[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.
  1110. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  1111. # <<file-warning>>
  1112. { pkgs, ... }:
  1113. {
  1114. services.gpg-agent = {
  1115. enable = true;
  1116. defaultCacheTtl = 1800;
  1117. enableSshSupport = true;
  1118. pinentryFlavor = "gtk2";
  1119. };
  1120. }
  1121. #+END_SRC
  1122. *** Vim
  1123. #+NAME: module-vim
  1124. #+BEGIN_SRC nix
  1125. ./modules/vim.nix
  1126. #+END_SRC
  1127. [[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
  1128. + Simplify maintenance and encourage contributions
  1129. + Split the work between multiple developers
  1130. + Enable advanced UIs without core modification
  1131. + Maximize extensibility
  1132. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  1133. # <<file-warning>>
  1134. { pkgs, ... }:
  1135. {
  1136. programs.neovim = {
  1137. enable = true;
  1138. viAlias = true;
  1139. vimAlias = true;
  1140. vimdiffAlias = true;
  1141. extraConfig = ''
  1142. set number relativenumber
  1143. set nobackup
  1144. '';
  1145. extraPackages = [
  1146. pkgs.nixfmt
  1147. ];
  1148. plugins = with pkgs.vimPlugins; [
  1149. vim-nix
  1150. vim-airline
  1151. vim-polyglot
  1152. ];
  1153. };
  1154. }
  1155. #+END_SRC
  1156. *** GTK
  1157. #+NAME: module-gtk
  1158. #+BEGIN_SRC nix
  1159. ./modules/gtk.nix
  1160. #+END_SRC
  1161. [[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.
  1162. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  1163. # <<file-warning>>
  1164. { pkgs, ... }:
  1165. {
  1166. home.packages = [
  1167. pkgs.nordic
  1168. pkgs.arc-icon-theme
  1169. pkgs.lxappearance
  1170. ];
  1171. home.file.".gtkrc-2.0" = {
  1172. text = ''
  1173. # gtk-theme-name="Nordic-Polar"
  1174. gtk-theme-name="Nordic-darker"
  1175. gtk-icon-theme-name="Arc"
  1176. gtk-font-name="Sans 10"
  1177. gtk-cursor-theme-size=0
  1178. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  1179. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  1180. gtk-button-images=0
  1181. gtk-menu-images=0
  1182. gtk-enable-event-sounds=1
  1183. gtk-enable-input-feedback-sounds=1
  1184. gtk-xft-antialias=1
  1185. gtk-xft-hinting=1
  1186. gtk-xft-hintstyle="hintmedium"
  1187. '';
  1188. };
  1189. }
  1190. #+END_SRC
  1191. * Emacs Configuration
  1192. #+NAME: module-emacs
  1193. #+BEGIN_SRC nix
  1194. ./modules/emacs.nix
  1195. #+END_SRC
  1196. [[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:
  1197. + Highly customizable
  1198. + Full Unicopde support
  1199. + Content-aware editing modes
  1200. + Complete built-in documentation
  1201. + Wide range of functionality beyond text editing
  1202. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  1203. # <<file-warning>>
  1204. { pkgs, ... }:
  1205. let
  1206. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  1207. config = ../README.org;
  1208. package = <<emacs-native-comp-package>>
  1209. alwaysEnsure = true;
  1210. alwaysTangle = true;
  1211. extraEmacsPackages = epkgs: [
  1212. # Required packages...
  1213. <<emacs-exwm-package>>
  1214. <<emacs-evil-package>>
  1215. <<emacs-general-package>>
  1216. <<emacs-which-key-package>>
  1217. # Optional packages.
  1218. <<emacs-org-package>>
  1219. <<emacs-org-roam-package>>
  1220. <<emacs-org-drill-package>>
  1221. <<emacs-pomodoro-package>>
  1222. <<emacs-writegood-package>>
  1223. <<emacs-http-package>>
  1224. <<emacs-hugo-package>>
  1225. <<emacs-reveal-package>>
  1226. <<emacs-pass-package>>
  1227. <<emacs-docker-package>>
  1228. <<emacs-mu4e-package>>
  1229. <<emacs-dired-package>>
  1230. <<emacs-icons-package>>
  1231. <<emacs-emoji-package>>
  1232. <<emacs-eshell-package>>
  1233. <<emacs-vterm-package>>
  1234. <<emacs-magit-package>>
  1235. <<emacs-fonts-package>>
  1236. <<emacs-elfeed-package>>
  1237. <<emacs-nix-mode-package>>
  1238. <<emacs-projectile-package>>
  1239. <<emacs-lsp-package>>
  1240. <<emacs-company-package>>
  1241. <<emacs-ccls-package>>
  1242. <<emacs-golang-package>>
  1243. <<emacs-python-package>>
  1244. <<emacs-rustic-package>>
  1245. <<emacs-plantuml-package>>
  1246. <<emacs-protobuf-package>>
  1247. <<emacs-swiper-package>>
  1248. <<emacs-desktop-package>>
  1249. <<emacs-doom-themes-package>>
  1250. <<emacs-doom-modeline-package>>
  1251. ];
  1252. };
  1253. in {
  1254. home.packages = [
  1255. <<emacs-exwm-extras>>
  1256. <<emacs-pass-extras>>
  1257. <<emacs-mu4e-extras>>
  1258. <<emacs-aspell-extras>>
  1259. <<emacs-texlive-extras>>
  1260. <<emacs-desktop-extras>>
  1261. <<emacs-plantuml-extras>>
  1262. <<emacs-nix-mode-extras>>
  1263. ];
  1264. programs.emacs = {
  1265. enable = true;
  1266. package = myEmacs;
  1267. };
  1268. <<emacs-exwm-config>>
  1269. <<emacs-exwm-xinitrc>>
  1270. <<emacs-mu4e-config>>
  1271. }
  1272. #+END_SRC
  1273. 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.
  1274. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  1275. ;; <<file-warning>>
  1276. ;; Required inputs.
  1277. <<emacs-exwm-elisp>>
  1278. <<emacs-evil-elisp>>
  1279. <<emacs-general-elisp>>
  1280. <<emacs-which-key-elisp>>
  1281. ;; Optional inputs.
  1282. <<emacs-org-elisp>>
  1283. <<emacs-org-roam-elisp>>
  1284. <<emacs-org-drill-elisp>>
  1285. <<emacs-org-agenda-elisp>>
  1286. <<emacs-pomodoro-elisp>>
  1287. <<emacs-writegood-elisp>>
  1288. <<emacs-aspell-elisp>>
  1289. <<emacs-eww-elisp>>
  1290. <<emacs-http-elisp>>
  1291. <<emacs-hugo-elisp>>
  1292. <<emacs-reveal-elisp>>
  1293. <<emacs-pass-elisp>>
  1294. <<emacs-docker-elisp>>
  1295. <<emacs-erc-elisp>>
  1296. <<emacs-mu4e-elisp>>
  1297. <<emacs-dired-elisp>>
  1298. <<emacs-icons-elisp>>
  1299. <<emacs-emoji-elisp>>
  1300. <<emacs-eshell-elisp>>
  1301. <<emacs-vterm-elisp>>
  1302. <<emacs-magit-elisp>>
  1303. <<emacs-fonts-elisp>>
  1304. <<emacs-elfeed-elisp>>
  1305. <<emacs-projectile-elisp>>
  1306. <<emacs-lsp-elisp>>
  1307. <<emacs-company-elisp>>
  1308. <<emacs-golang-elisp>>
  1309. <<emacs-python-elisp>>
  1310. <<emacs-rustic-elisp>>
  1311. <<emacs-plantuml-elisp>>
  1312. <<emacs-desktop-elisp>>
  1313. ;; User interface.
  1314. <<emacs-swiper-elisp>>
  1315. <<emacs-transparency-elisp>>
  1316. <<emacs-doom-themes-elisp>>
  1317. <<emacs-doom-modeline-elisp>>
  1318. #+END_SRC
  1319. 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=.
  1320. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  1321. ;; <<file-warning>>
  1322. <<emacs-disable-ui-elisp>>
  1323. <<emacs-native-comp-elisp>>
  1324. <<emacs-backup-files-elisp>>
  1325. <<emacs-shell-commands-elisp>>
  1326. #+END_SRC
  1327. ** Native Comp
  1328. #+NAME: emacs-native-comp-package
  1329. #+BEGIN_SRC nix
  1330. pkgs.emacsGcc;
  1331. #+END_SRC
  1332. 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.
  1333. #+NAME: emacs-native-comp-elisp
  1334. #+BEGIN_SRC emacs-lisp
  1335. ;; Silence warnings from packages that don't support `native-comp'.
  1336. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  1337. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  1338. #+END_SRC
  1339. ** Disable UI
  1340. [[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.
  1341. #+NAME: emacs-disable-ui-elisp
  1342. #+BEGIN_SRC emacs-lisp
  1343. ;; Disable unwanted UI elements.
  1344. (tooltip-mode -1)
  1345. (menu-bar-mode -1)
  1346. (tool-bar-mode -1)
  1347. (scroll-bar-mode -1)
  1348. ;; Fix the scrolling behaviour.
  1349. (setq scroll-conservatively 101)
  1350. ;; Fix mouse-wheel scrolling behaviour.
  1351. (setq mouse-wheel-follow-mouse t
  1352. mouse-wheel-progressive-speed t
  1353. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  1354. ;; Start in fullscreen/maximized.
  1355. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  1356. #+END_SRC
  1357. ** Backup Files
  1358. [[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.
  1359. #+NAME: emacs-backup-files-elisp
  1360. #+BEGIN_SRC emacs-lisp
  1361. ;; Disable unwanted features.
  1362. (setq make-backup-files nil
  1363. create-lockfiles nil)
  1364. #+END_SRC
  1365. ** Shell Commands
  1366. Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
  1367. 1) Method to run an external process, launching any application on a new process without interference
  1368. 2) Method to apply commands to the current call process, effecting the running instance
  1369. #+NAME: emacs-shell-commands-elisp
  1370. #+BEGIN_SRC emacs-lisp
  1371. ;; Define a method to run an external process.
  1372. (defun dotfiles/run (cmd)
  1373. "Run an external process."
  1374. (interactive (list (read-shell-command "λ ")))
  1375. (start-process-shell-command cmd nil cmd))
  1376. ;; Define a method to run a background process.
  1377. (defun dotfiles/run-in-background (cmd)
  1378. (let ((command-parts (split-string cmd "[ ]+")))
  1379. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  1380. #+END_SRC
  1381. ** Nix Mode
  1382. #+NAME: emacs-nix-mode-extras
  1383. #+BEGIN_SRC nix
  1384. pkgs.nixfmt
  1385. #+END_SRC
  1386. [[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.
  1387. #+NAME: emacs-nix-mode-package
  1388. #+BEGIN_SRC nix
  1389. epkgs.nix-mode
  1390. #+END_SRC
  1391. ** Evil Mode
  1392. [[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.
  1393. #+NAME: emacs-evil-package
  1394. #+BEGIN_SRC nix
  1395. epkgs.evil
  1396. epkgs.evil-collection
  1397. epkgs.evil-surround
  1398. epkgs.evil-nerd-commenter
  1399. #+END_SRC
  1400. 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]].
  1401. #+NAME: emacs-evil-elisp
  1402. #+BEGIN_SRC emacs-lisp
  1403. ;; Enable the Extensible VI Layer for Emacs.
  1404. (setq evil-want-integration t ;; Required for `evil-collection.'
  1405. evil-want-keybinding nil ;; Same as above.
  1406. evil-want-C-i-jump nil) ;; Disable jumping in terminal.
  1407. (evil-mode +1)
  1408. ;; Configure `evil-collection'.
  1409. (evil-collection-init)
  1410. ;; Configure `evil-surround'.
  1411. (global-evil-surround-mode +1)
  1412. ;; Configure `evil-nerd-commenter'.
  1413. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1414. ;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
  1415. (evil-define-key 'normal 'org-mode-map (kbd "<tab>") #'org-cycle)
  1416. #+END_SRC
  1417. ** EXWM
  1418. #+NAME: emacs-exwm-package
  1419. #+BEGIN_SRC nix
  1420. epkgs.exwm
  1421. #+END_SRC
  1422. [[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:
  1423. + Fully keyboard-driven operations
  1424. + Hybrid layout modes (tiling & stacking)
  1425. + Dynamic workspace support
  1426. + ICCM/EWMH compliance
  1427. #+NAME: emacs-exwm-extras
  1428. #+BEGIN_SRC nix
  1429. pkgs.nitrogen
  1430. pkgs.autorandr
  1431. #+END_SRC
  1432. 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]].
  1433. #+NAME: emacs-exwm-config
  1434. #+BEGIN_SRC nix
  1435. xsession = {
  1436. enable = true;
  1437. windowManager.command = ''
  1438. ${pkgs.nitrogen}/bin/nitrogen --restore
  1439. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1440. ${myEmacs}/bin/emacsclient -c
  1441. '';
  1442. };
  1443. #+END_SRC
  1444. [[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=.
  1445. #+NAME: emacs-exwm-xinitrc
  1446. #+BEGIN_SRC nix
  1447. home.file.".xinitrc" = {
  1448. text = ''
  1449. exec ./.xsession
  1450. '';
  1451. };
  1452. #+END_SRC
  1453. #+NAME: emacs-exwm-elisp
  1454. #+BEGIN_SRC emacs-lisp
  1455. ;; Configure `exwm'.
  1456. (setq exwm-layout-show-all-buffers t
  1457. exwm-worspace-show-all-buffers t)
  1458. ;; Configure input keys.
  1459. (setq exwm-input-prefix-keys
  1460. '(?\M-x
  1461. ?\C-g
  1462. ?\C-\ ))
  1463. (setq exwm-input-global-keys
  1464. `(([?\s-r] . exwm-reset)
  1465. ,@(mapcar (lambda (i)
  1466. `(,(kbd (format "s-%d" i)) .
  1467. (lambda ()
  1468. (interactive)
  1469. (exwm-workspace-switch-create ,i))))
  1470. (number-sequence 0 9))))
  1471. ;; Configure `exwm-randr'.
  1472. (require 'exwm-randr)
  1473. (exwm-randr-enable)
  1474. ;; Configure custom hooks.
  1475. (setq display-time-day-and-date t)
  1476. (add-hook 'exwm-init-hook
  1477. (lambda ()
  1478. (display-battery-mode +1) ;; Display battery info (if available).
  1479. (display-time-mode +1))) ;; Display the time in the modeline.
  1480. ;; Setup buffer display names.
  1481. (add-hook 'exwm-update-class-hook
  1482. (lambda ()
  1483. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1484. ;; Configure monitor hot-swapping.
  1485. (add-hook 'exwm-randr-screen-change-hook
  1486. (lambda ()
  1487. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1488. #+END_SRC
  1489. ** General
  1490. #+NAME: emacs-general-package
  1491. #+BEGIN_SRC nix
  1492. epkgs.general
  1493. #+END_SRC
  1494. [[https://github.com/noctuid/general.el][General.el]] provides a more convenient 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.
  1495. #+NAME: emacs-general-elisp
  1496. #+BEGIN_SRC emacs-lisp
  1497. ;; Use <SPC> as a leader key via `general.el'.
  1498. (general-create-definer dotfiles/leader
  1499. :keymaps '(normal insert visual emacs)
  1500. :prefix "SPC"
  1501. :global-prefix "C-SPC")
  1502. ;; Setup general to work with `evil-mode'.
  1503. (setq general-evil-setup t)
  1504. ;; Find files with <SPC> <period> ...
  1505. ;; Switch buffers with <SPC> <comma> ...
  1506. (dotfiles/leader
  1507. "." '(find-file :which-key "File")
  1508. "," '(switch-to-buffer :which-key "Buffer")
  1509. "k" '(kill-buffer :which-key "Kill")
  1510. "c" '(kill-buffer-and-window :which-key "Close"))
  1511. ;; Add keybindings for executing shell commands.
  1512. (dotfiles/leader
  1513. "r" '(:ignore t :which-key "Run")
  1514. "rr" '(dotfiles/run :which-key "Run")
  1515. "ra" '(async-shell-command :which-key "Async"))
  1516. ;; Add keybindings for quitting Emacs.
  1517. (dotfiles/leader
  1518. "q" '(:ignore t :which-key "Quit")
  1519. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1520. "qw" '(kill-emacs :which-key "Now")
  1521. "qf" '(delete-frame :which-key "Frame"))
  1522. ;; Add keybindings for toggles / tweaks.
  1523. (dotfiles/leader
  1524. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1525. ;; Add keybindings for working with frames to replace
  1526. ;; the C-x <num> <num> method of bindings, which is awful.
  1527. (dotfiles/leader
  1528. "w" '(:ignore t :which-key "Windows")
  1529. "ww" '(window-swap-states :which-key "Swap")
  1530. "wc" '(delete-window :which-key "Close")
  1531. "wh" '(windmove-left :which-key "Left")
  1532. "wj" '(windmove-down :which-key "Down")
  1533. "wk" '(windmove-up :which-key "Up")
  1534. "wl" '(windmove-right :which-key "Right")
  1535. "ws" '(:ignore t :which-key "Split")
  1536. "wsj" '(split-window-below :which-key "Below")
  1537. "wsl" '(split-window-right :which-key "Right"))
  1538. #+END_SRC
  1539. ** Which Key
  1540. [[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.
  1541. #+NAME: emacs-which-key-package
  1542. #+BEGIN_SRC nix
  1543. epkgs.which-key
  1544. #+END_SRC
  1545. #+NAME: emacs-which-key-elisp
  1546. #+BEGIN_SRC emacs-lisp
  1547. ;; Configure `which-key' to see keyboard bindings in the
  1548. ;; mini-buffer and when using M-x.
  1549. (setq which-key-idle-delay 0.0)
  1550. (which-key-mode +1)
  1551. #+END_SRC
  1552. ** EWW
  1553. [[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.
  1554. + Use ~eww~ as the default browser
  1555. + Don't use any special fonts or colours
  1556. #+NAME: emacs-eww-elisp
  1557. #+BEGIN_SRC emacs-lisp
  1558. ;; Set `eww' as the default browser.
  1559. (setq browse-url-browser-function 'eww-browse-url)
  1560. ;; Configure the `shr' rendering engine.
  1561. (setq shr-use-fonts nil
  1562. shr-use-colors nil)
  1563. #+END_SRC
  1564. ** ERC
  1565. [[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.
  1566. #+NAME: emacs-erc-elisp
  1567. #+BEGIN_SRC emacs-lisp
  1568. ;; Configure `erc'.
  1569. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
  1570. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1571. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1572. ;; Configure `erc-fill-column'.
  1573. (add-hook 'window-configuration-change-hook
  1574. '(lambda ()
  1575. (setq erc-fill-column (- (window-width) 12))))
  1576. ;; Connect to IRC via `erc'.
  1577. (defun dotfiles/erc-connect ()
  1578. "Connected to IRC via `erc'."
  1579. (interactive)
  1580. (erc-tls :server "irc.libera.chat"
  1581. :port 6697
  1582. :nick "megaphone"
  1583. :password (password-store-get "megaphone@libera.chat")
  1584. :full-name "Chris Hayward"))
  1585. ;; Configure keybindings.
  1586. (dotfiles/leader
  1587. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1588. #+END_SRC
  1589. ** Dired
  1590. #+NAME: emacs-dired-package
  1591. #+BEGIN_SRC nix
  1592. epkgs.dired-single
  1593. #+END_SRC
  1594. [[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.
  1595. #+NAME: emacs-dired-elisp
  1596. #+BEGIN_SRC emacs-lisp
  1597. ;; Include `dired-x' for the `jump' method.
  1598. (require 'dired-x)
  1599. ;; Configure `dired-single' to support `evil' keys.
  1600. (evil-collection-define-key 'normal 'dired-mode-map
  1601. "h" 'dired-single-up-directory
  1602. "l" 'dired-single-buffer)
  1603. ;; Setup `all-the-icons' and the `dired' extension.
  1604. ;; Configure keybindings for `dired'.
  1605. (dotfiles/leader
  1606. "d" '(dired-jump :which-key "Dired"))
  1607. #+END_SRC
  1608. ** Icons
  1609. #+NAME: emacs-icons-package
  1610. #+BEGIN_SRC nix
  1611. epkgs.all-the-icons
  1612. epkgs.all-the-icons-dired
  1613. #+END_SRC
  1614. [[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]].
  1615. #+NAME: emacs-icons-elisp
  1616. #+BEGIN_SRC emacs-lisp
  1617. ;; Setup `all-the-icons-dired'.
  1618. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1619. ;; Disable monochrome icons.
  1620. (setq all-the-icons-dired-monochrome nil)
  1621. ;; Display default font ligatures.
  1622. (global-prettify-symbols-mode +1)
  1623. #+END_SRC
  1624. ** Emojis
  1625. #+NAME: emacs-emoji-package
  1626. #+BEGIN_SRC nix
  1627. epkgs.emojify
  1628. #+END_SRC
  1629. [[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.
  1630. #+NAME: emacs-emoji-elisp
  1631. #+BEGIN_SRC emacs-lisp
  1632. ;; Setup `emojify'.
  1633. (add-hook 'after-init-hook 'global-emojify-mode)
  1634. #+END_SRC
  1635. ** EShell
  1636. #+NAME: emacs-eshell-package
  1637. #+BEGIN_SRC nix
  1638. epkgs.eshell-prompt-extras
  1639. #+END_SRC
  1640. [[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.
  1641. #+NAME: emacs-eshell-elisp
  1642. #+BEGIN_SRC emacs-lisp
  1643. ;; Configure `eshell'.
  1644. (setq eshell-highlight-prompt nil
  1645. eshell-prefer-lisp-functions nil)
  1646. ;; Configure the lambda prompt.
  1647. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1648. (setq eshell-prompt-function 'epe-theme-lambda)
  1649. ;; Configure keybindings for `eshell'.
  1650. (dotfiles/leader
  1651. "e" '(eshell :which-key "EShell"))
  1652. #+END_SRC
  1653. ** VTerm
  1654. [[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.
  1655. #+NAME: emacs-vterm-package
  1656. #+BEGIN_SRC nix
  1657. epkgs.vterm
  1658. #+END_SRC
  1659. #+NAME: emacs-vterm-elisp
  1660. #+BEGIN_SRC emacs-lisp
  1661. ;; Add keybindings for interacting with the shell(s).
  1662. (dotfiles/leader
  1663. "v" '(vterm :which-key "VTerm"))
  1664. #+END_SRC
  1665. ** Magit
  1666. [[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.
  1667. #+NAME: emacs-magit-package
  1668. #+BEGIN_SRC nix
  1669. epkgs.magit
  1670. #+END_SRC
  1671. #+NAME: emacs-magit-elisp
  1672. #+BEGIN_SRC emacs-lisp
  1673. ;; Add keybindings for working with `magit'.
  1674. (dotfiles/leader
  1675. "g" '(:ignore t :which-key "Git")
  1676. "gg" '(magit-status :which-key "Status")
  1677. "gc" '(magit-clone :which-key "Clone")
  1678. "gf" '(magit-fetch :which-key "Fetch")
  1679. "gp" '(magit-pull :which-key "Pull"))
  1680. #+END_SRC
  1681. ** Fonts
  1682. #+NAME: emacs-fonts-package
  1683. #+BEGIN_SRC nix
  1684. epkgs.hydra
  1685. #+END_SRC
  1686. #+NAME: emacs-fonts-elisp
  1687. #+BEGIN_SRC emacs-lisp
  1688. ;; Configure the font when running as `emacs-server'.
  1689. (custom-set-faces
  1690. '(default ((t (:inherit nil :height 120 :family "Iosevka")))))
  1691. ;; Set all three of Emacs' font faces.
  1692. ;; NOTE: This only works without `emacs-server'.
  1693. ;; (set-face-attribute 'default nil :font "Iosevka" :height 96)
  1694. ;; (set-face-attribute 'fixed-pitch nil :font "Iosevka" :height 96)
  1695. ;; (set-face-attribute 'variable-pitch nil :font "Iosevka" :height 96)
  1696. ;; Define a `hydra' function for scaling the text interactively.
  1697. (defhydra hydra-text-scale (:timeout 4)
  1698. "Scale text"
  1699. ("j" text-scale-decrease "Decrease")
  1700. ("k" text-scale-increase "Increase")
  1701. ("f" nil "Finished" :exit t))
  1702. ;; Create keybinding for calling the function.
  1703. (dotfiles/leader
  1704. "tf" '(hydra-text-scale/body :which-key "Font"))
  1705. #+END_SRC
  1706. ** Elfeed
  1707. #+NAME: emacs-elfeed-package
  1708. #+BEGIN_SRC nix
  1709. epkgs.elfeed
  1710. #+END_SRC
  1711. [[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.
  1712. #+NAME: emacs-elfeed-elisp
  1713. #+BEGIN_SRC emacs-lisp
  1714. ;; Configure `elfeed'.
  1715. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1716. ;; Add custom feeds for `elfeed' to fetch.
  1717. (setq elfeed-feeds (quote
  1718. (("https://hexdsl.co.uk/rss.xml")
  1719. ("https://lukesmith.xyz/rss.xml")
  1720. ("https://friendo.monster/rss.xml")
  1721. ("https://chrishayward.xyz/index.xml")
  1722. ("https://protesilaos.com/master.xml"))))
  1723. ;; Add custom keybindings for `elfeed'.
  1724. (dotfiles/leader
  1725. "l" '(:ignore t :which-key "Elfeed")
  1726. "ll" '(elfeed :which-key "Open")
  1727. "lu" '(elfeed-update :which-key "Update"))
  1728. #+END_SRC
  1729. ** Org Mode
  1730. #+NAME: emacs-org-package
  1731. #+BEGIN_SRC nix
  1732. epkgs.org
  1733. #+END_SRC
  1734. [[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.
  1735. #+NAME: emacs-org-elisp
  1736. #+BEGIN_SRC emacs-lisp
  1737. ;; Configure `org-mode' source blocks.
  1738. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1739. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1740. org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
  1741. org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
  1742. ;; Add an `org-mode-hook'.
  1743. (add-hook 'org-mode-hook
  1744. (lambda ()
  1745. (org-indent-mode)
  1746. (visual-line-mode)))
  1747. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1748. (setq org-export-html-validation-link nil
  1749. org-html-validation-link nil)
  1750. ;; Configure the keywords in the TODO -> DONE sequence.
  1751. (setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  1752. ;; Track ids globally.
  1753. (setq org-id-track-globally t)
  1754. ;; Configure `org-babel' languages.
  1755. (org-babel-do-load-languages
  1756. 'org-babel-load-languages
  1757. '((C . t)))
  1758. ;; Log / Clock into property drawers.
  1759. (setq org-log-into-drawer t
  1760. org-clock-into-drawer t)
  1761. ;; Encrypt files with the public key.
  1762. (setq epa-file-select-keys 2
  1763. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1764. epa-cache-passphrase-for-symmetric-encryption t)
  1765. ;; TODO: Configure default structure templates.
  1766. ;; (require 'org-tempo)
  1767. ;; Apply custom keybindings.
  1768. (dotfiles/leader
  1769. "o" '(:ignore t :which-key "Org")
  1770. "oe" '(org-export-dispatch :which-key "Export")
  1771. "ot" '(org-babel-tangle :which-key "Tangle")
  1772. "oi" '(org-toggle-inline-images :which-key "Images")
  1773. "of" '(:ignore t :which-key "Footnotes")
  1774. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1775. #+END_SRC
  1776. ** Org Roam
  1777. #+NAME: emacs-org-roam-package
  1778. #+BEGIN_SRC nix
  1779. epkgs.org-roam
  1780. # epkgs.org-roam-ui # TODO: Provide from Github
  1781. epkgs.websocket
  1782. epkgs.simple-httpd
  1783. epkgs.org-ref
  1784. epkgs.bibtex-completion
  1785. epkgs.org-roam-bibtex
  1786. #+END_SRC
  1787. [[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.
  1788. #+NAME: emacs-org-roam-elisp
  1789. #+BEGIN_SRC emacs-lisp
  1790. ;; Setup `org-roam'.
  1791. (require 'org-roam)
  1792. ;; Enable `visual-line-mode' in `org-roam' buffer.
  1793. (add-hook 'org-roam-mode-hook
  1794. (lambda ()
  1795. (visual-line-mode +1)))
  1796. ;; HACK: Set up `org-roam-ui'.
  1797. (add-to-list 'load-path "~/.local/source/org-roam-ui")
  1798. (load-library "org-roam-ui")
  1799. (setq org-roam-ui-follow t
  1800. org-roam-ui-sync-theme t
  1801. org-roam-ui-open-on-start t
  1802. org-roam-ui-update-on-save t
  1803. org-roam-ui-browser-function #'browse-url-firefox)
  1804. ;; Silence the migration warnings.
  1805. (setq org-roam-v2-ack t)
  1806. ;; Enable completion everywhere.
  1807. (setq org-roam-completion-everywhere t)
  1808. ;; Set the roam directories.
  1809. (setq org-roam-directory (expand-file-name "/etc/dotfiles")
  1810. org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
  1811. ;; Clear the deafult capture templates.
  1812. (setq org-roam-capture-templates '()
  1813. org-roam-dailies-capture-templates '())
  1814. ;; Override the default slug method.
  1815. (cl-defmethod org-roam-node-slug ((node org-roam-node))
  1816. (let ((title (org-roam-node-title node))
  1817. (slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
  1818. 769 ; U+0301 COMBINING ACUTE ACCENT
  1819. 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
  1820. 771 ; U+0303 COMBINING TILDE
  1821. 772 ; U+0304 COMBINING MACRON
  1822. 774 ; U+0306 COMBINING BREVE
  1823. 775 ; U+0307 COMBINING DOT ABOVE
  1824. 776 ; U+0308 COMBINING DIAERESIS
  1825. 777 ; U+0309 COMBINING HOOK ABOVE
  1826. 778 ; U+030A COMBINING RING ABOVE
  1827. 780 ; U+030C COMBINING CARON
  1828. 795 ; U+031B COMBINING HORN
  1829. 803 ; U+0323 COMBINING DOT BELOW
  1830. 804 ; U+0324 COMBINING DIAERESIS BELOW
  1831. 805 ; U+0325 COMBINING RING BELOW
  1832. 807 ; U+0327 COMBINING CEDILLA
  1833. 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
  1834. 814 ; U+032E COMBINING BREVE BELOW
  1835. 816 ; U+0330 COMBINING TILDE BELOW
  1836. 817 ; U+0331 COMBINING MACRON BELOW
  1837. )))
  1838. (cl-flet* ((nonspacing-mark-p (char)
  1839. (memq char slug-trim-chars))
  1840. (strip-nonspacing-marks (s)
  1841. (ucs-normalize-NFC-string
  1842. (apply #'string (seq-remove #'nonspacing-mark-p
  1843. (ucs-normalize-NFD-string s)))))
  1844. (cl-replace (title pair)
  1845. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1846. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
  1847. ("--*" . "-")
  1848. ("^-" . "")
  1849. ("-$" . "")))
  1850. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1851. (downcase slug)))))
  1852. ;; Configure capture templates.
  1853. ;; Standard document.
  1854. (add-to-list 'org-roam-capture-templates
  1855. '("d" "Default" plain "%?"
  1856. :target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
  1857. "
  1858. ,#+TITLE: ${title}
  1859. ,#+AUTHOR: Christopher James Hayward
  1860. ,#+EMAIL: chris@chrishayward.xyz
  1861. "
  1862. )
  1863. :unnarrowed t))
  1864. ;; Daily notes.
  1865. (add-to-list 'org-roam-dailies-capture-templates
  1866. '("d" "Default" entry "* %?"
  1867. :target (file+head "%<%Y-%m-%d>.org.gpg"
  1868. "
  1869. ,#+TITLE: %<%Y-%m-%d>
  1870. ,#+AUTHOR: Christopher James Hayward
  1871. ,#+EMAIL: chris@chrishayward.xyz
  1872. ")))
  1873. ;; Apply custom keybindings.
  1874. (dotfiles/leader
  1875. "or" '(:ignore t :which-key "Roam")
  1876. "ori" '(org-roam-node-insert :which-key "Insert")
  1877. "orf" '(org-roam-node-find :which-key "Find")
  1878. "orc" '(org-roam-capture :which-key "Capture")
  1879. "orb" '(org-roam-buffer-toggle :which-key "Buffer"))
  1880. ;; Apply custom keybindings for dailies.
  1881. (dotfiles/leader
  1882. "ord" '(:ignore t :which-key "Dailies")
  1883. "ordd" '(org-roam-dailies-goto-date :which-key "Date")
  1884. "ordt" '(org-roam-dailies-goto-today :which-key "Today")
  1885. "ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
  1886. "ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
  1887. ;; Run the setup command.
  1888. (org-roam-setup)
  1889. ;; Setup `org-roam-bibtex'.
  1890. (require 'org-ref)
  1891. (require 'org-roam-bibtex)
  1892. ;; Apply custom keybindings.
  1893. (dotfiles/leader
  1894. "orn" '(orb-note-actions :which-key "Notes")
  1895. "orl" '(orb-inset-link :which-key "Links"))
  1896. ;; Start `org-roam-bibtex'.
  1897. (org-roam-bibtex-mode)
  1898. #+END_SRC
  1899. ** Org Drill
  1900. #+NAME: emacs-org-drill-package
  1901. #+BEGIN_SRC nix
  1902. epkgs.org-drill
  1903. #+END_SRC
  1904. [[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.
  1905. #+NAME: emacs-org-drill-elisp
  1906. #+BEGIN_SRC emacs-lisp
  1907. ;; Exclude :drill: items from `org-roam'.
  1908. (setq org-roam-db-node-include-function
  1909. (defun dotfiles/org-roam-include ()
  1910. (not (member "drill" (org-get-tags)))))
  1911. ;; Configure keybindings for `org-drill'.
  1912. (dotfiles/leader
  1913. "od" '(:ignore t :which-key "Drill")
  1914. "odd" '(org-drill :which-key "Drill")
  1915. "odc" '(org-drill-cram :which-key "Cram")
  1916. "odr" '(org-drill-resume :which-key "Resume"))
  1917. #+END_SRC
  1918. ** Org Agenda
  1919. 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.
  1920. #+NAME: emacs-org-agenda-elisp
  1921. #+BEGIN_SRC emacs-lisp
  1922. ;; Configure `org-agenda' to use the project files.
  1923. (setq org-agenda-files '("/etc/dotfiles/"
  1924. "/etc/dotfiles/docs/"
  1925. "/etc/dotfiles/docs/daily/"))
  1926. ;; Include files encrypted with `gpg'.
  1927. (require 'org)
  1928. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1929. (setq org-agenda-file-regexp
  1930. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1931. org-agenda-file-regexp)))
  1932. ;; Open an agenda buffer with SPC o a.
  1933. (dotfiles/leader
  1934. "oa" '(org-agenda :which-key "Agenda"))
  1935. #+END_SRC
  1936. ** Org Pomodoro
  1937. #+NAME: emacs-pomodoro-package
  1938. #+BEGIN_SRC nix
  1939. epkgs.org-pomodoro
  1940. #+END_SRC
  1941. [[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.
  1942. #+NAME: emacs-pomodoro-elisp
  1943. #+BEGIN_SRC emacs-lisp
  1944. ;; Configure `org-pomodor' with the overtime workflow.
  1945. (setq org-pomodoro-manual-break t
  1946. org-pomodoro-keep-killed-time t)
  1947. ;; Configure keybindings.
  1948. (dotfiles/leader
  1949. "op" '(org-pomodoro :which-key "Pomodoro"))
  1950. #+END_SRC
  1951. ** Writegood Mode
  1952. #+NAME: emacs-writegood-package
  1953. #+BEGIN_SRC nix
  1954. epkgs.writegood-mode
  1955. #+END_SRC
  1956. [[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:
  1957. + Weasel Words
  1958. + Passive Voice
  1959. + Duplicate Words
  1960. #+NAME: emacs-writegood-elisp
  1961. #+BEGIN_SRC emacs-lisp
  1962. ;; Configure `writegood-mode'.
  1963. (dotfiles/leader
  1964. "tg" '(writegood-mode :which-key "Grammar"))
  1965. #+END_SRC
  1966. ** Aspell
  1967. #+NAME: emacs-aspell-extras
  1968. #+BEGIN_SRC nix
  1969. pkgs.aspell
  1970. pkgs.aspellDicts.en
  1971. pkgs.aspellDicts.en-science
  1972. pkgs.aspellDicts.en-computers
  1973. #+END_SRC
  1974. [[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.
  1975. #+NAME: emacs-aspell-elisp
  1976. #+BEGIN_SRC emacs-lisp
  1977. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1978. (setq ispell-program-name "aspell"
  1979. ispell-eextra-args '("--sug-mode=fast"))
  1980. ;; Configure the built-in `flyspell-mode'.
  1981. (dotfiles/leader
  1982. "ts" '(flyspell-mode :which-key "Spelling"))
  1983. #+END_SRC
  1984. ** TexLive
  1985. [[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/:
  1986. | Name | Derivation | Comment |
  1987. |---------+---------------------------------+------------------------------------------------------------|
  1988. | Full | texlive.combined.scheme-full | Contains every TeX Live package |
  1989. | Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
  1990. | Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
  1991. | Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
  1992. | Minimal | texlive.combined.scheme-minimal | Contains plain only |
  1993. #+NAME: emacs-texlive-extras
  1994. #+BEGIN_SRC nix
  1995. pkgs.texlive.combined.scheme-full
  1996. #+END_SRC
  1997. ** Http
  1998. #+NAME: emacs-http-package
  1999. #+BEGIN_SRC nix
  2000. epkgs.ob-http
  2001. #+END_SRC
  2002. 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.
  2003. #+NAME: emacs-http-elisp
  2004. #+BEGIN_SRC emacs-lisp
  2005. ;; Required to setup `ob-http'.
  2006. (org-babel-do-load-languages
  2007. 'org-babel-load-languages
  2008. '((http . t)))
  2009. #+END_SRC
  2010. ** Hugo
  2011. #+NAME: emacs-hugo-package
  2012. #+BEGIN_SRC nix
  2013. epkgs.ox-hugo
  2014. #+END_SRC
  2015. [[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/.
  2016. #+NAME: emacs-hugo-elisp
  2017. #+BEGIN_SRC emacs-lisp
  2018. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  2019. (require 'ox-hugo)
  2020. ;; Set up the base directory.
  2021. (setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
  2022. ;; Capture templates.
  2023. ;; Shared content
  2024. ;; (add-to-list 'org-roam-capture-templates
  2025. ;; '("p" "Post" plain "%?"
  2026. ;; :target (file+head "docs/posts/${slug}.org.gpg"
  2027. ;; "
  2028. ;; ,#+TITLE: ${title}
  2029. ;; ,#+AUTHOR: Christopher James Hayward
  2030. ;; ,#+DATE: %<%Y-%m-%d>
  2031. ;; ,#+EXPORT_FILE_NAME: ${slug}
  2032. ;; ,#+OPTIONS: num:nil todo:nil tasks:nil
  2033. ;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  2034. ;; ,#+HUGO_BASE_DIR: ../
  2035. ;; ,#+HUGO_AUTO_SET_LASTMOD: t
  2036. ;; ,#+HUGO_SECTION: posts
  2037. ;; ,#+HUGO_DRAFT: true
  2038. ;; "
  2039. ;; )
  2040. ;; :unnarrowed t))
  2041. #+END_SRC
  2042. ** Passwords
  2043. #+NAME: emacs-pass-extras
  2044. #+BEGIN_SRC nix
  2045. pkgs.pass
  2046. #+END_SRC
  2047. 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.
  2048. #+NAME: emacs-pass-package
  2049. #+BEGIN_SRC nix
  2050. epkgs.password-store
  2051. #+END_SRC
  2052. Configure keybindings for passwords behind =SPC p=:
  2053. #+NAME: emacs-pass-elisp
  2054. #+BEGIN_SRC emacs-lisp
  2055. ;; Set the path to the password store.
  2056. (setq password-store-dir (expand-file-name "~/.password-store"))
  2057. ;; Apply custom keybindings.
  2058. (dotfiles/leader
  2059. "p" '(:ignore t :which-key "Passwords")
  2060. "pp" '(password-store-copy :which-key "Copy")
  2061. "pe" '(password-store-edit :which-key "Edit")
  2062. "pi" '(password-store-insert :which-key "Insert")
  2063. "pr" '(password-store-rename :which-key "Rename")
  2064. "pg" '(password-store-generate :which-key "Generate"))
  2065. #+END_SRC
  2066. ** Docker
  2067. #+NAME: emacs-docker-package
  2068. #+BEGIN_SRC nix
  2069. epkgs.docker
  2070. epkgs.dockerfile-mode
  2071. #+END_SRC
  2072. 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.
  2073. #+NAME: emacs-docker-elisp
  2074. #+BEGIN_SRC emacs-lisp
  2075. ;; Apply custom keybindings.
  2076. (dotfiles/leader
  2077. "n" '(:ignore t :which-key "Containers")
  2078. "nd" '(docker :which-key "Docker"))
  2079. #+END_SRC
  2080. ** MU4E
  2081. #+NAME: emacs-mu4e-extras
  2082. #+BEGIN_SRC nix
  2083. pkgs.mu
  2084. pkgs.isync
  2085. #+END_SRC
  2086. #+NAME: emacs-mu4e-package
  2087. #+BEGIN_SRC nix
  2088. epkgs.mu4e-alert
  2089. #+END_SRC
  2090. #+NAME: emacs-mu4e-config
  2091. #+BEGIN_SRC nix
  2092. # Deploy the authinfo file.
  2093. home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
  2094. # Deploy the isync configuration file.
  2095. home.file.".mbsyncrc" = {
  2096. text = ''
  2097. IMAPStore xyz-remote
  2098. Host mail.chrishayward.xyz
  2099. User chris@chrishayward.xyz
  2100. PassCmd "pass chrishayward.xyz/chris"
  2101. SSLType IMAPS
  2102. MaildirStore xyz-local
  2103. Path ~/.cache/mail/
  2104. Inbox ~/.cache/mail/inbox
  2105. SubFolders Verbatim
  2106. Channel xyz
  2107. Far :xyz-remote:
  2108. Near :xyz-local:
  2109. Patterns * !Archives
  2110. Create Both
  2111. Expunge Both
  2112. SyncState *
  2113. '';
  2114. };
  2115. #+END_SRC
  2116. #+BEGIN_SRC sh
  2117. mbsync -a
  2118. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  2119. mu index
  2120. #+END_SRC
  2121. #+NAME: emacs-mu4e-elisp
  2122. #+BEGIN_SRC emacs-lisp
  2123. ;; Add the `mu4e' shipped with `mu' to the load path.
  2124. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  2125. (require 'mu4e)
  2126. ;; Confiugure `mu4e'.
  2127. (setq mu4e-maildir "~/.cache/mail"
  2128. mu4e-update-interval (* 5 60)
  2129. mu4e-get-mail-command "mbsync -a"
  2130. mu4e-compose-format-flowed t
  2131. mu4e-change-filenames-when-moving t
  2132. mu4e-compose-signature (concat "Chris Hayward\n"
  2133. "chris@chrishayward.xyz"))
  2134. ;; Sign all outbound email with GPG.
  2135. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  2136. (setq message-send-mail-function 'smtpmail-send-it
  2137. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  2138. ;; Setup `mu4e' accounts.
  2139. (setq mu4e-contexts
  2140. (list
  2141. ;; Main
  2142. ;; chris@chrishayward.xyz
  2143. (make-mu4e-context
  2144. :name "Main"
  2145. :match-func
  2146. (lambda (msg)
  2147. (when msg
  2148. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  2149. :vars
  2150. '((user-full-name . "Christopher James Hayward")
  2151. (user-mail-address . "chris@chrishayward.xyz")
  2152. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  2153. (smtpmail-smtp-service . 587)
  2154. (smtpmail-stream-type . starttls)))))
  2155. ;; Setup `mu4e-alert'.
  2156. (setq mu4e-alert-set-default-style 'libnotify)
  2157. (mu4e-alert-enable-notifications)
  2158. (mu4e-alert-enable-mode-line-display)
  2159. ;; Open the `mu4e' dashboard.
  2160. (dotfiles/leader
  2161. "m" '(mu4e :which-key "Mail"))
  2162. #+END_SRC
  2163. ** Projectile
  2164. #+NAME: emacs-projectile-package
  2165. #+BEGIN_SRC nix
  2166. epkgs.projectile
  2167. #+END_SRC
  2168. [[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.
  2169. #+NAME: emacs-projectile-elisp
  2170. #+BEGIN_SRC emacs-lisp
  2171. ;; Configure the `projectile-project-search-path'.
  2172. (setq projectile-project-search-path '("~/.local/source"))
  2173. (projectile-mode +1)
  2174. #+END_SRC
  2175. ** LSP Mode
  2176. #+NAME: emacs-lsp-package
  2177. #+BEGIN_SRC nix
  2178. epkgs.lsp-mode
  2179. epkgs.lsp-ui
  2180. #+END_SRC
  2181. 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:
  2182. + Auto Complete
  2183. + Go To Defintion
  2184. + Find All References
  2185. #+NAME: emacs-lsp-elisp
  2186. #+BEGIN_SRC emacs-lisp
  2187. ;; Configure `lsp-mode'.
  2188. (setq lsp-idle-delay 0.5
  2189. lsp-prefer-flymake t)
  2190. ;; Configure `lsp-ui'.
  2191. (setq lsp-ui-doc-position 'at-point
  2192. lsp-ui-doc-delay 0.5)
  2193. #+END_SRC
  2194. ** CCLS
  2195. #+NAME: emacs-ccls-package
  2196. #+BEGIN_SRC nix
  2197. epkgs.ccls
  2198. #+END_SRC
  2199. [[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.
  2200. #+NAME: emacs-ccls-elisp
  2201. #+BEGIN_SRC emacs-lisp
  2202. ;; Configure `ccls' to work with `lsp-mode'.
  2203. (defun dotfiles/ccls-hook ()
  2204. (require 'ccls)
  2205. (lsp))
  2206. ;; Configure `ccls' mode hooks.
  2207. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  2208. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  2209. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  2210. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  2211. #+END_SRC
  2212. ** Company Mode
  2213. #+NAME: emacs-company-package
  2214. #+BEGIN_SRC nix
  2215. epkgs.company
  2216. #+END_SRC
  2217. [[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.
  2218. #+NAME: emacs-company-elisp
  2219. #+BEGIN_SRC emacs-lisp
  2220. ;; Configure `company-mode'.
  2221. (setq company-backend 'company-capf
  2222. lsp-completion-provider :capf)
  2223. ;; Enable it globally.
  2224. (global-company-mode +1)
  2225. #+END_SRC
  2226. ** Go Mode
  2227. #+NAME: emacs-golang-package
  2228. #+BEGIN_SRC nix
  2229. epkgs.go-mode
  2230. #+END_SRC
  2231. [[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.
  2232. #+NAME: emacs-golang-elisp
  2233. #+BEGIN_SRC emacs-lisp
  2234. ;; Configure `go-mode' to work with `lsp-mode'.
  2235. (defun dotfiles/go-hook ()
  2236. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  2237. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  2238. ;; Configure a custom `before-save-hook'.
  2239. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  2240. #+END_SRC
  2241. ** Rustic
  2242. #+NAME: emacs-rustic-package
  2243. #+BEGIN_SRC nix
  2244. epkgs.rustic
  2245. #+END_SRC
  2246. 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!
  2247. #+NAME: emacs-rustic-elisp
  2248. #+BEGIN_SRC emacs-lisp
  2249. ;; Configure `rustic' with `lsp-mode'.
  2250. (setq rustic-format-on-save t
  2251. rustic-lsp-server 'rls)
  2252. #+END_SRC
  2253. ** Python Mode
  2254. #+NAME: emacs-python-package
  2255. #+BEGIN_SRC nix
  2256. epkgs.pretty-mode
  2257. #+END_SRC
  2258. 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.
  2259. #+NAME: emacs-python-elisp
  2260. #+BEGIN_SRC emacs-lisp
  2261. ;; Configure `pretty-mode' to work with `python-mode'.
  2262. (add-hook 'python-mode-hook
  2263. (lambda ()
  2264. (turn-on-pretty-mode)))
  2265. #+END_SRC
  2266. ** Protobuf Mode
  2267. #+NAME: emacs-protobuf-package
  2268. #+BEGIN_SRC nix
  2269. epkgs.protobuf-mode
  2270. #+END_SRC
  2271. ** PlantUML
  2272. #+NAME: emacs-plantuml-extras
  2273. #+BEGIN_SRC nix
  2274. pkgs.plantuml
  2275. #+END_SRC
  2276. [[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.
  2277. #+NAME: emacs-plantuml-package
  2278. #+BEGIN_SRC nix
  2279. epkgs.plantuml-mode
  2280. #+END_SRC
  2281. [[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]].
  2282. #+NAME: emacs-plantuml-elisp
  2283. #+BEGIN_SRC emacs-lisp
  2284. ;; Configure `plantuml-mode'.
  2285. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  2286. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  2287. (setq plantuml-default-exec-mode 'executable
  2288. org-plantuml-exec-mode 'plantuml)
  2289. #+END_SRC
  2290. ** Swiper
  2291. #+NAME: emacs-swiper-package
  2292. #+BEGIN_SRC nix
  2293. epkgs.ivy
  2294. epkgs.counsel
  2295. epkgs.ivy-rich
  2296. epkgs.ivy-bibtex
  2297. epkgs.ivy-posframe
  2298. epkgs.ivy-prescient
  2299. #+END_SRC
  2300. [[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.
  2301. #+NAME: emacs-swiper-elisp
  2302. #+BEGIN_SRC emacs-lisp
  2303. ;; Configure `ivy'.
  2304. (setq counsel-linux-app-format-function
  2305. #'counsel-linux-app-format-function-name-only)
  2306. (ivy-mode +1)
  2307. (counsel-mode +1)
  2308. ;; Configure `ivy-rich'.
  2309. (ivy-rich-mode +1)
  2310. ;; Configure `ivy-posframe'.
  2311. (setq ivy-posframe-parameters '((parent-frame nil))
  2312. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  2313. (ivy-posframe-mode +1)
  2314. ;; Configure `ivy-prescient'.
  2315. (setq ivy-prescient-enable-filtering nil)
  2316. (ivy-prescient-mode +1)
  2317. #+END_SRC
  2318. ** Transparency
  2319. 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.
  2320. #+NAME: emacs-transparency-elisp
  2321. #+BEGIN_SRC emacs-lisp
  2322. ;; Configure the default frame transparency.
  2323. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  2324. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  2325. #+END_SRC
  2326. ** Desktop Environment
  2327. #+NAME: emacs-desktop-extras
  2328. #+BEGIN_SRC nix
  2329. pkgs.brightnessctl
  2330. #+END_SRC
  2331. 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]].
  2332. #+NAME: emacs-desktop-package
  2333. #+BEGIN_SRC nix
  2334. epkgs.desktop-environment
  2335. #+END_SRC
  2336. 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.
  2337. #+NAME: emacs-desktop-elisp
  2338. #+BEGIN_SRC emacs-lisp
  2339. ;; Configure `desktop-environment'.
  2340. (require 'desktop-environment)
  2341. (desktop-environment-mode +1)
  2342. #+END_SRC
  2343. ** Doom Themes
  2344. #+NAME: emacs-doom-themes-package
  2345. #+BEGIN_SRC nix
  2346. epkgs.doom-themes
  2347. #+END_SRC
  2348. [[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.
  2349. #+NAME: emacs-doom-themes-elisp
  2350. #+BEGIN_SRC emacs-lisp
  2351. ;; Include modern themes from `doom-themes'.
  2352. (setq doom-themes-enable-bold t
  2353. doom-themes-enable-italic t)
  2354. ;; Load the `doom-nord' and `doom-nord-light' themes.
  2355. ;; (load-theme 'doom-nord-light t)
  2356. (load-theme 'doom-nord t)
  2357. (doom-modeline-mode +1)
  2358. ;; Load a new theme with <SPC> t t.
  2359. (dotfiles/leader
  2360. "tt" '(counsel-load-theme :which-key "Theme"))
  2361. #+END_SRC
  2362. ** Doom Modeline
  2363. #+NAME: emacs-doom-modeline-package
  2364. #+BEGIN_SRC nix
  2365. epkgs.doom-modeline
  2366. #+END_SRC
  2367. [[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.
  2368. #+NAME: emacs-doom-modeline-elisp
  2369. #+BEGIN_SRC emacs-lisp
  2370. ;; Add the `doom-modeline' after initialization.
  2371. (add-hook 'after-init-hook 'doom-modeline-mode)
  2372. (setq doom-modeline-height 16
  2373. doom-modeline-icon t)
  2374. #+END_SRC
  2375. * Footnotes