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.

3024 lines
95 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
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. # Fix graphical corruption on suspend.
  969. hardware.nvidia.powerManagement.enable = true;
  970. # Configure `offload-mode'.
  971. hardware.nvidia.prime = {
  972. offload.enable = true;
  973. intelBusId = myIntelBusId;
  974. nvidiaBusId = myNvidiaBusId;
  975. };
  976. # Add OpenGL support.
  977. hardware.opengl = {
  978. enable = true;
  979. driSupport = true;
  980. driSupport32Bit = true;
  981. extraPackages32 = with pkgs; [
  982. pkgsi686Linux.libva
  983. intel-media-driver
  984. vaapiIntel
  985. ];
  986. };
  987. # Create an external display setup.
  988. specialisation = {
  989. external-display.configuration = {
  990. system.nixos.tags = [ "external-display" ];
  991. hardware.nvidia.prime.offload.enable = lib.mkForce false;
  992. hardware.nvidia.powerManagement.enable = lib.mkForce false;
  993. };
  994. };
  995. # Add user to video group.
  996. users.users.chris = {
  997. extraGroups = [ "video" ];
  998. };
  999. }
  1000. #+END_SRC
  1001. ** Firefox
  1002. #+NAME: module-firefox
  1003. #+BEGIN_SRC nix
  1004. ./modules/firefox.nix
  1005. #+END_SRC
  1006. [[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.
  1007. #+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
  1008. # <<file-warning>>
  1009. { pkgs, ... }:
  1010. {
  1011. # NOTE: Use the binary until module is developed.
  1012. environment.systemPackages = [
  1013. pkgs.firefox-bin
  1014. ];
  1015. }
  1016. #+END_SRC
  1017. ** Jellyfin
  1018. #+NAME: module-jellyfin
  1019. #+BEGIN_SRC nix
  1020. ./modules/jellyfin.nix
  1021. #+END_SRC
  1022. [[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.
  1023. #+BEGIN_SRC nix :noweb yes :tangle modules/jellyfin.nix
  1024. # <<file-warning>>
  1025. { config, pkgs, ... }:
  1026. {
  1027. services.jellyfin = {
  1028. enable = true;
  1029. };
  1030. }
  1031. #+END_SRC
  1032. ** Moonlight
  1033. #+NAME: module-moonlight
  1034. #+BEGIN_SRC nix
  1035. ./modules/moonlight.nix
  1036. #+END_SRC
  1037. [[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.
  1038. #+BEGIN_SRC nix :noweb yes :tangle modules/moonlight.nix
  1039. # <<file-warning>>
  1040. { pkgs, ... }:
  1041. {
  1042. environment.systemPackages = [
  1043. pkgs.moonlight-qt
  1044. ];
  1045. }
  1046. #+END_SRC
  1047. ** Teamviewer
  1048. #+NAME: module-teamviewer
  1049. #+BEGIN_SRC nix
  1050. ./modules/teamviewer.nix
  1051. #+END_SRC
  1052. 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.
  1053. #+BEGIN_SRC nix :noweb yes :tangle modules/teamviewer.nix
  1054. # <<file-warning>>
  1055. { pkgs, ... }:
  1056. {
  1057. # NOTE: Neither of these are working!
  1058. # services.teamviewer.enable = true;
  1059. # environment.systemPackages = [
  1060. # pkgs.teamviewer
  1061. # ];
  1062. }
  1063. #+END_SRC
  1064. ** Home Manager
  1065. [[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.
  1066. #+NAME: module-home-manager
  1067. #+BEGIN_SRC nix :noweb yes
  1068. inputs.home-manager.nixosModules.home-manager {
  1069. home-manager.useGlobalPkgs = true;
  1070. home-manager.useUserPackages = true;
  1071. home-manager.users.chris = {
  1072. imports = [
  1073. <<module-git>>
  1074. <<module-gpg>>
  1075. <<module-vim>>
  1076. <<module-gtk>>
  1077. <<module-emacs>>
  1078. ];
  1079. };
  1080. }
  1081. #+END_SRC
  1082. *** Git
  1083. #+NAME: module-git
  1084. #+BEGIN_SRC nix
  1085. ./modules/git.nix
  1086. #+END_SRC
  1087. [[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.
  1088. #+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
  1089. # <<file-warning>>
  1090. { pkgs, ... }:
  1091. let
  1092. # Fix any corruptions in the local copy.
  1093. myGitFix = pkgs.writeShellScriptBin "git-fix" ''
  1094. if [ -d .git/objects/ ]; then
  1095. find .git/objects/ -type f -empty | xargs rm -f
  1096. git fetch -p
  1097. git fsck --full
  1098. fi
  1099. exit 1
  1100. '';
  1101. in {
  1102. home.packages = [ myGitFix ];
  1103. programs.git = {
  1104. enable = true;
  1105. userName = "Christopher James Hayward";
  1106. userEmail = "chris@chrishayward.xyz";
  1107. signing = {
  1108. key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
  1109. signByDefault = true;
  1110. };
  1111. };
  1112. }
  1113. #+END_SRC
  1114. *** Gpg
  1115. #+NAME: module-gpg
  1116. #+BEGIN_SRC nix
  1117. ./modules/gpg.nix
  1118. #+END_SRC
  1119. [[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.
  1120. #+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
  1121. # <<file-warning>>
  1122. { pkgs, ... }:
  1123. {
  1124. services.gpg-agent = {
  1125. enable = true;
  1126. defaultCacheTtl = 1800;
  1127. enableSshSupport = true;
  1128. pinentryFlavor = "gtk2";
  1129. };
  1130. }
  1131. #+END_SRC
  1132. *** Vim
  1133. #+NAME: module-vim
  1134. #+BEGIN_SRC nix
  1135. ./modules/vim.nix
  1136. #+END_SRC
  1137. [[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
  1138. + Simplify maintenance and encourage contributions
  1139. + Split the work between multiple developers
  1140. + Enable advanced UIs without core modification
  1141. + Maximize extensibility
  1142. #+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
  1143. # <<file-warning>>
  1144. { pkgs, ... }:
  1145. {
  1146. programs.neovim = {
  1147. enable = true;
  1148. viAlias = true;
  1149. vimAlias = true;
  1150. vimdiffAlias = true;
  1151. extraConfig = ''
  1152. set number relativenumber
  1153. set nobackup
  1154. '';
  1155. extraPackages = [
  1156. pkgs.nixfmt
  1157. ];
  1158. plugins = with pkgs.vimPlugins; [
  1159. vim-nix
  1160. vim-airline
  1161. vim-polyglot
  1162. ];
  1163. };
  1164. }
  1165. #+END_SRC
  1166. *** GTK
  1167. #+NAME: module-gtk
  1168. #+BEGIN_SRC nix
  1169. ./modules/gtk.nix
  1170. #+END_SRC
  1171. [[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.
  1172. #+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
  1173. # <<file-warning>>
  1174. { pkgs, ... }:
  1175. {
  1176. home.packages = [
  1177. pkgs.nordic
  1178. pkgs.arc-icon-theme
  1179. pkgs.lxappearance
  1180. ];
  1181. home.file.".gtkrc-2.0" = {
  1182. text = ''
  1183. # gtk-theme-name="Nordic-Polar"
  1184. gtk-theme-name="Nordic-darker"
  1185. gtk-icon-theme-name="Arc"
  1186. gtk-font-name="Sans 10"
  1187. gtk-cursor-theme-size=0
  1188. gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
  1189. gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
  1190. gtk-button-images=0
  1191. gtk-menu-images=0
  1192. gtk-enable-event-sounds=1
  1193. gtk-enable-input-feedback-sounds=1
  1194. gtk-xft-antialias=1
  1195. gtk-xft-hinting=1
  1196. gtk-xft-hintstyle="hintmedium"
  1197. '';
  1198. };
  1199. }
  1200. #+END_SRC
  1201. * Emacs Configuration
  1202. #+NAME: module-emacs
  1203. #+BEGIN_SRC nix
  1204. ./modules/emacs.nix
  1205. #+END_SRC
  1206. [[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:
  1207. + Highly customizable
  1208. + Full Unicopde support
  1209. + Content-aware editing modes
  1210. + Complete built-in documentation
  1211. + Wide range of functionality beyond text editing
  1212. #+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
  1213. # <<file-warning>>
  1214. { pkgs, ... }:
  1215. let
  1216. myEmacs = pkgs.emacsWithPackagesFromUsePackage {
  1217. config = ../README.org;
  1218. package = <<emacs-native-comp-package>>
  1219. alwaysEnsure = true;
  1220. alwaysTangle = true;
  1221. extraEmacsPackages = epkgs: [
  1222. # Required packages...
  1223. <<emacs-exwm-package>>
  1224. <<emacs-evil-package>>
  1225. <<emacs-general-package>>
  1226. <<emacs-which-key-package>>
  1227. # Optional packages.
  1228. <<emacs-org-package>>
  1229. <<emacs-org-roam-package>>
  1230. <<emacs-org-drill-package>>
  1231. <<emacs-pomodoro-package>>
  1232. <<emacs-writegood-package>>
  1233. <<emacs-http-package>>
  1234. <<emacs-hugo-package>>
  1235. <<emacs-reveal-package>>
  1236. <<emacs-pass-package>>
  1237. <<emacs-docker-package>>
  1238. <<emacs-mu4e-package>>
  1239. <<emacs-dired-package>>
  1240. <<emacs-icons-package>>
  1241. <<emacs-emoji-package>>
  1242. <<emacs-eshell-package>>
  1243. <<emacs-vterm-package>>
  1244. <<emacs-magit-package>>
  1245. <<emacs-fonts-package>>
  1246. <<emacs-elfeed-package>>
  1247. <<emacs-nix-mode-package>>
  1248. <<emacs-projectile-package>>
  1249. <<emacs-lsp-package>>
  1250. <<emacs-company-package>>
  1251. <<emacs-ccls-package>>
  1252. <<emacs-golang-package>>
  1253. <<emacs-python-package>>
  1254. <<emacs-rustic-package>>
  1255. <<emacs-plantuml-package>>
  1256. <<emacs-protobuf-package>>
  1257. <<emacs-swiper-package>>
  1258. <<emacs-desktop-package>>
  1259. <<emacs-doom-themes-package>>
  1260. <<emacs-doom-modeline-package>>
  1261. ];
  1262. };
  1263. in {
  1264. home.packages = [
  1265. <<emacs-exwm-extras>>
  1266. <<emacs-pass-extras>>
  1267. <<emacs-mu4e-extras>>
  1268. <<emacs-aspell-extras>>
  1269. <<emacs-texlive-extras>>
  1270. <<emacs-desktop-extras>>
  1271. <<emacs-plantuml-extras>>
  1272. <<emacs-nix-mode-extras>>
  1273. ];
  1274. programs.emacs = {
  1275. enable = true;
  1276. package = myEmacs;
  1277. };
  1278. <<emacs-exwm-config>>
  1279. <<emacs-exwm-xinitrc>>
  1280. <<emacs-mu4e-config>>
  1281. }
  1282. #+END_SRC
  1283. 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.
  1284. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/init.el
  1285. ;; <<file-warning>>
  1286. ;; Required inputs.
  1287. <<emacs-exwm-elisp>>
  1288. <<emacs-evil-elisp>>
  1289. <<emacs-general-elisp>>
  1290. <<emacs-which-key-elisp>>
  1291. ;; Optional inputs.
  1292. <<emacs-org-elisp>>
  1293. <<emacs-org-roam-elisp>>
  1294. <<emacs-org-drill-elisp>>
  1295. <<emacs-org-agenda-elisp>>
  1296. <<emacs-pomodoro-elisp>>
  1297. <<emacs-writegood-elisp>>
  1298. <<emacs-aspell-elisp>>
  1299. <<emacs-eww-elisp>>
  1300. <<emacs-http-elisp>>
  1301. <<emacs-hugo-elisp>>
  1302. <<emacs-reveal-elisp>>
  1303. <<emacs-pass-elisp>>
  1304. <<emacs-docker-elisp>>
  1305. <<emacs-erc-elisp>>
  1306. <<emacs-mu4e-elisp>>
  1307. <<emacs-dired-elisp>>
  1308. <<emacs-icons-elisp>>
  1309. <<emacs-emoji-elisp>>
  1310. <<emacs-eshell-elisp>>
  1311. <<emacs-vterm-elisp>>
  1312. <<emacs-magit-elisp>>
  1313. <<emacs-fonts-elisp>>
  1314. <<emacs-elfeed-elisp>>
  1315. <<emacs-projectile-elisp>>
  1316. <<emacs-lsp-elisp>>
  1317. <<emacs-company-elisp>>
  1318. <<emacs-golang-elisp>>
  1319. <<emacs-python-elisp>>
  1320. <<emacs-rustic-elisp>>
  1321. <<emacs-plantuml-elisp>>
  1322. <<emacs-desktop-elisp>>
  1323. ;; User interface.
  1324. <<emacs-swiper-elisp>>
  1325. <<emacs-transparency-elisp>>
  1326. <<emacs-doom-themes-elisp>>
  1327. <<emacs-doom-modeline-elisp>>
  1328. #+END_SRC
  1329. 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=.
  1330. #+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.emacs.d/early-init.el
  1331. ;; <<file-warning>>
  1332. <<emacs-disable-ui-elisp>>
  1333. <<emacs-native-comp-elisp>>
  1334. <<emacs-backup-files-elisp>>
  1335. <<emacs-shell-commands-elisp>>
  1336. #+END_SRC
  1337. ** Native Comp
  1338. #+NAME: emacs-native-comp-package
  1339. #+BEGIN_SRC nix
  1340. pkgs.emacsGcc;
  1341. #+END_SRC
  1342. 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.
  1343. #+NAME: emacs-native-comp-elisp
  1344. #+BEGIN_SRC emacs-lisp
  1345. ;; Silence warnings from packages that don't support `native-comp'.
  1346. (setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
  1347. native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
  1348. #+END_SRC
  1349. ** Disable UI
  1350. [[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.
  1351. #+NAME: emacs-disable-ui-elisp
  1352. #+BEGIN_SRC emacs-lisp
  1353. ;; Disable unwanted UI elements.
  1354. (tooltip-mode -1)
  1355. (menu-bar-mode -1)
  1356. (tool-bar-mode -1)
  1357. (scroll-bar-mode -1)
  1358. ;; Fix the scrolling behaviour.
  1359. (setq scroll-conservatively 101)
  1360. ;; Fix mouse-wheel scrolling behaviour.
  1361. (setq mouse-wheel-follow-mouse t
  1362. mouse-wheel-progressive-speed t
  1363. mouse-wheel-scroll-amount '(3 ((shift) . 3)))
  1364. ;; Start in fullscreen/maximized.
  1365. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  1366. #+END_SRC
  1367. ** Backup Files
  1368. [[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.
  1369. #+NAME: emacs-backup-files-elisp
  1370. #+BEGIN_SRC emacs-lisp
  1371. ;; Disable unwanted features.
  1372. (setq make-backup-files nil
  1373. create-lockfiles nil)
  1374. #+END_SRC
  1375. ** Shell Commands
  1376. Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
  1377. 1) Method to run an external process, launching any application on a new process without interference
  1378. 2) Method to apply commands to the current call process, effecting the running instance
  1379. #+NAME: emacs-shell-commands-elisp
  1380. #+BEGIN_SRC emacs-lisp
  1381. ;; Define a method to run an external process.
  1382. (defun dotfiles/run (cmd)
  1383. "Run an external process."
  1384. (interactive (list (read-shell-command "λ ")))
  1385. (start-process-shell-command cmd nil cmd))
  1386. ;; Define a method to run a background process.
  1387. (defun dotfiles/run-in-background (cmd)
  1388. (let ((command-parts (split-string cmd "[ ]+")))
  1389. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  1390. #+END_SRC
  1391. ** Nix Mode
  1392. #+NAME: emacs-nix-mode-extras
  1393. #+BEGIN_SRC nix
  1394. pkgs.nixfmt
  1395. #+END_SRC
  1396. [[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.
  1397. #+NAME: emacs-nix-mode-package
  1398. #+BEGIN_SRC nix
  1399. epkgs.nix-mode
  1400. #+END_SRC
  1401. ** Evil Mode
  1402. [[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.
  1403. #+NAME: emacs-evil-package
  1404. #+BEGIN_SRC nix
  1405. epkgs.evil
  1406. epkgs.evil-collection
  1407. epkgs.evil-surround
  1408. epkgs.evil-nerd-commenter
  1409. #+END_SRC
  1410. 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]].
  1411. #+NAME: emacs-evil-elisp
  1412. #+BEGIN_SRC emacs-lisp
  1413. ;; Enable the Extensible VI Layer for Emacs.
  1414. (setq evil-want-integration t ;; Required for `evil-collection.'
  1415. evil-want-keybinding nil ;; Same as above.
  1416. evil-want-C-i-jump nil) ;; Disable jumping in terminal.
  1417. (evil-mode +1)
  1418. ;; Configure `evil-collection'.
  1419. (evil-collection-init)
  1420. ;; Configure `evil-surround'.
  1421. (global-evil-surround-mode +1)
  1422. ;; Configure `evil-nerd-commenter'.
  1423. (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
  1424. ;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
  1425. (evil-define-key 'normal 'org-mode-map (kbd "<tab>") #'org-cycle)
  1426. #+END_SRC
  1427. ** EXWM
  1428. #+NAME: emacs-exwm-package
  1429. #+BEGIN_SRC nix
  1430. epkgs.exwm
  1431. #+END_SRC
  1432. [[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:
  1433. + Fully keyboard-driven operations
  1434. + Hybrid layout modes (tiling & stacking)
  1435. + Dynamic workspace support
  1436. + ICCM/EWMH compliance
  1437. #+NAME: emacs-exwm-extras
  1438. #+BEGIN_SRC nix
  1439. pkgs.nitrogen
  1440. pkgs.autorandr
  1441. #+END_SRC
  1442. 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]].
  1443. #+NAME: emacs-exwm-config
  1444. #+BEGIN_SRC nix
  1445. xsession = {
  1446. enable = true;
  1447. windowManager.command = ''
  1448. ${pkgs.nitrogen}/bin/nitrogen --restore
  1449. ${myEmacs}/bin/emacs --daemon -f exwm-enable
  1450. ${myEmacs}/bin/emacsclient -c
  1451. '';
  1452. };
  1453. #+END_SRC
  1454. [[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=.
  1455. #+NAME: emacs-exwm-xinitrc
  1456. #+BEGIN_SRC nix
  1457. home.file.".xinitrc" = {
  1458. text = ''
  1459. exec ./.xsession
  1460. '';
  1461. };
  1462. #+END_SRC
  1463. #+NAME: emacs-exwm-elisp
  1464. #+BEGIN_SRC emacs-lisp
  1465. ;; Configure `exwm'.
  1466. (setq exwm-layout-show-all-buffers t
  1467. exwm-worspace-show-all-buffers t)
  1468. ;; Configure input keys.
  1469. (setq exwm-input-prefix-keys
  1470. '(?\M-x
  1471. ?\C-g
  1472. ?\C-\ ))
  1473. (setq exwm-input-global-keys
  1474. `(([?\s-r] . exwm-reset)
  1475. ,@(mapcar (lambda (i)
  1476. `(,(kbd (format "s-%d" i)) .
  1477. (lambda ()
  1478. (interactive)
  1479. (exwm-workspace-switch-create ,i))))
  1480. (number-sequence 0 9))))
  1481. ;; Configure `exwm-randr'.
  1482. (require 'exwm-randr)
  1483. (exwm-randr-enable)
  1484. ;; Configure custom hooks.
  1485. (setq display-time-day-and-date t)
  1486. (add-hook 'exwm-init-hook
  1487. (lambda ()
  1488. (display-battery-mode +1) ;; Display battery info (if available).
  1489. (display-time-mode +1))) ;; Display the time in the modeline.
  1490. ;; Setup buffer display names.
  1491. (add-hook 'exwm-update-class-hook
  1492. (lambda ()
  1493. (exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
  1494. ;; Configure monitor hot-swapping.
  1495. (add-hook 'exwm-randr-screen-change-hook
  1496. (lambda ()
  1497. (dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
  1498. #+END_SRC
  1499. ** General
  1500. #+NAME: emacs-general-package
  1501. #+BEGIN_SRC nix
  1502. epkgs.general
  1503. #+END_SRC
  1504. [[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.
  1505. #+NAME: emacs-general-elisp
  1506. #+BEGIN_SRC emacs-lisp
  1507. ;; Use <SPC> as a leader key via `general.el'.
  1508. (general-create-definer dotfiles/leader
  1509. :keymaps '(normal insert visual emacs)
  1510. :prefix "SPC"
  1511. :global-prefix "C-SPC")
  1512. ;; Setup general to work with `evil-mode'.
  1513. (setq general-evil-setup t)
  1514. ;; Find files with <SPC> <period> ...
  1515. ;; Switch buffers with <SPC> <comma> ...
  1516. (dotfiles/leader
  1517. "." '(find-file :which-key "File")
  1518. "," '(switch-to-buffer :which-key "Buffer")
  1519. "k" '(kill-buffer :which-key "Kill")
  1520. "c" '(kill-buffer-and-window :which-key "Close"))
  1521. ;; Add keybindings for executing shell commands.
  1522. (dotfiles/leader
  1523. "r" '(:ignore t :which-key "Run")
  1524. "rr" '(dotfiles/run :which-key "Run")
  1525. "ra" '(async-shell-command :which-key "Async"))
  1526. ;; Add keybindings for quitting Emacs.
  1527. (dotfiles/leader
  1528. "q" '(:ignore t :which-key "Quit")
  1529. "qq" '(save-buffers-kill-emacs :which-key "Save")
  1530. "qw" '(kill-emacs :which-key "Now")
  1531. "qf" '(delete-frame :which-key "Frame"))
  1532. ;; Add keybindings for toggles / tweaks.
  1533. (dotfiles/leader
  1534. "t" '(:ignore t :which-key "Toggle / Tweak"))
  1535. ;; Add keybindings for working with frames to replace
  1536. ;; the C-x <num> <num> method of bindings, which is awful.
  1537. (dotfiles/leader
  1538. "w" '(:ignore t :which-key "Windows")
  1539. "ww" '(window-swap-states :which-key "Swap")
  1540. "wc" '(delete-window :which-key "Close")
  1541. "wh" '(windmove-left :which-key "Left")
  1542. "wj" '(windmove-down :which-key "Down")
  1543. "wk" '(windmove-up :which-key "Up")
  1544. "wl" '(windmove-right :which-key "Right")
  1545. "ws" '(:ignore t :which-key "Split")
  1546. "wsj" '(split-window-below :which-key "Below")
  1547. "wsl" '(split-window-right :which-key "Right"))
  1548. #+END_SRC
  1549. ** Which Key
  1550. [[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.
  1551. #+NAME: emacs-which-key-package
  1552. #+BEGIN_SRC nix
  1553. epkgs.which-key
  1554. #+END_SRC
  1555. #+NAME: emacs-which-key-elisp
  1556. #+BEGIN_SRC emacs-lisp
  1557. ;; Configure `which-key' to see keyboard bindings in the
  1558. ;; mini-buffer and when using M-x.
  1559. (setq which-key-idle-delay 0.0)
  1560. (which-key-mode +1)
  1561. #+END_SRC
  1562. ** EWW
  1563. [[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.
  1564. + Use ~eww~ as the default browser
  1565. + Don't use any special fonts or colours
  1566. #+NAME: emacs-eww-elisp
  1567. #+BEGIN_SRC emacs-lisp
  1568. ;; Set `eww' as the default browser.
  1569. (setq browse-url-browser-function 'eww-browse-url)
  1570. ;; Configure the `shr' rendering engine.
  1571. (setq shr-use-fonts nil
  1572. shr-use-colors nil)
  1573. #+END_SRC
  1574. ** ERC
  1575. [[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.
  1576. #+NAME: emacs-erc-elisp
  1577. #+BEGIN_SRC emacs-lisp
  1578. ;; Configure `erc'.
  1579. (setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
  1580. erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
  1581. erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
  1582. ;; Configure `erc-fill-column'.
  1583. (add-hook 'window-configuration-change-hook
  1584. '(lambda ()
  1585. (setq erc-fill-column (- (window-width) 12))))
  1586. ;; Connect to IRC via `erc'.
  1587. (defun dotfiles/erc-connect ()
  1588. "Connected to IRC via `erc'."
  1589. (interactive)
  1590. (erc-tls :server "irc.libera.chat"
  1591. :port 6697
  1592. :nick "megaphone"
  1593. :password (password-store-get "megaphone@libera.chat")
  1594. :full-name "Chris Hayward"))
  1595. ;; Configure keybindings.
  1596. (dotfiles/leader
  1597. "i" '(dotfiles/erc-connect :which-key "Chat"))
  1598. #+END_SRC
  1599. ** Dired
  1600. #+NAME: emacs-dired-package
  1601. #+BEGIN_SRC nix
  1602. epkgs.dired-single
  1603. #+END_SRC
  1604. [[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.
  1605. #+NAME: emacs-dired-elisp
  1606. #+BEGIN_SRC emacs-lisp
  1607. ;; Include `dired-x' for the `jump' method.
  1608. (require 'dired-x)
  1609. ;; Configure `dired-single' to support `evil' keys.
  1610. (evil-collection-define-key 'normal 'dired-mode-map
  1611. "h" 'dired-single-up-directory
  1612. "l" 'dired-single-buffer)
  1613. ;; Setup `all-the-icons' and the `dired' extension.
  1614. ;; Configure keybindings for `dired'.
  1615. (dotfiles/leader
  1616. "d" '(dired-jump :which-key "Dired"))
  1617. #+END_SRC
  1618. ** Icons
  1619. #+NAME: emacs-icons-package
  1620. #+BEGIN_SRC nix
  1621. epkgs.all-the-icons
  1622. epkgs.all-the-icons-dired
  1623. #+END_SRC
  1624. [[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]].
  1625. #+NAME: emacs-icons-elisp
  1626. #+BEGIN_SRC emacs-lisp
  1627. ;; Setup `all-the-icons-dired'.
  1628. (add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
  1629. ;; Disable monochrome icons.
  1630. (setq all-the-icons-dired-monochrome nil)
  1631. ;; Display default font ligatures.
  1632. (global-prettify-symbols-mode +1)
  1633. #+END_SRC
  1634. ** Emojis
  1635. #+NAME: emacs-emoji-package
  1636. #+BEGIN_SRC nix
  1637. epkgs.emojify
  1638. #+END_SRC
  1639. [[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.
  1640. #+NAME: emacs-emoji-elisp
  1641. #+BEGIN_SRC emacs-lisp
  1642. ;; Setup `emojify'.
  1643. (add-hook 'after-init-hook 'global-emojify-mode)
  1644. #+END_SRC
  1645. ** EShell
  1646. #+NAME: emacs-eshell-package
  1647. #+BEGIN_SRC nix
  1648. epkgs.eshell-prompt-extras
  1649. #+END_SRC
  1650. [[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.
  1651. #+NAME: emacs-eshell-elisp
  1652. #+BEGIN_SRC emacs-lisp
  1653. ;; Configure `eshell'.
  1654. (setq eshell-highlight-prompt nil
  1655. eshell-prefer-lisp-functions nil)
  1656. ;; Configure the lambda prompt.
  1657. (autoload 'epe-theme-lambda "eshell-prompt-extras")
  1658. (setq eshell-prompt-function 'epe-theme-lambda)
  1659. ;; Configure keybindings for `eshell'.
  1660. (dotfiles/leader
  1661. "e" '(eshell :which-key "EShell"))
  1662. #+END_SRC
  1663. ** VTerm
  1664. [[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.
  1665. #+NAME: emacs-vterm-package
  1666. #+BEGIN_SRC nix
  1667. epkgs.vterm
  1668. #+END_SRC
  1669. #+NAME: emacs-vterm-elisp
  1670. #+BEGIN_SRC emacs-lisp
  1671. ;; Add keybindings for interacting with the shell(s).
  1672. (dotfiles/leader
  1673. "v" '(vterm :which-key "VTerm"))
  1674. #+END_SRC
  1675. ** Magit
  1676. [[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.
  1677. #+NAME: emacs-magit-package
  1678. #+BEGIN_SRC nix
  1679. epkgs.magit
  1680. #+END_SRC
  1681. #+NAME: emacs-magit-elisp
  1682. #+BEGIN_SRC emacs-lisp
  1683. ;; Add keybindings for working with `magit'.
  1684. (dotfiles/leader
  1685. "g" '(:ignore t :which-key "Git")
  1686. "gg" '(magit-status :which-key "Status")
  1687. "gc" '(magit-clone :which-key "Clone")
  1688. "gf" '(magit-fetch :which-key "Fetch")
  1689. "gp" '(magit-pull :which-key "Pull"))
  1690. #+END_SRC
  1691. ** Fonts
  1692. #+NAME: emacs-fonts-package
  1693. #+BEGIN_SRC nix
  1694. epkgs.hydra
  1695. #+END_SRC
  1696. #+NAME: emacs-fonts-elisp
  1697. #+BEGIN_SRC emacs-lisp
  1698. ;; Configure the font when running as `emacs-server'.
  1699. (custom-set-faces
  1700. '(default ((t (:inherit nil :height 120 :family "Iosevka")))))
  1701. ;; Set all three of Emacs' font faces.
  1702. ;; NOTE: This only works without `emacs-server'.
  1703. ;; (set-face-attribute 'default nil :font "Iosevka" :height 96)
  1704. ;; (set-face-attribute 'fixed-pitch nil :font "Iosevka" :height 96)
  1705. ;; (set-face-attribute 'variable-pitch nil :font "Iosevka" :height 96)
  1706. ;; Define a `hydra' function for scaling the text interactively.
  1707. (defhydra hydra-text-scale (:timeout 4)
  1708. "Scale text"
  1709. ("j" text-scale-decrease "Decrease")
  1710. ("k" text-scale-increase "Increase")
  1711. ("f" nil "Finished" :exit t))
  1712. ;; Create keybinding for calling the function.
  1713. (dotfiles/leader
  1714. "tf" '(hydra-text-scale/body :which-key "Font"))
  1715. #+END_SRC
  1716. ** Elfeed
  1717. #+NAME: emacs-elfeed-package
  1718. #+BEGIN_SRC nix
  1719. epkgs.elfeed
  1720. #+END_SRC
  1721. [[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.
  1722. #+NAME: emacs-elfeed-elisp
  1723. #+BEGIN_SRC emacs-lisp
  1724. ;; Configure `elfeed'.
  1725. (setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
  1726. ;; Add custom feeds for `elfeed' to fetch.
  1727. (setq elfeed-feeds (quote
  1728. (("https://hexdsl.co.uk/rss.xml")
  1729. ("https://lukesmith.xyz/rss.xml")
  1730. ("https://friendo.monster/rss.xml")
  1731. ("https://chrishayward.xyz/index.xml")
  1732. ("https://protesilaos.com/master.xml"))))
  1733. ;; Add custom keybindings for `elfeed'.
  1734. (dotfiles/leader
  1735. "l" '(:ignore t :which-key "Elfeed")
  1736. "ll" '(elfeed :which-key "Open")
  1737. "lu" '(elfeed-update :which-key "Update"))
  1738. #+END_SRC
  1739. ** Org Mode
  1740. #+NAME: emacs-org-package
  1741. #+BEGIN_SRC nix
  1742. epkgs.org
  1743. #+END_SRC
  1744. [[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.
  1745. #+NAME: emacs-org-elisp
  1746. #+BEGIN_SRC emacs-lisp
  1747. ;; Configure `org-mode' source blocks.
  1748. (setq org-src-fontify-natively t ;; Make source blocks prettier.
  1749. org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
  1750. org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
  1751. org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
  1752. ;; Add an `org-mode-hook'.
  1753. (add-hook 'org-mode-hook
  1754. (lambda ()
  1755. (org-indent-mode)
  1756. (visual-line-mode)))
  1757. ;; Remove the `Validate XHTML 1.0' message from HTML export.
  1758. (setq org-export-html-validation-link nil
  1759. org-html-validation-link nil)
  1760. ;; Configure the keywords in the TODO -> DONE sequence.
  1761. (setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  1762. ;; Track ids globally.
  1763. (setq org-id-track-globally t)
  1764. ;; Configure `org-babel' languages.
  1765. (org-babel-do-load-languages
  1766. 'org-babel-load-languages
  1767. '((C . t)))
  1768. ;; Log / Clock into property drawers.
  1769. (setq org-log-into-drawer t
  1770. org-clock-into-drawer t)
  1771. ;; Encrypt files with the public key.
  1772. (setq epa-file-select-keys 2
  1773. epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  1774. epa-cache-passphrase-for-symmetric-encryption t)
  1775. ;; TODO: Configure default structure templates.
  1776. ;; (require 'org-tempo)
  1777. ;; Apply custom keybindings.
  1778. (dotfiles/leader
  1779. "o" '(:ignore t :which-key "Org")
  1780. "oe" '(org-export-dispatch :which-key "Export")
  1781. "ot" '(org-babel-tangle :which-key "Tangle")
  1782. "oi" '(org-toggle-inline-images :which-key "Images")
  1783. "of" '(:ignore t :which-key "Footnotes")
  1784. "ofn" '(org-footnote-normalize :which-key "Normalize"))
  1785. #+END_SRC
  1786. ** Org Roam
  1787. #+NAME: emacs-org-roam-package
  1788. #+BEGIN_SRC nix
  1789. epkgs.org-roam
  1790. # epkgs.org-roam-ui # TODO: Provide from Github
  1791. epkgs.websocket
  1792. epkgs.simple-httpd
  1793. epkgs.org-ref
  1794. epkgs.bibtex-completion
  1795. epkgs.org-roam-bibtex
  1796. #+END_SRC
  1797. [[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.
  1798. #+NAME: emacs-org-roam-elisp
  1799. #+BEGIN_SRC emacs-lisp
  1800. ;; Setup `org-roam'.
  1801. (require 'org-roam)
  1802. ;; Enable `visual-line-mode' in `org-roam' buffer.
  1803. (add-hook 'org-roam-mode-hook
  1804. (lambda ()
  1805. (visual-line-mode +1)))
  1806. ;; HACK: Set up `org-roam-ui'.
  1807. (add-to-list 'load-path "~/.local/source/org-roam-ui")
  1808. (load-library "org-roam-ui")
  1809. (setq org-roam-ui-follow t
  1810. org-roam-ui-sync-theme t
  1811. org-roam-ui-open-on-start t
  1812. org-roam-ui-update-on-save t
  1813. org-roam-ui-browser-function #'browse-url-firefox)
  1814. ;; Silence the migration warnings.
  1815. (setq org-roam-v2-ack t)
  1816. ;; Enable completion everywhere.
  1817. (setq org-roam-completion-everywhere t)
  1818. ;; Set the roam directories.
  1819. (setq org-roam-directory (expand-file-name "/etc/dotfiles")
  1820. org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
  1821. ;; Clear the deafult capture templates.
  1822. (setq org-roam-capture-templates '()
  1823. org-roam-dailies-capture-templates '())
  1824. ;; Override the default slug method.
  1825. (cl-defmethod org-roam-node-slug ((node org-roam-node))
  1826. (let ((title (org-roam-node-title node))
  1827. (slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
  1828. 769 ; U+0301 COMBINING ACUTE ACCENT
  1829. 770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
  1830. 771 ; U+0303 COMBINING TILDE
  1831. 772 ; U+0304 COMBINING MACRON
  1832. 774 ; U+0306 COMBINING BREVE
  1833. 775 ; U+0307 COMBINING DOT ABOVE
  1834. 776 ; U+0308 COMBINING DIAERESIS
  1835. 777 ; U+0309 COMBINING HOOK ABOVE
  1836. 778 ; U+030A COMBINING RING ABOVE
  1837. 780 ; U+030C COMBINING CARON
  1838. 795 ; U+031B COMBINING HORN
  1839. 803 ; U+0323 COMBINING DOT BELOW
  1840. 804 ; U+0324 COMBINING DIAERESIS BELOW
  1841. 805 ; U+0325 COMBINING RING BELOW
  1842. 807 ; U+0327 COMBINING CEDILLA
  1843. 813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
  1844. 814 ; U+032E COMBINING BREVE BELOW
  1845. 816 ; U+0330 COMBINING TILDE BELOW
  1846. 817 ; U+0331 COMBINING MACRON BELOW
  1847. )))
  1848. (cl-flet* ((nonspacing-mark-p (char)
  1849. (memq char slug-trim-chars))
  1850. (strip-nonspacing-marks (s)
  1851. (ucs-normalize-NFC-string
  1852. (apply #'string (seq-remove #'nonspacing-mark-p
  1853. (ucs-normalize-NFD-string s)))))
  1854. (cl-replace (title pair)
  1855. (replace-regexp-in-string (car pair) (cdr pair) title)))
  1856. (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
  1857. ("--*" . "-")
  1858. ("^-" . "")
  1859. ("-$" . "")))
  1860. (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
  1861. (downcase slug)))))
  1862. ;; Configure capture templates.
  1863. ;; Standard document.
  1864. (add-to-list 'org-roam-capture-templates
  1865. '("d" "Default" plain "%?"
  1866. :target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
  1867. "
  1868. ,#+TITLE: ${title}
  1869. ,#+AUTHOR: Christopher James Hayward
  1870. ,#+EMAIL: chris@chrishayward.xyz
  1871. "
  1872. )
  1873. :unnarrowed t))
  1874. ;; Daily notes.
  1875. (add-to-list 'org-roam-dailies-capture-templates
  1876. '("d" "Default" entry "* %?"
  1877. :target (file+head "%<%Y-%m-%d>.org.gpg"
  1878. "
  1879. ,#+TITLE: %<%Y-%m-%d>
  1880. ,#+AUTHOR: Christopher James Hayward
  1881. ,#+EMAIL: chris@chrishayward.xyz
  1882. ")))
  1883. ;; Apply custom keybindings.
  1884. (dotfiles/leader
  1885. "or" '(:ignore t :which-key "Roam")
  1886. "ori" '(org-roam-node-insert :which-key "Insert")
  1887. "orf" '(org-roam-node-find :which-key "Find")
  1888. "orc" '(org-roam-capture :which-key "Capture")
  1889. "orb" '(org-roam-buffer-toggle :which-key "Buffer"))
  1890. ;; Apply custom keybindings for dailies.
  1891. (dotfiles/leader
  1892. "ord" '(:ignore t :which-key "Dailies")
  1893. "ordd" '(org-roam-dailies-goto-date :which-key "Date")
  1894. "ordt" '(org-roam-dailies-goto-today :which-key "Today")
  1895. "ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
  1896. "ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
  1897. ;; Run the setup command.
  1898. (org-roam-setup)
  1899. ;; Setup `org-roam-bibtex'.
  1900. (require 'org-ref)
  1901. (require 'org-roam-bibtex)
  1902. ;; Apply custom keybindings.
  1903. (dotfiles/leader
  1904. "orn" '(orb-note-actions :which-key "Notes")
  1905. "orl" '(orb-inset-link :which-key "Links"))
  1906. ;; Start `org-roam-bibtex'.
  1907. (org-roam-bibtex-mode)
  1908. #+END_SRC
  1909. ** Org Drill
  1910. #+NAME: emacs-org-drill-package
  1911. #+BEGIN_SRC nix
  1912. epkgs.org-drill
  1913. #+END_SRC
  1914. [[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.
  1915. #+NAME: emacs-org-drill-elisp
  1916. #+BEGIN_SRC emacs-lisp
  1917. ;; Exclude :drill: items from `org-roam'.
  1918. (setq org-roam-db-node-include-function
  1919. (defun dotfiles/org-roam-include ()
  1920. (not (member "drill" (org-get-tags)))))
  1921. ;; Configure keybindings for `org-drill'.
  1922. (dotfiles/leader
  1923. "od" '(:ignore t :which-key "Drill")
  1924. "odd" '(org-drill :which-key "Drill")
  1925. "odc" '(org-drill-cram :which-key "Cram")
  1926. "odr" '(org-drill-resume :which-key "Resume"))
  1927. #+END_SRC
  1928. ** Org Agenda
  1929. 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.
  1930. #+NAME: emacs-org-agenda-elisp
  1931. #+BEGIN_SRC emacs-lisp
  1932. ;; Configure `org-agenda' to use the project files.
  1933. (setq org-agenda-files '("/etc/dotfiles/"
  1934. "/etc/dotfiles/docs/"
  1935. "/etc/dotfiles/docs/daily/"))
  1936. ;; Include files encrypted with `gpg'.
  1937. (require 'org)
  1938. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  1939. (setq org-agenda-file-regexp
  1940. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  1941. org-agenda-file-regexp)))
  1942. ;; Open an agenda buffer with SPC o a.
  1943. (dotfiles/leader
  1944. "oa" '(org-agenda :which-key "Agenda"))
  1945. #+END_SRC
  1946. ** Org Pomodoro
  1947. #+NAME: emacs-pomodoro-package
  1948. #+BEGIN_SRC nix
  1949. epkgs.org-pomodoro
  1950. #+END_SRC
  1951. [[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.
  1952. #+NAME: emacs-pomodoro-elisp
  1953. #+BEGIN_SRC emacs-lisp
  1954. ;; Configure `org-pomodor' with the overtime workflow.
  1955. (setq org-pomodoro-manual-break t
  1956. org-pomodoro-keep-killed-time t)
  1957. ;; Configure keybindings.
  1958. (dotfiles/leader
  1959. "op" '(org-pomodoro :which-key "Pomodoro"))
  1960. #+END_SRC
  1961. ** Writegood Mode
  1962. #+NAME: emacs-writegood-package
  1963. #+BEGIN_SRC nix
  1964. epkgs.writegood-mode
  1965. #+END_SRC
  1966. [[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:
  1967. + Weasel Words
  1968. + Passive Voice
  1969. + Duplicate Words
  1970. #+NAME: emacs-writegood-elisp
  1971. #+BEGIN_SRC emacs-lisp
  1972. ;; Configure `writegood-mode'.
  1973. (dotfiles/leader
  1974. "tg" '(writegood-mode :which-key "Grammar"))
  1975. #+END_SRC
  1976. ** Aspell
  1977. #+NAME: emacs-aspell-extras
  1978. #+BEGIN_SRC nix
  1979. pkgs.aspell
  1980. pkgs.aspellDicts.en
  1981. pkgs.aspellDicts.en-science
  1982. pkgs.aspellDicts.en-computers
  1983. #+END_SRC
  1984. [[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.
  1985. #+NAME: emacs-aspell-elisp
  1986. #+BEGIN_SRC emacs-lisp
  1987. ;; Use `aspell' as a drop-in replacement for `ispell'.
  1988. (setq ispell-program-name "aspell"
  1989. ispell-eextra-args '("--sug-mode=fast"))
  1990. ;; Configure the built-in `flyspell-mode'.
  1991. (dotfiles/leader
  1992. "ts" '(flyspell-mode :which-key "Spelling"))
  1993. #+END_SRC
  1994. ** TexLive
  1995. [[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/:
  1996. | Name | Derivation | Comment |
  1997. |---------+---------------------------------+------------------------------------------------------------|
  1998. | Full | texlive.combined.scheme-full | Contains every TeX Live package |
  1999. | Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
  2000. | Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
  2001. | Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
  2002. | Minimal | texlive.combined.scheme-minimal | Contains plain only |
  2003. #+NAME: emacs-texlive-extras
  2004. #+BEGIN_SRC nix
  2005. pkgs.texlive.combined.scheme-full
  2006. #+END_SRC
  2007. ** Http
  2008. #+NAME: emacs-http-package
  2009. #+BEGIN_SRC nix
  2010. epkgs.ob-http
  2011. #+END_SRC
  2012. 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.
  2013. #+NAME: emacs-http-elisp
  2014. #+BEGIN_SRC emacs-lisp
  2015. ;; Required to setup `ob-http'.
  2016. (org-babel-do-load-languages
  2017. 'org-babel-load-languages
  2018. '((http . t)))
  2019. #+END_SRC
  2020. ** Hugo
  2021. #+NAME: emacs-hugo-package
  2022. #+BEGIN_SRC nix
  2023. epkgs.ox-hugo
  2024. #+END_SRC
  2025. [[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/.
  2026. #+NAME: emacs-hugo-elisp
  2027. #+BEGIN_SRC emacs-lisp
  2028. ;; Configure `ox-hugo' as an `org-mode-export' backend.
  2029. (require 'ox-hugo)
  2030. ;; Set up the base directory.
  2031. (setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
  2032. ;; Capture templates.
  2033. ;; Shared content
  2034. ;; (add-to-list 'org-roam-capture-templates
  2035. ;; '("p" "Post" plain "%?"
  2036. ;; :target (file+head "docs/posts/${slug}.org.gpg"
  2037. ;; "
  2038. ;; ,#+TITLE: ${title}
  2039. ;; ,#+AUTHOR: Christopher James Hayward
  2040. ;; ,#+DATE: %<%Y-%m-%d>
  2041. ;; ,#+EXPORT_FILE_NAME: ${slug}
  2042. ;; ,#+OPTIONS: num:nil todo:nil tasks:nil
  2043. ;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  2044. ;; ,#+HUGO_BASE_DIR: ../
  2045. ;; ,#+HUGO_AUTO_SET_LASTMOD: t
  2046. ;; ,#+HUGO_SECTION: posts
  2047. ;; ,#+HUGO_DRAFT: true
  2048. ;; "
  2049. ;; )
  2050. ;; :unnarrowed t))
  2051. #+END_SRC
  2052. ** Passwords
  2053. #+NAME: emacs-pass-extras
  2054. #+BEGIN_SRC nix
  2055. pkgs.pass
  2056. #+END_SRC
  2057. 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.
  2058. #+NAME: emacs-pass-package
  2059. #+BEGIN_SRC nix
  2060. epkgs.password-store
  2061. #+END_SRC
  2062. Configure keybindings for passwords behind =SPC p=:
  2063. #+NAME: emacs-pass-elisp
  2064. #+BEGIN_SRC emacs-lisp
  2065. ;; Set the path to the password store.
  2066. (setq password-store-dir (expand-file-name "~/.password-store"))
  2067. ;; Apply custom keybindings.
  2068. (dotfiles/leader
  2069. "p" '(:ignore t :which-key "Passwords")
  2070. "pp" '(password-store-copy :which-key "Copy")
  2071. "pe" '(password-store-edit :which-key "Edit")
  2072. "pi" '(password-store-insert :which-key "Insert")
  2073. "pr" '(password-store-rename :which-key "Rename")
  2074. "pg" '(password-store-generate :which-key "Generate"))
  2075. #+END_SRC
  2076. ** Docker
  2077. #+NAME: emacs-docker-package
  2078. #+BEGIN_SRC nix
  2079. epkgs.docker
  2080. epkgs.dockerfile-mode
  2081. #+END_SRC
  2082. 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.
  2083. #+NAME: emacs-docker-elisp
  2084. #+BEGIN_SRC emacs-lisp
  2085. ;; Apply custom keybindings.
  2086. (dotfiles/leader
  2087. "n" '(:ignore t :which-key "Containers")
  2088. "nd" '(docker :which-key "Docker"))
  2089. #+END_SRC
  2090. ** MU4E
  2091. #+NAME: emacs-mu4e-extras
  2092. #+BEGIN_SRC nix
  2093. pkgs.mu
  2094. pkgs.isync
  2095. #+END_SRC
  2096. #+NAME: emacs-mu4e-package
  2097. #+BEGIN_SRC nix
  2098. epkgs.mu4e-alert
  2099. #+END_SRC
  2100. #+NAME: emacs-mu4e-config
  2101. #+BEGIN_SRC nix
  2102. # Deploy the authinfo file.
  2103. home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
  2104. # Deploy the isync configuration file.
  2105. home.file.".mbsyncrc" = {
  2106. text = ''
  2107. IMAPStore xyz-remote
  2108. Host mail.chrishayward.xyz
  2109. User chris@chrishayward.xyz
  2110. PassCmd "pass chrishayward.xyz/chris"
  2111. SSLType IMAPS
  2112. MaildirStore xyz-local
  2113. Path ~/.cache/mail/
  2114. Inbox ~/.cache/mail/inbox
  2115. SubFolders Verbatim
  2116. Channel xyz
  2117. Far :xyz-remote:
  2118. Near :xyz-local:
  2119. Patterns * !Archives
  2120. Create Both
  2121. Expunge Both
  2122. SyncState *
  2123. '';
  2124. };
  2125. #+END_SRC
  2126. #+BEGIN_SRC sh
  2127. mbsync -a
  2128. mu init --maildir="~/.cache/mail" --my-address="chris@chrishayward.xyz"
  2129. mu index
  2130. #+END_SRC
  2131. #+NAME: emacs-mu4e-elisp
  2132. #+BEGIN_SRC emacs-lisp
  2133. ;; Add the `mu4e' shipped with `mu' to the load path.
  2134. (add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
  2135. (require 'mu4e)
  2136. ;; Confiugure `mu4e'.
  2137. (setq mu4e-maildir "~/.cache/mail"
  2138. mu4e-update-interval (* 5 60)
  2139. mu4e-get-mail-command "mbsync -a"
  2140. mu4e-compose-format-flowed t
  2141. mu4e-change-filenames-when-moving t
  2142. mu4e-compose-signature (concat "Chris Hayward\n"
  2143. "chris@chrishayward.xyz"))
  2144. ;; Sign all outbound email with GPG.
  2145. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  2146. (setq message-send-mail-function 'smtpmail-send-it
  2147. mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  2148. ;; Setup `mu4e' accounts.
  2149. (setq mu4e-contexts
  2150. (list
  2151. ;; Main
  2152. ;; chris@chrishayward.xyz
  2153. (make-mu4e-context
  2154. :name "Main"
  2155. :match-func
  2156. (lambda (msg)
  2157. (when msg
  2158. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  2159. :vars
  2160. '((user-full-name . "Christopher James Hayward")
  2161. (user-mail-address . "chris@chrishayward.xyz")
  2162. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  2163. (smtpmail-smtp-service . 587)
  2164. (smtpmail-stream-type . starttls)))))
  2165. ;; Setup `mu4e-alert'.
  2166. (setq mu4e-alert-set-default-style 'libnotify)
  2167. (mu4e-alert-enable-notifications)
  2168. (mu4e-alert-enable-mode-line-display)
  2169. ;; Open the `mu4e' dashboard.
  2170. (dotfiles/leader
  2171. "m" '(mu4e :which-key "Mail"))
  2172. #+END_SRC
  2173. ** Projectile
  2174. #+NAME: emacs-projectile-package
  2175. #+BEGIN_SRC nix
  2176. epkgs.projectile
  2177. #+END_SRC
  2178. [[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.
  2179. #+NAME: emacs-projectile-elisp
  2180. #+BEGIN_SRC emacs-lisp
  2181. ;; Configure the `projectile-project-search-path'.
  2182. (setq projectile-project-search-path '("~/.local/source"))
  2183. (projectile-mode +1)
  2184. #+END_SRC
  2185. ** LSP Mode
  2186. #+NAME: emacs-lsp-package
  2187. #+BEGIN_SRC nix
  2188. epkgs.lsp-mode
  2189. epkgs.lsp-ui
  2190. #+END_SRC
  2191. 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:
  2192. + Auto Complete
  2193. + Go To Defintion
  2194. + Find All References
  2195. #+NAME: emacs-lsp-elisp
  2196. #+BEGIN_SRC emacs-lisp
  2197. ;; Configure `lsp-mode'.
  2198. (setq lsp-idle-delay 0.5
  2199. lsp-prefer-flymake t)
  2200. ;; Configure `lsp-ui'.
  2201. (setq lsp-ui-doc-position 'at-point
  2202. lsp-ui-doc-delay 0.5)
  2203. #+END_SRC
  2204. ** CCLS
  2205. #+NAME: emacs-ccls-package
  2206. #+BEGIN_SRC nix
  2207. epkgs.ccls
  2208. #+END_SRC
  2209. [[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.
  2210. #+NAME: emacs-ccls-elisp
  2211. #+BEGIN_SRC emacs-lisp
  2212. ;; Configure `ccls' to work with `lsp-mode'.
  2213. (defun dotfiles/ccls-hook ()
  2214. (require 'ccls)
  2215. (lsp))
  2216. ;; Configure `ccls' mode hooks.
  2217. (add-hook 'c-mode-hook 'dotfiles/ccls-hook)
  2218. (add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
  2219. (add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
  2220. (add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
  2221. #+END_SRC
  2222. ** Company Mode
  2223. #+NAME: emacs-company-package
  2224. #+BEGIN_SRC nix
  2225. epkgs.company
  2226. #+END_SRC
  2227. [[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.
  2228. #+NAME: emacs-company-elisp
  2229. #+BEGIN_SRC emacs-lisp
  2230. ;; Configure `company-mode'.
  2231. (setq company-backend 'company-capf
  2232. lsp-completion-provider :capf)
  2233. ;; Enable it globally.
  2234. (global-company-mode +1)
  2235. #+END_SRC
  2236. ** Go Mode
  2237. #+NAME: emacs-golang-package
  2238. #+BEGIN_SRC nix
  2239. epkgs.go-mode
  2240. #+END_SRC
  2241. [[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.
  2242. #+NAME: emacs-golang-elisp
  2243. #+BEGIN_SRC emacs-lisp
  2244. ;; Configure `go-mode' to work with `lsp-mode'.
  2245. (defun dotfiles/go-hook ()
  2246. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  2247. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  2248. ;; Configure a custom `before-save-hook'.
  2249. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  2250. #+END_SRC
  2251. ** Rustic
  2252. #+NAME: emacs-rustic-package
  2253. #+BEGIN_SRC nix
  2254. epkgs.rustic
  2255. #+END_SRC
  2256. 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!
  2257. #+NAME: emacs-rustic-elisp
  2258. #+BEGIN_SRC emacs-lisp
  2259. ;; Configure `rustic' with `lsp-mode'.
  2260. (setq rustic-format-on-save t
  2261. rustic-lsp-server 'rls)
  2262. #+END_SRC
  2263. ** Python Mode
  2264. #+NAME: emacs-python-package
  2265. #+BEGIN_SRC nix
  2266. epkgs.pretty-mode
  2267. #+END_SRC
  2268. 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.
  2269. #+NAME: emacs-python-elisp
  2270. #+BEGIN_SRC emacs-lisp
  2271. ;; Configure `pretty-mode' to work with `python-mode'.
  2272. (add-hook 'python-mode-hook
  2273. (lambda ()
  2274. (turn-on-pretty-mode)))
  2275. #+END_SRC
  2276. ** Protobuf Mode
  2277. #+NAME: emacs-protobuf-package
  2278. #+BEGIN_SRC nix
  2279. epkgs.protobuf-mode
  2280. #+END_SRC
  2281. ** PlantUML
  2282. #+NAME: emacs-plantuml-extras
  2283. #+BEGIN_SRC nix
  2284. pkgs.plantuml
  2285. #+END_SRC
  2286. [[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.
  2287. #+NAME: emacs-plantuml-package
  2288. #+BEGIN_SRC nix
  2289. epkgs.plantuml-mode
  2290. #+END_SRC
  2291. [[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]].
  2292. #+NAME: emacs-plantuml-elisp
  2293. #+BEGIN_SRC emacs-lisp
  2294. ;; Configure `plantuml-mode'.
  2295. (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  2296. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  2297. (setq plantuml-default-exec-mode 'executable
  2298. org-plantuml-exec-mode 'plantuml)
  2299. #+END_SRC
  2300. ** Swiper
  2301. #+NAME: emacs-swiper-package
  2302. #+BEGIN_SRC nix
  2303. epkgs.ivy
  2304. epkgs.counsel
  2305. epkgs.ivy-rich
  2306. epkgs.ivy-bibtex
  2307. epkgs.ivy-posframe
  2308. epkgs.ivy-prescient
  2309. #+END_SRC
  2310. [[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.
  2311. #+NAME: emacs-swiper-elisp
  2312. #+BEGIN_SRC emacs-lisp
  2313. ;; Configure `ivy'.
  2314. (setq counsel-linux-app-format-function
  2315. #'counsel-linux-app-format-function-name-only)
  2316. (ivy-mode +1)
  2317. (counsel-mode +1)
  2318. ;; Configure `ivy-rich'.
  2319. (ivy-rich-mode +1)
  2320. ;; Configure `ivy-posframe'.
  2321. (setq ivy-posframe-parameters '((parent-frame nil))
  2322. ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
  2323. (ivy-posframe-mode +1)
  2324. ;; Configure `ivy-prescient'.
  2325. (setq ivy-prescient-enable-filtering nil)
  2326. (ivy-prescient-mode +1)
  2327. #+END_SRC
  2328. ** Transparency
  2329. 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.
  2330. #+NAME: emacs-transparency-elisp
  2331. #+BEGIN_SRC emacs-lisp
  2332. ;; Configure the default frame transparency.
  2333. (set-frame-parameter (selected-frame) 'alpha '(95 . 95))
  2334. (add-to-list 'default-frame-alist '(alpha . (95 . 95)))
  2335. #+END_SRC
  2336. ** Desktop Environment
  2337. #+NAME: emacs-desktop-extras
  2338. #+BEGIN_SRC nix
  2339. pkgs.brightnessctl
  2340. #+END_SRC
  2341. 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]].
  2342. #+NAME: emacs-desktop-package
  2343. #+BEGIN_SRC nix
  2344. epkgs.desktop-environment
  2345. #+END_SRC
  2346. 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.
  2347. #+NAME: emacs-desktop-elisp
  2348. #+BEGIN_SRC emacs-lisp
  2349. ;; Configure `desktop-environment'.
  2350. (require 'desktop-environment)
  2351. (desktop-environment-mode +1)
  2352. #+END_SRC
  2353. ** Doom Themes
  2354. #+NAME: emacs-doom-themes-package
  2355. #+BEGIN_SRC nix
  2356. epkgs.doom-themes
  2357. #+END_SRC
  2358. [[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.
  2359. #+NAME: emacs-doom-themes-elisp
  2360. #+BEGIN_SRC emacs-lisp
  2361. ;; Include modern themes from `doom-themes'.
  2362. (setq doom-themes-enable-bold t
  2363. doom-themes-enable-italic t)
  2364. ;; Load the `doom-nord' and `doom-nord-light' themes.
  2365. ;; (load-theme 'doom-nord-light t)
  2366. (load-theme 'doom-nord t)
  2367. (doom-modeline-mode +1)
  2368. ;; Define a method for returning information about the current theme.
  2369. ;; This is based off the function `org-roam-ui-get-theme'.
  2370. (defun dotfiles/theme ()
  2371. "Return information about the current theme."
  2372. (list `(bg . ,(face-background hl-line-face))
  2373. `(bg-alt . ,(face-background 'default))
  2374. `(fg . ,(face-foreground 'default))
  2375. `(fg-alt . ,(face-foreground font-lock-comment-face))
  2376. `(red . ,(face-foreground 'error))
  2377. `(orange . ,(face-foreground 'warning))
  2378. `(yellow . ,(face-foreground font-lock-builtin-face))
  2379. `(green . ,(face-foreground 'success))
  2380. `(cyan . ,(face-foreground font-lock-constant-face))
  2381. `(blue . ,(face-foreground font-lock-keyword-face))
  2382. `(violet . ,(face-foreground font-lock-constant-face))
  2383. `(magenta . ,(face-foreground font-lock-preprocessor-face))))
  2384. ;; Load a new theme with <SPC> t t.
  2385. (dotfiles/leader
  2386. "tt" '(counsel-load-theme :which-key "Theme"))
  2387. #+END_SRC
  2388. ** Doom Modeline
  2389. #+NAME: emacs-doom-modeline-package
  2390. #+BEGIN_SRC nix
  2391. epkgs.doom-modeline
  2392. #+END_SRC
  2393. [[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.
  2394. #+NAME: emacs-doom-modeline-elisp
  2395. #+BEGIN_SRC emacs-lisp
  2396. ;; Add the `doom-modeline' after initialization.
  2397. (add-hook 'after-init-hook 'doom-modeline-mode)
  2398. (setq doom-modeline-height 16
  2399. doom-modeline-icon t)
  2400. #+END_SRC
  2401. * Footnotes