Go to file
2022-01-02 22:30:00 +08:00
hosts Update ni configuration 2021-12-26 18:43:49 +08:00
lib Make miscellaneous updates :) 2021-12-26 16:02:57 +08:00
modules Update bleachbit module in home-manager 2022-01-02 09:29:48 +08:00
pkgs gnome-shell-extension-desktop-cube: 5 -> 7 2022-01-02 07:47:25 +08:00
secrets Improve backup service 2021-12-19 17:37:22 +08:00
shells Add Rust development shell 2021-12-26 18:42:12 +08:00
users Make miscellaneous updates :) 2021-12-26 16:02:57 +08:00
.editorconfig Update package set and documentation 2021-11-29 18:27:56 +08:00
.gitignore Rewrite as a flake 2021-11-25 19:55:30 +08:00
.gitmodules Move the dotfiles to 'foo-dogsquared' user 2021-12-06 18:41:14 +08:00
flake.lock Update flake inputs 2022-01-02 08:53:59 +08:00
flake.nix Refactor flake configuration 2022-01-02 22:30:00 +08:00
Makefile Update our host and user config 2021-12-02 22:02:29 +08:00
README.adoc Update documentation 2021-12-26 18:43:23 +08:00
shell.nix Add a development shell for this project 2022-01-01 20:14:50 +08:00

This is my NixOS config as a Nix flake.

I finally have some time trying to grok flakes and redo my NixOS config from scratch after leaving it for some time (because I have work and have to quickly set things up without me trying to debug how NixOS works). Here is the result.

Installation

Since this uses Nix flakes, you should have Nix v2.4 and above installed.

This primarily uses Nix flakes so you can have a preview of whats available in my config.

nix flake show github:foo-dogsquared/nixos-config

It should export my NixOS configurations of my different hosts (of only one so far excluding VMs and VPSs ;p) among other things. To install it, run the nixos-install --flake github:foo-dogsquared/nixos-config#ni. (Please see the respective appropriate host README for more information.)

Tip
If you found some error regarding something in restricted mode, you can run the installation with --impure flag (i.e., nixos-install --impure --flake github:foo-dogsquared/nixos-config#ni).

Whats in my flake?

You can see the full details with nix flake show. As a helpful summary, heres what my flake should contain sorting from the most interesting and helpful outputs to the most boring and unnecessary.

  • packages contains my custom packages. It supports the default list of systems as defined from flake-utils.

  • devShells from my custom environments. Similar to homeManagerConfigurations, you can easily use it outside of NixOS.

  • nixosConfigurations which is where you can install my various NixOS configurations directly (e.g., nixos-install --flake MY_FLAKE_URL#HOST). This mainly uses the hosts configuration.

  • homeManagerConfigurations contains my various home-manager configurations from ./users/home-manager/. The neat thing about it is you can easily install it in a non-NixOS Linux distro.

  • nixosModules are composed from NixOS modules defined in ./modules/nixos. It can be used as additional modules for your own NixOS config in case you want to use mine for whatever reason. [1]

  • homeManagerModules are where my custom home-manager modules to be exported. [2]

  • lib is defined from my custom library. Its another unnecessary export but its there.

Project structure

My NixOS config should look like the following:

nixos-config
├── hosts/
├── lib/
├── modules/
├── pkgs/
├── secrets/
├── shells/
├── users/
├── flake.lock
├── flake.nix
└── README.adoc
  • ./hosts/ contain machine-specific configuration. This usually configures like the hardware setup, timezone, and users. Host configurations are also exported in the flakes in outputs.nixosConfigurations.

  • ./modules/ contain my custom modules including NixOS and home-manager modules. For more information, see the related documentation.

  • ./pkgs/ contains my custom packages. It is exported in the flakes at outputs.packages compiled through various systems.

  • ./secrets/ contains my secrets managed with agenix. [3]

  • ./shells/ contains my development shells for interacting with the usual type of projects. Setting this up can bring benefits outside of NixOS (unless youre interacting with projects with any OpenGL-related stuff). [4]

  • ./users/ contains my home-manager configurations and modules. It is exported in the flakes at outputs.homeConfigurations. For more information, see the related documentation.

TODO

In order of priority:

  • ✓ Create custom modules.

  • ✓ Create a themes system similar to this NixOS config.

  • ❏ Create a good workflow for creating ISOs.

  • ✓ Create development shells.

  • ✓ Manage secrets with agenix.

  • ❏ Create a good workflow for tests.

  • ✓ Automate backups with NixOS config.

  • ✓ Create custom packages and export it to flakes. (Maybe consider making it to upstream)

  • ✓ Create cluser-wide configs.

  • ✓ Create host-wide configs.

  • ✓ Create user-specific configs with home-manager.

  • Steal Get some ideas from this overengineered template.

  • ✓ Make use of other established utilities such as digga, flake-utils-plus, and home-manager once Im familiar to create my own Nix programs.

Out of scope:

  • Text editor configurations. They are often updated. I dont want to rebuild it every time I change it.

  • Migration of my dotfiles. I still use it on other non-NixOS systems.

Frequently asked questions (FAQ)

More like "Most anticipated questions (MAQ)" since almost no one asked me about this yet. :) However, it doesnt roll off the tongue.

  1. Hello! Im new to Nix and NixOS, where should I start?

    Oh no, youve seen the multiple configurations from other systems, didnt you? I hope youre ready for some time understanding because the learning curve is steeper than the Troll Wall. Ive written a blog post regarding my experience with Nix with a bunch of links for getting started. (Un)Fortunately, it is mostly the same experience now that Ive revisited it.

  2. Any requirements for this setup?

    You only need Nix 2.4 installed with the experimental features for Nix command and flakes enabled (i.e., experimental-features = nix-command flakes).

  3. Hey! I have an error something like /nix/${HASH}-nmd/ from my installation. Why it doesnt work?

    This error seems to be related to home-manager. See this issue for more details. Basically, you have to add --impure flag when running nixos-install.

  4. What is my experience on Nix flakes?

    I LIKE IT! There are still some hiccups like the strict tie-in to Git which leads to strange experience like having to add untracked files just to be recognized. However, this feature is still in the works so no surprise there.

  5. Is this based from devos?

    Yes but Ive created this from scratch. One of my goals when creating this config is to use as little dependency as much as possible. At the time Ive rewritten this configuration, I have little idea about Nix as a language and I find devos to be overwhelming so I doubled down to create from scratch.

    However, I can say that my configuration is moving in a similar direction to devos (which is intended to be modified anyways) as I explore more of Nix. In fact, Ive based much of my config from it and may even be ended up as one. It is nice that such a project exists serving as a reference for bigger configurations.

Inspirations

I stole got the ideas from the following projects:


1. I dont know why did I put it there but eh…
2. This is more useful than my NixOS modules.
3. It is advised you should minimize SSH keys with passphrases since it is annoying to reenter passwords every time.
4. Since packages brought from Nix shells can only work with the store, a container might be better at some situations.