### Static Configuration Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Sets configuration options statically by providing inline values. ```nix # Static - inline attribute set devShell.packages = [ pkgs.hello ]; ``` -------------------------------- ### Dynamic Configuration Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Sets configuration options dynamically by providing a function that receives necessary arguments, such as the package set. ```nix # Dynamic - function receiving packages devShell.packages = pkgs: [ pkgs.hello pkgs.world ]; ``` -------------------------------- ### Complex devShell Configuration Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/devShell-option.md Sets up a comprehensive development shell with Rust tools, external inputs, a custom shell hook, environment variables, disabled hardening, and a specific stdenv. This example demonstrates advanced configuration options. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell = pkgs: { packages = [ pkgs.rustfmt pkgs.cargo pkgs.rust-analyzer ]; inputsFrom = [ pkgs.libssl ]; shellHook = '' echo "Rust development shell loaded" export RUST_LOG=debug ''; env.RUST_BACKTRACE = "1"; hardeningDisable = [ "all" ]; stdenv = pkgs.clangStdenv; }; }; } ``` -------------------------------- ### Module Composition Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelightModules-option.md Demonstrates how Flakelight modules can import and extend other modules, enabling a compositional approach to flake configuration. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { flakelightModules = { base = { /* base module */ }; extensions = { imports = [ ./base.nix ]; config = { /* extended config */ }; }; }; }; } ``` -------------------------------- ### Complete Template-Enabled Flake Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md A comprehensive example of a flake that distributes templates for users, including basic and advanced options. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { # Main project config package = { stdenv }: stdenv.mkDerivation { /* ... */ }; # Distribute templates for users templates = { default = { path = ./templates/basic; description = "Basic project using this framework"; }; advanced = { path = ./templates/advanced; description = "Advanced project with all features"; welcomeText = '' Advanced template initialized. See templates/advanced/README.md for details. ''; }; }; }; } ``` -------------------------------- ### Simple Overlay Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/overlays-option.md Defines a single overlay that renames the 'hello' package to 'myapp' and adds a custom 'version' attribute. This overlay is merged into `overlays.default`. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { overlay = final: prev: { myapp = prev.hello; # Rename hello to myapp version = "1.0"; # Add custom attribute }; }; } ``` -------------------------------- ### Using legacyPackages with nix commands Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Examples of how to use the legacyPackages output with traditional Nix commands like nix-shell and nix-build. ```bash nix-shell -A legacyPackages.x86_64-linux.hello nix-build -A legacyPackages.x86_64-linux.mypackage nix eval .#legacyPackages.x86_64-linux.hello.version ``` -------------------------------- ### Configure C Application with Flakelight Source: https://github.com/nix-community/flakelight/blob/master/README.md Standard flake configuration for a C project using a make setup. ```nix { description = "My C application."; inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { license = "AGPL-3.0-or-later"; package = { stdenv, defaultMeta }: stdenv.mkDerivation { name = "hello-world"; src = ./.; installPhase = '' runHook preInstall make DESTDIR=$out install runHook postInstall ''; meta = defaultMeta; }; devShell.packages = pkgs: with pkgs; [ clang-tools coreutils ]; formatters = { "*.h" = "clang-format -i"; "*.c" = "clang-format -i"; } }; } ``` -------------------------------- ### Template flake.nix Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md A basic `flake.nix` structure required for a template. ```nix { description = "Project created from template"; inputs = { flakelight.url = "github:nix-community/flakelight"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; outputs = { flakelight, ... }: flakelight ./. { # Template-specific configuration }; } ``` -------------------------------- ### Module Autoloading from nix/apps/search.nix Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md An example of a per-app definition in `nix/apps/search.nix` for loading the ripgrep executable. ```nix # nix/apps/search.nix pkgs: "${pkgs.ripgrep}/bin/rg" ``` -------------------------------- ### Formatter Command Syntax Examples Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/formatter-option.md Illustrates different ways to specify formatter commands, including simple commands, commands with options, and full paths to executables. ```nix formatters = { "*.nix" = "nixpkgs-fmt"; # Simple command "*.rs" = "rustfmt --edition 2021"; # Command with options "*.js" = "${pkgs.prettier}/bin/prettier --write"; # Full path }; ``` -------------------------------- ### Convenient Overlay Syntax with withOverlays Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/core-options.md Applies overlays to the Nixpkgs instance using a convenient syntax. This example shows applying multiple overlays and a function-based overlay. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; emacs-overlay.url = "github:nix-community/emacs-overlay"; }; outputs = { flakelight, emacs-overlay, ... }: flakelight ./. { withOverlays = [ emacs-overlay.overlays.default (final: prev: { zig = final.zig_0_12; }) ]; }; } ``` -------------------------------- ### Multiple Overlays Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/overlays-option.md Defines multiple named overlays: `default`, `unstable`, and `experimental`. Each overlay provides its own set of package modifications or additions. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { overlays = { default = final: prev: { customPackage = prev.hello; }; unstable = final: prev: { latestTool = prev.cmake; }; experimental = final: prev: { newFeature = "test"; }; }; }; } ``` -------------------------------- ### Mixed Configuration with nixDir and Inline Options Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixDir-option.md Demonstrates combining inline configuration options with automatic loading from the `nixDir`. This example specifies systems inline and relies on Flakelight to load `package`, `devShell`, and `formatters` from `nix/`. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { systems = [ "x86_64-linux" "aarch64-linux" ]; # package loaded from nix/package.nix # devShell loaded from nix/devShell.nix # formatters loaded from nix/formatters.nix }; } ``` -------------------------------- ### Using Bundlers with `nix bundle` Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Illustrates the command-line usage for bundling a package using a specific bundler. This example shows how to bundle `myapp` using the `appimage` bundler. ```bash nix bundle .#packages.x86_64-linux.myapp --bundler appimage ``` -------------------------------- ### Dynamic Template Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md Example of configuring dynamic templates within `flake.nix`. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { templates = { inputs, ... }: { default = { path = ./templates/basic; description = "Basic template"; welcomeText = "Using ${inputs.flakelight}"; }; }; }; } ``` -------------------------------- ### Basic devShell Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/devShell-option.md Defines a basic development shell with 'hello' and 'coreutils' packages. This configuration creates a `devShells.${system}.default` entry. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell.packages = pkgs: [ pkgs.hello pkgs.coreutils ]; }; } ``` -------------------------------- ### Basic Home Configurations Setup Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixos-home-options.md Defines a basic Home Manager configuration for a user. Specify the system and the path to the user's Home Manager module. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; home-manager.url = "github:nix-community/home-manager/release-23.11"; }; outputs = { flakelight, ... }@inputs: flakelight ./. { homeConfigurations = { "user@hostname" = { system = "x86_64-linux"; modules = [ ./home/user.nix ]; }; }; }; } ``` -------------------------------- ### Default Template Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md Configures a single default template for project initialization. Use `nix flake init -t .` to initialize a project with this default template. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { template = { path = ./templates/default; description = "Default project template"; }; }; } ``` -------------------------------- ### Simple Package Project Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixDir-option.md Example of a simple application project structure and its corresponding `flake.nix`, `nix/package.nix`, and `nix/devShell.nix` files. Flakelight loads configurations from the `nix/` directory by default. ```nix # flake.nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. {}; # No explicit config, loaded from nix/ } # nix/package.nix { stdenv }: stdenv.mkDerivation { pname = "my-app"; version = "1.0.0"; src = ../..; installPhase = "make install"; } # nix/devShell.nix { packages = pkgs: [ pkgs.gcc pkgs.make ]; } ``` -------------------------------- ### DevShell with Input Dependencies from Packages Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/devShell-option.md Integrate existing package definitions into your development shell. This example includes 'myapp' and 'gdb' by referencing 'inputsFrom'. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { package = { stdenv }: stdenv.mkDerivation { pname = "myapp"; version = "1.0.0"; src = ./.; }; devShell = { inputsFrom = pkgs: [ pkgs.myapp ]; packages = pkgs: [ pkgs.gdb ]; }; }; } ``` -------------------------------- ### Simple Formatters Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/formatter-option.md Configure simple formatter commands for specific file patterns. This example sets up `rustfmt` for `.rs` files and `zig fmt` for `.zig` files. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell.packages = pkgs: [ pkgs.rustfmt pkgs.zig ]; formatters = { "*.rs" = "rustfmt"; "*.zig" = "zig fmt"; }; }; } ``` -------------------------------- ### Template .gitignore Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md Common entries for a `.gitignore` file within a template. ```gitignore result .envrc flake.lock ``` -------------------------------- ### Configure default devShell Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Example of configuring the default devShell using a function that takes the package set. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell = pkgs: { # Include build deps of emacs inputsFrom = [ pkgs.emacs ]; # Add coreutils to the shell packages = [ pkgs.coreutils ]; # Add shell hook. Can be a function if you need packages shellHook = '' echo Welcome to example shell! ''; # Set an environment var. `env` can be an be a function env.TEST_VAR = "test value"; stdenv = pkgs.clangStdenv; }; }; } ``` -------------------------------- ### Module Autoloading from nix/apps/edit.nix Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md An example of a per-app definition in `nix/apps/edit.nix` for loading the emacs executable. ```nix # nix/apps/edit.nix pkgs: "${pkgs.emacs}/bin/emacs" ``` -------------------------------- ### System Conditioning Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Applies conditional logic to configuration based on the target system architecture. This allows for system-specific package sets or derivations. ```nix # System Conditioning packages = { system, ... }: if system == "x86_64-linux" then { linux-only = { stdenv }: stdenv.mkDerivation { /* ... */ }; } else { }; ``` -------------------------------- ### Input Structure Transformation Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelight-lib-functions.md Illustrates the input and output structure when using `selectAttr` to extract the 'packages' attribute, showing how nested attributes are reorganized. ```nix inputs = { nixpkgs.packages.x86_64-linux = { hello = ...; }; other.packages.x86_64-linux = { world = ...; }; }; inputs' = { nixpkgs.packages = { hello = ...; }; other.packages = { world = ...; }; }; ``` -------------------------------- ### Configure additional devShells Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Examples of setting additional devShell outputs using configuration options or package definitions. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShells.testing = { packages = pkgs: [ pkgs.coreutils ]; env.TEST_VAR = "in testing shell"; }; }; } ``` ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShells.testing = { mkShell, coreutils }: mkShell { packages = [ coreutils ]; env.TEST_VAR = "in testing shell"; }; }; } ``` -------------------------------- ### Module Autoloading Bundler Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Shows how bundlers can be automatically loaded from `nix/bundler.nix` or `nix/bundlers/` directories. This example defines an identity bundler in `nix/bundler.nix`. ```nix # nix/bundler.nix pkgs: drv: drv # Identity bundler ``` -------------------------------- ### Basic Template Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md Defines multiple named templates (`rust` and `python`) for project scaffolding. Use `nix flake init -t .#rust` to initialize a project with the Rust template. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { templates.rust = { path = ./templates/rust; description = "Rust project template"; }; templates.python = { path = ./templates/python; description = "Python project template"; }; }; } ``` -------------------------------- ### Add build inputs to devShell Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Example of adding build inputs from a defined package to the devShell. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { package = { stdenv }: stdenv.mkDerivation { pname = "pkg1"; version = "0.0.1"; src = ./.; installPhase = "make DESTDIR=$out install"; }; devShell = { inputsFrom = pkgs: [ pkgs.pkg1 ]; }; }; } ``` -------------------------------- ### Basic Bundler Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Configures a single identity bundler for `bundlers.default`. This example demonstrates the basic structure for setting up a bundler within a Flake Light project. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { bundler = x: x; # Identity bundler }; } ``` -------------------------------- ### Configure Nixpkgs with 'nixpkgs.config' Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Pass configuration options to the Nixpkgs instance used for building packages and calling perSystem. This example shows how to allow building broken or unsupported packages. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { nixpkgs.config = { allowBroken = true; allowUnsupportedSystem = true; }; }; } ``` -------------------------------- ### Full Path Formatters Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/formatter-option.md Specify full paths to formatters for potentially slow-to-build tools. This example configures `rustfmt`, `clang-format`, and `black` using their absolute paths. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { formatters = pkgs: { "*.rs" = "${pkgs.rustfmt}/bin/rustfmt"; "*.c" = "${pkgs.clang-tools}/bin/clang-format -i"; "*.py" = "${pkgs.black}/bin/black"; }; }; } ``` -------------------------------- ### Per-System Generation Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md This snippet shows how Flakelight automatically generates per-system outputs for each system defined in the configuration. It's called with the system's package set. ```nix # For each system in config.systems: perSystem pkgsFor.${system} # Called with system's package set ``` -------------------------------- ### Usage for Scripted Apps Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md Example commands to run the scripted applications defined previously. These commands utilize `nix run` to execute the specified app targets. ```bash nix run .#deploy nix run .#test ``` -------------------------------- ### Multiple Flakelight Modules Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelightModules-option.md This example demonstrates how to define multiple named Flakelight modules using `flakelightModules`. Each entry in the attribute set creates a distinct module. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { flakelightModules = { default = { lib, ... }: { options.name = lib.mkOption { type = lib.types.str; default = "project"; }; config.outputs.name = config.name; }; feature1 = { lib, ... }: { options.feature1.enabled = lib.mkEnableOption "feature 1"; config.outputs.feature1 = config.feature1.enabled; }; feature2 = { lib, ... }: { options.feature2.enabled = lib.mkEnableOption "feature 2"; config.outputs.feature2 = config.feature2.enabled; }; }; }; } ``` -------------------------------- ### Apply a Single Overlay with Flakelight Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Configure `withOverlays` with a function to define a single overlay. This example sets a `testValue` and uses it in a shell script package. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { withOverlays = final: prev: { testValue = "hi"; }; package = { writeShellScript, testValue }: writeShellScript "test" "echo ${testValue}"; }; } ``` -------------------------------- ### Define project bundlers Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Configure bundlers to package applications. Examples show direct package return and using module arguments. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { bundler = x: x; }; } ``` ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { bundlers = { hello, ... }: { hello = x: hello; }; }; } ``` ```nix # nix/bundlers/hello.nix { hello, ... }: x: hello; ``` -------------------------------- ### NixOS Configuration Management Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Integrate Flakelight with NixOS configurations to manage system settings and modules. This example defines a NixOS configuration for a machine. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; outputs = { flakelight, ... }@inputs: flakelight ./. { nixosConfigurations.my-machine = { system = "x86_64-linux"; modules = [ ./nixos/configuration.nix ]; }; }; } ``` -------------------------------- ### Module Autoloading Multiple Bundlers Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Demonstrates automatic loading of multiple bundlers from `nix/bundlers/` directory. This example defines `appimage` and `container` bundlers in separate files. ```nix # nix/bundlers/appimage.nix pkgs: drv: pkgs.appimage-run drv # nix/bundlers/container.nix pkgs: drv: pkgs.dockerTools.buildImage { name = drv.name; contents = [ drv ]; } ``` -------------------------------- ### Apply Multiple Overlays with Flakelight Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Use `withOverlays` to apply a list of overlays to the Nixpkgs instance. This example shows applying the Emacs overlay and overriding the Zig version. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; emacs-overlay.url = "github:nix-community/emacs-overlay"; }; outputs = { flakelight, emacs-overlay, ... }: flakelight ./. { withOverlays = [ emacs-overlay.overlays.default (final: prev: { zig = final.zig_0_9; }) ]; }; } ``` -------------------------------- ### Define Custom Systems for Flakelight Outputs Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/core-options.md Specify a custom list of Nix system strings to enable per-system outputs for Flakelight. This example adds i686-linux and armv7l-linux to the default x86_64-linux and aarch64-linux. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { systems = [ "x86_64-linux" "aarch64-linux" "i686-linux" "armv7l-linux" ]; }; } ``` -------------------------------- ### Initialize Project from Template Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md Commands to initialize a new project using a specified template. ```bash # Use default template nix flake init -t . # Use named template nix flake init -t .#rust nix flake init -t .#web # Initialize in directory nix flake init -t .#web new-project cd new-project ``` -------------------------------- ### Shell Hook with Package Access Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/devShell-option.md Execute commands within the shell hook that require access to packages. This example shows how to get the version of a specific tool. ```nix devShell = pkgs: { shellHook = '' echo "Using $(${pkgs.cargo}/bin/cargo --version)" ''; }; ``` -------------------------------- ### Optional Function to Type Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelight-lib-functions.md Demonstrates the `optFunctionTo` type, which allows an option to accept either a direct value or a function that returns that value. It's shown here coercing to a list of packages. ```nix myOption = mkOption { type = optFunctionTo (listOf package); }; # Can be set to: myOption = [ pkgs.hello ]; # Or: myOption = pkgs: [ pkgs.hello ]; ``` -------------------------------- ### Nullable Type Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelight-lib-functions.md Illustrates the `nullable` type, which makes any other type optional, allowing it to be set to `null`. The example sets a default value of `null` for a path type. ```nix flakelight.types.nullable elementType myOption = mkOption { type = nullable path; default = null; }; ``` -------------------------------- ### Get paths to Nix files and directories Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelight-lib-functions.md Use `importDirPaths` to get paths to .nix files and directories containing default.nix from a specified directory. It returns an attribute set where keys are file/directory names and values are the paths to those files/directories. This is useful when you need to reference module files without evaluating them directly. ```nix flakelight.importDirPaths path ``` ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { nixosModules = flakelight.importDirPaths ./nix/nixos-modules; homeModules = flakelight.importDirPaths ./nix/home-modules; }; } ``` -------------------------------- ### Configure NixOS systems Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Set up NixOS configurations using nixpkgs.lib.nixosSystem arguments within the Flakelight output structure. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. ({ lib, config, ... }: { nixosConfigurations.test-system = { modules = [{ nixpkgs.hostPlatform.system = "x86_64-linux"; system.stateVersion = "25.05"; }]; }; }); } ``` -------------------------------- ### Override devShell with package definition Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Example of overriding the devShell using a package definition. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell = { mkShell, hello }: mkShell { packages = [ hello ]; }; }; } ``` -------------------------------- ### Module Autoloading from nix/app.nix Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md An example of an app definition in `nix/app.nix` that automatically loads an application, in this case, ripgrep. ```nix # nix/app.nix pkgs: "${pkgs.ripgrep}/bin/rg" ``` -------------------------------- ### Build a Simple Package Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Use this snippet to define a simple package with its source and version. It utilizes `stdenv.mkDerivation` for package construction. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { package = { stdenv }: stdenv.mkDerivation { pname = "myapp"; version = "0.1.0"; src = ./.; }; }; } ``` -------------------------------- ### Bundler Configuration with Package Access Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Demonstrates configuring bundlers while also providing access to packages and the Nix environment. This allows bundlers to use external tools like `hello` or `stdenv` for more complex bundling logic. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { package = { stdenv }: stdenv.mkDerivation { /* ... */ }; bundlers = { hello, ... }: { # Access to hello and stdenv default = x: x; with-hello = drv: stdenv.mkDerivation { name = "${drv.name}-bundled"; src = drv; buildInputs = [ hello ]; installPhase = "cp -r . $out"; }; }; }; } ``` -------------------------------- ### Automatic Package Checks Structure Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/checks-option.md When packages are configured, Flakelight automatically adds build checks. Each package gets its own check. ```nix outputs.checks = { ${system}.packages-{name} = derivation # One per package } ``` -------------------------------- ### Running Default and Named Apps Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md Demonstrates how to execute the default application defined in the flake using `nix run .` and a specifically named application using `nix run .#myapp`. ```bash # Run default app nix run . ``` ```bash # Run named app nix run .#myapp ``` -------------------------------- ### Define System-Conditional Checks Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/checks-option.md Conditionally define checks based on the target system. This example shows a check that only runs on x86_64-linux systems. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { checks = { system, ... }: if system == "x86_64-linux" then { linux-only = "uname -m | grep x86_64"; } else { }; }; } ``` -------------------------------- ### Set Up Development Shell Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Configure a development shell with specific packages like `cargo` and `rustfmt`. This is useful for setting up project-specific development environments. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell.packages = pkgs: [ pkgs.cargo pkgs.rustfmt ]; }; } ``` -------------------------------- ### Basic mkFlake Usage Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/mkFlake.md Demonstrates the most basic usage of mkFlake, defining packages for the development shell. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { devShell.packages = pkgs: [ pkgs.hello pkgs.coreutils ]; }; } ``` -------------------------------- ### Module Autoload from nix/overlay.nix Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/overlays-option.md Overlays can be automatically loaded from a single nix/overlay.nix file in the project root. ```nix # nix/overlay.nix final: prev: { customPkg = prev.hello; } ``` -------------------------------- ### Simple Bash Shell Hook Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/devShell-option.md Add custom commands or environment variables to your development shell. This example echoes a message and modifies the prompt. ```nix devShell = { shellHook = '' echo "Development environment loaded" export PS1="[dev] $PS1" ''; }; ``` -------------------------------- ### Custom Directory Structure Processing Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixDir-option.md Transform directory contents before they are used by Flakelight. This example shows how to process imported directories and combine their attributes. ```nix # nix/packages/default.nix flakelight.importDir ./. |> (pkgs: pkgs // { # Custom processing all = builtins.attrValues pkgs; }) ``` -------------------------------- ### Autoload Formatters from Nix Files Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/formatter-option.md Formatters can be automatically loaded by Flakelight if they are defined in 'nix/formatters.nix' or 'nix/formatter.nix'. This example shows a typical structure for 'nix/formatters.nix'. ```nix # nix/formatters.nix pkgs: { "*.rs" = "${pkgs.rustfmt}/bin/rustfmt"; "*.nix" = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"; } ``` -------------------------------- ### Select Attribute Usage Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelight-lib-functions.md Demonstrates how to use the `selectAttr` function to transform an attribute set by extracting a specific attribute (e.g., 'packages') from each of its values. ```nix inputs' = mapAttrs (_: selectAttr "packages") inputs; ``` -------------------------------- ### Define a Template with Welcome Text Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md This snippet shows how to define a custom template named 'mytemplate' with a specific path and a multi-line welcome message. The welcome message provides instructions for the user upon template selection. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { templates.mytemplate = { path = ./templates/mytemplate; description = "My custom template"; welcomeText = '' Welcome to My Template! To get started: 1. Edit flake.nix to configure your project 2. Run: nix flake update 3. Run: nix develop ''; }; }; } ``` -------------------------------- ### System-Conditional Bundlers Configuration Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Configures bundlers based on the target system architecture. This example provides an `appimage` bundler only for `x86_64-linux` and an empty configuration for other systems. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { bundlers = { system, pkgs, ... }: if system == "x86_64-linux" then { appimage = drv: pkgs.appimage-run drv; } else { }; }; } ``` -------------------------------- ### mkFlake Usage with Custom Inputs Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/mkFlake.md Demonstrates how to use mkFlake when custom inputs, such as a specific nixpkgs version, are defined in the flake. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; outputs = { flakelight, ... }@inputs: flakelight ./. { inherit inputs; devShell.packages = pkgs: [ pkgs.hello ]; }; } ``` -------------------------------- ### Running Apps with Arguments Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md Shows how to pass command-line arguments to a named application when running it with `nix run`. Arguments `arg1` and `arg2` are passed to `myapp`. ```bash # Run with arguments nix run .#myapp -- arg1 arg2 ``` -------------------------------- ### Define Package Dependencies Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/packages-option.md Packages can depend on other defined packages by including them as function parameters. This example shows how the 'app' package depends on the 'lib' package. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { packages = { lib = { stdenv }: stdenv.mkDerivation { /* ... */ }; app = { stdenv, lib }: stdenv.mkDerivation { buildInputs = [ lib ]; /* ... */ }; }; }; } ``` -------------------------------- ### Define System-Conditional Packages Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/packages-option.md Use the 'packages' attribute to define packages that are specific to certain system architectures. This example shows a package only available on 'x86_64-linux'. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { packages = { system, stdenv }: if system == "x86_64-linux" then { linux-only = stdenv.mkDerivation { pname = "linux-only"; version = "1.0.0"; src = ./.; }; } else { }; }; } ``` -------------------------------- ### Typical Flakelight Project Structure Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/README.md Illustrates the standard directory layout for a Flakelight project, including configuration files, source code, and NixOS modules. ```nix my-project/ ├── flake.nix # Flake definition ├── nix/ # Auto-loaded configurations │ ├── package.nix │ ├── packages/ # Multiple packages │ │ ├── app.nix │ │ └── lib.nix │ ├── devShell.nix │ ├── checks.nix │ ├── formatter.nix │ ├── overlays/ # Multiple overlays │ │ └── custom.nix │ ├── apps/ # Multiple apps │ │ └── build.nix │ └── nixos-modules/ # NixOS modules │ └── base.nix ├── src/ # Source code └── README.md ``` -------------------------------- ### Creating Custom Types with Flakelight Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/types.md Examples of composing basic types to create custom types for specific purposes, including optional types and attribute sets. ```nix # List of paths listOf path ``` ```nix # Optional string nullable str ``` ```nix # Attribute set of functions lazyAttrsOf function ``` ```nix # Optional function to attribute set optFunctionTo (lazyAttrsOf packageDef) ``` ```nix # Nullable function returning list nullable (functionTo (listOf package)) ``` -------------------------------- ### Configure Nixpkgs Initialization Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/core-options.md Passes configuration options to the Nixpkgs initialization process. Common options include allowing broken, unsupported, or unfree packages. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { nixpkgs.config = { allowBroken = true; allowUnsupported = true; allowUnfree = true; }; }; } ``` -------------------------------- ### Running Apps for a Specific System Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md Illustrates how to run a named application for a specific system architecture, in this case, 'aarch64-linux', using the `nix run` command. ```bash # Run for specific system nix run .#apps.aarch64-linux.myapp ``` -------------------------------- ### Using Overlay Results in Package Definitions Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/core-options.md Demonstrates how values defined in an overlay (like `myValue`) are accessible within package definitions and per-system configurations. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { withOverlays = final: prev: { myValue = "test"; }; package = { myValue, stdenv }: stdenv.mkDerivation { # myValue is available here inherit myValue; }; perSystem = pkgs: { example = pkgs.myValue; # myValue is available here too }; }; } ``` -------------------------------- ### Module Autoload from nix/overlays/ Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/overlays-option.md Multiple overlays can be automatically loaded by placing them in the nix/overlays/ directory, with each file defining a separate overlay. ```nix # nix/overlays/custom.nix final: prev: { ... } # nix/overlays/experimental.nix final: prev: { ... } ``` -------------------------------- ### Usage of legacyPackages with custom packages Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/bundlers-legacyPackages-options.md Demonstrates how to access default and nixpkgs packages when custom packages are combined with legacyPackages. ```bash nix-shell -A legacyPackages.x86_64-linux.default nix-shell -A legacyPackages.x86_64-linux.hello # nixpkgs packages ``` -------------------------------- ### Apply Patches to Nixpkgs with Flakelight Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Use the `nixpkgs.patches` option to apply local patch files to the Nixpkgs instance. This example applies a patch named `fix-hello.patch`. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { nixpkgs.patches = [ ./fix-hello.patch ]; }; } ``` -------------------------------- ### Define Custom Wrapper Scripts Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/apps-option.md Create executable wrapper scripts using `pkgs.writeShellScriptBin`. This is useful for setting up specific environments or calling binaries with custom arguments, such as setting `PATH` or `RUST_LOG`. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { apps = pkgs: { build = pkgs.writeShellScriptBin "build" '' #!/bin/bash export PATH="${pkgs.gcc}/bin:${pkgs.make}/bin:$PATH" make -j$(nproc) ''; debug = pkgs.writeShellScriptBin "debug" '' #!/bin/bash export RUST_LOG=debug ${pkgs.myapp}/bin/myapp ''; }; }; } ``` -------------------------------- ### Configure Full-Featured Template Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/templates-option.md Defines a full-featured template with a path, description, and welcome text. This is used for project scaffolding. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { templates = { full-featured = { path = ./templates/full; description = "Full-featured template"; welcomeText = '' Full-featured template: - Development shell configured - Multiple package definitions - Comprehensive checks - Formatter configured ''; }; }; }; } ``` -------------------------------- ### optListOf Type Example Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/types.md Coerces a single element to a list containing that element. Useful for options that accept both single values and lists. This implementation uses `coercedTo` with a `singleton` wrapper. ```nix flakelight.types.optListOf elemType optListOf str # Can be: value = "single" # Becomes ["single"] value = ["a" "b"] # Stays ["a" "b"] ``` -------------------------------- ### Home Configurations with Extra Special Arguments Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixos-home-options.md Shows how to provide extra arguments to Home Manager modules. This is useful for passing flake inputs or other context to your modules. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; home-manager.url = "github:nix-community/home-manager/release-23.11"; }; outputs = { flakelight, ... }@inputs: flakelight ./. { homeConfigurations = { "user@host" = { system = "x86_64-linux"; modules = [ ({ inputs, ... }: { home.stateVersion = "23.11"; home.packages = [ inputs.nixpkgs.legacyPackages.x86_64-linux.hello ]; }) ./home-configuration.nix ]; extraSpecialArgs = { inherit inputs; }; }; }; }; } ``` -------------------------------- ### Optional Call With Type Usage Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/flakelight-lib-functions.md Shows the signature for the `optCallWith` type, which coerces a non-function value into a function that is called with specific arguments. The example uses `moduleArgs` and `lazyAttrsOf packageDef`. ```nix flakelight.types.optCallWith args elementType myOption = mkOption { type = optCallWith moduleArgs (lazyAttrsOf packageDef); }; ``` -------------------------------- ### Accessing Flake Inputs within Home Manager Modules Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixos-home-options.md Demonstrates how to use `inputs'` within a module to access flake inputs, such as `nixpkgs`. This allows per-system access to packages and other resources. ```nix { inputs = { flakelight.url = "github:nix-community/flakelight"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; home-manager.url = "github:nix-community/home-manager/release-23.11"; }; outputs = { flakelight, ... }@inputs: flakelight ./. { homeConfigurations = { "user@host" = { system = "x86_64-linux"; modules = [ ({ inputs', ... }: { home.stateVersion = "23.11"; home.packages = [ inputs'.nixpkgs.hello ]; }) ./configuration.nix ]; }; }; }; } ``` -------------------------------- ### Directory Structure: Single File Per Option Source: https://github.com/nix-community/flakelight/blob/master/_autodocs/api-reference/nixDir-option.md Illustrates a directory structure where each Nix file directly corresponds to an option, enabling Flakelight to import them as single values. ```tree nix/ ├── package.nix # → config.package = import ./nix/package.nix ├── devShell.nix # → config.devShell = import ./nix/devShell.nix ├── checks.nix # → config.checks = import ./nix/checks.nix └── formatter.nix # → config.formatter = import ./nix/formatter.nix ``` -------------------------------- ### Configure Systems for Per-System Outputs Source: https://github.com/nix-community/flakelight/blob/master/API_GUIDE.md Sets the `systems` option to include `i686-linux` and `armv7l-linux` in addition to the defaults. ```nix { inputs.flakelight.url = "github:nix-community/flakelight"; outputs = { flakelight, ... }: flakelight ./. { systems = [ "x86_64-linux" "aarch64-linux" "i686-linux" "armv7l-linux" ]; }; } ```