Skip to content

Instantly share code, notes, and snippets.

@eqyiel
Last active October 8, 2021 00:28
Show Gist options
  • Save eqyiel/64007446616e412229fbfa07b6eef873 to your computer and use it in GitHub Desktop.
Save eqyiel/64007446616e412229fbfa07b6eef873 to your computer and use it in GitHub Desktop.
How to use nix-serve with an alternative store location

This is something you might want to do if you have an existing store directory on another dataset but don't want to overlay mount it onto /nix/store.

~/shell.nix is

{
  pkgs ? import <nixpkgs> {
    overlays = [
      (self: super: {
        nix = super.nix.override {
          storeDir = "/mnt/nix/store";
          stateDir = "/mnt/nix/var";
        };
      })
    ];
  }
}: pkgs.mkShell {
  buildInputs = [
    pkgs.nix
    pkgs.nix-serve
  ];
}

nixpkgs revision: https://github.com/NixOS/nixpkgs-channels/archive/fce7562cf46727fdaf801b232116bc9ce0512049.tar.gz

~ # readlink -f /root/.nix-defexpr/channels/nixos/
/nix/store/xv5v445yf322zfh0xirb05vpw2jyjk4m-nixos-20.09pre223023.fce7562cf46/nixos
~ # nix-shell

# ...

~ # nix-serve -p 8080

# in another terminal

~ # curl http://127.0.0.1:8080/nix-cache-info
StoreDir: /mnt/nix/store
WantMassQuery: 1
Priority: 30

~ # nixos-install --option extra-binary-caches http://127.0.0.1:8080/

warning: binary cache 'http://127.0.0.1:8080' is for Nix stores with prefix '/mnt/nix/store', not '/nix/store' 🥺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment