What nix channel is subscribed to by default - nix

I installed the nix package manager on my machine (macOS 10.12.6 Sierra) several weeks ago.
I want to update mylocal nixpkgs collection to bring it in sync with any upstream updates in the channel. My understanding is that this can be achieved by running: nix-channel --update. However when I run this I get the following output:
unpacking channels...
created 0 symlinks in user environment
Suggesting no expressions were updated in the channels my system is subscribed to. If I run nix-channel --list I don't see any channels listed. What channel is my system subscribed to by default? and should I expect it to be listed?
Is it the case that generally nix-channel --update will only produce local changes if I have modified the channels I'm subscribed to or if I'm subscribed to the unstable channel?

The following might be specific to OSX:
Nix channels are managed on a per-user basis (source). nix-channel --list's output is empty because by default you are not subscribed to any channels - only root is subscribed to nixpkgs-unstable (source).
You can run nix-channel --list as root to see his subscriptions. But
do not run it through sudo (see: https://github.com/NixOS/nix/issues/1548) and
do not use a simple sudo su because it doesn't load /etc/profile (source) and thus will not have the nix env variables set up (variables-setup).
Working example:
user$ nix-channel --list
user$ sudo su -
root# nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable

Your nix-channel --update suggests that you have zero channels in your channel list, not zero packages. You can see your channel configuration with nix-channel --list. You probably need to configure a channel.
The Nix install script currently configures a single channel with the name nixpkgs:
"$nix/bin/nix-channel" --add https://nixos.org/channels/nixpkgs-unstable
So that's the default channel and it should be listed in nix-channel --list after installation, until you nix-channel --remove nixpkgs or rm ~/.nix-channels.
The nix-channel command only updates your Nix expressions. It will not update any package installations. It will only affect future invocations of nix-build, nix-env and everything else that uses $NIX_PATH. (It resembles apt-get update in this respect, or brew update, except nix-channel will not update the installed version of Nix.)

Related

Nixos 22.05 system build fails when referencing channel "file 'nixos-2111' was not found in the Nix search path (add it using $NIX_PATH or -I)"

When running sudo nixos-rebuild --upgrade boot I run into an error of:
error: file 'nixos-2111' was not found in the Nix search path (add it using $NIX_PATH or -I)
at /etc/nixos/chris.nix:30:23:
29| };
30| nixos-2111 = import <nixos-2111> {
| ^
31| config = config.nixpkgs.config;
This only occurred after I updated the nixos channel with sudo nix-channel --add https://nixos.org/channels/nixos-22.05 nixos (for the purpose of upgrading my Nixos system). This config built correctly previously (which is on 20.09).
What might be the cause of this issue? How can I diagnose this further? That channel definitely exists according to:
sudo nix-channel --list
nixos https://nixos.org/channels/nixos-22.05
nixos-2003 https://nixos.org/channels/nixos-20.03
nixos-2111 https://nixos.org/channels/nixos-21.11
nixos2003 https://nixos.org/channels/nixos-20.03
nixos2009 https://nixos.org/channels/nixos-20.09
unstable https://nixos.org/channels/nixpkgs-unstable
And:
nix repl '<nixos-2111>'
Welcome to Nix version 2.3.11. Type :? for help.
Loading '<nixos-2111>'...
Added 15491 variables.
My only suspicion is the new nix version of 2.8 from the prior 2.3.11 - perhaps it uses an different set of channels?
Update: Just removed the references to this channel (and the associated packages), and it built successfully. Which is weird as there were other channels referenced in this exact format so maybe something specifically to do with 21.11...

Centos image build fails when I use rpms via docker

I'm currently working out a Dockerfile. So I am trying to build out a Centos 7.6 base image and I get a failure when I try to use any yum packages. I'm not sure what the cause of this is.
I've already attempted to make the user root to see if that makes a difference but it doesn't help the situation. I've also done a docker pull centos to recieve the latest version of centos.
I simplified the code and still the same error.
FROM centos
ARG MONGO-RAILS-VERSION="0.0"
RUN yum install vim
# curl -L get.rvm.io | bash -s stable \
# rvm install 2.3.1 \
# rvm use 2.3.1 --default \
# gem install rails
I get an error that looks something like this
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
14: curl#7 - "Failed to connect to 2001:1b48:203::4:10: Network is unreachable"
The command '/bin/sh -c yum install vim' returned a non-zero code: 1
You may want to have a look for Set build-time variables (--build-arg):
$ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 --build-arg FTP_PROXY=http://40.50.60.5:4567 .

I changed my nixos channel to unstable, why are my packages still not updated?

How do I update my packages from the nixos-18.09 channel to the nixos-unstable channel? I am trying to do this as I need to use updated versions of some packages.
Following the directions in the nixos manual, I have added the nixos-unstable channel https://nixos.org/channels/nixos-unstable, removed the nixos-18.09 channel https://nixos.org/channels/nixos-18.09,
and run $ nix-channel --update and $ sudo nixos-rebuild switch --upgrade.
Still, however, my installed packages are the old versions. I have also tried $ nix-env -u '*' and still have the old versions. What else do I need to do to update my packages to the nixos-unstable versions?
I am trying to do this as I need to use updated versions of some
packages.
You can use packages from different channels. So possibly keeping your default channel as stable, and just referencing particular packages from the unstable channel might be a better solution.
I have the following import in my config (using google-chrome from the channel I have assigned to unstable):
{ config, pkgs, ... }:
let
unstable = import <unstable> {
config = config.nixpkgs.config;
};
in
{
environment.systemPackages = with pkgs; [
awscli
google-cloud-sdk
kubectl
libreoffice
# ...
unstable.google-chrome
];
}
As to why your packages are not using the unstable channel, probably because they reference the nixos channel which you did not seem to modify (you seemed to only add a channel named nixos-unstable, but nothing referenced this channel name most probably).
To change to the unstable NixOS channel:
Become root; You want to change the root user's Nix channel: su
Remove the NixOS channel: nix-channel --remove nixos
Add the NixOS unstable channel and ensure it's named nixos: nix-channel --add nixos https://nixos.org/channels/nixos-unstable
Then you can upgrade as you normally would. For example, nixos-rebuild --upgrade boot will first update the NixOS channel and then install packages from the updated channel. Upon reboot you'd be updated.
Note: I advise against doing nixos-rebuild --upgrade switch, especially when changing channels, simply because NixOS won't restart all services anyway. Therefore the switch would be incomplete.
If you want to change all the packages to unstable
{ pkgs, ... }#args:
let
pkgsUrl = "https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz";
pkgs = import (builtins.fetchTarball pkgsUrl) {};
in
{...}

How to undo `nix-channel --update`

After clean installation via NixOps, I logined to machine and executed
# nix-channel --update
This pulled ~130Mb of nixpkgs into my /nix/store. How can I undo this?
On a normal Nix or NixOS install, if you've updated your channels by accident with nix-channel --update, you can undo this by running
nix-channel --rollback
See the manual for more details.
On a NixOps installation, channels are configured but not actually used. See the other answer for that.
On a NixOps installation it seems that channels are configured, but aren't actually used by NixOps. This means that running nix-channel --update will create the very first generation, and nix-channel --rollback won't work as that can't roll back past the first generation.
The following seems to work for clearing out this information.
Do not run this on a Nix or NixOS install! This is just for NixOps.
rm /nix/var/nix/profiles/per-user/root/channels-1-link
rm /nix/var/nix/profiles/per-user/root/channels
rm ~/.nix-defexpr/channels
nix-collect-garbage -d

NixOS: Setting the default channel in configuration.nix

How do I set the default channel in NixOS's /etc/configuration.nix?
There is a command to set it and rebuild with
sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable
sudo nixos-rebuild switch -I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs
but I'd like to have it setup in configuration.nix so I don't have to remember how to do this everytime. Thanks!
system.autoUpgrade.channel is what you might be looking for
set it to any channel e.g.
system.autoUpgrade.channel = "https://nixos.org/channels/nixos-16.03-small/";
the documentation says:
by default, this is the channel set using nix-channel (run
nix-channel --list to see the current value)
an up to date list of channels can be found on https://nixos.org/channels/
ref: https://nixos.org/nixos/manual/options.html#opt-system.autoUpgrade.channel
https://nixos.org/nixos/manual/index.html#idm140737317454064
Set nixPath = [ "nixpkgs=http://nixos.org/channels/nixos-unstable/nixexprs.tar.xz" ];, see https://github.com/snabblab/snabblab-nixos/blob/d8b9761b107293891b19021f2f0f77a0e3ba3746/modules/common.nix#L39
The nix.nixPath (ref) option looks like it will do what you're after.
Also the nixos-unstable channel might be more appropriate for you, rather than nixpkgs-unstable. I believe the pkgs in the nixpkgs channel are tested and built for non-nixOS systems, though I can't remember a reference for that at the moment.
nix-channel --add https://nixos.org/channels/nixos-unstable/
nix-channel --update nixos-unstable
# /etc/nixos/configuration.nix
# Put nixos-unstable at the front of nixPath
{ lib, ... }:
{
nix.nixPath = lib.mkDefault (lib.mkBefore [ "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos-unstable" ]);
}
If you want the imperative nix-channel commands in your configuration.nix as well you could write a small systemd service to do so, as shown here.
Edit: To ensure configuration.nix is built from the latest unstable channel just set the value of nixpkgs as in the answer from #iElectric and Nix will use the expressions contained at that URL whenever it evaluates configuration.nix.
PS I realised you could also just point the nixos path to the nixos-unstable channel by doing nix-channel --add https://nixos.org/channels/nixos-unstable/ nixos but I think the first solution is clearer.

Resources