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.

3046 lines
95 KiB

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