:PROPERTIES:
:ID: e4ad3dd5-0996-45bc-92ab-6bdbf16e4310
:ROAM_REFS: https://chrishayward.xyz/dotfiles/
:END:
#+TITLE: Dotfiles
#+AUTHOR: Christopher James Hayward
#+EMAIL: chris@chrishayward.xyz
#+STARTUP: overview
#+STARTUP: hideblocks
#+EXPORT_FILE_NAME: dotfiles
#+HUGO_BASE_DIR: docs
#+HUGO_AUTO_SET_LASTMOD: t
#+HUGO_SECTION:
#+HUGO_DRAFT: false
#+HTML:
#+HTML:
#+HTML:
#+NAME: description
#+BEGIN_SRC text
Immutable NixOS dotfiles.
#+END_SRC
#+ATTR_ORG: :width 800px
#+ATTR_HTML: :width 800px
#+ATTR_LATEX: :width 800px
[[./docs/images/desktop.png]]
Built for Life, Liberty, and the Open Road.
+ 100% Immutable
+ 100% Declarative
+ 100% Reproducible
* Introduction
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.
#+NAME: file-warning
#+BEGIN_SRC text
This file is controlled by /etc/dotfiles/README.org
#+END_SRC
** Getting Started
1) [[https://nixos.org/download.html][Download the latest version of NixOS]]
2) [[https://nixos.org/manual/nixos/stable/#sec-installation-partitioning][Partition your drives and mount the file system]]
3) Clone the project ~git clone git@git.chrishayward.xyz:chris/dotfiles /mnt/etc/dotfiles~
4) Load the default shell ~nix develop /mnt/etc/dotfiles~
5) Install the system ~sudo nixos-install --impure --flake /mnt/etc/dotfiles#nixos~
6) Reboot, login and start a graphical system ~startx~
** Making Changes
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:
#+NAME: rebuild-command-table
| Command | Description |
|----------+---------------------------------------------------------------------------------|
| boot | Build the new configuration and make it the boot default, without activation |
| test | Build and activate the new configuration, without adding it to the boot menu |
| switch | Build and activate the new configuration, making it the new boot default |
| build | Build the new configuration, without activation, nor adding it to the boot menu |
| build-vm | Build a script that starts a virtual machine with the desired configuration |
After making changes to the configuration the ~switch~ command will build and activate a new configuration.
#+BEGIN_SRC shell
# Build and activate a new configuration.
sudo nixos-rebuild switch --flake $FLAKE#$HOSTNAME
#+END_SRC
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.
#+BEGIN_SRC shell
# Rollback to the previous generation.
sudo nixos-rebuild switch --rollback
#+END_SRC
** Docker Container
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.
Install from the command line: ~docker pull ghcr.io/chayward1/dotfiles:main~
#+BEGIN_SRC dockerfile :tangle Dockerfile :noweb yes
# <>
# Derive from the official image.
FROM nixos/nix
# Setup the default environment.
WORKDIR /etc/dotfiles
COPY . .
# Load the default system shell.
RUN nix-shell /etc/dotfiles/shell.nix
#+END_SRC
* Operating System
#+ATTR_ORG: :width 400px
#+ATTR_HTML: :width 400px
#+ATTR_LATEX: :width 400px
[[./docs/images/nixos.png]]
[[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.
#+BEGIN_SRC nix :noweb yes :tangle flake.nix
# <>
{
description = "<>";
inputs = {
<>
<>
<>
<>
<>
};
outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, ... }: {
<>
} //
<>
}
#+END_SRC
** Nixpkgs
[[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:
1) The current stable release
2) The Unstable branch following the latest development
#+NAME: os-nixpkgs
#+BEGIN_SRC nix
nixpkgs.url = "nixpkgs/nixos-unstable";
nixpkgs-unstable.url = "nixpkgs/master";
#+END_SRC
** Flake Utils
[[https://github.com/numtide/flake-utils][Flake Utils]] is a collection of pure Nix functions that don't depend on Nixpkgs, and that are useful in the context of writing other Nix Flakes.
#+NAME: os-flake-utils
#+BEGIN_SRC nix
flake-utils.url = "github:numtide/flake-utils";
#+END_SRC
** Home Manager
[[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.
#+NAME: os-home-manager
#+BEGIN_SRC nix
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
#+END_SRC
** Emacs Overlay
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.
#+NAME: os-emacs-overlay
#+BEGIN_SRC nix
emacs-overlay.url = "github:nix-community/emacs-overlay";
#+END_SRC
** NixOS Hardware
[[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.
#+NAME: os-nixos-hardware
#+BEGIN_SRC nix
nixos-hardware.url = "github:nixos/nixos-hardware";
#+END_SRC
* Development Shells
The command ~nix develop~ will run a bash shell that provides the build environment of a derivation. It's an experimental replacement for the ~nix-shell~ command that is compliant with Nix Flakes. It provides an interactive build environment nearly identical to what Nix would use to build /installable/. Inside this shell, environment variables and shell functions are set up so that you can interactively and incrementally build your package(s).
#+NAME: development-shells
#+BEGIN_SRC nix
inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
rec {
devShells = {
default = import ./shell.nix { inherit pkgs; };
cc = import ./shells/cc.nix { inherit pkgs; };
go = import ./shells/go.nix { inherit pkgs; };
dart = import ./shells/dart.nix { inherit pkgs; };
grpc = import ./shells/grpc.nix { inherit pkgs; };
java = import ./shells/java.nix { inherit pkgs; };
node = import ./shells/node.nix { inherit pkgs; };
python = import ./shells/python.nix { inherit pkgs; };
rust = import ./shells/rust.nix { inherit pkgs; };
};
}
);
#+END_SRC
** Nix
#+ATTR_ORG: :width 300px
#+ATTR_HTML: :width 300px
#+ATTR_LATEX: :width 300px
[[./docs/images/nix.png]]
This shell adds a version of the ~nix~ command that is pre-configured to support Flakes. Flakes are the unit for packaging Nix code in a reproducible and discoverable way. They can have dependencies on other flakes, making it possible to have multi-repository Nix projects. A flake is a filesystem tree that contains a file named =flake.nix=. It specifies some metadata about the flake such as dependencies (inputs), as well as the values such as packages or modules (outputs).
Import this shell with ~nix develop $DOTFILES~
#+BEGIN_SRC nix :noweb yes :tangle shell.nix
# <>
{ pkgs ? import { } }:
with pkgs;
let
myNix = writeShellScriptBin "nix" ''
exec ${nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
'';
in mkShell {
buildInputs = [
git
myNix
];
shellHook = ''
export DOTFILES="$(pwd)"
'';
}
#+END_SRC
** Go
#+ATTR_ORG: :width 400px
#+ATTR_HTML: :width 400px
#+ATTR_LATEX: :width 400px
[[./docs/images/golang.png]]
#+BEGIN_SRC go
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#go~
#+BEGIN_SRC nix :noweb yes :tangle shells/go.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
go
gopls
protoc-gen-go
protoc-gen-go-grpc
];
shellHook = ''
export GO111MODULE=on
export GOPATH=$XDG_DATA_HOME/go
export PATH=$GOPATH/bin:$PATH
'';
}
#+END_SRC
** Dart
#+ATTR_ORG: :width 400px
#+ATTR_HTML: :width 400px
#+ATTR_LATEX: :width 400px
[[./docs/images/dart.png]]
[[https://dart.dev][Dart]] is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can be used to build server and desktop applications. It is an object-oriented, class-based, garbage-collected language with C-style syntax.
Import this shell with ~nix develop $DOTFILES#dart~
#+BEGIN_SRC nix :noweb yes :tangle shells/dart.nix
#<>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
dart
flutter
];
shellHook = ''
FLUTTER_SDK_DIR=${flutter}/bin/cache/dart-sdk/
'';
}
#+END_SRC
** Rust
#+ATTR_ORG: :width 400px
#+ATTR_HTML: :width 400px
#+ATTR_LATEX: :width 400px
[[./docs/images/rust.png]]
#+BEGIN_SRC rust
fn main() {
println!("Hello, world!");
}
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#rust~
#+BEGIN_SRC nix :noweb yes :tangle shells/rust.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
rustup
];
shellHook = ''
export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
export CARGO_HOME="$XDG_DATA_HOME/cargo"
export PATH="$CARGO_HOME/bin:$PATH"
'';
}
#+END_SRC
** Node
#+ATTR_ORG: :width 400px
#+ATTR_HTML: :width 400px
#+ATTR_LATEX: :width 400px
[[./docs/images/node.png]]
#+BEGIN_SRC js
var http = require('http');
http.createServer((req, res) => {
res.WriteHead(200, { 'Content-Type': 'text/html' });
res.end('Hello, world!');
});
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#node~
#+BEGIN_SRC nix :noweb yes :tangle shells/node.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
nodejs
yarn
];
shellHook = ''
export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
export NPM_CACHE_PREFIX="$XDG_CACHE_HOME/npm"
export PATH="$(yarn global bin):$PATH"
'';
}
#+END_SRC
** Java
#+ATTR_ORG: :width 300px
#+ATTR_HTML: :width 300px
#+ATTR_LATEX: :width 300px
[[./docs/images/java.png]]
#+BEGIN_SRC java
class Program {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#java~
#+BEGIN_SRC nix :noweb yes :tangle shells/java.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
jre8
jdk8
];
shellHook = ''
'';
}
#+END_SRC
** gRPC
#+ATTR_ORG: :width 300px
#+ATTR_HTML: :width 300px
#+ATTR_LATEX: :width 300px
[[./docs/images/grpc.png]]
#+BEGIN_SRC protobuf
service Greeter {
rpc SayHello (HelloRequest) returns (HelloResponse);
}
message HelloRequest { string name = 1; }
message HelloResponse { string response = 1; }
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#grpc~
#+BEGIN_SRC nix :noweb yes :tangle shells/grpc.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
buf
grpc
grpcui
grpcurl
grpc-tools
grpc-gateway
];
shellHook = ''
'';
}
#+END_SRC
** C/C++
#+ATTR_ORG: :width 300px
#+ATTR_HTML: :width 300px
#+ATTR_LATEX: :width 300px
[[./docs/images/cc.png]]
#+BEGIN_SRC c++
#include
int main() {
std::cout << "Hello, world!\n";
return 0;
}
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#cc~
#+BEGIN_SRC nix :noweb yes :tangle shells/cc.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
gdb
ccls
cmake
boost
gnumake
gcc-unwrapped
];
shellHook = ''
'';
}
#+END_SRC
** Python
#+ATTR_ORG: :width 400px
#+ATTR_HTML: :width 400px
#+ATTR_LATEX: :width 400px
[[./docs/images/python.png]]
#+BEGIN_SRC python
print("Hello, world!")
#+END_SRC
[[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.
Import this shell with ~nix develop $DOTFILES#python~
#+BEGIN_SRC nix :noweb yes :tangle shells/python.nix
# <>
{ pkgs ? import { } }:
with pkgs;
mkShell {
buildInputs = [
python310Packages.pip
python310Packages.pip-tools
# python310Packages.python-lsp-black #TODO: Marked broken.
# python310Packages.python-lsp-server #TODO: Marked broken.
# python310Packages.python-lsp-jsonrpc #TODO: Marked broken.
];
shellHook = ''
'';
}
#+END_SRC
* Host Configurations
[[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.
#+NAME: host-configurations
#+BEGIN_SRC nix :noweb yes
nixosConfigurations = {
<>
};
#+END_SRC
** Shared
NixOS makes it easier to share common configurations amongst all of the hosts, such as with pre-configured wireless networking:
#+NAME: host-config-wifi
#+BEGIN_SRC nix
networking.wireless.networks = {
MyWiFi_5C1870 = {
priority = 2;
pskRaw = "409b3c85fef1c5737f284d2f82f20dc6023e41804e862d4fa26265ef8193b326";
};
SM-G975W3034 = {
priority = 1;
pskRaw = "74835d96a98ca2c56ffe4eaf92223f8a555168b59ec2bb22b1e46b2a333adc80";
};
};
#+END_SRC
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:
#+NAME: host-config-home
#+BEGIN_SRC nix
networking.hosts = {
# "192.168.3.105" = [ "gamingpc" ];
# "192.168.3.163" = [ "acernitro" ];
# "192.168.3.182" = [ "raspberry" ];
# "192.168.3.183" = [ "homecloud" ];
};
#+END_SRC
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.
#+NAME: host-config-ssh
#+BEGIN_SRC nix
users.users.chris.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4wka/LfG3pto15DIm9LIRbb6rWr7/ipCRiCdAKSlY4 chris@chrishayward.xyz"
];
#+END_SRC
** Default
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.
#+NAME: host-default
#+BEGIN_SRC nix :noweb yes
nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./hosts/nixos
<>
<>
<>
<>
<>
<>
<>
<>
<>
];
};
#+END_SRC
Deploy this configuration with ~nixos-rebuild switch --flake /etc/dotfiles/#nixos~.
#+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/default.nix
# <>
{ ... }:
{
imports = [
./configuration.nix
./hardware.nix
];
}
#+END_SRC
*** Configuration
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.
#+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/configuration.nix
# <>
{ config, pkgs, inputs, ... }:
{
time.timeZone = "America/Toronto";
networking.hostName = "nixos";
networking.useDHCP = false;
networking.firewall.enable = false;
networking.interfaces.ens3.useDHCP = true;
<>
<>
programs.mtr.enable = true;
programs.fish.enable = true;
programs.gnupg.agent.enable = true;
users.users.chris = {
shell = pkgs.fish;
isNormalUser = true;
extraGroups = [ "wheel" ];
};
system.stateVersion = "23.05";
}
#+END_SRC
*** Hardware
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.
#+BEGIN_SRC nix :noweb yes :tangle hosts/nixos/hardware.nix
# <>
{ config, lib, pkgs, modulesPath, ... }:
{
imports =
[ (modulesPath + "/profiles/qemu-guest.nix")
];
boot.initrd.availableKernelModules = [ "ata_piix" "floppy" "sd_mod" "sr_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/sda";
fileSystems."/" =
{ device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
swapDevices =
[ { device = "/dev/disk/by-label/swap"; }
];
}
#+END_SRC
* Module Definitions
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.
** X11
#+NAME: module-x11
#+BEGIN_SRC nix
./modules/x11.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/x11.nix
# <>
{ config, pkgs, ... }:
{
services.xserver.enable = true;
services.xserver.layout = "us";
services.xserver.libinput.enable = true;
services.xserver.displayManager.startx.enable = true;
environment = {
variables = {
XDG_DESKTOP_DIR = "$HOME/";
XDG_CACHE_HOME = "$HOME/.cache";
XDG_CONFIG_HOME = "$HOME/.config";
XDG_DATA_HOME = "$HOME/.local/share";
XDG_BIN_HOME = "$HOME/.local/bin";
};
systemPackages = with pkgs; [
pkgs.sqlite
pkgs.pfetch
pkgs.cmatrix
pkgs.asciiquarium
];
extraInit = ''
export XAUTHORITY=/tmp/Xauthority
export xserverauthfile=/tmp/xserverauth
[ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY"
[ -e ~/.serverauth.* ] && mv -f ~/.serverauth.* "$xserverauthfile"
'';
};
services.picom.enable = true;
services.printing.enable = true;
fonts.fonts = with pkgs; [
iosevka-bin
fira-code-symbols
emacs-all-the-icons-fonts
];
}
#+END_SRC
** SSH
#+NAME: module-ssh
#+BEGIN_SRC nix
./modules/ssh.nix
#+END_SRC
[[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.
Apply some configuration to the default settings:
+ Disable logging in as =root=
+ Disable password authentication
#+BEGIN_SRC nix :noweb yes :tangle modules/ssh.nix
# <>
{ config, pkgs, ... }:
{
services.openssh = {
enable = true;
settings = {
PermitRootLogin = "no";
PasswordAuthentication = false;
};
};
}
#+END_SRC
** Hugo
#+NAME: module-hugo
#+BEGIN_SRC nix
./modules/hugo.nix
#+END_SRC
[[https://gohugo.io][Hugo]] is one of the most popular open-source static site generators. I use it to build https://chrishayward.xyz which is included in a later section of this configuration. This module adds a custom package to push the site to the server.
#+BEGIN_SRC nix :noweb yes :tangle modules/hugo.nix
# <>
{ config, pkgs, ... }:
let
mySiteDir = "/etc/dotfiles/docs/public/";
mySiteTgt = "ubuntu@chrishayward.xyz:/var/www/chrishayward";
mySiteBuild = pkgs.writeShellScriptBin "site-build" ''
pushd ${mySiteDir}../ > /dev/null &&
${pkgs.hugo}/bin/hugo -v ;
popd > /dev/null
'';
mySiteUpdate = pkgs.writeShellScriptBin "site-update" ''
${pkgs.rsync}/bin/rsync -aP ${mySiteDir} ${mySiteTgt}
'';
in {
environment.systemPackages = [
pkgs.hugo
mySiteBuild
mySiteUpdate
];
}
#+END_SRC
** Godot
#+NAME: module-godot
#+BEGIN_SRC nix
./modules/godot.nix
#+END_SRC
[[https://godotengine.org][Godot]] is a cross-platform, free and open-source game engine released under the MIT license. It provides a huge set of common tools, so you can focus on making your game without reinventing the wheel. It's completely free and open-source, no strings attached, no royalties. The game belongs to the creator down to each line of the engine code.
#+BEGIN_SRC nix :noweb yes :tangle modules/godot.nix
# <>
{ config, pkgs, ... }:
{
environment.systemPackages = [
pkgs.tiled
pkgs.godot
pkgs.godot-server
pkgs.godot-headless
pkgs.gdtoolkit
];
}
#+END_SRC
** Flakes
#+NAME: module-flakes
#+BEGIN_SRC nix
./modules/flakes.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/flakes.nix
# <>
{ config, pkgs, inputs, ... }:
{
nix = {
package = pkgs.nixUnstable;
extraOptions = ''
experimental-features = nix-command flakes
'';
};
nixpkgs = {
config = { allowUnfree = true; };
overlays = [ inputs.emacs-overlay.overlay ];
};
}
#+END_SRC
** Cachix
#+NAME: module-cachix
#+BEGIN_SRC nix
./modules/cachix.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/cachix.nix
# <>
{ config, ... }:
{
nix = {
settings = {
substituters = [
"https://nix-community.cachix.org"
];
trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
};
}
#+END_SRC
** Docker
#+NAME: module-docker
#+BEGIN_SRC nix
./modules/docker.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/docker.nix
# <>
{ config, pkgs, ... }:
{
# Enable the docker virutalization platform.
virtualisation.docker = {
enable = true;
enableOnBoot = true;
autoPrune.enable = true;
};
# Required for the `docker' command.
users.users.chris.extraGroups = [ "docker" ];
# Add docker extensions.
environment.systemPackages = [
pkgs.docker-compose
pkgs.docker-machine
];
}
#+END_SRC
** Firefox
#+NAME: module-firefox
#+BEGIN_SRC nix
./modules/firefox.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/firefox.nix
# <>
{ config, pkgs, ... }:
let
myFirefox = pkgs.writeShellScriptBin "firefox" ''
HOME=~/.local/share/mozilla ${pkgs.firefox-bin}/bin/firefox
'';
in {
# NOTE: Use the binary until module is developed.
environment.systemPackages = [
myFirefox
];
}
#+END_SRC
** Home Manager
[[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 ~, instead of ~nixos-rebuild~, and ~home-manager~ seperately.
#+NAME: module-home-manager
#+BEGIN_SRC nix :noweb yes
inputs.home-manager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.chris = {
home.stateVersion = "23.05";
imports = [
<>
<>
<>
<>
<>
];
};
}
#+END_SRC
Certain modules have to be included within home manager or they will not function correctly.
#+NAME: home-manager-warning
#+BEGIN_SRC text
This module MUST be included within home manager
#+END_SRC
*** Git
#+NAME: module-git
#+BEGIN_SRC nix
./modules/git.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/git.nix
# <>
# <>
{ pkgs, ... }:
let
# Fix any corruptions in the local copy.
myGitFix = pkgs.writeShellScriptBin "git-fix" ''
if [ -d .git/objects/ ]; then
find .git/objects/ -type f -empty | xargs rm -f
git fetch -p
git fsck --full
fi
exit 1
'';
in {
home.packages = [ myGitFix ];
programs.git = {
enable = true;
userName = "Christopher James Hayward";
userEmail = "chris@chrishayward.xyz";
signing = {
key = "37AB1CB72B741E478CA026D43025DCBD46F81C0F";
signByDefault = true;
};
};
}
#+END_SRC
*** Gpg
#+NAME: module-gpg
#+BEGIN_SRC nix
./modules/gpg.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/gpg.nix
# <>
# <>
{ pkgs, ... }:
{
services.gpg-agent = {
enable = true;
defaultCacheTtl = 1800;
enableSshSupport = true;
pinentryFlavor = "gtk2";
};
}
#+END_SRC
*** Vim
#+NAME: module-vim
#+BEGIN_SRC nix
./modules/vim.nix
#+END_SRC
[[https://neovim.io][Neovim]] is a project that seeks to aggressively refactor Vim in order to:
+ Simplify maintenance and encourage contributions
+ Split the work between multiple developers
+ Enable advanced UIs without core modification
+ Maximize extensibility
#+BEGIN_SRC nix :noweb yes :tangle modules/vim.nix
# <>
# <>
{ pkgs, ... }:
{
programs.neovim = {
enable = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
extraConfig = ''
set number relativenumber
set nobackup
'';
extraPackages = [
pkgs.nixfmt
];
plugins = with pkgs.vimPlugins; [
vim-nix
vim-airline
vim-polyglot
];
};
}
#+END_SRC
*** GTK
#+NAME: module-gtk
#+BEGIN_SRC nix
./modules/gtk.nix
#+END_SRC
[[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.
#+BEGIN_SRC nix :noweb yes :tangle modules/gtk.nix
# <>
# <>
{ pkgs, ... }:
{
home.packages = [
pkgs.nordic
pkgs.arc-icon-theme
pkgs.lxappearance
];
home.file.".gtkrc-2.0" = {
text = ''
gtk-theme-name="Nordic-darker"
gtk-icon-theme-name="Arc"
gtk-font-name="Iosevka 11"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=0
gtk-menu-images=0
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle="hintmedium"
'';
};
home.file.".config/gtk-2.0/gtkfilechooser.ini" = {
text = ''
[Filechooser Settings]
LocationMode=path-bar
ShowHidden=false
ShowSizeColumn=true
GeometryX=442
GeometryY=212
GeometryWidth=1036
GeometryHeight=609
SortColumn=name
SortOrder=ascending
StartupMode=recent
'';
};
home.file.".config/gtk-3.0/settings.ini" = {
text = ''
[Settings]
gtk-theme-name=Nordic-darker
gtk-icon-theme-name=Arc
gtk-font-name=Iosevka 11
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=0
gtk-menu-images=0
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle=hintmedium
'';
};
}
#+END_SRC
** Emacs Configuration
#+ATTR_ORG: :width 300px
#+ATTR_HTML: :width 300px
#+ATTR_LATEX: :width 300px
[[./docs/images/emacs.png]]
#+NAME: module-emacs
#+BEGIN_SRC nix
./modules/emacs.nix
#+END_SRC
[[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:
+ Highly customizable
+ Full Unicopde support
+ Content-aware editing modes
+ Complete built-in documentation
+ Wide range of functionality beyond text editing
#+BEGIN_SRC nix :noweb yes :tangle modules/emacs.nix
# <>
# <>
{ pkgs, ... }:
let
myEmacs = pkgs.emacsWithPackagesFromUsePackage {
config = ../README.org;
package = <>
alwaysEnsure = true;
alwaysTangle = true;
extraEmacsPackages = epkgs: [
# Required packages...
<>
<>
<>
<>
# Optional packages.
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
# User interface packages.
<>
<>
<>
<>
<>
];
};
in {
home.packages = [
<>
<>
<>
<>
<>
<>
<>
<>
<>
];
programs.emacs = {
enable = true;
package = myEmacs;
};
<>
<>
<>
}
#+END_SRC
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.
#+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.config/emacs/init.el
;; <>
;; Required inputs.
<>
<>
<>
<>
;; Optional inputs.
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
<>
;; User interface.
<>
<>
<>
<>
<>
#+END_SRC
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=.
#+BEGIN_SRC emacs-lisp :noweb yes :tangle ~/.config/emacs/early-init.el
;; <>
<>
<>
<>
<>
<>
#+END_SRC
*** Native Comp
#+NAME: emacs-native-comp-package
#+BEGIN_SRC nix
pkgs.emacs-unstable;
#+END_SRC
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.
#+NAME: emacs-native-comp-elisp
#+BEGIN_SRC emacs-lisp
;; Silence warnings from packages that don't support `native-comp'.
(setq comp-async-report-warnings-errors nil ;; Emacs 27.2 ...
native-comp-async-report-warnings-errors nil) ;; Emacs 28+ ...
#+END_SRC
*** Disable UI
[[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.
#+NAME: emacs-disable-ui-elisp
#+BEGIN_SRC emacs-lisp
;; Disable unwanted UI elements.
(tooltip-mode -1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Fix the scrolling behaviour.
(setq scroll-conservatively 101)
;; Fix mouse-wheel scrolling behaviour.
(setq mouse-wheel-follow-mouse t
mouse-wheel-progressive-speed t
mouse-wheel-scroll-amount '(3 ((shift) . 3)))
;; Start in fullscreen/maximized.
(add-to-list 'default-frame-alist '(fullscreen . maximized))
#+END_SRC
*** Backup Files
[[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.
#+NAME: emacs-backup-files-elisp
#+BEGIN_SRC emacs-lisp
;; Disable unwanted features.
(setq make-backup-files nil
create-lockfiles nil)
#+END_SRC
*** Shell Commands
Define some methods for interaction between [[https://gnu.org/software/emacs/][GNU/Emacs]], and the systems underyling shell:
1) Method to run an external process, launching any application on a new process without interference
2) Method to apply commands to the current call process, effecting the running instance
#+NAME: emacs-shell-commands-elisp
#+BEGIN_SRC emacs-lisp
;; Define a method to run an external process.
(defun dotfiles/run (cmd)
"Run an external process."
(interactive (list (read-shell-command "λ ")))
(start-process-shell-command cmd nil cmd))
;; Define a method to run a background process.
(defun dotfiles/run-in-background (cmd)
(let ((command-parts (split-string cmd "[ ]+")))
(apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
#+END_SRC
*** Improved prompts
By default Emacs will ask you to enter 'Yes' or 'No' instead of 'Y' or 'N'. This is a relatively conservative design decision, based on the fact that certain prompts may be important enough to warrant typing three characters.
#+NAME: emacs-improved-prompts
#+BEGIN_SRC emacs-lisp
;; Use 'y' and 'n' instead of 'yes' and 'no'.
(defalias 'yes-or-no-p 'y-or-n-p)
#+END_SRC
*** Nix Mode
#+NAME: emacs-nix-mode-extras
#+BEGIN_SRC nix
pkgs.nixfmt
pkgs.rnix-lsp
#+END_SRC
[[https://github.com/nixos/nix-mode][Nix Mode]] is an [[https://gnu.org/software/emacs/][Emacs]] major mode for editing [[https://nixos.org/manual/nix/stable/][Nix]] expressions. This provides basic handling of =.nix= files. Syntax highlighting and indentation support using =SMIE= are provided. [[https:github.com/nix-community/rnix-lsp][rnix-lsp]] is a work-in-progress language server for Nix with syntax checking and basic completion.
#+NAME: emacs-nix-mode-package
#+BEGIN_SRC nix
epkgs.nix-mode
#+END_SRC
*** Evil Mode
[[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.
#+NAME: emacs-evil-package
#+BEGIN_SRC nix
epkgs.evil
epkgs.evil-collection
epkgs.evil-surround
epkgs.evil-nerd-commenter
#+END_SRC
The next time [[https://gnu.org/software/emacs/][Emacs]] is started, it will come up in /normal state/, denoted by == 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]].
#+NAME: emacs-evil-elisp
#+BEGIN_SRC emacs-lisp
;; Enable the Extensible VI Layer for Emacs.
(setq evil-want-integration t ;; Required for `evil-collection.'
evil-want-keybinding nil ;; Same as above.
evil-want-C-i-jump nil) ;; Disable jumping in terminal.
(evil-mode +1)
;; Configure `evil-collection'.
(evil-collection-init)
;; Configure `evil-surround'.
(global-evil-surround-mode +1)
;; Configure `evil-nerd-commenter'.
(global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
;; Invoke `org-cycle' in normal mode inside of `org-mode' buffers.
(evil-define-key 'normal 'org-mode-map (kbd "") #'org-cycle)
#+END_SRC
*** EXWM
#+NAME: emacs-exwm-package
#+BEGIN_SRC nix
epkgs.exwm
#+END_SRC
[[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:
+ Fully keyboard-driven operations
+ Hybrid layout modes (tiling & stacking)
+ Dynamic workspace support
+ ICCM/EWMH compliance
#+NAME: emacs-exwm-extras
#+BEGIN_SRC nix
pkgs.arandr
pkgs.nitrogen
pkgs.autorandr
#+END_SRC
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]].
#+NAME: emacs-exwm-config
#+BEGIN_SRC nix
xsession = {
enable = true;
windowManager.command = ''
${pkgs.nitrogen}/bin/nitrogen --restore
${myEmacs}/bin/emacs --daemon -f exwm-enable
${myEmacs}/bin/emacsclient -c
'';
};
#+END_SRC
[[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=.
#+NAME: emacs-exwm-xinitrc
#+BEGIN_SRC nix
home.file.".xinitrc" = {
text = ''
exec ./.xsession
'';
};
#+END_SRC
#+NAME: emacs-exwm-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `exwm'.
(setq exwm-workspace-number 5
exwm-layout-show-all-buffers t
exwm-worspace-show-all-buffers t)
;; Configure input keys.
(setq exwm-input-prefix-keys
'(?\M-x
?\C-g
?\C-\ ))
(setq exwm-input-global-keys
`(([?\s-r] . exwm-reset)
,@(mapcar (lambda (i)
`(,(kbd (format "s-%d" i)) .
(lambda ()
(interactive)
(exwm-workspace-switch-create ,i))))
(number-sequence 0 9))))
;; Configure `exwm-randr'.
(require 'exwm-randr)
(exwm-randr-enable)
;; Configure custom hooks.
(setq display-time-day-and-date t)
(add-hook 'exwm-init-hook
(lambda ()
(display-battery-mode +1) ;; Display battery info (if available).
(display-time-mode +1))) ;; Display the time in the modeline.
;; Setup buffer display names.
(add-hook 'exwm-update-class-hook
(lambda ()
(exwm-workspace-rename-buffer exwm-class-name))) ;; Use the system class name.
;; Configure monitor hot-swapping.
(add-hook 'exwm-randr-screen-change-hook
(lambda ()
(dotfiles/run-in-background "autorandr --change --force"))) ;; Swap to the next screen config.
#+END_SRC
*** General
#+NAME: emacs-general-package
#+BEGIN_SRC nix
epkgs.general
#+END_SRC
[[https://github.com/noctuid/general.el][General.el]] provides a more conven1ent method for binding keys in [[https://gnu.org/software/emacs/][Emacs]], providing a unified interface for key definitions. Its primary purpose is to build on /existing/ functionality to make key definitions more clear and concise.
#+NAME: emacs-general-elisp
#+BEGIN_SRC emacs-lisp
;; Use as a leader key via `general.el'.
(general-create-definer dotfiles/leader
:keymaps '(normal insert visual emacs)
:prefix "SPC"
:global-prefix "C-SPC")
;; Setup general to work with `evil-mode'.
(setq general-evil-setup t)
;; Find files with ...
;; Switch buffers with ...
(dotfiles/leader
"." '(find-file :which-key "File")
"," '(switch-to-buffer :which-key "Buffer")
"k" '(kill-buffer :which-key "Kill")
"c" '(kill-buffer-and-window :which-key "Close"))
;; Add keybindings for executing shell commands.
(dotfiles/leader
"r" '(:ignore t :which-key "Run")
"rr" '(dotfiles/run :which-key "Run")
"ra" '(async-shell-command :which-key "Async"))
;; Add keybindings for quitting Emacs.
(dotfiles/leader
"q" '(:ignore t :which-key "Quit")
"qq" '(save-buffers-kill-emacs :which-key "Save")
"qw" '(kill-emacs :which-key "Now")
"qf" '(delete-frame :which-key "Frame"))
;; Add keybindings for toggles / tweaks.
(dotfiles/leader
"t" '(:ignore t :which-key "Toggle / Tweak"))
;; Add keybinding to navigate to scratch buffer.
(dotfiles/leader
"s" '((lambda () (interactive) (switch-to-buffer "*scratch*")) :which-key "Scratch"))
#+END_SRC
*** Which Key
[[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.
#+NAME: emacs-which-key-package
#+BEGIN_SRC nix
epkgs.which-key
#+END_SRC
#+NAME: emacs-which-key-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `which-key' to see keyboard bindings in the
;; mini-buffer and when using M-x.
(setq which-key-idle-delay 0.0)
(which-key-mode +1)
#+END_SRC
*** EWW
[[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.
+ Use ~eww~ as the default browser
+ Don't use any special fonts or colours
#+NAME: emacs-eww-elisp
#+BEGIN_SRC emacs-lisp
;; Set `eww' as the default browser.
(setq browse-url-browser-function 'eww-browse-url)
;; Configure the `shr' rendering engine.
(setq shr-use-fonts nil
shr-use-colors nil)
#+END_SRC
*** ERC
[[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.
#+NAME: emacs-erc-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `erc'.
(setq erc-autojoin-channels-alist '(("irc.libera.chat" "#emacs" "#nixos" "#org-mode" "#systemcrafters"))
erc-track-exclude-types '("JOIN" "NICK" "QUIT" "MODE")
erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
;; Configure `erc-fill-column'.
(add-hook 'window-configuration-change-hook
'(lambda ()
(setq erc-fill-column (- (window-width) 12))))
;; Connect to IRC via `erc'.
(defun dotfiles/erc-connect ()
"Connected to IRC via `erc'."
(interactive)
(erc-tls :server "irc.libera.chat"
:port 6697
:nick "megaphone"
:password (password-store-get "libera.chat/megaphone")
:full-name "Chris Hayward"))
;; Configure keybindings.
(dotfiles/leader
"i" '(dotfiles/erc-connect :which-key "Chat"))
#+END_SRC
*** Dired
#+NAME: emacs-dired-package
#+BEGIN_SRC nix
epkgs.dired-single
#+END_SRC
[[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.
#+NAME: emacs-dired-elisp
#+BEGIN_SRC emacs-lisp
;; Include `dired-x' for the `jump' method.
(require 'dired-x)
;; Configure `dired-single' to support `evil' keys.
(evil-collection-define-key 'normal 'dired-mode-map
"h" 'dired-single-up-directory
"l" 'dired-single-buffer)
;; Configure keybindings for `dired'.
(dotfiles/leader
"d" '(dired-jump :which-key "Dired"))
#+END_SRC
*** Icons
#+NAME: emacs-icons-package
#+BEGIN_SRC nix
epkgs.nerd-icons
epkgs.all-the-icons
epkgs.all-the-icons-dired
epkgs.all-the-icons-ivy-rich
#+END_SRC
[[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]].
#+NAME: emacs-icons-elisp
#+BEGIN_SRC emacs-lisp
;; Setup `all-the-icons-dired'.
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
;; Disable monochrome icons.
(setq all-the-icons-dired-monochrome nil)
;; Display default font ligatures.
(global-prettify-symbols-mode +1)
#+END_SRC
*** Emojis
#+NAME: emacs-emoji-package
#+BEGIN_SRC nix
epkgs.emojify
#+END_SRC
[[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.
#+NAME: emacs-emoji-elisp
#+BEGIN_SRC emacs-lisp
;; Setup `emojify'.
;; TODO: Causes an exception.
(add-hook 'after-init-hook 'global-emojify-mode)
#+END_SRC
*** EShell
#+NAME: emacs-eshell-package
#+BEGIN_SRC nix
epkgs.eshell-prompt-extras
#+END_SRC
[[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.
#+NAME: emacs-eshell-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `eshell'.
(setq eshell-highlight-prompt nil
eshell-prefer-lisp-functions nil)
;; Configure the lambda prompt.
(autoload 'epe-theme-lambda "eshell-prompt-extras")
(setq eshell-prompt-function 'epe-theme-lambda)
;; Configure keybindings for `eshell'.
(dotfiles/leader
"e" '(eshell :which-key "EShell"))
#+END_SRC
*** VTerm
[[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.
#+NAME: emacs-vterm-package
#+BEGIN_SRC nix
epkgs.vterm
epkgs.multi-vterm
#+END_SRC
#+NAME: emacs-vterm-elisp
#+BEGIN_SRC emacs-lisp
;; Set the dedicated terminal height.
(setq multi-vterm-dedicated-window-height-percent 30)
;; Add keybindings for interacting with the shell(s).
(dotfiles/leader
"v" '(:ignore t :which-key "VTerm")
"vj" '(multi-vterm :which-key "New")
"vl" '(multi-vterm-next :which-key "Next")
"vh" '(multi-vterm-prev :which-key "Previous")
"vk" '(multi-vterm-project :which-key "Project")
"vv" '(multi-vterm-dedicated-toggle :which-key "Dedicated"))
#+END_SRC
*** Magit
[[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.
#+NAME: emacs-magit-package
#+BEGIN_SRC nix
epkgs.magit
#+END_SRC
#+NAME: emacs-magit-elisp
#+BEGIN_SRC emacs-lisp
;; Add keybindings for working with `magit'.
(dotfiles/leader
"g" '(:ignore t :which-key "Git")
"gg" '(magit-status :which-key "Status")
"gc" '(magit-clone :which-key "Clone")
"gf" '(magit-fetch :which-key "Fetch")
"gp" '(magit-pull :which-key "Pull"))
#+END_SRC
*** Hydra
#+NAME: emacs-hydra-package
#+BEGIN_SRC nix
epkgs.hydra
#+END_SRC
[[https://github.com/abo-abo/hydra][Hydra]] allows you to create keymaps for related commands, with the ability to easily repeat commands using a single keystroke.
*** Fonts
[[https://typeof.net/Iosevka][Iosevka]] is an open-source, sans-serif + slab-serif, monospace + quasi-proportional typeface family, designed for writing code, using in terminals, and preparing technical documents. Configure it as the default font face inside of [[https://gnu.org/software/emacs/][Emacs]] and define a [[https://github.com/abo-abo/hydra][Hydra]] command for quickly scaling text.
#+NAME: emacs-fonts-elisp
#+BEGIN_SRC emacs-lisp
;; Configure the font when running as `emacs-server'.
(custom-set-faces
'(default ((t (:inherit nil :height 120 :family "Iosevka")))))
;; Define a `hydra' function for scaling the text interactively.
(defhydra hydra-text-scale (:timeout 4)
"Scale the text in the current buffer."
("k" text-scale-decrease "Decrease")
("j" text-scale-increase "Increase")
("f" nil "Finished" :exit t))
;; Create keybinding for calling the function.
(dotfiles/leader
"tf" '(hydra-text-scale/body :which-key "Font"))
#+END_SRC
*** Ligatures
#+NAME: emacs-ligatures-package
#+BEGIN_SRC nix
epkgs.ligature
#+END_SRC
Ligature.el maps ordinary graphmemes (characters) to fancy ligatures, if both the version of [[https://gnu.org/software/emacs/][Emacs]] and the font supports it. It can control where [[https://gnu.org/software/emacs/][Emacs]] must display ligatures, useful if only a subset of the ligatures in certain major modes is required.
#+NAME: emacs-ligatures-elisp
#+BEGIN_SRC emacs-lisp
(ligature-set-ligatures 't '("www"))
;; Enable traditional ligature support in eww-mode, if the
;; `variable-pitch' face supports it
(ligature-set-ligatures 'eww-mode '("ff" "fi" "ffi"))
;; Enable all Cascadia Code ligatures in programming modes
(ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" ">" "###" "#_(" "..<"
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
"<$" "<=" "<>" "<-" "<<" "<+" "" "#{" "#[" "#:" "#=" "#!"
"##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
"?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
"\\\\" "://"))
;; Enables ligature checks globally in all buffers. You can also do it
;; per mode with `ligature-mode'.
(global-ligature-mode t)
#+END_SRC
*** Frames
Sometimes it's useful to resize the current frame without using the mouse (always). The default behaviour when calling ~shrink-window~ and ~enlarge-window~ only changes the size by a small margin. I solved this problem with the same method used for scaling text:
#+NAME: emacs-frames-elisp
#+BEGIN_SRC emacs-lisp
;; Define a `hydra' function for resizing the current frame.
(defhydra hydra-resize-frame (:timeout 4)
"Scale the current frame."
("h" shrink-window-horizontally "Left")
("j" enlarge-window "Down")
("k" shrink-window "Up")
("l" enlarge-window-horizontally "Right")
("f" nil "Finished" :exit t))
;; Add keybindings for working with frames to replace
;; the C-x method of bindings, which is awful.
(dotfiles/leader
"w" '(:ignore t :which-key "Windows")
"ww" '(window-swap-states :which-key "Swap")
"wc" '(delete-window :which-key "Close")
"wh" '(windmove-left :which-key "Left")
"wj" '(windmove-down :which-key "Down")
"wk" '(windmove-up :which-key "Up")
"wl" '(windmove-right :which-key "Right")
"ws" '(:ignore t :which-key "Split")
"wsj" '(split-window-below :which-key "Below")
"wsl" '(split-window-right :which-key "Right")
"wr" '(hydra-resize-frame/body :which-key "Resize"))
#+END_SRC
*** Elfeed
#+NAME: emacs-elfeed-package
#+BEGIN_SRC nix
epkgs.elfeed
#+END_SRC
[[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.
#+NAME: emacs-elfeed-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `elfeed'.
(setq elfeed-db-directory (expand-file-name "~/.cache/elfeed"))
;; Add custom feeds for `elfeed' to fetch.
(setq elfeed-feeds (quote
(("https://hexdsl.co.uk/rss.xml")
("https://lukesmith.xyz/rss.xml")
("https://friendo.monster/rss.xml")
("https://chrishayward.xyz/index.xml")
("https://protesilaos.com/master.xml"))))
;; Add custom keybindings for `elfeed'.
(dotfiles/leader
"f" '(:ignore t :which-key "Elfeed")
"fl" '(elfeed :which-key "Open")
"fu" '(elfeed-update :which-key "Update"))
#+END_SRC
*** Org Mode
#+NAME: emacs-org-package
#+BEGIN_SRC nix
epkgs.org
#+END_SRC
[[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.
#+NAME: emacs-org-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `org-mode' source blocks.
(setq org-src-fontify-natively t ;; Make source blocks prettier.
org-src-tab-acts-natively t ;; Use TAB indents within source blocks.
org-hide-emphasis-markers t ;; Don't show emphasis markup.
org-src-preserve-indentation t ;; Stop `org-mode' from formatting blocks.
org-confirm-babel-evaluate nil) ;; Don't ask for confirmation to evaluate blocks.
;; Add an `org-mode-hook'.
(add-hook 'org-mode-hook
(lambda ()
(org-indent-mode)
(visual-line-mode)))
;; Remove the `Validate XHTML 1.0' message from HTML export.
(setq org-export-html-validation-link nil
org-html-validation-link nil)
;; Configure the keywords in the TODO -> DONE sequence.
(setq org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
;; Track ids globally.
(setq org-id-track-globally t)
;; Configure `org-babel' languages.
(org-babel-do-load-languages
'org-babel-load-languages
'((C . t)))
;; Log / Clock into property drawers.
(setq org-log-into-drawer t
org-clock-into-drawer t)
;; Encrypt files with the public key.
(setq epa-file-select-keys 2
epa-file-encrypt-to "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
epa-cache-passphrase-for-symmetric-encryption t)
;; TODO: Configure default structure templates.
;; (require 'org-tempo)
;; Don't use native image sizes in previews.
(setq org-image-actual-width nil)
;; Apply custom keybindings.
(dotfiles/leader
"o" '(:ignore t :which-key "Org")
"oe" '(org-export-dispatch :which-key "Export")
"ot" '(org-babel-tangle :which-key "Tangle")
"oi" '(org-toggle-inline-images :which-key "Images")
"of" '(:ignore t :which-key "Footnotes")
"ofn" '(org-footnote-normalize :which-key "Normalize"))
#+END_SRC
*** Org Roam
#+NAME: emacs-org-roam-package
#+BEGIN_SRC nix
epkgs.org-roam
#+END_SRC
[[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.
#+NAME: emacs-org-roam-elisp
#+BEGIN_SRC emacs-lisp
;; Setup `org-roam'.
(require 'org-roam)
;; Silence the migration warnings.
(setq org-roam-v2-ack t)
;; Enable `visual-line-mode' in `org-roam' buffer.
(add-hook 'org-roam-mode-hook
(lambda ()
(visual-line-mode +1)))
;; Enable completion everywhere.
(setq org-roam-completion-everywhere t)
;; Set the roam directories.
(setq org-roam-directory (expand-file-name "/etc/dotfiles")
org-roam-dailies-directory (concat org-roam-directory "/docs/daily"))
;; Clear the deafult capture templates.
(setq org-roam-capture-templates '()
org-roam-dailies-capture-templates '())
;; Override the default slug method.
(cl-defmethod org-roam-node-slug ((node org-roam-node))
(let ((title (org-roam-node-title node))
(slug-trim-chars '(768 ; U+0300 COMBINING GRAVE ACCENT
769 ; U+0301 COMBINING ACUTE ACCENT
770 ; U+0302 COMBINING CIRCUMFLEX ACCENT
771 ; U+0303 COMBINING TILDE
772 ; U+0304 COMBINING MACRON
774 ; U+0306 COMBINING BREVE
775 ; U+0307 COMBINING DOT ABOVE
776 ; U+0308 COMBINING DIAERESIS
777 ; U+0309 COMBINING HOOK ABOVE
778 ; U+030A COMBINING RING ABOVE
780 ; U+030C COMBINING CARON
795 ; U+031B COMBINING HORN
803 ; U+0323 COMBINING DOT BELOW
804 ; U+0324 COMBINING DIAERESIS BELOW
805 ; U+0325 COMBINING RING BELOW
807 ; U+0327 COMBINING CEDILLA
813 ; U+032D COMBINING CIRCUMFLEX ACCENT BELOW
814 ; U+032E COMBINING BREVE BELOW
816 ; U+0330 COMBINING TILDE BELOW
817 ; U+0331 COMBINING MACRON BELOW
)))
(cl-flet* ((nonspacing-mark-p (char)
(memq char slug-trim-chars))
(strip-nonspacing-marks (s)
(ucs-normalize-NFC-string
(apply #'string (seq-remove #'nonspacing-mark-p
(ucs-normalize-NFD-string s)))))
(cl-replace (title pair)
(replace-regexp-in-string (car pair) (cdr pair) title)))
(let* ((pairs `(("[^[:alnum:][:digit:]]" . "-")
("--*" . "-")
("^-" . "")
("-$" . "")))
(slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
(downcase slug)))))
;; Configure capture templates.
;; Standard document.
(add-to-list 'org-roam-capture-templates
'("d" "Default" plain "%?"
:target (file+head "docs/%<%Y%m%d%H%M%S>-${slug}.org.gpg"
"
,#+TITLE: ${title}
,#+AUTHOR: Christopher James Hayward
,#+EMAIL: chris@chrishayward.xyz
"
)
:unnarrowed t))
;; Daily notes.
(add-to-list 'org-roam-dailies-capture-templates
'("d" "Default" entry "* %?"
:target (file+head "%<%Y-%m-%d>.org.gpg"
"
,#+TITLE: %<%Y-%m-%d>
,#+AUTHOR: Christopher James Hayward
,#+EMAIL: chris@chrishayward.xyz
")))
;; Apply custom keybindings.
(dotfiles/leader
"or" '(:ignore t :which-key "Roam")
"ori" '(org-roam-node-insert :which-key "Insert")
"orf" '(org-roam-node-find :which-key "Find")
"orc" '(org-roam-capture :which-key "Capture")
"org" '(org-id-get-create :which-key "Get/Create")
"orb" '(org-roam-buffer-toggle :which-key "Buffer"))
;; Apply custom keybindings for dailies.
(dotfiles/leader
"ord" '(:ignore t :which-key "Dailies")
"ordd" '(org-roam-dailies-goto-date :which-key "Date")
"ordt" '(org-roam-dailies-goto-today :which-key "Today")
"ordm" '(org-roam-dailies-goto-tomorrow :which-key "Tomorrow")
"ordy" '(org-roam-dailies-goto-yesterday :which-key "Yesterday"))
;; Run the setup command.
(org-roam-setup)
#+END_SRC
*** Org Roam UI
#+NAME: emacs-org-roam-ui-package
#+BEGIN_SRC nix
epkgs.org-roam-ui
epkgs.websocket
epkgs.simple-httpd
#+END_SRC
[[https://github.com/org-roam/org-roam-ui][Org Roam UI]] is a graphical frontend for exploring your [[https://github.com/org-roam/org-roam][Org Roam]] [[https://zettelkasten.de][Zettelkasten]]. It's meant as a successor to [[https://github.com/org-roam/org-roam-server][Org Roam Server]] that extends functionality of Org Roam with a web application that runs side-by-side with [[https://gnu.org/software/emacs/][Emacs]].
#+NAME: emacs-org-roam-ui-elisp
#+BEGIN_SRC emacs-lisp
;; HACK: Set up `org-roam-ui'.
;; (add-to-list 'load-path "~/.local/source/org-roam-ui")
(load-library "org-roam-ui")
;; Configure `org-roam-ui'.
(setq org-roam-ui-follow t
org-roam-ui-sync-theme t
org-roam-ui-open-on-start t
org-roam-ui-update-on-save t
org-roam-ui-browser-function #'browse-url-firefox)
;; Configure keybindings.
(dotfiles/leader
"oru" '(:ignore t :which-key "UI")
"oruu" '(org-roam-ui-mode :which-key "Toggle UI")
"orut" '(org-roam-ui-sync-theme :which-key "Sync Theme"))
#+END_SRC
*** Org Drill
#+NAME: emacs-org-drill-package
#+BEGIN_SRC nix
epkgs.org-drill
#+END_SRC
[[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.
#+NAME: emacs-org-drill-elisp
#+BEGIN_SRC emacs-lisp
;; Exclude :drill: items from `org-roam'.
(setq org-roam-db-node-include-function
(defun dotfiles/org-roam-include ()
(not (member "drill" (org-get-tags)))))
;; Configure keybindings for `org-drill'.
(dotfiles/leader
"od" '(:ignore t :which-key "Drill")
"odd" '(org-drill :which-key "Drill")
"odc" '(org-drill-cram :which-key "Cram")
"odr" '(org-drill-resume :which-key "Resume"))
#+END_SRC
*** Org Agenda
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.
#+NAME: emacs-org-agenda-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `org-agenda' to use the project files.
(setq org-agenda-files '("/etc/dotfiles/"
"/etc/dotfiles/docs/"
"/etc/dotfiles/docs/daily/"))
;; Include files encrypted with `gpg'.
(require 'org)
(unless (string-match-p "\\.gpg" org-agenda-file-regexp)
(setq org-agenda-file-regexp
(replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
org-agenda-file-regexp)))
;; Open an agenda buffer with SPC o a.
(dotfiles/leader
"oa" '(org-agenda :which-key "Agenda"))
#+END_SRC
*** Org Pomodoro
#+NAME: emacs-pomodoro-package
#+BEGIN_SRC nix
epkgs.org-pomodoro
#+END_SRC
[[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.
#+NAME: emacs-pomodoro-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `org-pomodor' with the overtime workflow.
(setq org-pomodoro-manual-break t
org-pomodoro-keep-killed-time t)
;; Configure keybindings.
(dotfiles/leader
"op" '(org-pomodoro :which-key "Pomodoro"))
#+END_SRC
*** Writegood Mode
#+NAME: emacs-writegood-package
#+BEGIN_SRC nix
epkgs.writegood-mode
#+END_SRC
[[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:
+ Weasel Words
+ Passive Voice
+ Duplicate Words
#+NAME: emacs-writegood-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `writegood-mode'.
(dotfiles/leader
"tg" '(writegood-mode :which-key "Grammar"))
#+END_SRC
*** Aspell
#+NAME: emacs-aspell-extras
#+BEGIN_SRC nix
pkgs.aspell
pkgs.aspellDicts.en
pkgs.aspellDicts.en-science
pkgs.aspellDicts.en-computers
#+END_SRC
[[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.
#+NAME: emacs-aspell-elisp
#+BEGIN_SRC emacs-lisp
;; Use `aspell' as a drop-in replacement for `ispell'.
(setq ispell-program-name "aspell"
ispell-eextra-args '("--sug-mode=fast"))
;; Configure the built-in `flyspell-mode'.
(dotfiles/leader
"ts" '(flyspell-mode :which-key "Spelling"))
#+END_SRC
*** TexLive
[[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/:
| Name | Derivation | Comment |
|---------+---------------------------------+------------------------------------------------------------|
| Full | texlive.combined.scheme-full | Contains every TeX Live package |
| Medium | texlive.combined.scheme-medium | Contains everything in small + more packages and languages |
| Small | texlive.combined.scheme-small | Contains everything in basic + xetex + metapost |
| Basic | texlive.combined.scheme-basic | Contains everything in the plain scheme but includes latex |
| Minimal | texlive.combined.scheme-minimal | Contains plain only |
#+NAME: emacs-texlive-extras
#+BEGIN_SRC nix
# pkgs.texlive.combined.scheme-full
#+END_SRC
*** Http
#+NAME: emacs-http-package
#+BEGIN_SRC nix
epkgs.ob-http
#+END_SRC
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.
#+NAME: emacs-http-elisp
#+BEGIN_SRC emacs-lisp
;; Required to setup `ob-http'.
(org-babel-do-load-languages
'org-babel-load-languages
'((http . t)))
#+END_SRC
*** Hugo
#+NAME: emacs-hugo-package
#+BEGIN_SRC nix
epkgs.ox-hugo
#+END_SRC
[[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/.
#+NAME: emacs-hugo-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `ox-hugo' as an `org-mode-export' backend.
(require 'ox-hugo)
;; Set up the base directory.
(setq org-hugo-base-dir (expand-file-name "/etc/dotfiles/docs"))
;; Capture templates.
;; Shared content
;; (add-to-list 'org-roam-capture-templates
;; '("p" "Post" plain "%?"
;; :target (file+head "docs/posts/${slug}.org.gpg"
;; "
;; ,#+TITLE: ${title}
;; ,#+AUTHOR: Christopher James Hayward
;; ,#+DATE: %<%Y-%m-%d>
;; ,#+EXPORT_FILE_NAME: ${slug}
;; ,#+OPTIONS: num:nil todo:nil tasks:nil
;; ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
;; ,#+HUGO_BASE_DIR: ../
;; ,#+HUGO_AUTO_SET_LASTMOD: t
;; ,#+HUGO_SECTION: posts
;; ,#+HUGO_DRAFT: true
;; "
;; )
;; :unnarrowed t))
#+END_SRC
*** Passwords
#+NAME: emacs-pass-extras
#+BEGIN_SRC nix
pkgs.pass
(pkgs.writeShellScriptBin "pass-init" ''
${pkgs.git}/bin/git clone git@git.chrishayward.xyz:chris/passwords /home/chris/.password-store
${pkgs.pass}/bin/pass init
'')
#+END_SRC
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.
#+NAME: emacs-pass-package
#+BEGIN_SRC nix
epkgs.password-store
#+END_SRC
Configure keybindings for passwords behind =SPC p=:
#+NAME: emacs-pass-elisp
#+BEGIN_SRC emacs-lisp
;; Set the path to the password store.
(setq password-store-dir (expand-file-name "~/.password-store"))
;; Apply custom keybindings.
(dotfiles/leader
"p" '(:ignore t :which-key "Passwords")
"pp" '(password-store-copy :which-key "Copy")
"pe" '(password-store-edit :which-key "Edit")
"pi" '(password-store-insert :which-key "Insert")
"pr" '(password-store-rename :which-key "Rename")
"pg" '(password-store-generate :which-key "Generate"))
#+END_SRC
*** Docker
#+NAME: emacs-docker-package
#+BEGIN_SRC nix
epkgs.docker
epkgs.dockerfile-mode
#+END_SRC
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.
#+NAME: emacs-docker-elisp
#+BEGIN_SRC emacs-lisp
;; Apply custom keybindings.
(dotfiles/leader
"n" '(:ignore t :which-key "Containers")
"nd" '(docker :which-key "Docker"))
#+END_SRC
*** MU4E
#+NAME: emacs-mu4e-extras
#+BEGIN_SRC nix
pkgs.mu
pkgs.isync
(pkgs.writeShellScriptBin "mail-init" ''
${pkgs.mu}/bin/mu init --maildir="/home/chris/.cache/mail" --my-address="chris@chrishayward.xyz"
${pkgs.mu}/bin/mu index
'')
(pkgs.writeShellScriptBin "mail-sync" ''
${pkgs.isync}/bin/mbsync -a
'')
#+END_SRC
[[https://github.com/djcb/mu][MU]] is a tool for dealing with email messages stored in the Maildir-format. Its purpose is to help quickly find the messages needed, and allows users to view messages, extract attachments, create new maildirs, and much more. It's written in C and C++, and includes extensions for Emacs (MU4E) and guile scheme.
#+NAME: emacs-mu4e-package
#+BEGIN_SRC nix
epkgs.mu4e-alert
#+END_SRC
[[https://emacswiki.org/emacs/mu4e][MU4E]] is an email client for Emacs. It's based on the mu email indexer / searcher.
+ Fully search based: no folders, only queries
+ Fully documented, with example configurations
+ User-interface optimized for speed, with quick keystrokes for common actions
+ Asynchronous; heavy actions do not block Emacs
+ Support for non-English languages
+ Support for signing and encryption
+ Address auto-completion based on existing messages
+ Extensibile with existing code and snippets
#+NAME: emacs-mu4e-config
#+BEGIN_SRC nix
# Deploy the authinfo file.
home.file.".authinfo.gpg".source = ../config/authinfo.gpg;
# Deploy the isync configuration file.
home.file.".mbsyncrc" = {
text = ''
IMAPStore xyz-remote
Host mail.chrishayward.xyz
User chris@chrishayward.xyz
PassCmd "pass chrishayward.xyz/chris"
SSLType IMAPS
MaildirStore xyz-local
Path ~/.cache/mail/
Inbox ~/.cache/mail/inbox
SubFolders Verbatim
Channel xyz
Far :xyz-remote:
Near :xyz-local:
Patterns * !Archives
Create Both
Expunge Both
SyncState *
'';
};
#+END_SRC
Before using the software inside of Emacs, the maildir must be created in the local filesystem, and indexed. This is done with a single custom shell script binary ~mail-init~ which wraps the underlying mu commands. The emacs extension is shipped with the mu mail indexer. To utilize it, it must be added to the load path inside of Emacs.
#+NAME: emacs-mu4e-elisp
#+BEGIN_SRC emacs-lisp
;; Add the `mu4e' shipped with `mu' to the load path.
(add-to-list 'load-path "/etc/profiles/per-user/chris/share/emacs/site-lisp/mu4e/")
(require 'mu4e)
;; Confiugure `mu4e'.
(setq mu4e-maildir "~/.cache/mail"
mu4e-update-interval (* 5 60)
mu4e-get-mail-command "mail-sync"
mu4e-compose-format-flowed t
mu4e-change-filenames-when-moving t
mu4e-compose-signature (concat "Chris Hayward\n"
"chris@chrishayward.xyz"))
;; Sign all outbound email with GPG.
(add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
(setq message-send-mail-function 'smtpmail-send-it
mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
;; Setup `mu4e' accounts.
(setq mu4e-contexts
(list
;; Main
;; chris@chrishayward.xyz
(make-mu4e-context
:name "Main"
:match-func
(lambda (msg)
(when msg
(string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
:vars
'((user-full-name . "Christopher James Hayward")
(user-mail-address . "chris@chrishayward.xyz")
(smtpmail-smtp-server . "mail.chrishayward.xyz")
(smtpmail-smtp-service . 587)
(smtpmail-stream-type . starttls)))))
;; Setup `mu4e-alert'.
(setq mu4e-alert-set-default-style 'libnotify)
(mu4e-alert-enable-notifications)
(mu4e-alert-enable-mode-line-display)
;; Open the `mu4e' dashboard.
(dotfiles/leader
"m" '(mu4e :which-key "Mail"))
#+END_SRC
*** Projectile
#+NAME: emacs-projectile-package
#+BEGIN_SRC nix
epkgs.projectile
#+END_SRC
[[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.
#+NAME: emacs-projectile-elisp
#+BEGIN_SRC emacs-lisp
;; Configure the `projectile-project-search-path'.
(setq projectile-project-search-path '("~/.local/source"))
(projectile-mode +1)
#+END_SRC
*** Electric Pair
#+NAME: emacs-electric-pair-elisp
#+BEGIN_SRC emacs-lisp
;; Enable smart parenthesis.
(electric-pair-mode 1)
(setq electric-pair-preserve-balance nil)
#+END_SRC
*** LSP Mode
#+NAME: emacs-lsp-package
#+BEGIN_SRC nix
epkgs.lsp-mode
epkgs.lsp-ui
#+END_SRC
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:
+ Auto Complete
+ Go To Defintion
+ Find All References
#+NAME: emacs-lsp-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `lsp-mode'.
(setq lsp-idle-delay 0.5
lsp-prefer-flymake t)
;; Configure `lsp-ui'.
(setq lsp-ui-doc-position 'at-point
lsp-ui-doc-delay 0.5)
;; Add custom keybindings for `lsp'.
(dotfiles/leader
"l" '(:ignore t :which-key "LSP")
"ll" '(lsp :which-key "LSP")
"lr" '(lsp-rename :which-key "Rename")
"lf" '(lsp-format-buffer :which-key "Format")
"lo" '(lsp-organize-imports :which-key "Organize"))
#+END_SRC
*** CCLS
#+NAME: emacs-ccls-package
#+BEGIN_SRC nix
epkgs.ccls
#+END_SRC
[[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.
#+NAME: emacs-ccls-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `ccls' to work with `lsp-mode'.
(defun dotfiles/ccls-hook ()
(require 'ccls)
(lsp))
;; Configure `ccls' mode hooks.
(add-hook 'c-mode-hook 'dotfiles/ccls-hook)
(add-hook 'c++-mode-hook 'dotfiles/ccls-hook)
(add-hook 'objc-mode-hook 'dotfiles/ccls-hook)
(add-hook 'cuda-mode-hook 'dotfiles/ccls-hook)
#+END_SRC
*** Company Mode
#+NAME: emacs-company-package
#+BEGIN_SRC nix
epkgs.company
#+END_SRC
[[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.
#+NAME: emacs-company-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `company-mode'.
(setq company-backend 'company-capf
lsp-completion-provider :capf)
;; Enable it globally.
(global-company-mode +1)
#+END_SRC
*** GDScript Mode
#+NAME: emacs-gdscript-package
#+BEGIN_SRC nix
epkgs.gdscript-mode
#+END_SRC
https://github.com/godotengine/emacs-gdscript-mode is an Emacs package to get GDScript support and syntax highlighting. Some of its features include:
+ Syntax highlighting
+ Code folding
+ Debugger support
+ Support for scenes and script files
+ Comment wrapping
+ Indentation
+ Automatic parsing
+ Code formatting
#+NAME: emacs-gdscript-elisp
#+BEGIN_SRC emacs-lisp
(require 'gdscript-mode)
;; Silence lsp warnings for gdscript.
(defun lsp--gdscript-ignore-errors (original-function &rest args)
"Ignore the error message resulting from Godot not replying to the `JSONRPC' request."
(if (string-equal major-mode "gdscript-mode")
(let ((json-data (nth 0 args)))
(if (and (string= (gethash "jsonrpc" json-data "") "2.0")
(not (gethash "id" json-data nil))
(not (gethash "method" json-data nil)))
nil; (message "Method not found")
(apply original-function args)))
(apply original-function args)))
;; Run the function around `lsp--get-message-type' to suppress warnings.
(advice-add #'lsp--get-message-type :around #'lsp--gdscript-ignore-errors)
;; Add custom keybinds.
(dotfiles/leader
"lg" '(gdscript-hydra-show :which-key "GDScript"))
#+END_SRC
*** Go Mode
#+NAME: emacs-golang-package
#+BEGIN_SRC nix
epkgs.go-mode
#+END_SRC
[[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.
#+NAME: emacs-golang-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `go-mode' to work with `lsp-mode'.
(defun dotfiles/go-hook ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
;; Configure a custom `before-save-hook'.
(add-hook 'go-mode-hook #'dotfiles/go-hook)
#+END_SRC
*** Dart Mode
#+NAME: emacs-dart-package
#+BEGIN_SRC nix
epkgs.dart-mode
epkgs.lsp-dart
epkgs.hover
#+END_SRC
[[https://github.com/emacs-lsp/lsp-dart][Emacs Dart IDE]] using LSP Mode to connect to Dart Analysis Server.
#+NAME: emacs-dart-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `dart-mode' to work with `lsp-mode'.
(add-hook 'dart-mode-hook 'lsp)
;; Help Emacs find Flutter packages.
(setq lsp-dart-sdk-dir (getenv "$FLUTTER_SDK_DIR"))
#+END_SRC
*** Rustic
#+NAME: emacs-rustic-package
#+BEGIN_SRC nix
epkgs.rustic
#+END_SRC
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!
#+NAME: emacs-rustic-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `rustic' with `lsp-mode'.
(setq rustic-format-on-save t
rustic-lsp-server 'rls)
#+END_SRC
*** Python Mode
#+NAME: emacs-python-package
#+BEGIN_SRC nix
epkgs.pretty-mode
#+END_SRC
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.
#+NAME: emacs-python-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `pretty-mode' to work with `python-mode'.
(add-hook 'python-mode-hook
(lambda ()
(turn-on-pretty-mode)))
#+END_SRC
*** Protobuf Mode
#+NAME: emacs-protobuf-package
#+BEGIN_SRC nix
epkgs.protobuf-mode
#+END_SRC
Protobuf mode is an Emacs major mode for editing protocol buffers.
*** Typescript Mode
#+NAME: emacs-typescript-package
#+BEGIN_SRC nix
epkgs.typescript-mode
#+END_SRC
Typescript.el is a self-contained, lightweight and minimalist major-mode focused on providing basic font-lock/syntax-highlighting and indentation for Typescript syntax, without any external dependencies.
#+NAME: emacs-typescript-elisp
#+BEGIN_SRC emacs-lisp
;; Use spaces instead of tabs.
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
;; Create a custom hook for typescript mode.
(defun dotfiles/typescript-hook ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
;; Apply the hook.
(add-hook 'typescript-mode-hook #'dotfilers/typescript-hook)
#+END_SRC
*** YAML Mode
#+NAME: emacs-yaml-mode-package
#+BEGIN_SRC nix
epkgs.yaml-mode
#+END_SRC
YAML Mode helps you edit =YAML= ~.yml~ and ~.yaml~ files. It features font locking for data forms and comments, and some electric keys to help with block literals.
*** PlantUML
#+NAME: emacs-plantuml-extras
#+BEGIN_SRC nix
pkgs.plantuml
#+END_SRC
[[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.
#+NAME: emacs-plantuml-package
#+BEGIN_SRC nix
epkgs.plantuml-mode
#+END_SRC
[[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]].
#+NAME: emacs-plantuml-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `plantuml-mode'.
(add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
(org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
(setq plantuml-default-exec-mode 'executable
org-plantuml-exec-mode 'plantuml)
#+END_SRC
*** Neotree
#+NAME: emacs-neotree-package
#+BEGIN_SRC nix
epkgs.neotree
#+END_SRC
[[https://github.com/jaypei/emacs-neotree][Emacs Neotree]] is an Emacs tree plugin similar to NerdTree for Vim.
#+NAME: emacs-neotree-elisp
#+BEGIN_SRC emacs-lisp
;; Enable all-the-icons font support.
(setq neo-theme (if (display-graphic-p) 'icons 'arrow))
;; Add a key to toggle the window.
(dotfiles/leader
"tr" '(neotree-toggle :which-key "Neotree"))
#+END_SRC
*** Swiper
#+NAME: emacs-swiper-package
#+BEGIN_SRC nix
epkgs.ivy
epkgs.counsel
epkgs.ivy-rich
epkgs.ivy-posframe
epkgs.ivy-prescient
#+END_SRC
[[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.
#+NAME: emacs-swiper-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `ivy'.
(setq counsel-linux-app-format-function
#'counsel-linux-app-format-function-name-only)
(ivy-mode +1)
(counsel-mode +1)
;; Configure `ivy-rich'.
(ivy-rich-mode +1)
;; Configure `ivy-posframe'.
(setq ivy-posframe-parameters '((parent-frame nil))
ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
(ivy-posframe-mode +1)
;; Configure `ivy-prescient'.
(setq ivy-prescient-enable-filtering nil)
(ivy-prescient-mode +1)
#+END_SRC
*** Transparency
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.
#+NAME: emacs-transparency-elisp
#+BEGIN_SRC emacs-lisp
;; Configure the default frame transparency.
(set-frame-parameter (selected-frame) 'alpha '(85 . 85))
(add-to-list 'default-frame-alist '(alpha . (85 . 85)))
#+END_SRC
*** Desktop Environment
#+NAME: emacs-desktop-extras
#+BEGIN_SRC nix
pkgs.brightnessctl
#+END_SRC
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]].
#+NAME: emacs-desktop-package
#+BEGIN_SRC nix
epkgs.desktop-environment
#+END_SRC
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.
#+NAME: emacs-desktop-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `desktop-environment'.
(require 'desktop-environment)
(desktop-environment-mode +1)
#+END_SRC
*** Doom Themes
#+NAME: emacs-doom-themes-package
#+BEGIN_SRC nix
epkgs.doom-themes
#+END_SRC
[[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.
#+NAME: emacs-doom-themes-elisp
#+BEGIN_SRC emacs-lisp
;; Include modern themes from `doom-themes'.
(setq doom-themes-enable-bold t
doom-themes-enable-italic t)
;; Load the `doom-nord' and `doom-nord-light' themes.
(load-theme 'doom-nord-aurora t)
;; (load-theme 'doom-nord-light t)
;; (load-theme 'doom-nord t)
;; Define a method for returning information about the current theme.
;; This is based off the function `org-roam-ui-get-theme'.
(defun dotfiles/theme ()
"Return information about the current theme."
(list `(bg . ,(face-background hl-line-face))
`(bg-alt . ,(face-background 'default))
`(fg . ,(face-foreground 'default))
`(fg-alt . ,(face-foreground font-lock-comment-face))
`(red . ,(face-foreground 'error))
`(orange . ,(face-foreground 'warning))
`(yellow . ,(face-foreground font-lock-builtin-face))
`(green . ,(face-foreground 'success))
`(cyan . ,(face-foreground font-lock-constant-face))
`(blue . ,(face-foreground font-lock-keyword-face))
`(violet . ,(face-foreground font-lock-constant-face))
`(magenta . ,(face-foreground font-lock-preprocessor-face))))
;; Load a new theme with t t.
(dotfiles/leader
"tt" '(counsel-load-theme :which-key "Theme"))
#+END_SRC
Create a shell command that returns a JSON string of the current theme in the following format:
#+BEGIN_SRC json
{
"bg": "#272C36",
"bg-alt": "#2E3440",
"fg": "#ECEFF4",
"fg-alt": "#6f7787",
"red": "#BF616A",
"orange": "#EBCB8B",
"yellow": "#81A1C1",
"green": "#A3BE8C",
"cyan": "#81A1C1",
"blue": "#81A1C1",
"violet": "#81A1C1",
"magenta": "#81A1C1"
}
#+END_SRC
#+NAME: emacs-doom-themes-extras
#+BEGIN_SRC nix
(pkgs.writeShellScriptBin "dotfiles-theme" ''
${myEmacs}/bin/emacsclient --no-wait --eval '(json-encode (dotfiles/theme))' | sed "s/\\\\//g" | sed -e 's/^"//' -e 's/"$//'
'')
#+END_SRC
*** Doom Modeline
#+NAME: emacs-doom-modeline-package
#+BEGIN_SRC nix
epkgs.doom-modeline
#+END_SRC
[[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.
#+NAME: emacs-doom-modeline-elisp
#+BEGIN_SRC emacs-lisp
;; Configure `doom-modeline'.
(require 'doom-modeline)
(setq doom-modeline-height 16
doom-modeline-icon t)
;; Launch after initialization.
(add-hook 'after-init-hook 'doom-modeline-mode)
;; Define a modeline segment to show the workspace information.
(doom-modeline-def-segment dotfiles/workspaces
(exwm-workspace--update-switch-history)
(concat
(doom-modeline-spc)
(elt (let* ((num (exwm-workspace--count))
(sequence (number-sequence 0 (1- num)))
(not-empty (make-vector num nil)))
(dolist (i exwm--id-buffer-alist)
(with-current-buffer (cdr i)
(when exwm--frame
(setf (aref not-empty
(exwm-workspace--position exwm--frame))
t))))
(mapcar
(lambda (i)
(mapconcat
(lambda (j)
(format (if (= i j) "[%s]" " %s ")
(propertize
(apply exwm-workspace-index-map (list j))
'face
(cond ((frame-parameter (elt exwm-workspace--list j)
'exwm-urgency)
'(:inherit warning :weight bold))
((= i j) '(:inherit underline :weight bold))
((aref not-empty j) '(:inherit success :weight bold))
(t `((:foreground ,(face-foreground 'mode-line-inactive))))))))
sequence ""))
sequence))
(exwm-workspace--position (selected-frame)))))
;; Define a custom modeline to override the default.
(doom-modeline-def-modeline 'dotfiles/modeline
'(bar workspace-name dotfiles/workspaces window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info)
'(objed-state misc-info persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
;; Define a method to load the modeline.
(defun dotfiles/load-modeline ()
"Load the default modeline."
(doom-modeline-set-modeline 'dotfiles/modeline 'default))
;; Enable `doom-modeline'.
(add-hook 'doom-modeline-mode-hook 'dotfiles/load-modeline)
(doom-modeline-mode +1)
(doom-modeline-set-modeline 'dotfiles/modeline 'default)
#+END_SRC
** Website Configuration
#+ATTR_ORG: :width 800px
#+ATTR_HTML: :width 800px
#+ATTR_LATEX: :width 800px
[[./docs/images/website.png]]
My [[https://chrishayward.xyz][personal website]] is a static HTML page written with [[https://gohugo.io][Hugo]], and is fully integrated into this configuration. It uses the ~config.toml~, ~config.yaml~, or ~config.json~ file (found in the sites root directory) as the default site config. Working with this requires the module to be enabled.
#+BEGIN_SRC conf :noweb yes :tangle docs/config.toml
# <>
title = "Chris Hayward"
copyright = "Licensed under Attribution 4.0 International (CC BY 4.0)"
baseURL = "https://chrishayward.xyz/"
theme = "hello-friend-ng"
languageCode = "en-us"
defaultContentLanguage = "en"
pygmentsCodefences = true
pygmentsUseClasses = false
pygmentsStyle = "dracula"
<>
<>
<>
#+END_SRC
*** Params
Dates are important in [[https://gohugo.io][Hugo]], and they configure how dates are assigned and displayed in your content pages. Themes are also able to extract information from the configuration to display, including social media icons, subtitles, and footer sections.
#+NAME: website-params
#+BEGIN_SRC conf
[params]
dateform = "Jan 2, 2006"
dateformShort = "Jan 2"
dateformNum = "2006-01-02"
dateformNumTime = "2006-01-02 15:04 -0700"
authorName = "Christopher James Hayward"
homeSubtitle = "Airplanes, Linux, and Metalcore"
footerCopyright = ' · CC BY 4.0'
enableThemeToggle = true
[[params.social]]
name = "paypal"
url = "https://paypal.me/chrishaywardxyz"
[[params.social]]
name = "github"
url = "https://github.com/chayward1/"
[[params.social]]
name = "gitlab"
url = "https://gitlab.com/chayward1/"
[[params.social]]
name = "email"
url = "mailto:chris@chrishayward.xyz"
#+END_SRC
*** Privacy
I do not use any analytics or tracking in my website. Depending on the theme selected, some of these features may be enabled. I opt to override those settings here to make sure no unwanted trackers are loaded.
#+NAME: website-privacy
#+BEGIN_SRC conf
[privacy]
[privacy.disqus]
disable = true
[privacy.googleAnalytics]
disable = true
[privacy.instagram]
disable = true
[privacy.twitter]
disable = true
[privacy.vimeo]
disable = true
[privacy.youtube]
disable = true
#+END_SRC
*** Layout
Individual pages can be configured here to define the layout of the page. This is where quick links can be configured, and other sections such as blog posts, an about section, or a contact page can be added.
#+NAME: website-layout
#+BEGIN_SRC conf
[menu]
[[menu.main]]
identifier = "cloud"
name = "Cloud"
url = "https://cloud.chrishayward.xyz"
[[menu.main]]
identifier = "dotfiles"
name = "Dotfiles"
url = "/dotfiles"
[[menu.main]]
identifier = "projects"
name = "Projects"
url = "https://git.chrishayward.xyz"
#+END_SRC
* Footnotes