Photo - Kobi Li
Photo

Hoverbear

Nix

Extending NixOS Configurations

Using Nix flakes to extend an existing NixOS configuration with additional settings or modules.

NixOS modules and configurations offer us a tantilizing way to express and share systems. My friends and I can publish our own flakes containing nixosModules and/or nixosConfigurations outputs which can be imported, reused, and remixed. When it comes to secret projects though, that openness and ease of sharing can be a bit of a problem.

Let's pretend my friend wants to share a secret NixOS module or package with me, they've already given me access to the GitHub repository, and now I need to add it to my flake. My flake is public and has downstream users. I can't just up and add it as an input. For one thing, it'd break everything downstream. More importantly, my friend asked me not to.

It's terribly inconvienent to add the project as an input and be careful to never commit that change to the repository. Worse, if I did screw up and commit it, my friend might be disappointed in me. We simply can't have that.

Let's explore how to create a flake which extends some existing flake, a pattern which can be combined with a git+ssh flake URL to resolve this precarious situation.

Continue reading...

Nix on the Steam Deck

What's Linux without the Nix?

When I first started using Linux in 2006 I remember dreaming of a Linux Console. The idea maybe wasn't so far fetched at the time, the PlayStation 3 had just been released with OtherOS support which allowed users to install Linux (or BSD). Still, it seemed that a Linux-first console would only ever be a dream. Now in 2022, Valve's Steam Deck is a hackable Linux-first portable console.

Today, we'll be putting Nix on it, because what's Linux without Nix?

Continue reading...

Declarative GNOME configuration with NixOS

Using Home Manager to declaratively set key desktop environment knobs.

I adore tinkering with my machine, trying new tools, extensions, themes, and ideas. When I was younger, it was simply a way to learn. Now, it's a way for me to refine my workspace and bring myself small joys.

While tinkering can be fun, it can be a chore to set up a new machine, keep configurations up to date between machines, or even just remember to keep up to date backups. We've previously explored how to create Configurable Nix packages, which solves the problem for things like neovim, but what about when a package isn't practically configurable?

What about when we want to configure a whole desktop environment? While NixOS offers configuration settings like services.gnome.gnome-keyring.enable for systemwide features, there's a void of knobs when you want to set things like user-specific GNOME 'Favorite Apps' or extensions.

Let's explore a useful addition to your NixOS configuration: Home Manager and its dconf module.

Continue reading...

Configurable Nix packages

Let your users bring their settings with them.

The vim and neovim packages in Nixpkgs allow users to set custom configuration, including their customRC and any plugins they might want.

How do they accomplish it?

In this article, we'll explore how to create packages with similar behavior. We'll create a simple Rust app that consumes a configuration file, then create a Nix flake containing both an unwrapped binary package as well as a configurable package.

Continue reading...

A Flake for your Crate

Creating a Nix Flake for your Rust crate.

Nix (PDF) provides users a way to access the massive Nixpkgs library of packages, create reproducable builds of software, roll slim containers, create declarative VMs, or run their whole machines. A new feature of Nix, Flakes, is bringing a convention to how projects like Rust crates can be accessed, integrated, and used within Nix (or NixOS.)

Let's explore how we can make our Rust crate usable as a Nix flake. At the end of this, any nix user with Flakes enabled should be able to run your project with something like nix run github:user/project. They'll be able to add your repository as a Nix overlay, install the package, do interactive builds, or create a portable bundle of it.

Continue reading...

Using rust-bindgen in Nix

Getting things linking.

While building the Nix packages for pl/Rust I bumped into a curious issue: I couldn't link to stdio.h, or stdbool.h! They were clearly on my path, too.

It flummoxed me for quite some time, but exploring the firefox package led to a way forward. It was rust-bindgen not finding libraries!

Continue reading...

Custom live media with Nix flakes

How to make live media with Nix flakes.

I've always been quite fond of booting live media. To test or install a new operating system, to recover an old one, find some privacy, or to do a myriad of other specialized tasks. LiveUSBs and liveCDs introduced to me a new way of thinking about my computer.

It improved my mental model of the separation of between the machine, the UEFI (or BIOS), any bootloaders, and the operating system itself.

As I learnt about them over 15 years ago I spent months exploring ways to use them. I used them to rescue systems for myself and others, diagnose hardware, recovery files, and quickly set up machines.

With Nix flakes, we can define a custom live system and build it with minimal steps. This NixOS live system which could be a composition of existing NixOS modules, or an entirely new configuration.

Continue reading...
6c3fee57ca834cb9f133106444ebe3bf12a9628e