Skip to content

HestHub/nixos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

❄️ Hest's Nix Config ❄️

NixOS home-manager nix-darwin

License Last commit Repo Size

πŸ“– Overview

This config is tailored to my needs, and is not meant to be a tutorial, but if you do find anything you like, feel free to yank it :)

This repository is home to the nix code that builds my systems:

  • NixOS Desktop: NixOS with Flakes, Home-manager, Sops-Nix, etc.
  • MacOS Laptop: nix-darwin with home-manager, share the same home-manager configuration with NixOS.
  • HomeLab server: (TODO)
  • Rpi-HomeAssistant: (TODO)

πŸ“¦ Main Components

Component NixOS MacOS
Color Scheme Nord Nord
Dev environment direnv + devenv direnv + devenv
Editor Neovim Neovim
File Manager lf lf
Fonts Fira Code Fira Code
Input remapper N/A Kanata
Launcher Default Raycast
Multiplexer Zellij Zellij
Shell Fish + Nushell Fish + Nushell
Terminal Ghostty Ghostty
VPN Tailscale Tailscale
Window Manager PopShell Yabai

πŸ“· Screenshots

TODO PICTURE

🏠 Home Manager

Most of the packages / programs used are installed and configured using home manager.

β”œβ”€β”€ core.nix # shared packages
β”œβ”€β”€ darwin.nix # MacOS specific config
β”œβ”€β”€ linux.nix # NixOS specific config 
└── programs # complex or optional config
    β”œβ”€β”€ ...

To evaluate and list installed packages run:

nix eval .#nixosConfigurations.nixos.config.home-manager.users.<USERNAME>.home.packages --json | jq

πŸ“‚ Modules

  • home-manager
  • nix-darwin
  • sops-nix
β”œβ”€β”€ darwin
β”‚   β”œβ”€β”€ apps.nix # system packages & Homebrew
β”‚   └── system.nix # system settings & MacOS-defaults
└── linux
    β”œβ”€β”€ configuration.nix # system settings
    └── hardware-configuration.nix # auto generated

To evaluate the packages installed system-wide:

nix eval .#darwinConfigurations.<HOST>.config.environment.systemPackages --json | jq

✏️ Editor

NeoVim is configured directly in this repo and symlinked to $XDG_CONFIG_HOME/nvim when built.

// TODO PICTURE

Nvim config can be found here => ./dotfiles/nvim/

πŸ–₯️ Terminal

Ghostty enabled using home-manager

Currently there are some build issues on darwin, so on darwin, Ghostty is install using Homebrew and only configured by home-manager

./home/programs/ghostty.nix

🐚 Shell

Fish enabled using home-manager

On darwin, the default shell needs to be updated using

chsh -s /etc/profiles/per-user/hest/bin/fish

Plugins:

Nushell - WIP

πŸ” Secrets Management

I manage the secrets used in this repository using Sops-Nix. The secrets are encrypted and then stored in a private repository that is then used as a flake input.

All the secrets are encrypted using age and the secrets can only be decrypted host specific keys, that needs to be generated before initial setup.

setup sops

For the initial setup a new private repo is used.

Following this blog post the first step is to create a host specific age key file that is used encrypt/decrypt.

mkdir -p ~/.config/sops/age
age-keygen -o ~/.config/sops/age/keys.txt # generate key
age-keygen -y ~/.config/sops/age/keys.txt # fetch public key

To generate secrets, sops need a blueprint file to know what to do:

In the private repo create .sops.yaml

keys:
  - &host1 <YOUR PUBLIC KEY>
creation_rules:
  - path_regex: secrets.yaml$
    key_groups:
    - age:
      - *host1

Once the age file and sops blueprint is in place, modifying sops secrets are done using the sops CLI

# if sops is not installed yet
nix-shell -p sops --run "sops secrets.yaml"

# if sops already in place
sops secrets.yaml

This will open a decrypted secrets.yaml file that can be edited freely. On closing the file, sops will re-encrypt the file, making it safe to store/send.

using secrets

To use sops secrets in the flake, the first step is to import the sops module as well as the private repo as a flake.

flake.nix

inputs = {
  sops-nix.url = "github:Mic92/sops-nix";

  dot-secrets = {
    url = "git+ssh://[email protected]/HestHub/dot-secrets.git";
    flake = false;
  };
};
...
# include sops module in home manager

home-manager.darwinModules.home-manager
{
  ...
  home-manager.sharedModules = [
    sops-nix.homeManagerModules.sops
  ];
  ...
}

Then in the home-manager config, sops can be used to pick out and decrypt any defined secrets. Sops will create new files with the content found in the secrets.yaml file

  sops = {
    # select key to use for decryption
    age.keyFile = "${config.home.homeDirectory}/.config/sops/age/keys.txt";

    # select file to decrypt from secrets repo
    defaultSopsFile = "${inputs.dot-secrets}/secrets.yaml";
    
    secrets = {
      # create new file from the secret used
      "ssh/key".path = "${config.home.homeDirectory}/.ssh/id_X";
    };
  };

adding new hosts

To allow a new host to decrypt the secrets, it has to be added as a new sops recipient

keys:
  - &host1 <YOUR PUBLIC KEY>
  - &host2 <SECOND PUBLIC KEY>
creation_rules:
  - path_regex: secrets.yaml$
    key_groups:
      - age: [*host1, *host2]

With the new host key in place, sops updatekeys secrets.yaml will add host2 key as a new recipient

alternatives

Another popular, possibly simpler solution is to use Agenix to manage secrets. Sops demands a somewhat more complex initial setup, but once in place, the workflow it quite simple.

The primary reason Sops is used over Agenix is due to some rumblings online that Agenix needs some workarounds to work well on Darwin.

This might be old hat and not applicable anymore, but Sops seemed to be the safe choice for Darwin.

πŸ“œ Cheatsheet / How to Deploy this Flake?

πŸ”΄ IMPORTANT: Do not try to deploy this flake as is ❗ It will not succeed. This flake contains my hardware configuration, and requires my private secrets repository using Sops-Nix to deploy. Only use this repo as a reference to build your own setup

If you like to deploy a flake like this, read through the code and pick out the pieces that seems relevant and create your own flake, or just fork it and remove anything not relevant. Most important parts to remove is the hardware-configuration for NixOS, the secrets management in home manager and swap host-names and user-names.

Bootstrapping

NixOS:

  # clone repo
  git clone https://github.com/HestHub/nixos.git
  
  # fetch tools
  nix-shell -p age just
 
  # create new age key
  mkdir -p ~/.config/sops/age
  age-keygen -o ~/.config/sops/age/keys.txt
  age-keygen -y ~/.config/sops/age/keys.txt

  # (Move key to secret repo & add as recipient)

  # rebuild system
  sudo nixos-rebuild switch --flake .#<HOSTNAME>

  # or deploy via `just`(a command runner with similar syntax to make) & Justfile
  nix-shell -p just
  just build

MacOS:

  #install Xcode
  xcode-select --install
  
  # Install nix (Say NO to install determinate)
  curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

  # install Homebrew
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  # clone repo
  git clone https://github.com/HestHub/nixos.git
  
  # fetch tools
  nix-shell -p age just
 
  # create new age key
  mkdir -p ~/.config/sops/age
  age-keygen -o ~/.config/sops/age/keys.txt
  age-keygen -y ~/.config/sops/age/keys.txt

  # (Move key to secret repo & add as recipient)

  # Deploy Dariwn config
  just build

🚧 Roadmap

  • Nushell
  • Disko
  • Cleanup
  • CI
  • Move scripts to repo
  • Security hardening
  • adding server to combined config
  • expanding secrets management

πŸ”— Useful links

Good reads and dotfiles that inspired me:

About

nixos config

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published