Skip to content

Latest commit

 

History

History
166 lines (108 loc) · 5.1 KB

readme.md

File metadata and controls

166 lines (108 loc) · 5.1 KB

NixOS configuration

Installation

You may need to enable flakes since they are still experimental

export NIX_CONFIG="experimental-features = nix-command flakes"

Clone the configuration into /etc/nixos.

nixos-install --flake '/mnt/etc/nixos#<config>'

After the installation finished, set a password for the user:

passwd <user>

Updating

Update all flake inputs:

nix flake update

Update a specific flake input:

nix flake lock --update-input <input>

Rebuilding the system

Rebuild the system:

sudo nixos-rebuild switch
# Or if nomos-rebuild custom package is already installed:
sudo nomos-rebuild switch

Structure of the configuration:

hosts/{hostname}

Contains the configuration for each host. The hostname of the machine must match the name of the folder.

It must contain these files: [default.nix ] that are imported by the flake.nix. See here

hosts/{hostname}/overrides.nix

Overrides for the mkHost nixos configuration generator Example: {system = "aarch64-linux";}

hosts/{hostname}/default.nix

The main configuration file for the host. Use as a normal nixos configuration file. You can also use the generated options to enable some of the generated modules. You should not do any complex logic over here, instead use the modules/generated/nixos folder and create module for that and just enable it over here. (Unless it is specific to the host, such as windows dual boot mount)

hosts/{hostname}/hardware-configuration.nix

Contains the hardware configuration for the host. Usually generated by the nixos-generate-config command.

hosts/{hostname}/hardware-partitions.nix

Contains the partition configuration for the host. Usually generated by the nixos-generate-config command.

modules/

This is the most complex part about this config. Modules is split into 3 sub folders nixos, home-manager and generated.

modules/nixos/

Contains the nixos modules. And default.nix which specifies which modules to import (into each nixos host (configuration)).

modules/home-manager/

Contains the home-manager modules. And default.nix which specifies which modules to import (into each home-manager host (configuration)). The default.nix will also be included when using home-manager as nixos module. This is done automatically if you use the lib'.mkHomeNixOsUser function.

modules/generated/

Contains the MODULE GENERATOR, the heart of this config. This is where all the magic happens. That's why it has it's own readme.

lib/

Contains helper functions:

mkOverlay: Creates a nixpkgs overlay from just the name of the input, You must provide the name of the input and the flake.nix must have input named nixpkgs-${name}.

NixOS:

mkHost: Generates nixosConfigurations.${hostname} config, this will:

mkHomeNixOsUser: Takes 2 arguments:

  • username
  • additional modules Generates a home-manager user when home-manager is used as a nixos module. This will:
  • Import the default home-manager modules modules/home-manager/default.nix.
  • Import the home configuration as specified in home/.
  • Import the default home-manager options based on nixos config home/nixosDefaults.nix.

Usage example:

home-manager.users = self.lib'.internal.mkHomeNixOsUser "martin" [];

Home-manager:

mkHomeModules:

home/

Contains the home-manager configuration.

home/default.nix

Included every single time for every user (stand alone or as nixos module).

home/{username}/default.nix

Included every single time (stand alone or as nixos module).

home/{username}/nixos.nix

Included only when home-manager is used as a nixos module.

home/{username}/{hostname}.nix

Included only if the hostname matches. (stand alone or as nixos module).

home/nixosDefaults.nix

Included only when home-manager is used as a nixos module. This file includes default values that should be used if used as nixos module. The default values are chosen based on the nixosConfig that the home-manager is being used in.

overlays/

Contains nixpkgs overlays. Mainly generated by the mkOverlay lib function.