DavHau / nix-portable

Nix - Static, Permissionless, Installation-free, Pre-configured
MIT License
788 stars 29 forks source link

How to upgrade nix? #27

Open yajo opened 2 years ago

yajo commented 2 years ago

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.

ShamrockLee commented 2 years ago

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

nomeata commented 2 years ago

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?

ShamrockLee commented 2 years ago

@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.