Too much disk usage after garbage collecting and optimising

Hello!

I have an issue with the amount of space the /nix/store is using.
I wanted to update today and I found out my root partition ran out of space, so I did some garbage collecting and even nix store optimise to reduce the space usage but I’ve reached a limit and I don’t know how to reduce it further.

When I rebuild, it says that my configuration is around 19GiB, but my /nix/store is currently 54GiB even after having done sudo nix-collect-garbage -d and nix store optimise

It is of note that I recently changed from the unstable channel to the stable one (25.11) and there have been some weird things that arose after that.

For example my home-manager: when I do a home-manager switch it raises the warning that there’s a version miss-match (26.05) even though I have in my flake that home-manager should follow nixpkgs (25.11) (flake bellow).
Another weird thing is that after having collected old generations, I saw once a systemd boot option for a 26.05 version. Could it be that I have a parasitic generation that is linked but have not been able to unlink?

Thanks in advance

My flake:

{
  description = "Nixos config flake";

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

    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";

    nixpkgs-old-gtk = {
      url = "github.com/NixOS/nixpkgs/6d674616a4c9fb815c2599c6615e3c34b6027cee";
      flake = false;
    };

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    stylix = {
      url = "github:danth/stylix/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nvf = {
      url = "github:NotAShelf/nvf";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    zen-browser = {
      url = "github:youwen5/zen-browser-flake";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    my-nvf-config = {
      url = "github:MijaToka/nvf-config";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      home-manager,
      stylix,
      nvf,
      zen-browser,
      ...
    }@inputs:
    let
      system = "x86_64-linux";
    in
    {
      nixosConfigurations = {
        nixos = nixpkgs.lib.nixosSystem {
          specialArgs = { inherit inputs; };
          inherit system;
          modules = [
            ./nixos/configuration.nix
            (
              { pkgs, ... }:
              {
                environment.systemPackages = [ inputs.my-nvf-config.packages.${system}.default ];
              }
            )
          ];
        };
      };

      homeConfigurations = {
        mija = home-manager.lib.homeManagerConfiguration {
          pkgs = nixpkgs.legacyPackages.${system};
          modules = [
            ./Mija/home.nix
            stylix.homeManagerModules.stylix
          ];
        };
      };
    };
}

Did you ever run nix-collect-garbage without sudo?

Also checking GC roots across the system always helps. sudo nix-store --gc --print-roots will print all of them, if you choose to not use sudo then running processes will only be displayed as {censored}.

1 Like

Now I did, and I felt silly for not having done it, but I did not remove as much as I hoped it would.
When doing the sudo nix-store --gc --print-roots I see as the last result /tmp/nh-oswl3qDb/result → /nix/store/gg2a8828ggrcxiq6pgw9cbrw4fgl2yi3-nixos-system-nixos-26.05.20251205.f61125awhich jumps to attention the 26.05 version. After that I don’t know what should I be looking for in this.

That entry looks like a leftover of some build. By default, /tmp is wiped on reboot.

I reboot-ed not long ago (right after writing the post to see if the boot entry appeared once again), and this says its from over a month ago :frowning:, how do I do to remove that old build in a more forceful manner? Can I delete /nix/store/gg2a8828ggrcxiq6pgw9cbrw4fgl2yi3-nixos-system-nixos-26.05.20251205.f61125a somehow?

You delete the link, /tmp/....

No, it’s not.

@MijaToka You can enable boot.tmp.cleanOnBoot if you want. Then, future garbage collections will be a bit more effective.

Seems as if I misremembered the default, thank you for clarifying.

1 Like

Cleaning /tmp and then collecting garbage solved it!

1 Like

You might also want to look into services.angrr; it’s easy to accidentally end up with links like that when using nix, that service makes sure they get cleaned up.