Flakes: Difference between revisions

imported>Alyaeanyx
Add instructions to use nonfree software
imported>Malteneuss
Add a NixOS config flake skeleton to show practical example of using two or more channels
Line 385: Line 385:
</syntaxHighlight>
</syntaxHighlight>
should make a package accessible through <syntaxHighlight>pkgs.unstable.package</syntaxHighlight>
should make a package accessible through <syntaxHighlight>pkgs.unstable.package</syntaxHighlight>
For example, a NixOS config flake skeleton could be as follows:
<syntaxHighlight lang=nix>
{
  description = "NixOS configuration with two or more channels";
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-21.11";
    nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
  };
  outputs = { self, nixpkgs, nixpkgs-unstable }:
    let
      overlay-unstable = final: prev: {
        unstable = nixpkgs-unstable.legacyPackages.${prev.system};
      };
    in {
      nixosConfigurations.<hostname> = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          # Overlays-module makes "pkgs.unstable" available in configuration.nix
          ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
          ./configuration.nix
        ];
      };
    };
}
# NixOS configuration.nix, can now use "pkgs.app" or "pkgs.unstable.app"
{ config, pkgs, ... }: {
  environment.systemPackages = [pkgs.firefox pkgs.unstable.chromium];
  # ...
}
</syntaxHighlight>
Same can be done with the NURs, as it already has an ''overlay'' attribute in the flake.nix of the project, you can just add <syntaxHighlight>nixpkgs.overlays = [ nur.overlay ];</syntaxHighlight>
Same can be done with the NURs, as it already has an ''overlay'' attribute in the flake.nix of the project, you can just add <syntaxHighlight>nixpkgs.overlays = [ nur.overlay ];</syntaxHighlight>