Unable to nixos-rebuild due to invalid character in Base64 string

nixos-rebuild fails with the following logs:

❯ sudo nixos-rebuild switch
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
warning: don't know how to open Nix store 'hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ='
error: invalid character in Base64 string: '

I already removed the hydra.iohk.io cache from the nixos configs.

This is what the generated nix.conf looks like:

# WARNING: this file is generated from the nix.* options in
# your NixOS configuration, typically
# /etc/nixos/configuration.nix.  Do not edit it!
allowed-users = *
auto-optimise-store = true
builders = 
cores = 0
extra-sandbox-paths = 
max-jobs = auto
require-sigs = true
sandbox = true
sandbox-fallback = false
substituters = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= https://cache.nixos.org/
system-features = nixos-test benchmark big-parallel kvm
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= https://hydra.iohk.io
trusted-substituters = 
trusted-users = root sureyeaah
experimental-features = nix-command flakes

How can I fix this? I’m unable to rebuild my system because of this issue :confused:

Edit: now that I think about it, this is a bad idea. Follow NobbZ’s advice.

You should probably manually edit nix.conf. The warning sign is there because the config is autogenerated, meaning that any changes you make to it will not be preserved. But that’s fine, since this is only temporary.

Move the old nix.conf (which is probably a symlink) into some backup location:

$ sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.bk

Copy the old content into a new file:

$ cat /etc/nix/nix.conf.bk | sudo tee /etc/nix/nix.conf

Manually edit it to delete all mentions of hydra.iohk.io, then rebuild.

Fix the entries in your system configuration, then nixos-rebuild switch --option substituters https://cache.nixos.org.

@virchau13’s suggestion will probably work as well, it still requires fixing the setting in the system config that actually causes the malformated nix.conf.

This helped, thanks!!