Option ...program.<package> does not exist even when in home.packages

Hello guys, I’m quite new to NixOS, I’m still adapting to the NixOS way.
Recently I installed a new package via home manager. Also I wanted to configure the program but to me it seems, that it cannot find the packages installed via home.nix configuration.

I couldn’t find any information online, the examples only configure packages installed in configuration.nix and not those from home.nix
Please help me

On rebuild I get the following error:
The option `home-manager.users.aschulz.programs.nh' does not exist.

home.nix

{
  config,
  pkgs,
  ...
}: {
  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "aschulz";
  home.homeDirectory = "/home/aschulz";

  # This value determines the Home Manager release that your configuration is
  # compatible with. This helps avoid breakage when a new Home Manager release
  # introduces backwards incompatible changes.
  #
  # You should not change this value, even if you update Home Manager. If you do
  # want to update the value, then make sure to first check the Home Manager
  # release notes.
  home.stateVersion = "23.11"; # Please read the comment before changing.

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = with pkgs; [
    # Utils
    firefox
    chromium
    thunderbird
    libreoffice
    
    # ...
    # Shell/Bash/Zsh
    nh
    thefuck
    zoxide
    bat
  ];

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
# ...
  };

  # Home Manager can also manage your environment variables through
  # 'home.sessionVariables'. 
  home.sessionVariables = {
    # EDITOR = "emacs";
  };

  home.sessionPath = [
    "$HOME/.local/bin"
  ];
  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;

  programs.zsh = {
    enable = true;
    enableCompletion = true;
    enableAutosuggestions = true;
    syntaxHighlighting.enable = true;
    shellAliases = {
      ll = "ls -l";
      vim = "nvim";
      shell = "nix-shell";
    };
    history.size = 10000;
    history.path = "${config.xdg.dataHome}/zsh/history";
    oh-my-zsh = {
      enable = true;
      plugins = ["git" "thefuck"];
      theme = "robbyrussell";
    };
    initExtra = "eval \"$(zoxide init zsh)\"";
  };
  programs.bash = {
    enable = true;
    shellAliases = {
      vim = "nvim";
    };
  };

  programs.git = {
    enable = true;
    userName = "";
    userEmail = "";
  };

  programs.nh = {
    enable = true;
    clean.enable = true;
    clean.extraArgs = "--keep-since 4d --keep 3";
    flake = "/home/aschulz/nixos";
  };

  programs.neovim = {
    enable = true;
    defaultEditor = true;
    extraPackages = with pkgs; [
      gcc
    ];
  };
}

configuration.nix

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{
  lib,
  config,
  pkgs,
  inputs,
  ...
}: {
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "nixos"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  nix.settings.experimental-features = ["nix-command" "flakes"];
  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

  # Set your time zone.
  # time.timeZone = "Europe/Berlin";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "de_DE.UTF-8";
    LC_IDENTIFICATION = "de_DE.UTF-8";
    LC_MEASUREMENT = "de_DE.UTF-8";
    LC_MONETARY = "de_DE.UTF-8";
    LC_NAME = "de_DE.UTF-8";
    LC_NUMERIC = "de_DE.UTF-8";
    LC_PAPER = "de_DE.UTF-8";
    LC_TELEPHONE = "de_DE.UTF-8";
    LC_TIME = "de_DE.UTF-8";
  };

  # Enable the X11 windowing system.
  services.xserver.enable = true;

  # Enable the KDE Plasma Desktop Environment.
  services.xserver.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma6.enable = true;

  # Configure keymap in X11
  services.xserver = {
    layout = "de";
    xkbVariant = "";
  };

  # Configure console keymap
  console.keyMap = "de";

  # Enable CUPS to print documents.
  services.printing.enable = true;

  # Enable sound with pipewire.
  sound.enable = true;
  hardware.pulseaudio.enable = false;
  hardware.bluetooth.enable = true; # enables support for Bluetooth
  hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  services.automatic-timezoned.enable = true;
  time.hardwareClockInLocalTime = true;
  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Enable docker
  virtualisation.docker.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.aschulz = {
    isNormalUser = true;
    description = "";
    extraGroups = ["networkmanager" "wheel" "docker"];
  };

  users.defaultUserShell = pkgs.zsh;
  home-manager = {
    # also pass inputs to home-manager modules
    extraSpecialArgs = {inherit inputs;};
    users = {
      "aschulz" = import ./home.nix;
    };
    useGlobalPkgs = true;
    useUserPackages = true;
  };

  # Allow unfree packages
  #  nixpkgs.config.allowUnfree = true;
  nixpkgs.config.allowUnfreePredicate = pkg:
    builtins.elem (lib.getName pkg) [
      # Add additional package names here
      "obsidian"
      "vscode"
      "jetbrains-toolbox"
      "spotify"
      "discord"
    ];

  # To allow packages to be installed even when they are marked as insecure.
  #  nixpkgs.config.permittedInsecurePackages = ["adobe-reader-9.5.5"];
  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    libnotify
    git
    neovim
    usbutils
    alejandra
    zsh
    oh-my-zsh
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  programs.zsh.enable = true;

  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "23.11"; # Did you read the comment?
}

flake.nix

{
  description = "Nixos config flake";

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

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in
    {
    
      nixosConfigurations.default = nixpkgs.lib.nixosSystem {
          specialArgs = {inherit inputs;};
          modules = [ 
            ./hosts/default/configuration.nix
            inputs.home-manager.nixosModules.default
          ];
        };

    };
}

Directory structure:

~/nixos/
├── flake.lock
├── flake.nix
└── hosts
    └── default
        ├── configuration.nix
        ├── hardware-configuration.nix
        ├── home.nix

Hello and welcome to Nix/NixOS, @a-schulz !

You get the error because nh isn’t part of Home Manager. You can check Appendix A of the Home Manager Manual for available options. It is included in the unstable branch of Nixpkgs though.

So, remove

 programs.nh = {
    enable = true;
    clean.enable = true;
    clean.extraArgs = "--keep-since 4d --keep 3";
    flake = "/home/aschulz/nixos";
  };

from your home.nix file and add it to your configuration.nix. You also don’t need to add nh to home.packages, options like programs.<appName>.enable take care of installing the necessary packages. That should solve the issue you’re facing.

1 Like

Thanks for your quick response. Tried it out but I still get the same error. Do I need to change something in my flake to enable unstable options?
When i add nh to the systemPackages it is installed correctly but the option programs.nh.enable = true; is not working. Without this, I’m also unable to configure the package correctly.

Hm, strange. First of all, if you do programs.nh.enable = true; then you don’t need to add it anywhere else, adding it to environment.systemPackages is redundant.

No, that’s not necessary since you’re on unstable already: in your flake.nix there’s inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; .

Now, just to be sure, when you say the error is the same, then you mean literally

The option `home-manager.users.aschulz.programs.nh’ does not exist.

right? Did you completely remove

 programs.nh = {
    enable = true;
    clean.enable = true;
    clean.extraArgs = "--keep-since 4d --keep 3";
    flake = "/home/aschulz/nixos";
  };

from home.nix and only include it in configuration.nix?

1 Like

Adding the package to the systemPackages was just the test for me, that the package can be found and installed. And it is installed correctly. I will remove it after the option-method works.

This is the concrete error message.

error: The option `programs.nh' does not exist. Definition values:
       - In `/nix/store/41ns8l9yrl9h6ma8bswmgcgv3p4gby1v-source/hosts/default/configuration.nix':
           {
             enable = true;
           }

configuration.nix

{
  lib,
  config,
  pkgs,
  inputs,
  ...
}: {
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "nixos"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  nix.settings.experimental-features = ["nix-command" "flakes"];
  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

  # Set your time zone.
  # time.timeZone = "Europe/Berlin";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "de_DE.UTF-8";
    LC_IDENTIFICATION = "de_DE.UTF-8";
    LC_MEASUREMENT = "de_DE.UTF-8";
    LC_MONETARY = "de_DE.UTF-8";
    LC_NAME = "de_DE.UTF-8";
    LC_NUMERIC = "de_DE.UTF-8";
    LC_PAPER = "de_DE.UTF-8";
    LC_TELEPHONE = "de_DE.UTF-8";
    LC_TIME = "de_DE.UTF-8";
  };

  # Enable the X11 windowing system.
  services.xserver.enable = true;

  # Enable the KDE Plasma Desktop Environment.
  services.xserver.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma6.enable = true;

  # Configure keymap in X11
  services.xserver = {
    layout = "de";
    xkbVariant = "";
  };

  # Configure console keymap
  console.keyMap = "de";

  # Enable CUPS to print documents.
  services.printing.enable = true;

  # Enable sound with pipewire.
  sound.enable = true;
  hardware.pulseaudio.enable = false;
  hardware.bluetooth.enable = true; # enables support for Bluetooth
  hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  services.automatic-timezoned.enable = true;
  time.hardwareClockInLocalTime = true;
  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Enable docker
  virtualisation.docker.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.aschulz = {
    isNormalUser = true;
    description = "";
    extraGroups = ["networkmanager" "wheel" "docker"];
  };

  users.defaultUserShell = pkgs.zsh;
  home-manager = {
    # also pass inputs to home-manager modules
    extraSpecialArgs = {inherit inputs;};
    users = {
      "aschulz" = import ./home.nix;
    };
    useGlobalPkgs = true;
    useUserPackages = true;
  };

  # Allow unfree packages
  #  nixpkgs.config.allowUnfree = true;
  nixpkgs.config.allowUnfreePredicate = pkg:
    builtins.elem (lib.getName pkg) [
      # Add additional package names here
      "obsidian"
      "vscode"
      "jetbrains-toolbox"
      "spotify"
      "discord"
    ];

  # To allow packages to be installed even when they are marked as insecure.
  #  nixpkgs.config.permittedInsecurePackages = ["adobe-reader-9.5.5"];
  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    libnotify
    git
    neovim
    usbutils
    alejandra
    zsh
    oh-my-zsh
    wl-clipboard
    nh
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  programs.zsh.enable = true;
 programs.nh.enable = true;
....

Sorry for the late reply

So, I temporarily switched my Desktop PC to Unstable just to test this and can confirm that programs.nh.enable = true; works as expected.
In a terminal I get:

$ nh --version
nh 3.5.10
$ nh --help
nh is yet another nix helper

Usage: nh [OPTIONS] <COMMAND>

Commands:
  os           NixOS functionality
  home         Home-manager functionality
  search       Searches packages by querying search.nixos.org
  clean        Enhanced nix cleanup
  completions  Generate shell completion files into stdout

Options:
  -v, --verbose  Show debug logs
  -h, --help     Print help
  -V, --version  Print version

Are you sure you’re running unstable NixOS 24.05 (Uakari)?

1 Like

Strange…
I don’t know what else to change/test.

nix-info -m

  • system: "x86_64-linux"
  • host os: Linux 6.6.25, NixOS, 24.05 (Uakari), 24.05.20240406.ff0dbd9
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.18.2
  • channels(root): "home-manager, nixos-23.11"
  • nixpkgs: /nix/store/j10523yhkcc34478azkgcl70yzcx6j2j-source

Just to be sure: to realize your config, inside the directory containing flake.nix, you do

sudo nixos-rebuild boot --flake .

(or switch instead of boot) right?

I’m at a loss here. This line puzzles me:

channels(root): "home-manager, nixos-23.11"

The only explanation I can think of right now is that you try to do sudo nixos-rebuild switch without the --flake . part and Nix tries to realize the config in /etc/nixos/configuration.nix with the nixos-23.11 channel and fails…

1 Like

Sorry for the trouble. Thanks for all your help.

sudo nix-channel --update
nix flake update

This fixed the issue. I guess my version didn’t had the option

Was a tedious debugging but i learned a lot how nixos works searching through all the documentation and forums.

Thank you!!

Aha! Glad you were able to solve the issue! :+1:

1 Like