Error with install non-free packages

I’m new to NixOS, but I love it (I came from Arch, where I always have problems with packages from the AUR).
I wanted to install the following fonts:

nix profile add nixpkgs#vista-fonts
and
nix profile add nixpkgs#corefonts

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
    ];
  #aggiunte voci 
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
  # nixpkgs.config.allowUnfree = true;
  # Bootloader.
  boot.loader.grub.enable = true;
  boot.loader.grub.device = "/dev/sdb";
  #  boot.loader.grub.useOSProber = true;

  # Use latest kernel.
  boot.kernelPackages = pkgs.linuxPackages_latest;

  networking.hostName = "z800"; # 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 = "Europe/Rome";

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

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

  # Enable the X11 windowing system.
  # You can disable this if you're only using the Wayland session.
  # services.xserver.enable = true;

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

  # Configure keymap in X11
  services.xserver.xkb = {
    layout = "it";
    variant = "winkeys";
  };

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

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

  # Enable sound with pipewire.
  services.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;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.utente = {
    isNormalUser = true;
    description = "utente";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      kdePackages.kate
    #  thunderbird
    ];
  };

  # Install firefox.
  # programs.firefox.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; [
  #  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:

  # 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 = "25.11"; # Did you read the comment?

}

but they cause the same error:

error:
       … in the condition of the assert statement
         at /nix/store/wzcf74b2g5c3qfg4rcswcz28ngiwzzp0-source/lib/customisation.nix:447:9:
          446|       drvPath =
          447|         assert condition;
             |         ^
          448|         drv.drvPath;

       … while evaluating the attribute 'handled'
         at /nix/store/wzcf74b2g5c3qfg4rcswcz28ngiwzzp0-source/pkgs/stdenv/generic/check-meta.nix:745:9:
          744|         valid = "no";
          745|         handled = handled;
             |         ^
          746|       };

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

       error: Package ‘corefonts-1’ in /nix/store/wzcf74b2g5c3qfg4rcswcz28ngiwzzp0-source/pkgs/by-name/co/corefonts/package.nix:146 has an unfree license (‘unfreeRedistributable’), refusing to evaluate.

       a) To temporarily allow unfree packages, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNFREE=1

          Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnfree = true; }
       in configuration.nix to override this.

       Alternatively you can configure a predicate to allow specific packages:
         { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "corefonts"
           ];
         }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnfree = true; }
       to ~/.config/nixpkgs/config.nix.

What did I forget and/or not do correctly?

Is there a reason you try to add the fonts to your profile instead of using the respective module options to add fonts?

I assume that you want to have them available for your system and thus you likely want to use the font module options around fonts.packages, and then allow unfree packages (either all of them or just the one you explicitly install) by setting nixpkgs.config.allowUnfree* (so either by predicate or all)

In nixos you mostly never want to use imperative management of packages.

1 Like

No, there’s no specific reason.
I’ve only been learning about nixOS for a few days.
But what’s the best solution for package management?

Declaration via configuration.nix.

Ditch everything you read about nix profile or nix-env -i those are most of the time not what you want and will break your things at some point.

For non global stuff (e.G development shells) use shell.nix and friends (recommend to use those with nix-direnv)

I’m still trying to understand the difference between modules and flakes and how to manage configuration flakes in my home folder.
But where do I find the module and how do I install it or where do I put it?

When possible, stick to declaring all your packages in your config for now. Profile items are useful but only when you know exactly why you want that.

You can manage your home configs with nix, but that’s not a default option in nixos and other tools exist for that. You can use them, like Home-Manager or Hjem or Nix-Maid. But also classically managed tools like Chezmoi and Stow among others work as normally.

Nix home tools can install packages, classic ones cannot, tho.

For your fonts though,

Add them to the option:

fonts.packages = with pkgs; [
  vista-fonts
  # etc etc
];

As that’ll properly install them into your system.

1 Like

Flakes are just code around a nixosSystem call and other possible “outputs” (packages, modules, …). In addition it gives input pinning by default.

As flakes are an experimental feature (those flags are there for reason), I am not sure if you want to start your journey with those experimental things right away, when in early learning phase.

If there is a feature of it that you want to use, feel free to do so (btw I am using flakes too), but might be worth to just start on the bare stable feature set.

nixosModules on the other hand are those things that you use in a configuration.nix (or friends when using flakes). A nixosModule can either define values for other modules or at some point generate some text files (like configs), symlinks or other parts that define your system.

I hope that helps a bit in understanding the differences on all those things. I know that the learning curve is very hard and likely most will never master everything (I am also learning every day new stuff)

2 Likes