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
- NixOS Manual: Installation
- NixOS Wiki: Creating a NixOS live CD
- NixOS Manual: Building a NixOS (Live) ISO
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.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.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.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
Usage
{inputs, ...}: let
inherit (inputs.nix-config.lib.modules) setModuleContext;
in # ...
Source
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.resolvers
lib.resolvers.resolve
Resolve modules in a module directory.
Type
resolve :: Path -> String -> AttrSet
Arguments
Usage
{inputs, ...}: let
inherit (inputs.nix-config.lib.resolvers) resolve;
in # ...
Source
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
Usage
{inputs, ...}: let
inherit (inputs.nix-config.lib.trivial) applyIfFunction;
in # ...
Source
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.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.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
Packages
This section documents the custom packages.
anyrun-power-plugin: Power plugin for Anyrunnix-config-doc: Documentation for Bricked’s Nix Configurationnushell-login: Login shell wrapper for Nushell
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.
anyrunawwwbootconsoledesktopdifftasticgamingghosttygitgremlin-shellhelixlanzabootelibrewolfmangomergirafnixnushellprintingproton-vpnruststarshipstylixsystem
anyrun
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.anyrun];
}
Source
awww
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.awww];
}
Source
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
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
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
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
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
difftastic
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.difftastic];
}
Source
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
ghostty
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.ghostty];
}
Source
git
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.git];
}
Source
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
lanzaboote
NixOS module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.nixosModules.lanzaboote];
}
Source
librewolf
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.librewolf];
}
Source
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
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.mango];
}
Source
mergiraf
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.mergiraf];
}
Source
nix
NixOS module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.nixosModules.nix];
}
Source
nushell
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.nushell];
}
Source
printing
NixOS module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.nixosModules.printing];
}
Source
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
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
NixOS module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.nixosModules.rust];
}
Source
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.rust];
}
Source
starship
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.starship];
}
Source
stylix
Common module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.commonModules.stylix];
}
Source
NixOS module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.nixosModules.stylix];
}
Source
Home Manager module
No options.
Usage
{inputs, ...}: {
imports = [inputs.nix-dots.homeModules.stylix];
}
Source
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
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];
}