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:
- NixOS configurations specify a NixOS operating system.
- NixOS generates specify a NixOS generate, typically a NixOS image.
- NixOS modules specify NixOS settings.
- Home Manager configurations specify Home Manager settings for a specific user.
- Home Manager modules specify Home Manager settings.
- Darwin configurations specify nix-darwin systems for use with macOS.
- Darwin modules specify nix-darwin modules specify Darwin settings.
- Home Manager provides functionality for user-specific configuration.
- nix-darwin provides Nix modules for macOS.
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.
- Create the configuration unit to import in the flake to be imported from.
In the example below this is theuser-alpha
NixOS module in the flakemynixos/my-user-configs
. - Create a released version of the flake which is imported from.
In the example below this is themynixos/my-user-configs
flake. - Create the configuration unit to import into in a second flake.
In the example below this is thenixos
NixOS configuration in themynixos/my-os-configs
flake. - Navigate to the configuration unit to import from.
In the example below this is themynixos-my-user-configs
flake. - 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 themynixos/my-os-configs
flake selected in the upper right corner. - 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 theuser-alpha
NixOS module in the first image, selecting thenixos
target configuration unit in themynixos/my-os-configs
flake.
- The configuration units must be compatible as described in "Allowed imports".
- The flake being imported from must be released prior to creating the import.