EDIT: Huge caveat - I strongly recommend not mixing stable with unstable on the same system. It’s unsupported and can lead to confusing errors when going to run programs, due to glibc and graphics driver mismatches.
Never set pkgs
directly in the NixOS module system, as the other answers are indicating.
Here’s a couple of concepts you need to know:
- If you want to access some inputs, or some other value across your config without creating an explicit option for it, use
specialArgs
or_module.args
. (For things that youimport
, you must pass them inspecialArgs
specifically to avoid infrec.) - Changing
pkgs
requires an overlay; however, for this application, you may not necessarily need one if you are willing to get away from thepkgs.unstable
syntax specifically.
Which means the following:
-
Add an entry to your
inputs
, and pass them to your config viaspecialArgs
, in yourflake.nix
:inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { nixpkgs, ... }@inputs: nixosConfigurations = { foo = nixpkgs.lib.nixosSystem { #... specialArgs = { inherit inputs; }; }; }; };
-
Since you need an unfree package specifically, allow the unfree package somewhere in your NixOS config:
{ nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "osu-lazer-bin" ]; }
or if you want, you can just blanket allow all unfree packages, that’s up to you:
{ nixpkgs.config.allowUnfree = true; }
-
Then, use that config when importing the unstable nixpkgs, and then use the appropriate module arg in your package list.
a. EITHER create a new module arg:{ config, inputs, pkgs, pkgsUnstable, ... }: { # this allows you to access `pkgsUnstable` anywhere in your config _module.args.pkgsUnstable = import inputs.nixpkgs-unstable { inherit (pkgs.stdenv.hostPlatform) system; inherit (config.nixpkgs) config; }; environment.systemPackages = [ pkgsUnstable.osu-lazer-bin ]; }
b. OR, add an overlay to modify the existing nixpkgs instance (
pkgs
):{ inputs, pkgs, ... }: { nixpkgs.overlays = [ (final: _: { # this allows you to access `pkgs.unstable` anywhere in your config unstable = import inputs.nixpkgs-unstable { inherit (final.stdenv.hostPlatform) system; inherit (final) config; }; }) ]; environment.systemPackages = [ pkgs.unstable.osu-lazer-bin ]; }
I’m personally against 3b, because an overlay for this is completely unnecessary and will likely slow down eval.
PS this has got to be one of the most-asked questions, it’s silly that we are still having to rewrite the answers from scratch in 2024…