New user here, can anyone look at my configuration.nix weird error

Hey guys I’m new to Nix and was trying out my first system setup but ran into some weird errors beyond my skills. Here’s my 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’).

{ config, pkgs, ... }:

{
  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 = "Spellbook"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # 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 = "America/Los_Angeles";

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

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "en_US.UTF-8";
    LC_IDENTIFICATION = "en_US.UTF-8";
    LC_MEASUREMENT = "en_US.UTF-8";
    LC_MONETARY = "en_US.UTF-8";
    LC_NAME = "en_US.UTF-8";
    LC_NUMERIC = "en_US.UTF-8";
    LC_PAPER = "en_US.UTF-8";
    LC_TELEPHONE = "en_US.UTF-8";
    LC_TIME = "en_US.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.plasma5.enable = true;

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

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

  # Enable sound with pipewire.
  sound.enable = true;
  hardware.pulseaudio.enable = false;
  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;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  services.xserver.libinput.enable = true;
  
  hardware.nvidia = {
    modesetting.enable = true;
    nvidiaSettings = true;
    open = false;
    powerManagement = {
        enable = true;
        #finegrained = true;
      };
    prime = {  
      offload.enable = true;   
      intelBusId = "PCI:0:2:0"; 
      nvidiaBusId = "PCI:1:0:0";       
    }; 
  };

  services.xserver.videoDrivers = ["nvidia"];

  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  programs.steam = {
    enable = true;
    remotePlay.openFirewall = true; # Open ports in the firewall for Steam Remote Play
    dedicatedServer.openFirewall = true; # Open ports in the firewall for Source Dedicated Server
  };

  boot.extraModulePackages = [
    config.boot.kernelPackages.r8168
  ];  
  
  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.kamek = {
    isNormalUser = true;
    description = "kamek";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      nixos.betterbird
      microsoft-edge-stable
      sublimetext
      nixos.git
      nixos.ripcord
      nixos.vscode
      #mercury
      #thunderbird
    ];
  };

  programs.fish.enable = true;

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    nixos.helix
    vim
    neovim
    wget
    curl
    nixos.git
    silver-searcher
    fishPlugins.fzf-fish
    nixos.nextdns
  #  vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #  wget
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:
  services.fstrim.enable = true;
  # 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 = true;

  # 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?
}

When I try to nixos-rebuild switch I get:

error:
       … while calling the 'head' builtin

         at /nix/store/rgn0yj6h0n6vxzlzxyw856y11vgps9f0-nixos/nixos/lib/attrsets.nix:850:11:

          849|         || pred here (elemAt values 1) (head values) then
          850|           head values
             |           ^
          851|         else

       … while evaluating the attribute 'value'

         at /nix/store/rgn0yj6h0n6vxzlzxyw856y11vgps9f0-nixos/nixos/lib/modules.nix:807:9:

          806|     in warnDeprecation opt //
          807|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          808|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: value is a function while a set was expected

What am I doing wrong here? I cobbled it together from stuff I found around the net for nvidia prime and such. Edit: the trace is quite long but if needed I can post it.

Yeah, these are always a bit of a pain. One or more of the configuration options you set does not have the correct type for whatever it’s supposed to be.

Apparently getting a nicer error message would require writing a SAT solver because nix doesn’t currently expose enough metadata to the language itself (and nixpkgs is written in nix and therefore has no lower level access to what nix is doing), so this is what we’re stuck with - or at least that’s how I understood the last discussion on why these errors are so bad.

What’s wrong can be hard to see at a glance if you make lots of changes in one go, usually easier to know where the culprit is if the last change you made caused the error. So to avoid things like this, I advise not writing full system configurations without incrementally testing them. Language servers like nil or nixd can help spot these things right in your editor so you don’t even need to try and evaluate it manually.

That said, knowing how to avoid an issue doesn’t help if you already have it.

In this case, I’m going to guess it’s all the nixos.<something> packages:

Specifically, nixos.betterbird, nixos.git, nixos.ripcord and nixos.vscode. You have similar things elsewhere, too.

You don’t have any weird overlays that would create a nixos attribute in pkgs, so this is something in nixpkgs by default.

Can’t say I’ve touched it myself before, but here’s the definition if you’re curious. It basically seems to just give you the result of import <nixpkgs> { }, to be used as a dependency when people define spicy packages that want to contain a NixOS (e.g. some virtual machine thing). Definitely not to include in your package list :wink:

So, pkgs.nixos is a function then, and you’re trying to access the betterbird attribute (among others) of it. Since functions aren’t sets, nix sees that the type is wrong (since . can only be used on sets), and you get the error you’re seeing.

Just remove all the nixos. from your package lists and you should be good to go.

Where did you get the idea you needed that in the first place?

1 Like

Was just trying to get everything I regularly use installed was all. Did some searches on the packages and it seemed right to me lol. I’ll cut it back and do stuff line by line then and see where it’s at. Should I install all that stuff in my user.pkgs? Or should I do it the other way after the system is booted up and install it I think it was with nix-shell I was reading. Anyway thanks for quick response, a bit too much hubris on my part thinking I’d just do a config all at once. The Nvidia prime stuff looks all good though? That’s the main deal, the rest I’d assume I could install from a bin or Deb type thing later if I have to.

I think the issue isn’t the packages you want to install, but the way you’re trying to install them. There’s no nixos.git package, for example, it’s called just git. In case of git it’s even better to use options (this is my config, adjust to your needs):

  programs.git = {
    enable = true;
    config = {
      user.name = "Your Name";
      user.email = "your@email.tld";
      credential.helper = "cache --timeout=86400";
    };
    lfs.enable = true;
  };

Instead of nixos.ripcord use ripcord, instead of nixos.vscode use vscode etc., basically just lose the nixos prefix for package names.

1 Like

Sorry, my bad, I probably overexplained that. @Rikudou is right, I think you only need to make these exact changes:

--- configuration.nix
+++ configuration.nix
@@ -117,12 +117,12 @@
     description = "kamek";
     extraGroups = [ "networkmanager" "wheel" ];
     packages = with pkgs; [
-      nixos.betterbird
+      betterbird
       microsoft-edge-stable
       sublimetext
-      nixos.git
-      nixos.ripcord
-      nixos.vscode
+      git
+      ripcord
+      vscode
       #mercury
       #thunderbird
     ];
@@ -136,15 +136,15 @@
   # List packages installed in system profile. To search, run:
   # $ nix search wget
   environment.systemPackages = with pkgs; [
-    nixos.helix
+    helix
     vim
     neovim
     wget
     curl
-    nixos.git
+    git
     silver-searcher
     fishPlugins.fzf-fish
-    nixos.nextdns
+    nextdns
   #  vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
   #  wget
   ];

I don’t quite understand how you got the idea that betterbird is referred to as nixos.betterbird. If you could point it out, maybe we can help fix whatever guide suggests this.

I would recommend installing most things through user.pkgs or environment.systemPackages for now (or using options like programs.git.enable as @Rikudou suggests).

nix-shell is awesome, but should only be used for packages you intend to use temporarily, and want to uninstall immediately after you stop using your terminal.

At a glance, yes, but I don’t know your hardware so who knows if your bus IDs are correct, or the particular driver version, or whether your card even supports prime. You’ll find out if you try to boot!

Actually, it’s quite tricky to install precompiled software on NixOS due to how it manages shared libraries and glibc among other things. I’d recommend using the nix package manager (and configuration.nix) as much as possible, especially when you’re still new to the distro.

1 Like

Thanks guys, that got it everything is good. I have to say the community here seems really good, and the forum is really well designed. Is this forum done with nix? Like the server bits or templating or anything?

1 Like

I’m pretty sure this is deployed with nix.

if you want to deploy a ‘service’ , then you first port of call is .
https://search.nixos.org/options?query=discourse

you can then see if there a service module to deploy your service.

if you can’t figure out how to get running there are more ports of call

you scan github or sourcegraph and see if anyone has deployed this service…

the third port of call is something caled a nixos test, these are full end to end intergration tests…

lets see if discourse has one.

it does, from there you can see the test setups a server and a client. from this you’ll be able to piece together how to deploy the services from these tests.

Nixos has many of these full end to end intergrations tests… it’s basically the ‘hidden’ bit of nix that often gets overlooked by new users… …and they are great source of ‘documentation’.

maybe have a play deploying and eaiser service first, like a web server, and see how you go.

the open source way is ‘use the source luke’… for nix open devops it’s ‘use the tests luke’

Welcome, and may the nix be with you…Always.

1 Like

AIUI https://flyingcircus.io/ donate the infrastructure that this discourse runs on (though this may have changed, I’m not in the foundation so I only know about chatter that reaches us here), and they as a company basically host stuff on NixOS for you, so I’d assume the discourse instance is running on NixOS.

That said, the actual web server (i.e. “templating or anything”) is https://www.discourse.org/, which is some ruby-on-rails thing afaik. It’s used by a handful of FOSS projects, recently even gnome adopted it afaik. nix isn’t really used to build applications (and hopefully never will be, it’s not designed to be a general-purpose lang).

1 Like

Wow. There is quite a bit to this nix stuff. Using garuda-nixos-subsystem right now, it’s awesome. My first idea was to try to replicate my previous garuda linux system config but the author has already done it for me. Ok I gotta go read. Thanks guys.