Install NIX on TrueNAS SCALE

Since TrueNAS is quite locked down in what you can do, I figured NIX would be an ideal way to have flexibility of getting any package I want vs. not breaking TrueNAS. People who don’t fully understand this, please familiarize yourself with NIX - its awesome.

To install NIX you need to do few very straight-forward steps :

  1. I use single-user mode as it’s very simple.

  2. Figure out where you want to place NIX store (I placed it on NVMe array), create /nix (you will need mount -o rw,remount / for this)

  3. Create systemd mount unit that bind-mounts your chosen NIX store location into /nix (google how to create mount unit files, its easy). Enable and start it.

  4. Since we will be installing NIX as root, you need this :
    echo "build-users-group =" > /etc/nix/nix.conf

  5. Install NIX
    TMPDIR=/root/nix-install sh <(curl -L https://nixos.org/nix/install) --no-daemon

  6. Don’t remember if it auto-creates .bash_profile but you need below in it. I guess it can also go into .bashrc :

[[ -f /root/.nix-profile/etc/profile.d/nix.sh ]] && . /root/.nix-profile/etc/profile.d/nix.sh

  1. I use S3 cache for NIX stuff via MinIO that runs on TrueNAS. To configure you need :
    a. install MinIO and create s3 access keys (google how)
    b. Create :
.aws/config
[default]
region = us-east-1
s3 =
    signature_version = s3v4
endpoint_url = https://<MINIO HOST>:9000

.aws/credentials
[default]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx

c. Create .config/nix/nix.conf

cat .config/nix/nix.conf
substituters = s3://nix-cache?scheme=https&endpoint=<MINIO HOST>:9000 https://cache.nixos.org
experimental-features = nix-command flakes
post-build-hook = /root/bin/upload-to-cache.sh

where upload-to-cache.sh looks like

# cat /root/bin/upload-to-cache.sh
#!/bin/sh

set -eu
set -f
export IFS=' '

server="<MINIO HOST>:9000"

echo "Uploading paths" $OUT_PATHS
exec nix copy --to "s3://nix-cache?scheme=https&endpoint=${server}&compression=zstd" $OUT_PATHS
  1. Source nix-profile . /root/.nix-profile/etc/profile.d/nix.sh

  2. And start installing stuff like there is no tomorrow

nix-env -iA nixpkgs.git
nix-env -iA nixpkgs.awscli
nix-env -iA nixpkgs.hddtemp

Fully functional NIX without breaking TrueNAS at all.

…or so you pretend.
Do not install stuff (other than scripts) on your root/admin account, make a VM or sandbox instead.

1 Like

Its just a nas what can possibly go wrong.

I guess it can be installed as non-root user too, I was just too lazy to do it.

to be honest, I did it because I needed hddtemp