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.

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