nix-portable icon indicating copy to clipboard operation
nix-portable copied to clipboard

How to upgrade nix?

Open yajo opened this issue 3 years ago • 3 comments

No matter what I try, I always get:

$ nix --version
nix (Nix) 2.4pre20201201_5a6ddb3

How can I upgrade nix version inside the container?

The closest I can get is change the channel as indicated in #26 and run nix-shell -p nix, but that removes the comfort of using nix from outside the container by creating a symlink from nix to nix-portable.

Thanks.

yajo avatar Jan 12 '22 09:01 yajo

@Yajo You can produce the upgraded nix-portable declaratively by overriding the flake inputs.

ShamrockLee avatar Jan 23 '22 17:01 ShamrockLee

Can you elaborate for beginners like me? My build script (for netlify) looks like

wget -nv https://github.com/DavHau/nix-portable/releases/download/v009/nix-portable
chmod +x nix-portable
./nix-portable nix-build 

how would I change that to get a specific version of nix?

nomeata avatar Mar 08 '22 11:03 nomeata

@nomeata Sorry for late reply.

As nix-portable enables the flake features by default, you can make use it to build and run the Nix Flakes. You can find a Flakes introduction on the NixOS Wiki:

https://nixos.wiki/wiki/Flakes

There are several ways to build nix-portable from flake.

The most reliable one is to write a flake.nix. This one will work if you simply want to get an updated nix-portable.

{
  description = "My custom overrided nix-portable flake";

  # The nixpkgs revision to use
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
  # The nix revision to use
  inputs.nix.url = "github:NixOS/nix/2.5.1";
  inputs.nix.inputs.nixpkgs.follows = "nixpkgs";
  # We don't need to benchmark Nix here.
  # Let's opt out the additional nixpkgs
  # that causes constant changes of `flake.lock`.
  inputs.nix.inputs.nixpkgs-regression.follows = "nixpkgs";
  inputs.nix-portable-flake.url = "github:DavHau/nix-portable/v009";
  inputs.nix-portable-flake.inputs.nixpkgs.follows = "nixpkgs";
  inputs.nix-portable-flake.inputs.defaultChannel.follows = "nixpkgs";
  inputs.nix-portable-flake.inputs.nix.follows = "nix";

  outputs = { nix-portable-flake, ... }: nix-portable-flake.outputs;
}

If the file is inside a Git repo, you can then run

$ nix build my/directory#nix-portable

to build the executable with the specified Nixpkgs and Nix versions.

If the file is not inside a Git repo, change my/directory to path:my/directory.

ShamrockLee avatar Apr 12 '22 07:04 ShamrockLee