Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bricked’s Nix Configuration

Welcome to my Nix configuration! It provides:

  • NixOS and Home Manager configurations for my machines
  • Reusable NixOS and Home Manager modules
  • Useful library functions
  • Custom packages
  • A unique directory layout that groups related files
  • Guides to related topics

Resources

Showcase

Installing NixOS

This Nix configuration provides its own installation image. Unlike the official NixOS installer, it bundles the Nix configuration and most of its packages.

nixos-rebuild build-image --image-variant iso-installer --flake .#installer-homes

Burn the installation image onto a flash drive.

On the target system, disable Secure Boot and boot the flash drive. You will automatically be logged in and greeted by Gremlin Shell. This desktop environment lets you test the bundled applications before installing NixOS. The Nix configuration is symlinked to /etc/nixos.

Partition the drives with Disko.

Warning

This will erase everything on those drives.

sudo disko --mode destroy,format,mount --flake /etc/nixos#<host>

You will be asked to enter a password for disk encryption.

Install the NixOS configuration.

sudo nixos-install --no-root-password --flake /etc/nixos#<host>

Don’t forget to set up user passwords.

sudo nixos-enter --command "passwd <user>"

Finally, reboot into the newly installed NixOS system.

See also

Applying Configurations

NixOS configurations

Applying NixOS configurations on an existing NixOS system is straightforward.

nixos-rebuild switch --sudo --flake .#<host>

Home Manager configurations

Home Manager configurations are provided for each user listed in the host’s users.nix module.

home-manager switch -b backup --flake .#<user>@<host>

NixOS and Home Manager configurations for all users

NixOS configurations with the -homes suffix apply both the NixOS configuration and Home Manager configurations for all users listed in the host’s users.nix module.

nixos-rebuild switch --sudo --flake .#<host>-homes

Using the Binary Cache

This Flake provides a binary cache, courtesy of Cachix and GitHub Actions.

The binary cache is already configured for this Flake. To use it, simply accept adding it as substituter when running a Nix command.

URL

https://bricked.cachix.org

Public key

bricked.cachix.org-1:SPpNjrCYzlfisekwWTN7dEUQs+OrirrM92h1ZoEnciY=

Flakes

To use the binary cache in your own Flake, add it to your Flake’s hints.

# flake.nix

{
  nixConfig = {
    extra-substituters = ["https://bricked.cachix.org"];
    extra-trusted-public-keys = ["bricked.cachix.org-1:SPpNjrCYzlfisekwWTN7dEUQs+OrirrM92h1ZoEnciY="];
  };
}

See also

Enabling Secure Boot

Lanzaboote will automatically generate Secure Boot keys when the system is first run. Launch the UEFI to enter Secure Boot Setup Mode. Boot the sytem so Lanzaboote can automatically enroll the Secure Boot keys. Launch the UEFI again and enable Secure Boot. Running bootctl status should now log Secure Boot: enabled.

See also

TPM Disk Unlock

Encrypted disks can automatically be unlocked during Secure Boot. Enable TPM in the UEFI. For each encrypted partition, set up disk unlock by replacing <encrypted-partion> with its identifier, e.g. nvme0n1p1, sda1.

sudo systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=platform-code+external-code+secure-boot-policy+kernel-config /dev/<encrypted-partition>

To prevent unauthorized access to the encrypted disks, TPM disk unlock will stop working if any policy listed after --tpm-pcrs changes. To enable TPM disk unlock after it stops working, wipe its slot.

sudo systemd-cryptenroll --tpm2-device=auto --wipe-slot tpm2 /dev/<encrypted-partition>

Now, set up TPM disk unlock again.

See also

File Structure

/
├── flake.nix # Input and output definitions
│
├── doc
│   └── src # Documentation
│
├── lib
│   └── <name>
│       └── lib.nix # Function definitions
│
├── packages
│   └── <name>
│       └── package.nix # Package definition
│
├── modules
│   └── <name>
│       ├── nixos.nix # NixOS module
│       ├── home.nix # Home Manager module
│       └── common.nix # Shared NixOS + Home Manager module
│
├── hosts # Per-host configurations
│   └── <name>
│       ├── nixos.nix # NixOS configuration
│       ├── home.nix # Home Manager configuration
│       ├── users.nix # NixOS + Home Manager users
│       ├── disko.nix # Disko filesystem configuration
│       └── hardware.nix # Generated hardware configuration
│
└── users # Per-user configurations
    └── <name>
        └── home.nix # Home Manager configuration

Library

This section documents the custom library functions.

lib.imports

lib.imports.importLib

Import and evaluate a library. If the imported library is a function, this calls it with specialArgs.

Type

importLib :: a -> Path -> b

Arguments

specialArgs
Arguments to pass to the library.
path
Path to the library.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.imports) importLib;
in # ...

Source

lib/imports/lib.nix:27

lib.imports.importModule

Import and evaluate a module. If the imported module is a function, this wraps it in another function that applies specialArgs when the module is evaluated.

Type

importModule :: a -> Path -> b

Arguments

specialArgs
Arguments to bind to the module.
path
Path to the module.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.imports) importModule;
in # ...

Source

lib/imports/lib.nix:48

lib.imports.importPackage

Import and evaluate a package. If the imported package is a function, this wraps it in another function that applies specialArgs when evaluated.

Type

importPackage :: a -> Path -> b

Arguments

pkgs
The Nixpkgs instance to call the package with.
specialArgs
Arguments to bind to the package.
path
Path to the package.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.imports) importPackage;
in # ...

Source

lib/imports/lib.nix:76

lib.modules

lib.modules.setModuleContext

Add context attributes to a module. This creates a new module with the specified context attributes that imports the given module.

Type

setModuleContext :: a -> b -> c

Arguments

context
Context attributes to add.
module
Module to add the context attributes to.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.modules) setModuleContext;
in # ...

Source

lib/modules/lib.nix:19

lib.options

lib.options.enabledOption

Attributes for an enabled boolean option.

Type

enabledOption :: a

Examples

mkEnableOption "foo" // enabledOption

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.options) enabledOption;
in # ...

Source

lib/options/lib.nix:18

lib.resolvers

lib.resolvers.resolve

Resolve modules in a module directory.

Type

resolve :: Path -> String -> AttrSet

Arguments

root
Directory path containing the modules.
name
Name of the module files.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.resolvers) resolve;
in # ...

Source

lib/resolvers/lib.nix:24

lib.trivial

lib.trivial.applyIfFunction

Apply a function to a value if it is also a function.

Type

applyIfFunction :: ((a -> b) -> c) -> (a -> b) -> c
applyIfFunction :: ((a -> b) -> c) -> d -> d

Arguments

fn
Function to apply.
value
Value to apply the function to, if it is also a function.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.trivial) applyIfFunction;
in # ...

Source

lib/trivial/lib.nix:28

lib.trivial.bindArgs

Bind arguments to a function. This wraps the function in another function that applies specialArgs when called.

Type

bindArgs :: a -> (b -> c) -> (d -> c)

Arguments

specialArgs
Arguments to bind to the function.
fn
Function to bind to.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.trivial) bindArgs;
in # ...

Source

lib/trivial/lib.nix:50

lib.trivial.bindIntersectArgs

Bind arguments to a function, passing only arguments the function explicitly takes. This wraps the function in another function that applies the attributes of specialArgs present in the function’s parameter list when called.

Type

bindIntersectArgs :: a -> (b -> c) -> (d -> c)

Arguments

specialArgs
Arguments to bind to the function.
path
Function to bind to.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.trivial) bindIntersectArgs;
in # ...

Source

lib/trivial/lib.nix:72

lib.trivial.callIntersectArgs

Calls a function, passing only arguments the function explicitly takes. This calls the function with the attributes of specialArgs present in the function’s parameter list.

Type

callIntersectArgs :: a -> (b -> c) -> (d -> c)

Arguments

specialArgs
Arguments to pass to the function.
path
Function to call.

Usage

{inputs, ...}: let
  inherit (inputs.nix-config.lib.trivial) callIntersectArgs;
in # ...

Source

lib/trivial/lib.nix:94

Packages

This section documents the custom packages.

power

Power plugin for Anyrun.

Source

packages/anyrun-power-plugin/package.nix

nix-config-doc

Documentation for Bricked’s Nix Configuration.

Source

packages/nix-config-doc/package.nix

nushell-login

Login shell wrapper for Nushell.

Usage

Nix command

nix run git+https://codeberg.org/bricked/nix-config#nushell-login

NixOS

{inputs, pkgs, ...}: let
  inherit (pkgs.stdenv.hostPlatform) system;
  nixConfigPkgs = inputs.nix-config.packages.${system};
in {
  environment.systemPackages = [nixConfigPkgs.nushell-login];
}

Home Manager

{inputs, pkgs, ...}: let
  inherit (pkgs.stdenv.hostPlatform) system;
  nixConfigPkgs = inputs.nix-config.packages.${system};
in {
  home.packages = [nixConfigPkgs.nushell-login];
}

Source

packages/nushell-login/package.nix

Modules

This section documents the custom modules.

anyrun

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.anyrun];
}

Source

modules/anyrun/home.nix

awww

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.awww];
}

Source

modules/awww/home.nix

boot

NixOS module

boot.silent

Whether to enable silent boot.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.boot];
}

Source

modules/boot/nixos.nix

console

NixOS module

profiles.console.enable

Whether to enable the console profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.console];
}

Source

modules/console/nixos.nix

Home Manager module

profiles.console.enable

Whether to enable the console profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.console];
}

Source

modules/console/home.nix

desktop

NixOS module

profiles.desktop.enable

Whether to enable the desktop profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.desktop];
}

Source

modules/desktop/nixos.nix

Home Manager module

profiles.desktop.enable

Whether to enable the desktop profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.desktop];
}

Source

modules/desktop/home.nix

difftastic

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.difftastic];
}

Source

modules/difftastic/home.nix

gaming

NixOS module

profiles.gaming.enable

Whether to enable the gaming profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.gaming];
}

Source

modules/gaming/nixos.nix

ghostty

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.ghostty];
}

Source

modules/ghostty/home.nix

git

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.git];
}

Source

modules/git/home.nix

gremlin-shell

NixOS module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.gremlin-shell];
}

Source

modules/gremlin-shell/nixos.nix

helix

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.helix];
}

Source

modules/helix/home.nix

lanzaboote

NixOS module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.lanzaboote];
}

Source

modules/lanzaboote/nixos.nix

librewolf

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.librewolf];
}

Source

modules/librewolf/home.nix

mango

NixOS module

programs.mango.withUWSM

Whether to enable launching Mango with UWSM.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.mango];
}

Source

modules/mango/nixos.nix

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.mango];
}

Source

modules/mango/home.nix

mergiraf

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.mergiraf];
}

Source

modules/mergiraf/home.nix

nix

NixOS module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.nix];
}

Source

modules/nix/nixos.nix

nushell

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.nushell];
}

Source

modules/nushell/home.nix

printing

NixOS module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.printing];
}

Source

modules/printing/nixos.nix

proton-vpn

Home Manager module

programs.proton-vpn.autostart

Whether to start the client on login.

Type

boolean

Default

true

Example

false

programs.proton-vpn.cliPackage

The proton-vpn-cli package to use.

Type

package

Default

pkgs.proton-vpn-cli

programs.proton-vpn.enable

Whether to enable the Proton VPN client.

Type

boolean

Default

false

Example

true

programs.proton-vpn.package

The proton-vpn package to use.

Type

package

Default

pkgs.proton-vpn

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.proton-vpn];
}

Source

modules/proton-vpn/home.nix

rust

Common module

programs.rust.docs.enable

Whether to enable Rust documentation script.

Type

boolean

Default

true

Example

true

programs.rust.docs.package

The Rust documentation script.

Type

null or package

Default

null

programs.rust.enable

Whether to enable Rust toolchain.

Type

boolean

Default

false

Example

true

programs.rust.package

The Rust toolchain to use.

Type

null or package

Default

let
  inherit (pkgs.stdenv.hostPlatform) system;
  rustPkgs = inputs.rust-overlay.packages.${system};
in rustPkgs.rust.override {
  extensions = ["rust-analyzer"];
}

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.commonModules.rust];
}

Source

modules/rust/common.nix

NixOS module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.rust];
}

Source

modules/rust/nixos.nix

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.rust];
}

Source

modules/rust/home.nix

starship

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.starship];
}

Source

modules/starship/home.nix

stylix

Common module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.commonModules.stylix];
}

Source

modules/stylix/common.nix

NixOS module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.stylix];
}

Source

modules/stylix/nixos.nix

Home Manager module

No options.

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.stylix];
}

Source

modules/stylix/home.nix

system

NixOS module

profiles.system.enable

Whether to enable the system profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.nixosModules.system];
}

Source

modules/system/nixos.nix

Home Manager module

profiles.system.enable

Whether to enable the system profile.

Type

boolean

Default

false

Example

true

Usage

{inputs, ...}: {
  imports = [inputs.nix-dots.homeModules.system];
}

Source

modules/system/home.nix