Help with transitioning /etc/nixos to a flake setup

Hi,

I am trying to transition my /etc/nixos/configuration.nix to a flake-based setup. I have been following these two guides:
https://nixos.wiki/wiki/Flakes

I am simply trying to take my existing configuration.nix that works and try it with a flake. Here is my flake in /etc/nixos/flake.nix

{
  description = "flake for yourHostNameGoesHere";

  inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;

  outputs = { self, nixpkgs, ... }: {
    nixosConfigurations."foobar" = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
        ];
    };
  };
  
}

When I try to run the rebuild command, I get some strange errors I cannot decipher:

[root@nixos:/etc/nixos]# nixos-rebuild switch --flake '.#foobar'
error:
       … while updating the lock file of flake 'path:/etc/nixos?lastModified=1704487271&narHash=sha256-IlRuxHOZE1vr%2BeYpWqlE32PpNoIMMeaBXHuxQDmXGeA%3D'

       … while updating the flake input 'nixpkgs'

       … while fetching the input 'github:NixOS/nixpkgs/nixos-unstable'

       error: failed to extract archive (Write failed)

I had found another topic to try build but getting same error

[root@nixos:/etc/nixos]# nix build -vvv '.#nixosConfigurations.foobar.config.system.build.toplevel'
evaluating derivation 'path:/etc/nixos#nixosConfigurations.foobar.config.system.build.toplevel'...
copying '/etc/nixos'...
linking '/nix/store/9lc4bryry5hwh35rp7fcvwaqqpz1330j-source/configuration.nix' to '/nix/store/.links/1g3aza31ackyclcnvf88xcc5z8pq152pf8n0v7h1y196vcgpd3ws'
linking '/nix/store/9lc4bryry5hwh35rp7fcvwaqqpz1330j-source/hardware-configuration.nix' to '/nix/store/.links/1p53bhsq5jmqncbfbz21z84b0mpmvrmlpqay3mdkz70pj3x9wqz9'
linking '/nix/store/9lc4bryry5hwh35rp7fcvwaqqpz1330j-source/disko-config.nix' to '/nix/store/.links/1pf87csmizvdssh688g6d613qzjc4q15z7wz081hmxsivwgvc18q'
evaluating file '/nix/store/9lc4bryry5hwh35rp7fcvwaqqpz1330j-source/flake.nix'
error:
       … while updating the lock file of flake 'path:/etc/nixos?lastModified=1704487271&narHash=sha256-IlRuxHOZE1vr%2BeYpWqlE32PpNoIMMeaBXHuxQDmXGeA%3D'

       … while updating the flake input 'nixpkgs'

       … while fetching the input 'github:NixOS/nixpkgs/nixos-unstable'

       error: failed to extract archive (Write failed)

Some other topics mentioned disk space being a culprit but I have plenty and / and /tmp.

[root@nixos:/etc/nixos]# ls -l /etc/nixos
total 20
-rw-r--r-- 1 root root 6338 Dec 26 11:34 configuration.nix
-rw-r--r-- 1 root root  857 Dec 22 09:41 disko-config.nix
-rw-r--r-- 1 root root  324 Jan  5 15:41 flake.nix
-rw-r--r-- 1 root root 1138 Dec 22 16:32 hardware-configuration.nix

[root@nixos:/etc/nixos]# df -h
Filesystem                            Size  Used Avail Use% Mounted on
devtmpfs                              1.6G     0  1.6G   0% /dev
tmpfs                                  16G     0   16G   0% /dev/shm
tmpfs                                 7.8G  6.6M  7.8G   1% /run
tmpfs                                  16G  960K   16G   1% /run/wrappers
/dev/disk/by-partlabel/disk-vdb-root  916G  3.8G  866G   1% /
none                                  200M     0  200M   0% /tmp
/dev/nvme0n1p1                        500M   27M  474M   6% /boot
tmpfs                                 3.2G  4.0K  3.2G   1% /run/user/1000

Thanks for any help

The problem is you have /tmp mounted on a 200 MiB tmpfs. That’s no where near enough because Nix uses /tmp for builds. It may not have been an issue in the past because you were able to download everything from the cache, but you’re following unstable. Sometimes things in unstable are not yet in the cache and need to be built locally.
Try dropping the tmpfs on /tmp, using a bigger one…

In your case, /tmp has none as the filesystem. Still, probably worth trying what’s being suggested? i.e., creating a bigger tmpfs and mount it at /tmp or some such

Source: Reddit - Dive into anything

1 Like

Amazing thanks. I updated /tmp to 1 GB and was able to use the flake.

1 Like