- Nix 96.7%
- Just 3.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .git-crypt | ||
| home | ||
| keyboard | ||
| pkgs | ||
| secrets | ||
| .gitattributes | ||
| configuration.nix | ||
| file-cleanup.nix | ||
| flake.lock | ||
| flake.nix | ||
| hardware-configuration.nix | ||
| id_ed25519.pub | ||
| justfile | ||
| projects.nix | ||
| README.md | ||
My NixOS config
This is my NixOS config. Always and proudly work in progress.
Unstable Channel as Opt-in
I'm using stable nixpkgs as the default, and unstable as opt-in.
I used to do this the other way around, but unstable nixpkgs hit cache misses way too often, and I was constantly stuck compiling some huge software instead of pulling a precompiled binary; that's why I switched to stable-first.
# flake.nix
{
inputs = {
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
};
outputs =
{
nixpkgs-unstable,
nixpkgs,
...
}@inputs:
let
unstable = import nixpkgs-unstable {
system = system;
config.allowUnfree = true;
};
in
{
nixosConfigurations.myHostName = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs unstable;
};
};
};
}
Then, packages are taken from the stable channel unless I explicitly specify I want the unstable version:
# configuration.nix
{
pkgs,
unstable,
...
}:
{
environment.systemPackages = with pkgs; [
jq # stable
unstable.just # unstable
];
}
When adding a package, I check
search.nixos.org/packages for the versions
available in channel 26.05 and unstable and compare that with the program's
changelog. If the version in the stable channel is reasonably recent and there
aren't any missing features that I need, I use the stable version. If even the
unstable version is too stale for me, I look for a flake of that program and add
it to flakes.nix.
# flake.nix
{
inputs = {
savepoint = {
url = "github:NamtaoProductions/savepoint";
};
};
outputs = {
modules = [
{
nixpkgs.overlays = [
(final: prev: {
savepoint = inputs.savepoint.packages.x86_64-linux.default;
})
];
}
]
};
}
# configuration.nix
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
savepoint
];
}
Why Flakes
There seems to be some controversy regarding flakes in the Nix community, which I won't pretend to understand. I've chosen to use flakes for the following reasons:
1. I Want a Lockfile
The promise of NixOS is to have a completely reproducible system, and that's simply not the case without proper version pinning. Flakes pin all packages by default, and provides a simple way to update to newer versions.
I'm told that the same could be achieved with npins, and that's probably right.
2. My Program Is Not in Nixpkgs
Sometimes even the unstable nixpkgs don't have the (version of the) package I need. Flakes have become a popular way to distribute niche software, and I welcome that.
3. My Friends Use Them
I take inspiration from my friends' NixOS configurations:
They all use flakes, so I benefit from this shared base.
Compose Key
I want to be able to enter special characters without needing to constantly look
them up online. This includes typographical characters like em- & en- dashes,
but also emojis that I use often. The Compose Key with a custom .XCompose file
has served me well in that regard. It works like this: you bind one keyboard key
as your Compose Key (I use CapsLock), then after pressing the key, you press a
predefined sequence of keys, and your desired character appears. For example, to
type the en-dash in my setup, I sequentially press: CapsLock, hyphen, N.
This is amazing not only because you now have a way to enter virtually any
special character that you might need. You can also modify the sequences to suit
your needs. This is what a .XCompose file is for. You can look into
mine to get the gist of how it works.
Rather inconveniently, there's a long
lasting bug in
Chromium that causes all Chromium
and Electron based apps to ignore your custom .XCompose and only serve you
their own pre-bundled sequences. This is annoying, because it causes your
keyboard to behave differently in different apps. Luckily, there's a way to
walkaround this: the cryptically named fcitx5 package.
In most environments, there are many Compose Key sequences predefined. This
includes the obvious ones like a + e = æ, but also weird ones like # + S = ♬,
F + U = 🖕 and ? + \ = ☭. One small catch when defining custom Compose Key
sequences is that you can choose to inherit the default ones with include "%L", but you also get the weird ones, or you don't include them, but all your
combining/dead keys stop working. If you're determined, though, you can
re-implement all the dead keys yourself – see my
.XCompose for the reimplementation of Czech dead keys.
{ ... }:
{
services.xserver.xkb = {
layout = "cz"; variant = "qwerty"; # fill in your preferred keyboard layout
options = "compose:caps"; # sets CapsLock as Compose Key
};
console.useXkbConfig = true;
# Enable fcitx5, so that Chromium & Electron respect your .XCompose
i18n.inputMethod = {
enable = true;
type = "fcitx5";
fcitx5 = {
waylandFrontend = true;
addons = [ pkgs.fcitx5-gtk ]; # enable fcitx for GTK apps
settings.inputMethod = {
GroupOrder."0" = "Default";
"Groups/0" = {
Name = "Default";
"Default Layout" = "cz-qwerty"; # fill in your keyboard layout
DefaultIM = "keyboard-cz-qwerty"; # fill in your keyboard layout
};
"Groups/0/Items/0".Name = "keyboard-cz-qwerty"; # fill in your keyboard layout
};
};
};
environment.sessionVariables.GTK_IM_MODULE = "fcitx"; # make GTK apps use fcitx
home-manager.users.${username} = {
home.file.".XCompose".text = ''
include "%L" # inherit default XCompose from your locale
# Remove the previous line to get rid of default Compose sequences.
# However, this also includes stuff like ´ + A = Á, so you will have
# to reimplement these sequences yourself.
<Multi_key> <minus> <n> : "–" # en dash
<Multi_key> <minus> <m> : "—" # em dash
'';
};
}
Secrets
Background
It's a wonderful thing that people share their NixOS configs online. Being able to effortlessly copy someone else's setup is a dimension of open source that had been hidden from me up until now. However, having all your system configuration available online would be a terrible idea if that also meant sharing all your passwords. This is where secrets come in -- they're a mechanism that lets you share all except for a small part of the config.
The most common way to do secrets on NixOS seems to be agenix (an example here). Agenix only makes the secrets available after login ("at activation time", rather than "at build time"). This is an intentional decision -- for example it's the only way to make secrets only available to one user of the machine. However, I'm on a single-user installation, and my threat model is that if you ever decrypt my laptop's drive, it's gg anyway.
The problem with secrets at activation time is that this significantly limits
how these secrets can be used. For example, Home Manager's
calendars
have a passwordCommand setting that allows you to retreive a password at
runtime, however no such options exist for url and userName. Home Manager
expect you to pass both url and username at buildtime. In this specific
example, it would still be possible to walkaround this issue with
pimsync.extraRemoteStorageDirectives and dynamic
parameters.
But it would be annoying! And it seems like a matter of time until I run
across something that I want to keep secret but is genuninely needed at runtime.
I considered out-of-tree secrets for a while, but Nix really hates including
files that aren't tracked by git. I would have to include the --impure flag in
the check and apply recipes, and that would also disable many other useful
checks.
After some playing with git-agecrypt only to learn it's discouraged even by
its very author, I
landed with git-crypt. It works similarly
to LFS -- you tell it which files to track, and it processes them behind the
scenes, so that the file you push/pull from the remote is actually different
from the file you see locally. In this case, it encrypts the file when pushing,
and decrypts it when pulling.
One thing thing that git-crypt lacks when compared to agenix is a clear and unambiguous separation between secrets and plaintext. With agenix, you don't have to store the secrets as plaintext, ever. With git-crypt, you're always one bad config or sloppy command from committing your secrets as plaintext. So if I ever leak my e-mails and app passwords, this is why.
Setup
# secrets/schema.nix
{ ... }:
{
# This is a module where we define what secrets are even available.
# This file is commited in plaintext -- if somebody clones the repo,
# this file tells them what shape should values.nix have.
options.secrets = {
mySecretApp.topSecretPassword = lib.mkOption {
type = lib.types.str;
description = "The password to my secret app";
};
};
}
# secrets/values.nix
{ ... }:
{
# This module is encrypted, it holds the actual values of the secrets.
config.secrets.mySecretApp.topSecretPassword = "minipig";
}