Go to file
Gabriel Arazas f8aec6c47c users/foo-dogsquared: update XDG folders config
It is too interruptive at this point. I would rather have the usual
library folder to be manually added if I want to include it to an
application.
2022-07-09 10:52:54 +08:00
.github/workflows .github/workflows: add automation for updating dotfiles input 2022-07-08 09:39:34 +08:00
hosts hosts/bootstrap: fix configuration 2022-07-08 09:46:56 +08:00
lib flake.nix: move flake utilities in the file 2022-07-09 06:51:16 +08:00
modules profiles/system: update store optimization to occur weekly 2022-07-09 10:52:54 +08:00
pkgs awesome-cli: init at 0.7.2 2022-07-09 07:06:31 +08:00
secrets secrets: rekey all files 2022-07-06 07:46:40 +08:00
shells shells/gnu: add more tools in the shell 2022-06-23 17:02:04 +08:00
templates/basic-devshell update various files 2022-04-30 20:31:11 +08:00
users users/foo-dogsquared: update XDG folders config 2022-07-09 10:52:54 +08:00
.editorconfig Update package set and documentation 2021-11-29 18:27:56 +08:00
.envrc Clean up files 2022-02-11 12:31:44 +08:00
.gitignore Update README and gitignore 2022-01-03 17:30:24 +08:00
.gitmodules hosts/ni: update config with setup 2022-07-06 07:38:21 +08:00
flake.lock flake.lock: update inputs 2022-07-08 00:28:28 +08:00
flake.nix flake.nix: update rust-overlay overlay attribute 2022-07-09 10:52:54 +08:00
Makefile update various files 2022-04-30 20:31:11 +08:00
README.adoc docs: update the READMEs 2022-07-06 07:46:40 +08:00
shell.nix Update various files 2022-01-25 09:32:17 +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.

Getting started

Caution

Despite being a NixOS system, it isnt entirely reproducible to the point of installing this config will work out-of-the-box. It has some things needed in the first place to work like my external backup setup where it needs my SSH private keys to work in the first place. Nonetheless, the parts is it isnt reproducible is only about 10% of this config. Everything else is fine and dandy.

Hey there, fellow traveler! Youve fell into the rabbit hole we call Nix where it leads to other rabbit holes such as functional package management, reproducibility, declarative systems, and immutable operating systems.

This is one of the many tickets to that rabbit hole, allow me to be your guide in this mark:[painful] wonderful declarative journey. Hope to see you on the other side!

Installation

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

If youre going to install one of my NixOS configs, be sure to download the unstable versions from their release page. As an additional option, you can also use my personalized NixOS installers which is primarily intended for me configs.

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.

  • 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.

  • 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.

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

  • 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. [2]

  • templates which contains my templates. Though, these are just templates mostly for my own purposes so it is not as useful as the other outputs.

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

The remote repo

For a complete overkill, we use a CI to further the configuration abomination. It uses GitHub workflows to enable things such as…

  • Automatically building my custom packages and sending them to my binary cache to easily distribute it for others.

  • Building my personalized NixOS installers and making a release out of it.

  • Testing the flake outputs (in progress lel).

Project structure

Last and foremost, we have the project directory — the environment youll be living in for the next year, tinkering your Nix configs. . It is required to be familiar with the workspace, after all. My configuration takes a lot of cues from devos (which is unfortunately is a lot to take if youre just beginning to grok Nix as a whole).

My NixOS config should look like the following:

nixos-config
├── hosts/
├── lib/
├── modules/
├── pkgs/
├── secrets/
├── shells/
├── templates/
├── users/
├── flake.lock
├── flake.nix
└── README.adoc

Most of the said folders are related to a flake output attribute, see Whats in my flake? for more details.

  • ./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]

  • ./templates/ contains my custom templates handy for quickly initializing for various types of projects.

  • ./users/ contains my home-manager configurations. 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:

  • Set most program configurations with Nix. This is especially applicable to programs I always use such as my text editor configs.

    • The reason: managing them can be chaotic when applied with Nix. The potential for it is pretty nice especially when seen with similar implementations such as Guix home environment. However, I dont want to rebuild it every time I change it.

    • Plus, most of my applications are now installed using Flatpak anyways. It is a tad easier to manage configurations installed this way (e.g., just copy ~/.var between your systems or make backups with it).

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

  • To be a configuration framework. This is my personal configuration which means experimentation will always be here. Sudden changes can happen at any point.

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. Fortunately [5], it is mostly the same experience now that Ive revisited it. (That said, Nix Pills is getting better!)

    For a more practical start, I recommend to look into several configurations to see the general gist of configuration with Nix. Heres a few I personally dug into:

  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.

    With that said, it is workable to be a daily part of the NixOS experience especially with the benefits of Nix flakes.

    • More user-friendly compared to Nix channels.

    • Just one reference file to know what is being exported from a project.

    • Unification with commonly-agreed schemas.

      This feature somewhat helped me understand more about the Nix language, oddly. I guess those lightbulb moments can come from random places.

  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 and to understand more whats going under the hood with Nix. 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 several parts of this configuration from the following projects:


1. This is more useful than my NixOS modules.
2. I dont know why did I put it there but eh…
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.
5. Or unfortunately from a different perspective.