Skip to content

Latest commit

 

History

History
126 lines (96 loc) · 4.63 KB

README.org

File metadata and controls

126 lines (96 loc) · 4.63 KB

Nix & Flakes - Reproducible machines

https://img.shields.io/badge/NixOS-grey.svg?style=flat-square&logo=NixOS&logoColor=white

These are my NixOS and home-manager configurations. They aim for maximum reproducibility through Flakes. This repo is composed by modules to provide plug&play configuration based on hosts and users.

I’m using the standalone approach for home-manager, but it shouldn’t be difficult to integrate all this with the NixOS module.

Be careful if you want to use this “template”, this is not a framework neither an easy-come-easy-go library. I’m a totally beginner.

./assets/patrick-meme.jpg

Structure

Here the top-level structure of this repository. I will put a tree like this in every important folder.

.
├── flake.nix
├── flake.lock                  
├── shell.nix                   # Shell declaration for this repo 
├── wallpapers
├── home                        # Home-manager configuration 
│   ├── mario                   # User configuration, per host files/folders
│   └── modules                 # Modules :: options to build a cute home
├── lib                         # Utility functions
│   ├── default.nix             
│   ├── home.nix                # Home configurations generator
│   └── nixos.nix               # System configurations generator             
├── overlays                    # Overlays folder
├── packages                    # Personal packages folder
└── system                      # System configurations
    ├── hosts                   # System configuration, olders for each host
    └── modules                 # Modules :: options for system related stuff

Instructions

Installation with new hardware

  1. Boot into the NixOS installer;
  2. Switch to root user;
  3. Do your manual partitioning, and mount all (if you don’t know how to do this step, go away);
  4. Installation process:
nix-shell -p git nixFlakes

# Set HOST for the hostname of the new system
HOST=...
# Set USER to your desired username
USER=...

git clone https://github.com/archer-65/nix-dotfiles /etc/dotfiles
cd /etc/dotfiles

# Create a new host folder
mkdir -p system/hosts/$HOST

# This step generates your hardware-configuration and a basic configuration file
nixos-generate-config --root /mnt --dir /etc/dotfiles/system/hosts/$HOST
# You can remove the `configuration.nix` file, follow the other hosts structure to create your own configuration
rm -f system/hosts/$HOST/configuration.nix
# [OPTIONAL] You can copy the other files and modify what you want (be careful!), for instance:
cp system/hosts/mate/{default.nix,options.nix} system/hosts/$HOST/

# Add a set definition in `flake.nix` for the desired host

# Flakes need staged files
git add .

# Install
nixos-install --root /mnt --flake .#$HOST

# Finally move your files where you want. Example:
mv /etc/dotfiles /mnt/home/$USER/.dotfiles
  1. Reboot;
  2. Change your password;
  3. Enjoy;

Once installed

I’m assuming you’re referring to flake configurations in your working directory…but it doesn’t matter, you can build from github, from other folders or from another planet :).

If you want to build your home-manager configuration:

# Create your own folder with `default.nix` under `/home/configurations`
cp -R /home/$USER/mate.nix /home/$USER/${HOSTNAME}.nix

# Add a set definition in `flake.nix` for the desired host

# Build and activate!
nix build .#homeConfigurations."${USER}@${HOSTNAME}".activationPackage
./result/activate

Once in a while

Update your lock file!

nix flake update

To rebuild system/home:

nixos-rebuild switch --flake .#$HOSTNAME
home-manager switch --flake .#"${USER}@${HOSTNAME}"

How did I accomplish this?

Well, I “borrowed” many ideas and functions from other repos…learning nix is really hard, with a steep learning curve.

Thanks to: