Using home-manager with only home-manager channel

Hi everyone,

I installed Nix with DetSys installer. I saw I don’t follow any channels.

user@raspberrypi:~ $ nix-channel --list

On home-manager manual, it says:

Add the appropriate Home Manager channel. If you are following Nixpkgs master or an unstable channel you can run

$ nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
$ nix-channel --update

and if you follow a Nixpkgs version 23.05 channel you can run

$ nix-channel --add https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz home-manager
$ nix-channel --update

I used the first command. Now I’m following only the home-manager channel:

user@raspberrypi:~ $ nix-channel --list
home-manager https://github.com/nix-community/home-manager/archive/master.tar.gz

It works perfectly so far. Even though I was following no nixpkgs channels before I installed home-manager.

Is there a problem? Can there be problems with updating? Is home-manager separate from nix installation, so was the manual actually talking about the nixpkgs channel I want to follow ‘inside’ the home-manager?

I’ll use Nix only for my user, through home-manager. So I felt no need to follow a nixpkgs channel.

Environment: 64-bit Raspbian Raspberry Pi Zero 2W (aarch64)

Hi
because :

i guess you probably added nixpkgs channel when you installed nix (or maybe in some other way there is a default one)
what is the output of

sudo nix-channel --list

Running nix-channel --list as root, still nothing.

I vaguely remember something about DetSys nix installer not choosing a channel because they want to fasten the transition to flakes…

If this setup works fine, is there anything wrong about it?

as my name says i am a newbie but i think there is no problem

I frankly have no idea how this can work, the very first thing home-manager does is import nixpkgs from your NIX_PATH (which is normally fed by your channels): https://github.com/nix-community/home-manager/blob/8765d4e38aa0be53cdeee26f7386173e6c65618d/home-manager/home-manager.nix#L1

Without it, home-manager simply could not even run. It’s getting nixpkgs from somewhere, and I’m not aware of any other mechanism.

Are you using flakes and have manually written a nixpkgs entry to NIX_PATH or something?

It’s possible the detsys installer does something like that, in which case my main concern is that you have no way to update your software without knowing what exactly it’s doing to achieve this. What is in NIX_PATH?

What is in NIX_PATH ?
Exactly nothing.

aerbil313@raspberrypi ~> echo $NIX_PATH

aerbil313@raspberrypi ~> bash
aerbil313@raspberrypi:~ $ echo $NIX_PATH

aerbil313@raspberrypi:~ $ 
exit
aerbil313@raspberrypi ~> LC_ALL=C nix-shell -p hello

[nix-shell:~]$ echo $NIX_PATH


[nix-shell:~]$ hello
Hello, world!

[nix-shell:~]$
exit
aerbil313@raspberrypi ~ [1]> su -
Password:
Welcome to fish, the friendly interactive shell
root@raspberrypi ~# echo $NIX_PATH

root@raspberrypi ~# bash
root@raspberrypi ~# echo $NIX_PATH

Notice that nix-shell knows where to get hello from. And also, isn’t it odd that while I am in nix-shell, output of echo $NIX_PATH increased from one blank lines to two?

Are you using flakes and have manually written a nixpkgs entry to NIX_PATH or something?

DetSys installer enables flakes by default. No, I didn’t. The system is quite fresh.

What this means is that it writes the flags to enable nix’ experimental flakes feature (and presumably the nix-command feature) into the nix config. It does not mean that you are using flakes to configure your system.

So I looked up the NIX_PATH variable in the manual:

If NIX_PATH is not set at all, Nix will fall back to the following list in impure and unrestricted evaluation mode:

  1. $HOME/.nix-defexpr/channels
  2. nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs
  3. /nix/var/nix/profiles/per-user/root/channels

This means either your user or your root user must have channels, otherwise none of this should work. Perhaps the detsys installer writes a channel to the root channel location without actually registering this in the data structure nix-channel inspects?

Sorry for the late reply.

nixpkgs environment variable does not exist, for both root and user shells.
I couldn’t see any nixpkgs anywhere except nix-defexpr/channels/home-manager/default.nix.

root@raspberrypi ~# /nix/var/nix/profiles/per-user/

root@raspberrypi /n/v/n/p/per-user# ls root/channels/
manifest.nix@

root@raspberrypi /n/v/n/p/per-user# cat root/channels/manifest.nix 
[ ]⏎                                  

user@raspberrypi ~> cat ~/.nix-channels
https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz home-manager

user@raspberrypi ~> ls .nix-defexpr/
channels@  channels_root@

user@raspberrypi ~> ls .nix-defexpr/channels/
home-manager@  manifest.nix@

user@raspberrypi ~> cat .nix-defexpr/channels/manifest.nix 
[ { meta = { }; name = "home-manager-23.05.tar.gz"; out = { outPath = "/nix/store/jhp3nclndsa53lrpgjgm7pkkr3805b2f-home-manager-23.05.tar.gz"; }; outPath = "/nix/store/jhp3nclndsa53lrpgjgm7pkkr3805b2f-home-manager-23.05.tar.gz"; outputs = [ "out" ]; system = "builtin"; type = "derivation"; } ]⏎                                                                                                                                                                                     

user@raspberrypi ~> ls .nix-defexpr/channels/home-manager/
default.nix  docs/  flake.lock  flake.nix  format*  home-manager/  lib/  LICENSE  Makefile  modules/  nix-darwin/  nixos/  overlay.nix  README.md  templates/  tests/  xgettext*

user@raspberrypi ~> ls .nix-defexpr/channels_root/
manifest.nix@

user@raspberrypi ~> cat .nix-defexpr/channels_root/manifest.nix 
[ ]⏎                                                                                                                                                                                                                                          

user@raspberrypi ~> cat .nix-defexpr/channels/home-manager/default.nix 
{ pkgs ? import <nixpkgs> { } }:

rec {
  docs = with import ./docs { inherit pkgs; }; {
    html = manual.html;
    manPages = manPages;
    json = options.json;
    jsonModuleMaintainers = jsonModuleMaintainers; # Unstable, mainly for CI.
  };

  home-manager = pkgs.callPackage ./home-manager { path = toString ./.; };

  install =
    pkgs.callPackage ./home-manager/install.nix { inherit home-manager; };

  nixos = import ./nixos;

  path = ./.;
}
user@raspberrypi ~> cat .nix-defexpr/channels/home-manager/flake.nix
{
  description = "Home Manager for Nix";

  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";

  outputs = { self, nixpkgs, ... }:
    {
      nixosModules = rec {
        home-manager = import ./nixos;
        default = home-manager;
      };
      # deprecated in Nix 2.8
      nixosModule = self.nixosModules.default;

      darwinModules = rec {
        home-manager = import ./nix-darwin;
        default = home-manager;
      };
      # unofficial; deprecated in Nix 2.8
      darwinModule = self.darwinModules.default;

      templates = {
        standalone = {
          path = ./templates/standalone;
          description = "Standalone setup";
        };
        nixos = {
          path = ./templates/nixos;
          description = "Home Manager as a NixOS module,";
        };
        nix-darwin = {
          path = ./templates/nix-darwin;
          description = "Home Manager as a nix-darwin module,";
        };
      };

      defaultTemplate = self.templates.standalone;

      lib = {
        hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm;
        homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib
          , extraSpecialArgs ? { }, check ? true
            # Deprecated:
          , configuration ? null, extraModules ? null, stateVersion ? null
          , username ? null, homeDirectory ? null, system ? null }@args:
          let
            msgForRemovedArg = ''
              The 'homeManagerConfiguration' arguments

                - 'configuration',
                - 'username',
                - 'homeDirectory'
                - 'stateVersion',
                - 'extraModules', and
                - 'system'

              have been removed. Instead use the arguments 'pkgs' and
              'modules'. See the 22.11 release notes for more: https://nix-community.github.io/home-manager/release-notes.html#sec-release-22.11-highlights 
            '';

            throwForRemovedArgs = v:
              let
                used = builtins.filter (n: (args.${n} or null) != null) [
                  "configuration"
                  "username"
                  "homeDirectory"
                  "stateVersion"
                  "extraModules"
                  "system"
                ];
                msg = msgForRemovedArg + ''


                  Deprecated args passed: ''
                  + builtins.concatStringsSep " " used;
              in lib.throwIf (used != [ ]) msg v;

          in throwForRemovedArgs (import ./modules {
            inherit pkgs lib check extraSpecialArgs;
            configuration = { ... }: {
              imports = modules
                ++ [{ programs.home-manager.path = toString ./.; }];
              nixpkgs = { inherit (pkgs) config overlays; };
            };
          });
      };
    } // (let
      forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
    in {
      devShells = forAllSystems (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
          tests = import ./tests { inherit pkgs; };
        in tests.run);

      packages = forAllSystems (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
          docs = import ./docs { inherit pkgs; };
          hmPkg = pkgs.callPackage ./home-manager { path = toString ./.; };
        in {
          default = hmPkg;
          home-manager = hmPkg;

          docs-html = docs.manual.html;
          docs-json = docs.options.json;
          docs-manpages = docs.manPages;
        });

      defaultPackage = forAllSystems (system: self.packages.${system}.default);
    });
}

edited to put a new line before new shell prompt.

Can you, in nix repl, try:

nix-repl> <nixpkgs>

That will give you the path your system is grabbing nixpkgs from, at which point we at least know that your system in fact has a definition for nixpkgs somewhere. You can also check the .version file in the repo to see the major version.

For reference, having unset my NIX_PATH (I don’t use channels), I get:

error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «string»:1:1:

            1| <nixpkgs>
             | ^

I’m sorry for the very late reply. Yes,
nix-repl> <nixpkgs>
gives me a path in nix store.

Since my last reply time has passed and I no longer need the system in question. However for any future visitors I found this thread (while searching for another thing) which may be helpful: No Nix Channels listed with nix-channel when installing on MacOS · Issue #3595 · NixOS/nix · GitHub

That’s the thing, you tried that:

And your <nixpkgs> actually works, despite there being no channels or any other reference to a nixpkgs anywhere nix would care to find it.

Shame we won’t get to the bottom of this, it’s a fascinating problem.

I also have a similar config. I think the answer to this riddle is that /etc/nix.conf contains extra-nix-path = nixpkgs=flake:nixpkgs.