Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to upgrade nix? #27

Open
yajo opened this issue Jan 12, 2022 · 3 comments
Open

How to upgrade nix? #27

yajo opened this issue Jan 12, 2022 · 3 comments

Comments

@yajo
Copy link

yajo commented Jan 12, 2022

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
Copy link
Contributor

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

@nomeata
Copy link

nomeata commented Mar 8, 2022

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
Copy link
Contributor

ShamrockLee commented Apr 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants