Unfree software: Difference between revisions

From NixOS Wiki
Klinger (talk | contribs)
Tags: Mobile edit Mobile web edit
Frontear (talk | contribs)
rewrite this page with better formatting
Line 1: Line 1:
'''Unfree software''', sometimes called '''nonfree software''', is software that cannot be freely modified or distributed. [[Nixpkgs]] provides packages for unfree software, but additional configuration is required before they can be used.
Unfree software refers to software that has restrictive licensing on modification and/or redistribution. These types of software cannot be freely provided or distributed in an official capacity, which means that they are neither built by [[Hydra]], nor as they cached on the official [[Binary Cache|binary cache]]. Despite this, Nixpkgs offers a very large collection of unfree software as derivations, however they cannot be accessed by default unless you opt-in.


== Using unfree packages ==
== Configuring ==
=== Per-package (preferred) ===
This method works for both NixOS system level configuration and [[Home Manager]]:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
=== For NixOS ===
{
[[NixOS]] offers a module that can configure Nixpkgs, which will retroactively change the pkgs across your configuration to use the new settings, including allowing for unfree packages.<syntaxhighlight lang="nixos">
{ config, lib, pkgs, ... }: {
  nixpkgs.config.allowUnfree = true; # Allows all packages that are marked unfree to be built.
 
  environment.systemPackages = with pkgs; [
    steam # No error!
  ];
}
</syntaxhighlight>You may instead configure this on a per-package basis via <code>allowUnfreePredicate</code>.
{{Note|Please note that this function has awkward semantics and occasionally doesn't work as expected. Issues like this should be raised directly in [https://github.com/NixOS/nixpkgs/issues Nixpkgs].}}<syntaxhighlight lang="nixos">
{ config, lib, pkgs, ... }: {
  # Add packages by their "derivation name" here.
  # Find the derivation name from https://search.nixos.org/
   nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
   nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
     "vscode"
     "steam"
   ];
   ];
}
}
</syntaxhighlight>


</nowiki>}}
=== For Nix CLI ===
 
As you may have noticed, the above configuration does not apply globally to your NixOS system (and is not applicable for non-NixOS users). Instead, you can configure Nixpkgs at a user level by writing your configuration in <code>~/.config/nixpkgs/config.nix</code>.
=== For all packages ===
{{Note|This file is ignored using nix3 commands, which internally leverage flakes and/or the flake registry. See Tips and Tricks for an alternative.}}{{file|~/.config/nixpkgs/config.nix|nix|3={
 
This method works for both NixOS system level configuration and [[Home Manager]]:
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  nixpkgs.config.allowUnfree = true;
}
</nowiki>}}
 
=== Command line ===
 
You won't be able to install or search for an unfree package as a user unless you explicitly enable it:
 
{{file|~/.config/nixpkgs/config.nix|nix|<nowiki>
{
   allowUnfree = true;
   allowUnfree = true;
}
<nowiki>}</nowiki>}}You can alternatively set the environment variable <code>NIXPKGS_ALLOW_UNFREE=1</code>, which is automatically picked up by the Nix CLI. For newer nix3 commands, you will need to additionally pass <code>--impure</code>, otherwise the environment variable is ignored.<syntaxhighlight lang="bash">
</nowiki>}}
$ export NIXPKGS_ALLOW_UNFREE=1
 
$ nix-shell -p vscode --command 'code' # nix-legacy
=== Temporarily allowing ===
$ nix run --impure nixpkgs#vscode # nix3
 
For temporary allowing unfree packages, you can use an environment variable:
 
<syntaxhighlight lang="bash">
$ NIXPKGS_ALLOW_UNFREE=1 nix-shell -p vscode
</syntaxhighlight>
</syntaxhighlight>
Note for the new nix3-style commands, you need to pass <code>--impure</code> as well:
<syntaxhighlight lang="bash">
$ NIXPKGS_ALLOW_UNFREE=1 nix run nixpkgs#vscode --impure
</syntaxhighlight>
== Hydra ==
[[Hydra]] does not build unfree software, and unfree software is unavailable in <code>cache.nixos.org</code>.


== See also ==
== See also ==

Revision as of 01:05, 18 October 2024

Unfree software refers to software that has restrictive licensing on modification and/or redistribution. These types of software cannot be freely provided or distributed in an official capacity, which means that they are neither built by Hydra, nor as they cached on the official binary cache. Despite this, Nixpkgs offers a very large collection of unfree software as derivations, however they cannot be accessed by default unless you opt-in.

Configuring

For NixOS

NixOS offers a module that can configure Nixpkgs, which will retroactively change the pkgs across your configuration to use the new settings, including allowing for unfree packages.

{ config, lib, pkgs, ... }: {
  nixpkgs.config.allowUnfree = true; # Allows all packages that are marked unfree to be built.

  environment.systemPackages = with pkgs; [
    steam # No error!
  ];
}

You may instead configure this on a per-package basis via allowUnfreePredicate.

Note: Please note that this function has awkward semantics and occasionally doesn't work as expected. Issues like this should be raised directly in Nixpkgs.
{ config, lib, pkgs, ... }: {
  # Add packages by their "derivation name" here.
  # Find the derivation name from https://search.nixos.org/
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "steam"
  ];
}

For Nix CLI

As you may have noticed, the above configuration does not apply globally to your NixOS system (and is not applicable for non-NixOS users). Instead, you can configure Nixpkgs at a user level by writing your configuration in ~/.config/nixpkgs/config.nix.

Note: This file is ignored using nix3 commands, which internally leverage flakes and/or the flake registry. See Tips and Tricks for an alternative.
~/.config/nixpkgs/config.nix
{
  allowUnfree = true;
}

You can alternatively set the environment variable NIXPKGS_ALLOW_UNFREE=1, which is automatically picked up by the Nix CLI. For newer nix3 commands, you will need to additionally pass --impure, otherwise the environment variable is ignored.

$ export NIXPKGS_ALLOW_UNFREE=1
$ nix-shell -p vscode --command 'code' # nix-legacy
$ nix run --impure nixpkgs#vscode # nix3

See also