Imports

Imports is a powerful mechanism to re-use configurations within and between flakes.

Configuration units

NixOS option assignments, or settings, can be used with the following configuration units:

Allowed imports

Configuration units may import other configuration units as follows:

  • NixOS configurations can import NixOS modules and Home Manager configurations.
  • NixOS generates can import NixOS modules and Home Manager configurations.
  • NixOS modules can import other NixOS modules and Home Manager configurations.
  • Home Manager configurations can import Home Manager modules.
  • Home Manager modules can import other Home Manager modules.
  • Darwin configurations can import Darwin modules and Home Manager configurations.
  • Darwin modules can import other Darwin modules and Home Manager configurations.

How to import within a flake

Start by creating a flake and flake output, as described in either Nix development shell, Home Manager configuration, NixOS configuration, or NixOS generate.

After creating two compatible configuration units, an import may be created by hovering the target configuration unit and selecting the "Import" button, shown with an arrow pointing down.

Shown below is an example of a NixOS modules nginx containing settings for the nginx web server. To the left is shown the import menu used to assign an import of the nginx NixOS module into the NixOS configuration nixos. The right image shows the created import.

How to import between flakes

Imports can also be used between compatible configuration units defined in separate flakes.

  1. Create the configuration unit to import in the flake to be imported from.
    In the example below this is the user-alpha NixOS module in the flake mynixos/my-user-configs.
  2. Create a released version of the flake which is imported from.
    In the example below this is the mynixos/my-user-configs flake.
  3. Create the configuration unit to import into in a second flake.
    In the example below this is the nixos NixOS configuration in the mynixos/my-os-configs flake.
  4. Navigate to the configuration unit to import from.
    In the example below this is the mynixos-my-user-configs flake.
  5. Ensure that the flake being imported into is selected in the flake selector to the upper right of the screen.
    In the example below this is the mynixos/my-os-configs flake selected in the upper right corner.
  6. Click the "Export" button on the exporting configuration unit (with the upwards pointing arrow), and select the importing configuration unit.
    In the example below this is the user-alpha NixOS module in the first image, selecting the nixos target configuration unit in the mynixos/my-os-configs flake.

External information