### Basic mkFlake Usage Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md A basic example demonstrating the usage of `mkFlake` for configuring flake outputs. This serves as a starting point for more complex configurations. ```nix let lib = inputs.snowfall-lib.mkLib { inherit inputs; src = ./.; # You can optionally place your Snowfall-related files in another # directory. snowfall.root = ./nix; }; in lib.mkFlake { } ``` -------------------------------- ### Example Overlay Structure Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md This shows the resulting structure of overlays created by `create-overlays`. ```nix { default = final: prev: {}; my-example = final: prev: {}; some-overlay = final: prev: {}; } ``` -------------------------------- ### Example Template Structure Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md This illustrates the output structure when creating flake templates. ```nix { another-template = ...; my-template = ...; default = ...; } ``` -------------------------------- ### lib.snowfall.fs.get-nix-files-recursive Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get nix files at a given path, traversing any directories within. ```APIDOC ## lib.snowfall.fs.get-nix-files-recursive ### Description Get nix files at a given path, traversing any directories within. ### Type `Path -> [Path]` ### Usage ```nix get-nix-files "./something" ``` ### Result ```nix [ "./something/a.nix" ] ``` ``` -------------------------------- ### Home-Manager Configuration: Before v3 Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/migration/v3.md Example of Home-Manager package declaration in Snowfall Lib v2. ```nix { # Before home-manager.users.my-user.packages = with pkgs; [ my-package ]; } ``` -------------------------------- ### lib.snowfall.fs.get-nix-files Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get nix files at a given path. ```APIDOC ## lib.snowfall.fs.get-nix-files ### Description Get nix files at a given path. ### Type `Path -> [Path]` ### Usage ```nix get-nix-files "./something" ``` ### Result ```nix [ "./something/a.nix" ] ``` ``` -------------------------------- ### Home-Manager Configuration: After v3 Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/migration/v3.md Example of Home-Manager package declaration in Snowfall Lib v3, using the new `snowfallorg.users` path. ```nix { # After snowfallorg.users.my-user.home.config.packages = with pkgs; [ my-package ]; } ``` -------------------------------- ### lib.snowfall.fs.get-default-nix-files Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get nix files at a given path named "default.nix". ```APIDOC ## lib.snowfall.fs.get-default-nix-files ### Description Get nix files at a given path named "default.nix". ### Type `Path -> [Path]` ### Usage ```nix get-default-nix-files "./something" ``` ### Result ```nix [ "./something/default.nix" ] ``` ``` -------------------------------- ### Configure Flake with System Modules and Special Args Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/systems.md Example of a flake configuration that adds NixOS modules to all systems, a specific module to a host, and sets custom special arguments. ```nix { description = "My Flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; # Add modules to all NixOS systems. systems.modules.nixos = with inputs; [ # my-input.nixosModules.my-module ]; # If you wanted to configure a Darwin (macOS) system. # systems.modules.darwin = with inputs; [ # my-input.darwinModules.my-module # ]; # Add a module to a specific host. systems.hosts.my-host.modules = with inputs; [ # my-input.nixosModules.my-module ]; # Add a custom value to `specialArgs`. systems.hosts.my-host.specialArgs = { my-custom-value = "my-value"; }; }; } ``` -------------------------------- ### lib.snowfall.fs.get-default-nix-files-recursive Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get nix files at a given path named "default.nix", traversing any directories within. ```APIDOC ## lib.snowfall.fs.get-default-nix-files-recursive ### Description Get nix files at a given path named "default.nix", traversing any directories within. ### Type `Path -> [Path]` ### Usage ```nix get-default-nix-files-recursive "./something" ``` ### Result ```nix [ "./something/some-directory/default.nix" ] ``` ``` -------------------------------- ### lib.snowfall.fs.get-files Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get files at a given path. ```APIDOC ## lib.snowfall.fs.get-files ### Description Get files at a given path. ### Type `Path -> [Path]` ### Usage ```nix get-files ./something ``` ### Result ```nix [ "./something/a-file" ] ``` ``` -------------------------------- ### Get Nix Files at Path Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of Nix files (`.nix`) at the specified path. Usage: `get-nix-files "./something"`. ```nix get-nix-files "./something" ``` -------------------------------- ### lib.snowfall.fs.get-directories Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get directories at a given path. ```APIDOC ## lib.snowfall.fs.get-directories ### Description Get directories at a given path. ### Type `Path -> [Path]` ### Usage ```nix get-directories ./something ``` ### Result ```nix [ "./something/a-directory" ] ``` ``` -------------------------------- ### Get Files at Path Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of files located at the specified path. Usage: `get-files ./something`. ```nix get-files ./something ``` -------------------------------- ### lib.snowfall.fs.get-non-default-nix-files Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get nix files at a given path not named "default.nix". ```APIDOC ## lib.snowfall.fs.get-non-default-nix-files ### Description Get nix files at a given path not named "default.nix". ### Type `Path -> [Path]` ### Usage ```nix get-non-default-nix-files "./something" ``` ### Result ```nix [ "./something/a.nix" ] ``` ``` -------------------------------- ### lib.snowfall.fs.get-files-recursive Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get files at a given path, traversing any directories within. ```APIDOC ## lib.snowfall.fs.get-files-recursive ### Description Get files at a given path, traversing any directories within. ### Type `Path -> [Path]` ### Usage ```nix get-files-recursive ./something ``` ### Result ```nix [ "./something/some-directory/a-file" ] ``` ``` -------------------------------- ### Configure Snowfall Lib Options Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/quickstart.md Customize Snowfall Lib's behavior using the `snowfall` attribute within `mkFlake`. This example shows how to set the root directory for Nix files, define a namespace for flake components, and add metadata for tools like Snowfall Frost. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; # Configure Snowfall Lib, all of these settings are optional. snowfall = { # Tell Snowfall Lib to look in the `./nix/` directory for your # Nix files. root = ./nix; # Choose a namespace to use for your flake's packages, library, # and overlays. namespace = "my-namespace"; # Add flake metadata that can be processed by tools like Snowfall Frost. meta = { # A slug to use in documentation when displaying things like file paths. name = "my-awesome-flake"; # A title to show for your flake, typically the name. title = "My Awesome Flake"; }; }; }; } ``` -------------------------------- ### Get Directories at Path Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of directories located at the specified path. Usage: `get-directories ./something`. ```nix get-directories ./something ``` -------------------------------- ### Get Default Nix Files at Path Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of Nix files named `default.nix` at the specified path. Usage: `get-default-nix-files "./something"`. ```nix get-default-nix-files "./something" ``` -------------------------------- ### lib.snowfall.fs.get-file Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get a file path relative to the user's flake. ```APIDOC ## lib.snowfall.fs.get-file ### Description Get a file path relative to the user's flake. ### Type `Path -> Path` ### Usage ```nix get-file "systems" ``` ### Result ```nix "/user-source/systems" ``` ``` -------------------------------- ### lib.snowfall.fs.get-snowfall-file Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get a file path relative to the user's snowfall directory. ```APIDOC ## lib.snowfall.fs.get-snowfall-file ### Description Get a file path relative to the user's snowfall directory. ### Type `Path -> Path` ### Usage ```nix get-snowfall-file "systems" ``` ### Result ```nix "/user-source/snowfall-dir/systems" ``` ``` -------------------------------- ### Get system builder function Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Obtain the system builder function for a given target with `get-system-builder`. This function is used to construct system configurations. ```nix get-system-builder "x86_64-iso" ``` -------------------------------- ### lib.snowfall.fs.get-non-default-nix-files-recursive Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Get nix files at a given path not named "default.nix", traversing any directories within. ```APIDOC ## lib.snowfall.fs.get-non-default-nix-files-recursive ### Description Get nix files at a given path not named "default.nix", traversing any directories within. ### Type `Path -> [Path]` ### Usage ```nix get-non-default-nix-files-recursive "./something" ``` ### Result ```nix [ "./something/some-directory/a.nix" ] ``` ``` -------------------------------- ### Get parent directory path Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves the parent directory of a given file path. ```nix get-parent-directory "/a/b/c" ``` -------------------------------- ### Get metadata for target systems Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Fetch structured metadata for all systems associated with a specific target using `get-target-systems-metadata`. This provides details like system name, path, and target. ```nix get-target-systems-metadata "x86_64-linux" ``` -------------------------------- ### Add Snowfall Lib to Nix Flake Inputs Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/quickstart.md Import Snowfall Lib into your Nix flake by adding it to the `inputs` attribute. Ensure the input name is exactly `snowfall-lib` as required by the library. This example also shows how to correctly follow the `nixpkgs` input. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; # The name "snowfall-lib" is required due to how Snowfall Lib processes your # flake's inputs. snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; # We will handle this in the next section. outputs = inputs: {}; } ``` -------------------------------- ### Get Non-Default Nix Files at Path Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of Nix files not named `default.nix` at the specified path. Usage: `get-non-default-nix-files "./something"`. ```nix get-non-default-nix-files "./something" ``` -------------------------------- ### Get metadata for target homes Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Fetch structured metadata for all homes within a specified directory using `get-target-homes-metadata`. This provides details about each home's system, name, and path. ```nix get-target-homes-metadata ./homes ``` -------------------------------- ### Default Flake Generation Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Generates outputs for all systems, modules, packages, overlays, and shells based on the Flake Structure. This is the basic setup for a Snowfall Lib flake. ```nix { description = "My Flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: # This is an example and in your actual flake you can use `snowfall-lib.mkFlake` # directly unless you explicitly need a feature of `lib`. let lib = inputs.snowfall-lib.mkLib { # You must pass in both your flake's inputs and the root directory of # your flake. inherit inputs; src = ./.; }; in lib.mkFlake { }; } ``` -------------------------------- ### Get Default Nix Files Recursively Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of all Nix files named `default.nix`, including those in subdirectories. Usage: `get-default-nix-files-recursive "./something"`. ```nix get-default-nix-files-recursive "./something" ``` -------------------------------- ### Get flake output for system target Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `get-system-output` to determine the flake output attribute name for a specific system target. This is essential for flake integration. ```nix get-system-output "aarch64-darwin" ``` -------------------------------- ### Create a single system configuration Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `create-system` to define and configure a single system. It takes attributes like the system's path as input. ```nix create-system { path = ./systems/my-system; } ``` -------------------------------- ### Configure User with Home Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/systems.md This snippet shows the basic configuration for a user, including enabling their home directory and setting its path. It demonstrates the primary structure for user configuration in Snowfall Lib. ```nix { snowfallorg.users.my-user = { create = true; admin = false; home = { enable = true; path = "/mnt/home/my-user"; config = {}; }; }; } ``` -------------------------------- ### Create multiple system configurations Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md The `create-systems` function generates configurations for all available systems. It accepts attributes for hosts and modules. ```nix create-systems { hosts.my-host.specialArgs.x = true; modules.nixos = [ my-shared-module ]; } ``` -------------------------------- ### Initialize a Nix Flake Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/quickstart.md Use this command to create a new Nix flake in your current directory if you don't have one already. This sets up the basic structure for a Nix flake. ```bash nix flake init ``` -------------------------------- ### Get file extension Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Extracts the file extension from a given file name. ```nix get-file-extension "my-file.final.txt" ``` -------------------------------- ### Nix File for a Home Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/homes.md Defines the configuration for a new home, providing access to lib, pkgs, inputs, and metadata. ```nix { # Snowfall Lib provides a customized `lib` instance with access to your flake's library # as well as the libraries available from your flake's inputs. lib, # An instance of `pkgs` with your overlays and packages applied is also available. pkgs, # You also have access to your flake's inputs. inputs, # Additional metadata is provided by Snowfall Lib. namespace, # The namespace used for your flake, defaulting to "internal" if not set. home, # The home architecture for this host (eg. `x86_64-linux`). target, # The Snowfall Lib target for this home (eg. `x86_64-home`). format, # A normalized name for the home target (eg. `home`). virtual, # A boolean to determine whether this home is a virtual target using nixos-generators. host, # The host name for this home. # All other arguments come from the home home. config, ... }: { # Your configuration. } ``` -------------------------------- ### Create a single home configuration Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md The `create-home` function is used to define a user's home environment configuration. It requires the path to the home configuration files. ```nix create-home { path = ./homes/my-home; } ``` -------------------------------- ### Applying External Overlays and Modules Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Integrates external overlays and modules from flake inputs into NixOS systems, Darwin systems, and home configurations. Demonstrates how to add overlays and modules to specific systems or all systems. ```nix { description = "My Flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: # This is an example and in your actual flake you can use `snowfall-lib.mkFlake` # directly unless you explicitly need a feature of `lib`. let lib = inputs.snowfall-lib.mkLib { # You must pass in both your flake's inputs and the root directory of # your flake. inherit inputs; src = ./.; }; in lib.mkFlake { # Add overlays for the `nixpkgs` channel. overlays = with inputs; [ # my-inputs.overlays.my-overlay ]; # Add modules to all NixOS systems. systems.modules.nixos = with inputs; [ # my-input.nixosModules.my-module ]; # Add modules to all Darwin systems. systems.modules.darwin = with inputs; [ # my-input.darwinModules.my-module ]; # Add modules to a specific system. systems.hosts.my-host = with inputs; [ # my-input.nixosModules.my-module ]; # Add modules to all homes. homes.modules = with inputs; [ # my-input.homeModules.my-module ]; # Add modules to a specific home. homes.users."my-user@my-host".modules = with inputs; [ # my-input.homeModules.my-module ]; }; } ``` -------------------------------- ### Configure Flake with Homes Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/homes.md Sets up a flake to include Snowfall Lib, add modules to all homes, and configure specific homes with special arguments. ```nix { description = "My Flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; # Add modules to all homes. homes.modules = with inputs; [ # my-input.homeModules.my-module ]; # Add modules to a specific home. homes.users."my-user@my-host".modules = with inputs; [ # my-input.homeModules.my-module ]; # Add modules to a specific home. homes.users."my-user@my-host".specialArgs = { my-custom-value = "my-value"; }; }; } ``` -------------------------------- ### Get file name without extension Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Extracts the file name from a path, excluding its extension. ```nix get-file-name-without-extension ./some-directory/my-file.pdf ``` -------------------------------- ### Create a Library Instance with mkLib Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `mkLib` to generate a library instance for your Nix Flake. You must pass in the flake's inputs and the root directory. Optionally, specify a different directory for Snowfall-related files using `snowfall.root`. ```nix { description = "My Flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: let lib = inputs.snowfall-lib.mkLib { # You must pass in both your flake's inputs and the root directory of # your flake. inherit inputs; src = ./.; # You can optionally place your Snowfall-related files in another # directory. snowfall.root = ./nix; }; in # We'll cover what to do here next. { }; } ``` -------------------------------- ### Create Overlays Builder Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use this to create a flake-utils-plus overlays builder. It takes source, namespace, and extra overlays as arguments. ```nix create-overlays-builder { src = ./my-overlays; namespace = "my-namespace"; extra-overlays = []; } ``` -------------------------------- ### Configure Home-Manager Settings for User Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/systems.md Use the `home.config` option to pass specific configuration settings directly to home-manager for the user. This replaces the need to directly configure `home-manager.users.`. ```nix { snowfallorg.users.my-user = { home = { config = { # Everything in here is home-manager configuration. gtk.theme.package = pkgs.gnome.gnome-themes-extra; home.packages = with pkgs; [ my-package ]; }; }; }; } ``` -------------------------------- ### Create Overlays Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Generates overlays for flake outputs. Configure with source, package sources, namespace, and additional overlays. ```nix create-overlays { ssrc = ./my-overlays; packages-src = ./my-packages; namespace = "my-namespace"; extra-overlays = { my-example = final: prev: {}; }; } ``` -------------------------------- ### Get Files Recursively Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of all files at the specified path, including those in subdirectories. Usage: `get-files-recursive ./something`. ```nix get-files-recursive ./something ``` -------------------------------- ### Create Home Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/homes.md Creates a new directory for a home, following Snowfall Lib's target format. ```bash # Create a directory in the `homes` directory for a new home. This should follow # Snowfall Lib's required home target format to ensure that the correct architecture # and output are used. mkdir -p ./homes/x86_64-linux/user@my-home ``` -------------------------------- ### Check if a system is Linux Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `is-linux` to check if a system string corresponds to a Linux environment. This function helps in platform-specific setups. ```nix is-linux "x86_64-linux" ``` -------------------------------- ### Create multiple home configurations Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `create-homes` to generate configurations for all defined user homes. This function allows specifying user-specific settings and shared modules. ```nix create-homes { users."my-user@my-system".specialArgs.x = true; modules = [ my-shared-module ]; } ``` -------------------------------- ### Get virtual system type Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieve the specific type of a virtual system using `get-virtual-system-type`. This function is useful for identifying the virtualization technology. ```nix get-virtual-system-type "x86_64-iso" ``` -------------------------------- ### Create Overlay Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/overlays.md Use this command to create a new directory for your overlay within the `overlays` directory. ```bash # Create a directory in the `overlays` directory for a new overlay. mkdir -p ./overlays/my-overlay ``` -------------------------------- ### Configure NixPkgs Channels with Snowfall Lib Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/channels.md Use `channels-config` to pass additional configuration directly to NixPkgs when instantiating the package set. This allows for options like `allowUnfree`, `permittedInsecurePackages`, and package-specific configurations. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; # The attribute set specified here will be passed directly to NixPkgs when # instantiating the package set. channels-config = { # Allow unfree packages. allowUnfree = true; # Allow certain insecure packages permittedInsecurePackages = [ "firefox-100.0.0" ]; # Additional configuration for specific packages. config = { # For example, enable smartcard support in Firefox. firefox.smartcardSupport = true; }; }; }; } ``` -------------------------------- ### Create System Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/systems.md Use this command to create a new directory for your system, following the required Snowfall Lib target format. ```bash # Create a directory in the `systems` directory for a new system. This should follow # Snowfall Lib's required system target format to ensure that the correct architecture # and output are used. mkdir -p ./systems/x86_64-linux/my-system ``` -------------------------------- ### Get Non-Default Nix Files Recursively Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a list of all Nix files not named `default.nix`, including those in subdirectories. Usage: `get-non-default-nix-files-recursive "./something"`. ```nix get-non-default-nix-files-recursive "./something" ``` -------------------------------- ### Overlay Arguments: Before v3 Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/migration/v3.md Overlay function signature in Snowfall Lib v2, receiving `my-input`, `channels`, and other arguments. ```nix # Before { my-input, channels, ... }: final: prev: { # ... } ``` -------------------------------- ### Organize Modules for NixOS, Darwin, and Home-Manager Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/migration/v2.md Move existing NixOS modules to `modules/nixos`. Darwin modules should go into `modules/darwin`, and Home-Manager modules into `modules/home-manager`. ```nix inputs.snowfall-lib.mkFlake { # Before: # systems.modules = with inputs; [ # my-input.nixosModules.my-module # ]; # After: systems.modules.nixos = with inputs; [ my-input.nixosModules.my-module ]; systems.modules.darwin = with inputs; [ my-input.darwinModules.my-module ]; } ``` -------------------------------- ### Create system modules for home-manager Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Generate system modules compatible with home-manager integration using `create-home-system-modules`. This function helps in setting up user environments within NixOS. ```nix create-home-system-modules { users."my-user@my-system".specialArgs.x = true; modules = [ my-shared-module ]; } ``` -------------------------------- ### Resolve non-virtual system target Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md The `get-resolved-system-target` function returns the actual system target, resolving any virtual system types. Use this to get the base system for configurations. ```nix get-resolved-system-target "x86_64-iso" ``` -------------------------------- ### Get File Path Relative to Snowfall Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a file path relative to the user's Snowfall directory. Usage: `get-snowfall-file "systems"`. ```nix get-snowfall-file "systems" ``` -------------------------------- ### Snowfall Configuration with Namespace and Meta Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Configures Snowfall Lib functionality and interoperability using the 'snowfall' attribute passed to mkLib. Includes setting a namespace and meta information for the flake. ```nix { description = "My Flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: # This is an example and in your actual flake you can use `snowfall-lib.mkFlake` # directly unless you explicitly need a feature of `lib`. let lib = inputs.snowfall-lib.mkLib { # You must pass in both your flake's inputs and the root directory of # your flake. inherit inputs; src = ./.; snowfall = { namespace = "my-namespace"; meta = { # Your flake's preferred name in the flake registry. name = "my-flake"; # A pretty name for your flake. title = "My Flake"; }; }; }; in lib.mkFlake { }; } ``` -------------------------------- ### Get File Path Relative to User Flake Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Retrieves a file path relative to the user's flake directory. Usage: `get-file "systems"`. ```nix get-file "systems" ``` -------------------------------- ### Create Flake Templates Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use this utility to create flake templates. It accepts source and overrides for template configuration. ```nix create-templates { src = ./my-templates; overrides = { inherit another-template; }; alias = { default = "another-template"; }; } ``` -------------------------------- ### Create Flake Outputs with Snowfall Lib Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/quickstart.md Define your flake's outputs by calling `mkFlake` from Snowfall Lib. Pass your flake's inputs and the source directory to `mkFlake`. This is the core step to enable Snowfall Lib's flake management capabilities. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { # You must provide our flake inputs to Snowfall Lib. inherit inputs; # The `src` must be the root of the flake. See configuration # in the next section for information on how you can move your # Nix files to a separate directory. src = ./.; }; } ``` -------------------------------- ### Define a New Shell with Nix Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/shells.md Define your shell's packages and configurations using Nix. This file is placed at `shells//default.nix`. ```nix { # Snowfall Lib provides a customized `lib` instance with access to your flake's library # as well as the libraries available from your flake's inputs. lib, # You also have access to your flake's inputs. inputs, # The namespace used for your flake, defaulting to "internal" if not set. namespace, # All other arguments come from NixPkgs. You can use `pkgs` to pull shells or helpers # programmatically or you may add the named attributes as arguments here. pkgs, mkShell, ... }: mkShell { # Create your shell packages = with pkgs; [ ]; } ``` -------------------------------- ### Create Module Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/modules.md Use this command to create a new directory for your module within the appropriate modules directory (nixos, darwin, or home). ```bash mkdir -p ./modules/nixos/my-module ``` -------------------------------- ### lib.snowfall.home Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Utilities for managing user home configurations. ```APIDOC ## split-user-and-host ### Description Get the user and host from a combined string. ### Type `String -> Attrs` ### Usage ```nix split-user-and-host "myuser@myhost" ``` ### Result ```nix { user = "myuser"; host = "myhost"; } ``` ``` ```APIDOC ## create-home ### Description Create a home configuration. ### Type `Attrs -> Attrs` ### Usage ```nix create-home { path = ./homes/my-home; } ``` ### Result ```nix ``` ``` ```APIDOC ## create-homes ### Description Create all available home configurations. ### Type `Attrs -> Attrs` ### Usage ```nix create-homes { users."my-user@my-system".specialArgs.x = true; modules = [ my-shared-module ]; } ``` ### Result ```nix { "my-user@my-system" = ; } ``` ``` ```APIDOC ## get-target-homes-metadata ### Description Get structured data about all homes for a given target. ### Type `String -> [Attrs]` ### Usage ```nix get-target-homes-metadata ./homes ``` ### Result ```nix [ { system = "x86_64-linux"; name = "my-home"; path = "/homes/x86_64-linux/my-home";} ] ``` ``` ```APIDOC ## create-home-system-modules ### Description Create system modules for home-manager integration. ### Type `Attrs -> [Module]` ### Usage ```nix create-home-system-modules { users."my-user@my-system".specialArgs.x = true; modules = [ my-shared-module ]; } ``` ### Result ```nix [Module] ``` ``` -------------------------------- ### Create Library Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/library.md Use this command to create a new directory within the `lib` directory for organizing your library methods. ```bash mkdir -p ./lib/my-lib ``` -------------------------------- ### Combine mkLib and mkFlake Calls Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `mkFlake` as a convenience wrapper to combine `mkLib` and `mkFlake` calls into a single, more concise expression. This simplifies flake configuration. ```nix inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; }; ``` -------------------------------- ### lib.snowfall.system Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Utilities for working with system targets. ```APIDOC ## is-darwin ### Description Check whether a named system is macOS. ### Type `String -> Bool` ### Usage ```nix is-darwin "x86_64-linux" ``` ### Result ```nix false ``` ``` ```APIDOC ## is-linux ### Description Check whether a named system is Linux. ### Type `String -> Bool` ### Usage ```nix is-linux "x86_64-linux" ``` ### Result ```nix true ``` ``` ```APIDOC ## is-virtual ### Description Check whether a named system is virtual. ### Type `String -> Bool` ### Usage ```nix is-linux "x86_64-iso" ``` ### Result ```nix true ``` ``` ```APIDOC ## get-virtual-system-type ### Description Get the virtual system type of a system target. ### Type `String -> String` ### Usage ```nix get-virtual-system-type "x86_64-iso" ``` ### Result ```nix "iso" ``` ``` ```APIDOC ## get-inferred-system-name ### Description Get the name of a system based on its file path. ### Type `Path -> String` ### Usage ```nix get-inferred-system-name "/systems/my-system/default.nix" ``` ### Result ```nix "my-system" ``` ``` ```APIDOC ## get-target-systems-metadata ### Description Get structured data about all systems for a given target. ### Type `String -> [Attrs]` ### Usage ```nix get-target-systems-metadata "x86_64-linux" ``` ### Result ```nix [ { target = "x86_64-linux"; name = "my-machine"; path = "/systems/x86_64-linux/my-machine"; } ] ``` ``` ```APIDOC ## get-system-builder ### Description Get the system builder for a given target. ### Type `String -> Function` ### Usage ```nix get-system-builder "x86_64-iso" ``` ### Result ```nix (args: ) ``` ``` ```APIDOC ## get-system-output ### Description Get the flake output attribute for a system target. ### Type `String -> String` ### Usage ```nix get-system-output "aarch64-darwin" ``` ### Result ```nix "darwinConfigurations" ``` ``` ```APIDOC ## get-resolved-system-target ### Description Get the resolved (non-virtual) system target. ### Type `String -> String` ### Usage ```nix get-resolved-system-target "x86_64-iso" ``` ### Result ```nix "x86_64-linux" ``` ``` ```APIDOC ## create-system ### Description Create a system. ### Type `Attrs -> Attrs` ### Usage ```nix create-system { path = ./systems/my-system; } ``` ### Result ```nix ``` ``` ```APIDOC ## create-systems ### Description Create all available systems. ### Type `Attrs -> Attrs` ### Usage ```nix create-systems { hosts.my-host.specialArgs.x = true; modules.nixos = [ my-shared-module ]; } ``` ### Result ```nix { my-host = ; } ``` ``` -------------------------------- ### Create a New Template Directory Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/templates.md Use this command to create a new directory for your custom template within the `templates` directory. Ensure you are in the root of your project. ```bash # Create a directory in the `templates` directory for a new template. mkdir -p ./templates/my-templates ``` -------------------------------- ### System Nix File Structure Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/systems.md This is the basic structure of a Nix file for a system, defining available libraries and inputs. ```nix { # Snowfall Lib provides a customized `lib` instance with access to your flake's library # as well as the libraries available from your flake's inputs. lib, # An instance of `pkgs` with your overlays and packages applied is also available. pkgs, # You also have access to your flake's inputs. inputs, # Additional metadata is provided by Snowfall Lib. namespace, # The namespace used for your flake, defaulting to "internal" if not set. system, # The system architecture for this host (eg. `x86_64-linux`). target, # The Snowfall Lib target for this system (eg. `x86_64-iso`). format, # A normalized name for the system target (eg. `iso`). virtual, # A boolean to determine whether this system is a virtual target using nixos-generators. systems, # An attribute map of your defined hosts. # All other arguments come from the system system. config, ... }: { # Your configuration. } ``` -------------------------------- ### lib.snowfall.overlay.create-overlays-builder Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Creates a flake-utils-plus overlays builder. This utility helps in constructing overlays for flake outputs. ```APIDOC ## `lib.snowfall.overlay.create-overlays-builder` ### Description Creates a flake-utils-plus overlays builder. This utility helps in constructing overlays for flake outputs. ### Type `Attrs -> Attrs -> [(a -> b -> c)]` ### Usage ```nix create-overlays-builder { src = ./my-overlays; namespace = "my-namespace"; extra-overlays = []; } ``` ### Result ```nix (channels: [ ... ]) ``` ``` -------------------------------- ### Create flake output packages Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Use `create-packages` to define and manage packages within a flake. It supports specifying sources, overrides, and aliases for packages. ```nix create-packages { inherit channels; src = ./my-packages; overrides = { inherit another-package; }; alias = { default = "another-package"; }; } ``` -------------------------------- ### Configure Template Description in Flake Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/templates.md Add a description for your new template in your flake's `templates` attribute. This makes the template discoverable and provides users with information about it. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; templates = { my-template.description = "This is my template created with Snowfall Lib!"; }; }; } ``` -------------------------------- ### Overlay Arguments: After v3 Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/migration/v3.md Updated overlay function signature in Snowfall Lib v3, receiving `inputs`, `channels`, and `lib`. ```nix # After { inputs, channels, lib, ... }: let my-input = inputs.my-input; in final: prev: { # ... } ``` -------------------------------- ### Create Flake Output Modules Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Creates flake output modules from a source directory, allowing for overrides and aliases. Usage: `create-modules { src = ./my-modules; overrides = { inherit another-module; }; alias = { default = "another-module" }; }`. ```nix create-modules { src = ./my-modules; overrides = { inherit another-module; }; alias = { default = "another-module" }; } ``` -------------------------------- ### lib.snowfall.module.create-modules Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Create flake output modules. ```APIDOC ## lib.snowfall.module.create-modules ### Description Create flake output modules. ### Type `Attrs -> Attrs` ### Usage ```nix create-modules { src = ./my-modules; overrides = { inherit another-module; }; alias = { default = "another-module" }; } ``` ### Result ```nix { another-module = ...; my-module = ...; default = ...; } ``` ``` -------------------------------- ### Set User Name Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/homes.md Sets the username, which is automatically provided to home-manager's `home.username` option. ```nix { snowfallorg.user.name = "my-user"; } ``` -------------------------------- ### Using Outputs Builder for Generic Outputs Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/guides/lib/generic.md Utilize the 'outputs-builder' from flake-utils-plus to construct flake outputs for each supported system. This method is suitable when you need to define system-specific generic outputs. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; snowfall-lib = { url = "github:snowfallorg/lib"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = inputs: inputs.snowfall-lib.mkFlake { inherit inputs; src = ./.; # The outputs builder receives an attribute set of your available NixPkgs channels. # These are every input that points to a NixPkgs instance (even forks). In this # case, the only channel available in this flake is `channels.nixpkgs`. outputs-builder = channels: { # Outputs in the outputs builder are transformed to support each system. This # entry will be turned into multiple different outputs like `formatter.x86_64-linux.* formatter = channels.nixpkgs.alejandra; }; }; } ``` -------------------------------- ### lib.snowfall.overlay.create-overlays Source: https://github.com/snowfallorg/docs/blob/main/src/content/docs/reference/lib.md Creates overlays to be used for flake outputs. It allows defining custom overlays and merging them with existing ones. ```APIDOC ## `lib.snowfall.overlay.create-overlays` ### Description Creates overlays to be used for flake outputs. It allows defining custom overlays and merging them with existing ones. ### Type `Attrs -> Attrs` ### Usage ```nix create-overlays { src = ./my-overlays; packages-src = ./my-packages; namespace = "my-namespace"; extra-overlays = { my-example = final: prev: {}; }; } ``` ### Result ```nix { default = final: prev: {}; my-example = final: prev: {}; some-overlay = final: prev: {}; } ``` ```