About me: My name is Solène Rapenne, pronouns she/her. I like learning and sharing knowledge. Hobbies: '(NixOS BSD OpenBSD Lisp cmdline gaming security QubesOS internet-stuff). I love percent and lambda characters. OpenBSD developer solene@.

Contact me: solene+www at dataswamp dot org or @solene@bsd.network (mastodon). If for some reason you want to support my work, this is my paypal address: donate@perso.pw.

Consider sponsoring me on Patreon to help me writing this blog and contributing to Free Software as my daily job.

Using nix download bandwidth limit feature

Written by Solène, on 23 August 2022.
Tags: #bandwidth #nix #linux

Comments on Fediverse/Mastodon

1. Introduction §

I submitted a change to the nix package manager last week, and it got merged! It's now possible to define a bandwidth speed limit in the nix.conf configuration file.

Link to the GitHub pull request

This kind of limit setting is very important for users who don't have a fast Internet access, this allows the service to download packages while keep the network usable meanwhile.

Unfortunately, we need to wait for the next Nix version to be available to use it, fortunately it's easy to override a package settings to use the merge commit as a new version for nix.

Let's see how to configure NixOS to use a newer Nix version from git.

2. Setup §

On NixOS, we will override the nix package attributes to change its version and the according checksum.

We want the new option "download-speed" that takes a value for the kilobytes per second speed limit.

  nix.extraOptions = ''
    download-speed = 800
  nixpkgs.overlays = [
      (self: super:
          nix = super.nix.overrideDerivation (oldAttrs: {
              name = "nix-unstable";
              src = super.fetchFromGitHub {
                  owner = "NixOS";
                  repo = "nix";
                  rev = "8d84634e26d6a09f9ca3fe71fcf9cba6e4a95107";
                  sha256 = "sha256-Z6weLCmdPZR044PIAA4GRlkQRoyAc0s5ASeLr+eK1N0=";

Run "nixos-rebuild switch" as root, and voilà!

For non-NixOS, you can clone the git repository, checkout the according commit, build nix and install it on your system.

3. Going further §

Don't forget to remove that override setting once a new nix release will be published, or you will keep an older version of nix.