### Building a Specific Example Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Provides a configuration to build only a particular example from the project's examples directory by setting `pname` and modifying `cargo_build_options`. ```nix naersk.buildPackage { pname = "your-example-name"; src = ./.; overrideMain = old: { preConfigure = '' cargo_build_options="$cargo_build_options --example your-example-name" ''; }; } ``` -------------------------------- ### Niv Configuration for Naersk Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md A `default.nix` example for a Rust project using Naersk with Niv. It imports sources and calls `buildPackage`. ```nix let pkgs = import {}; sources = import ./nix/sources.nix; naersk = pkgs.callPackage sources.naersk {}; in naersk.buildPackage ./. ``` -------------------------------- ### Niv Configuration with Custom Rust Toolchain Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Example `default.nix` for using a custom Rust toolchain with Naersk and Niv. It overlays nixpkgs with a specific Rust channel. ```nix let sources = import ./nix/sources.nix; nixpkgs-mozilla = import sources.nixpkgs-mozilla; pkgs = import sources.nixpkgs { overlays = [ nixpkgs-mozilla ]; }; toolchain = (pkgs.rustChannelOf { rustToolchain = ./rust-toolchain; sha256 = ""; # ^ After you run `nix-build`, replace this with the actual # hash from the error message }).rust; naersk = pkgs.callPackage sources.naersk { cargo = toolchain; rustc = toolchain; }; in naersk.buildPackage ./ ``` -------------------------------- ### Flakes Configuration for Naersk Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md A `flake.nix` example for a Rust project using Naersk. It sets up packages and a development shell. ```nix { inputs = { flake-utils.url = "github:numtide/flake-utils"; naersk = { url = "github:nix-community/naersk"; inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; outputs = { flake-utils, naersk, nixpkgs, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = (import nixpkgs) { inherit system; }; naersk' = pkgs.callPackage naersk {}; in { # For `nix build` & `nix run`: packages.default = naersk'.buildPackage { src = ./.; }; # For `nix develop` (optional, can be skipped): devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ rustc cargo ]; }; } ); } ``` -------------------------------- ### Flakes Configuration with Custom Rust Toolchain Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Example `flake.nix` for using a custom Rust toolchain with Naersk. It overlays nixpkgs with a specific Rust channel. ```nix { inputs = { flake-utils.url = "github:numtide/flake-utils"; naersk.url = "github:nix-community/naersk"; nixpkgs-mozilla = { url = "github:mozilla/nixpkgs-mozilla"; flake = false; }; }; outputs = { flake-utils, naersk, nixpkgs, nixpkgs-mozilla, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = (import nixpkgs) { inherit system; overlays = [ (import nixpkgs-mozilla) ]; }; toolchain = (pkgs.rustChannelOf { rustToolchain = ./rust-toolchain; sha256 = ""; # ^ After you run `nix build`, replace this with the actual # hash from the error message }).rust; naersk' = pkgs.callPackage naersk { cargo = toolchain; rustc = toolchain; }; in { # For `nix build` & `nix run`: packages.default = naersk'.buildPackage { src = ./.; }; # For `nix develop` (optional, can be skipped): devShell = pkgs.mkShell { nativeBuildInputs = [ toolchain ]; }; } ); } ``` -------------------------------- ### Basic Naersk Usage Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md A simple example of how to use `naersk.buildPackage` to build a Rust project. This assumes your `Cargo.lock` and source code are in the specified directory. ```nix naersk.buildPackage { src = ./.; # Wherever your Cargo.lock and the rest of your source code are } ``` -------------------------------- ### Integrating Naersk into System Packages Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Example of including a Naersk-built Rust application as a system package in NixOS configuration. ```nix environment.systemPackages = [ (naersk.buildPackage { src = ./my-cool-app; }) ]; ``` -------------------------------- ### Nix Flakes Configuration for Naersk Source: https://github.com/nix-community/naersk/blob/master/README.md A flake.nix configuration for building a Rust project with Naersk. This setup is for projects where Cargo.toml and Cargo.lock are in the root. ```nix { inputs = { flake-utils.url = "github:numtide/flake-utils"; naersk = { url = "github:nix-community/naersk"; inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; outputs = { flake-utils, naersk, nixpkgs, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = (import nixpkgs) { inherit system; }; naersk' = pkgs.callPackage naersk {}; in { # For `nix build` & `nix run`: packages.default = naersk'.buildPackage { src = ./.; }; # For `nix develop` (optional, can be skipped): devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ rustc cargo ]; }; } ); } ``` -------------------------------- ### Basic buildPackage Usage Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Demonstrates the fundamental usage of `buildPackage` with source directory and basic options. Assumes `Cargo.toml` is in the root. ```nix naersk.buildPackage { # Assuming there's `Cargo.toml` right in this directory: src = ./.; someOption = "yass"; someOtherOption = false; CARGO_ENVIRONMENTAL_VARIABLE = "test"; } ``` -------------------------------- ### Correct buildPackage Usage with Parameters Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Shows the recommended way to pass build parameters like `buildInputs` or environment variables directly into the `buildPackage` function. ```nix { pkgs, naersk, ... }: naersk.buildPackage { src = ./.; buildInputs = [ pkgs.cmake ]; SOME_ENV_VAR = "yes"; } ``` -------------------------------- ### Initialize Naersk Project with Niv Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Commands to initialize a new project using Naersk with Niv for dependency management. ```shell $ niv init $ niv add nix-community/naersk ``` -------------------------------- ### Initialize Naersk Project with Flakes Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Commands to initialize a new project using Naersk with Nix Flakes. ```shell $ nix flake init -t github:nix-community/naersk $ nix flake lock ``` -------------------------------- ### Running Multiple Binaries Source: https://github.com/nix-community/naersk/blob/master/examples/multiple-binaries/README.md Execute the 'bar' and 'foo' binaries from the Nix Naersk workspace to demonstrate their independent operation. ```shell nix run .#bar Hello, Bar! nix run .#foo Hello, Foo! ``` -------------------------------- ### Correct buildPackage Usage with override Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Demonstrates using the `override` function within `buildPackage` when parameter names might conflict with Naersk's reserved names. ```nix { pkgs, naersk, ... }: naersk.buildPackage { src = ./.; override = p: { # ... }; } ``` -------------------------------- ### Initialize Naersk Project with Flakes Source: https://github.com/nix-community/naersk/blob/master/README.md Command to initialize a new project using Naersk with Nix Flakes. ```shell nix flake init -t github:nix-community/naersk nix flake lock ``` -------------------------------- ### Add nixpkgs-mozilla with Niv Source: https://github.com/nix-community/naersk/blob/master/README.md Command to add the nixpkgs-mozilla repository using Niv, typically for custom Rust toolchain configurations. ```shell niv add mozilla/nixpkgs-mozilla ``` -------------------------------- ### buildPackage with Single-Step Compilation Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Explains how to disable Naersk's incremental compilation mechanism using `singleStep = true` to allow `overrideAttrs` on the final derivation. ```nix { pkgs, naersk, ... }: let app = naersk.buildPackage { src = ./.; singleStep = true; # here }; in app.overrideAttrs (p: { buildInputs = p.buildInputs + [ pkgs.cmake ]; }) ``` -------------------------------- ### Handling CMakeCache.txt Stale Files Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Shows how to use the `preBuild` hook to remove stale `CMakeCache.txt` files, resolving common CMake build errors. ```nix naersk.buildPackage { # ... preBuild = '' find \ -name CMakeCache.txt \ -exec rm {} \; ''; } ``` -------------------------------- ### Build Individual Naersk Test Source: https://github.com/nix-community/naersk/blob/master/test/README.md This command allows you to build and run a specific test case, such as 'simple-dep'. Replace 'simple-dep' with the name of the test you wish to run. ```bash nix build .#tests.simple-dep ``` -------------------------------- ### Build All Naersk Tests Source: https://github.com/nix-community/naersk/blob/master/test/README.md Run this command to build and execute all available tests for the Naersk project. Ensure you are in the project's root directory. ```bash nix build .#tests.all ``` -------------------------------- ### Build Fast Naersk Tests Source: https://github.com/nix-community/naersk/blob/master/test/README.md Use this command to build and execute a subset of fast-running tests. This is useful for quicker feedback cycles during development. ```bash nix build .#tests.fast ``` -------------------------------- ### Incorrect overrideAttrs Usage Source: https://github.com/nix-community/naersk/blob/master/README.tpl.md Illustrates an incorrect way to modify build inputs or environment variables using `overrideAttrs`, which can lead to issues with dependency compilation. ```nix { pkgs, naersk, ... }: let app = naersk.buildPackage { src = ./.; }; in app.overrideAttrs (p: { buildInputs = p.buildInputs + [ pkgs.cmake ]; SOME_ENV_VAR = "yes"; }) ``` -------------------------------- ### Expected Error Message for Unresolved Symlink Source: https://github.com/nix-community/naersk/blob/master/test/fast/git-symlink/README.md This is the error message that would occur if symlinks are not resolved during dependency unpacking. It indicates a 'No such file or directory' error when trying to access a symlinked file. ```text error: couldn't read /nix/store/...-crates-io/dep/src/../symlink.txt: No such file or directory (os error 2) --> /sources/.../src/lib.rs:2:5 | | | include_str!("../symlink.txt") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.