### Configure Meson installation tags Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of setting mesonInstallTags as a list of strings. ```nix mesonInstallTags = [ "emulator" "assembler" ]; ``` -------------------------------- ### Example configuration values Source: https://nixos.org/manual/nixpkgs/unstable Examples for specific configuration fields. ```nix [ "ut1999" ] ``` ```nix "it's dangerous." ``` -------------------------------- ### Cross-build using system examples Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Instantiate a cross-build using a predefined system example. ```bash $ nix-build '' --arg crossSystem '(import ).systems.examples.fooBarBaz' -A whatever ``` -------------------------------- ### Initialize libglycin build environment Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example setup for a Rust package using libglycin and glycin-loaders within a Nix derivation. ```nix { lib, rustPlatform, libglycin, glycin-loaders, wrapGAppsHook4, }: rustPlatform.buildRustPackage { ``` -------------------------------- ### Use mkPackageOption Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples of creating package options with various configurations for defaults, examples, and nullability. ```nix mkPackageOption pkgs "hello" { } => { ...; default = pkgs.hello; defaultText = literalExpression "pkgs.hello"; description = "The hello package to use."; type = package; } mkPackageOption pkgs "GHC" { default = [ "ghc" ]; example = "pkgs.haskellPackages.ghc.withPackages (hkgs: [ hkgs.primes ])"; } => { ...; default = pkgs.ghc; defaultText = literalExpression "pkgs.ghc"; description = "The GHC package to use."; example = literalExpression "pkgs.haskellPackages.ghc.withPackages (hkgs: [ hkgs.primes ])"; type = package; } mkPackageOption pkgs [ "python3Packages" "pytorch" ] { extraDescription = "This is an example and doesn't actually do anything."; } => { ...; default = pkgs.python3Packages.pytorch; defaultText = literalExpression "pkgs.python3Packages.pytorch"; description = "The pytorch package to use. This is an example and doesn't actually do anything."; type = package; } mkPackageOption pkgs "nushell" { nullable = true; } => { ...; default = pkgs.nushell; defaultText = literalExpression "pkgs.nushell"; description = "The nushell package to use."; type = nullOr package; } mkPackageOption pkgs "coreutils" { default = null; } => { ...; description = "The coreutils package to use."; type = package; } ``` -------------------------------- ### Example gitConfig Source: https://nixos.org/manual/nixpkgs/unstable An example configuration for overriding URLs to point to local mirrors. ```nix { url = { "https://my-github-mirror.local" = { insteadOf = [ "https://github.com" ]; }; }; } ``` -------------------------------- ### lib.fileset.fromSource usage examples Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples demonstrating how to convert existing sources to file sets and perform operations like difference. ```nix # There's no cleanSource-like function for file sets yet, # but we can just convert cleanSource to a file set and use it that way toSource { root = ./.; fileset = fromSource (lib.sources.cleanSource ./.); } ``` ```nix # Keeping a previous sourceByRegex (which could be migrated to `lib.fileset.unions`), # but removing a subdirectory using file set functions difference (fromSource (lib.sources.sourceByRegex ./. [ "^README\\.md$" # This regex includes everything in ./doc "^doc(/.*)?$" ]) ./doc/generated ``` -------------------------------- ### Usage examples for lib.fileset.toSource Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples demonstrating how to import directories and files into the store, including handling of unions and error cases for files outside the root. ```nix # Import the current directory into the store # but only include files under ./src toSource { root = ./.; fileset = ./src; } => "/nix/store/...-source" ``` ```nix # Import the current directory into the store # but only include ./Makefile and all files under ./src toSource { root = ./.; fileset = union ./Makefile ./src; } => "/nix/store/...-source" ``` ```nix # Trying to include a file outside the root will fail toSource { root = ./.; fileset = unions [ ./Makefile ./src ../LICENSE ]; } => ``` -------------------------------- ### Configure Nixpkgs to allow unfree packages Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of a user-specific configuration file to enable the installation of unfree software. ```nix { allowUnfree = true; } ``` -------------------------------- ### Install executables with installBin Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Use installBin to place files into outputBin. Rename files before installation if the source name is undesirable. ```nix { nativeBuildInputs = [ installShellFiles ]; # Sometimes the file has an undesirable name. It should be renamed before # being installed via installBin postInstall = '' mv a.out delmar installBin foobar delmar ''; } ``` -------------------------------- ### Create a complex setup hook with substitutions Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates a setup hook that uses substitutions to inject paths to dependencies and registers a function to preConfigureHooks. ```nix pkgs.makeSetupHook { name = "run-hello-hook"; # Put dependencies here if they have hooks or necessary dependencies propagated # otherwise prefer direct paths to executables. propagatedBuildInputs = [ pkgs.hello pkgs.cowsay ]; substitutions = { shell = "${pkgs.bash}/bin/bash"; cowsay = "${pkgs.cowsay}/bin/cowsay"; }; } ( writeScript "run-hello-hook.sh" '' #!@shell@ # the direct path to the executable has to be here because # this will be run when the file is sourced # at which point '$PATH' has not yet been populated with inputs @cowsay@ cow _printHelloHook() { hello } preConfigureHooks+=(_printHelloHook) '' ) ``` -------------------------------- ### Install Shell Completions Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates explicit and implicit shell completion installation using installShellCompletion. ```nix { nativeBuildInputs = [ installShellFiles ]; postInstall = '' # explicit behavior installShellCompletion --bash --name foobar.bash share/completions.bash installShellCompletion --fish --name foobar.fish share/completions.fish installShellCompletion --nushell --name foobar share/completions.nu installShellCompletion --zsh --name _foobar share/completions.zsh # implicit behavior installShellCompletion share/completions/foobar.{bash,fish,zsh,nu} ''; } ``` -------------------------------- ### Example flake configuration Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage A complete flake example demonstrating how to define the darwin-builder and integrate it into darwinConfigurations. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-22.11-darwin"; darwin.url = "github:nix-darwin/nix-darwin/master"; darwin.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, darwin, nixpkgs, ... }@inputs: let inherit (darwin.lib) darwinSystem; system = "aarch64-darwin"; pkgs = nixpkgs.legacyPackages."${system}"; linuxSystem = builtins.replaceStrings [ "darwin" ] [ "linux" ] system; darwin-builder = nixpkgs.lib.nixosSystem { system = linuxSystem; modules = [ "${nixpkgs}/nixos/modules/profiles/nix-builder-vm.nix" { virtualisation = { host.pkgs = pkgs; darwin-builder.workingDirectory = "/var/lib/darwin-builder"; darwin-builder.hostPort = 22; }; } ]; }; in { darwinConfigurations = { machine1 = darwinSystem { inherit system; modules = [ { nix.distributedBuilds = true; nix.buildMachines = [ { hostName = "localhost"; sshUser = "builder"; sshKey = "/etc/nix/builder_ed25519"; system = linuxSystem; maxJobs = 4; supportedFeatures = [ "kvm" "benchmark" "big-parallel" ]; } ]; launchd.daemons.darwin-builder = { command = "${darwin-builder.config.system.build.macos-builder-installer}/bin/create-builder"; serviceConfig = { KeepAlive = true; RunAtLoad = true; StandardOutPath = "/var/log/darwin-builder.log"; StandardErrorPath = "/var/log/darwin-builder.log"; }; }; } ]; }; }; }; } ``` -------------------------------- ### Define a basic setup hook with makeSetupHook Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Creates a simple setup hook by specifying dependencies and a path to a shell script. ```nix pkgs.makeSetupHook { name = "something-hook"; propagatedBuildInputs = [ pkgs.commandsomething ]; depsTargetTargetPropagated = [ pkgs.libsomething ]; } ./script.sh ``` -------------------------------- ### Configure buildDubPackage attributes Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example configuration for a D package build, including lockfile specification and custom install phase. ```nix # generated by dub-to-nix, see below dubLock = ./dub-lock.json; buildInputs = [ ncurses zlib ]; installPhase = '' runHook preInstall install -Dm755 btdu -t $out/bin runHook postInstall ''; } ``` -------------------------------- ### Install Manpage Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Installs a manpage from a file using the installManPage hook. ```nix postInstall = '' installManPage -- --name ''; ``` -------------------------------- ### installBin Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Installs one or more files as executable binaries into the outputBin directory. ```APIDOC ## installBin ### Description Takes one or more paths to files and installs them as executable files into the `outputBin` directory. ### Usage `installBin [file2 ...]` ``` -------------------------------- ### Usage examples for lib.fixedPoints.extends Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Various scenarios for extending fixed-point functions. ```nix f = final: { a = 1; b = final.a + 2; } fix f => { a = 1; b = 3; } fix (extends (final: prev: { a = prev.a + 10; }) f) => { a = 11; b = 13; } fix (extends (final: prev: { b = final.a + 5; }) f) => { a = 1; b = 6; } fix (extends (final: prev: { c = final.a + final.b; }) f) => { a = 1; b = 3; c = 4; } ``` -------------------------------- ### Full Crystal Package Build Example Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage A complete example of a Nix expression for building a Crystal package with dependencies. ```nix with import { }; crystal.buildCrystalPackage rec { version = "0.5.0"; pname = "mint"; src = fetchFromGitHub { owner = "mint-lang"; repo = "mint"; tag = version; hash = "sha256-dFN9l5fgrM/TtOPqlQvUYgixE4KPr629aBmkwdDoq28="; }; shardsFile = ./shards.nix; crystalBinaries.mint.src = "src/mint.cr"; buildInputs = [ openssl ]; } ``` -------------------------------- ### Override build and install phases Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates manual compilation and installation by overriding the default buildPhase and installPhase attributes. ```nix stdenv.mkDerivation { pname = "fnord"; version = "4.5"; # ... buildPhase = '' runHook preBuild gcc foo.c -o foo runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out/bin cp foo $out/bin runHook postInstall ''; } ``` -------------------------------- ### Setup MPI check phase hook Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of including the mpiCheckPhaseHook in a derivation. ```nix { mpiCheckPhaseHook, mpi, ... }: { ``` -------------------------------- ### Using postgresqlTestHook Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Basic setup for using postgresqlTestHook to start a database server during the checkPhase. ```nix { stdenv, postgresql, postgresqlTestHook, }: stdenv.mkDerivation { ``` -------------------------------- ### Configure Emscripten Package Phases Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of overriding build phases like configure, build, and install for an Emscripten package, including environment variable adjustments. ```nix # we need to reset this setting! env = (old.env or { }) // { NIX_CFLAGS_COMPILE = ""; }; configurePhase = '' # FIXME: Some tests require writing at $HOME HOME=$TMPDIR runHook preConfigure #export EMCC_DEBUG=2 emconfigure ./configure --prefix=$out --shared runHook postConfigure ''; dontStrip = true; outputs = [ "out" ]; buildPhase = '' runHook preBuild emmake make runHook postBuild ''; installPhase = '' runHook preInstall emmake make install runHook postInstall ''; checkPhase = '' runHook preCheck echo "================= testing zlib using node =================" echo "Compiling a custom test" set -x emcc -O2 -s EMULATE_FUNCTION_POINTER_CASTS=1 test/example.c -DZ_SOLO \ libz.so.${old.version} -I . -o example.js echo "Using node to execute the test" ${pkgs.nodejs}/bin/node ./example.js set +x if [ $? -ne 0 ]; then echo "test failed for some reason" exit 1; else echo "it seems to work! very good." fi echo "================= /testing zlib using node =================" runHook postCheck ''; postPatch = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin '' substituteInPlace configure \ --replace-fail '/usr/bin/libtool' 'ar' \ --replace-fail 'AR="libtool"' 'AR="ar"' \ --replace-fail 'ARFLAGS="-o"' 'ARFLAGS="-r"' ''; }) ``` -------------------------------- ### Define meta.teams example Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example usage of the meta.teams option. ```nix [ lib.teams.acme lib.teams.haskell ] ``` -------------------------------- ### Define meta.maintainers example Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example usage of the meta.maintainers option. ```nix [ lib.maintainers.alice lib.maintainers.bob ] ``` -------------------------------- ### Initialize nix-shell for package building Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Prepare the environment by setting the output directory before running build phases. ```bash cd "$(mktemp -d)" nix-shell '' -A some_package export out=$(pwd)/out ``` -------------------------------- ### Install with mods Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Apply specific mods to the Cataclysm DDA installation. ```nix cataclysm-dda.withMods (mods: with mods; [ tileset.UndeadPeople ]) ``` -------------------------------- ### Update Nixpkgs Configuration to use lib Source: https://nixos.org/manual/nixpkgs/unstable/release-notes Examples showing the transition from using pkgs to lib in Nixpkgs configuration for improved performance and recursion safety. ```nix { pkgs, ... }: { allowlistedLicenses = [ pkgs.lib.licenses.nasa13 ]; blocklistedLicenses = with pkgs.lib.licenses; [ gpl3Only gpl3Plus ]; } ``` ```nix { lib, ... }: { allowlistedLicenses = [ lib.licenses.nasa13 ]; blocklistedLicenses = with lib.licenses; [ gpl3Only gpl3Plus ]; } ``` ```nix { pkgs, lib ? pkgs.lib, ... }: { allowlistedLicenses = [ lib.licenses.nasa13 ]; blocklistedLicenses = with lib.licenses; [ gpl3Only gpl3Plus ]; } ``` -------------------------------- ### Example patchShebangs usage Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples of using patchShebangs with host and build flags. ```bash patchShebangs --host /nix/store/-hello-1.0/bin ``` ```bash patchShebangs --build configure ``` -------------------------------- ### Viewing nix-prefetch-docker help Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Display the help menu for the nix-prefetch-docker utility to see all supported arguments. ```bash $ nix run nixpkgs#nix-prefetch-docker -- --help (output removed for clarity) ``` -------------------------------- ### Configure install targets Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Specifies custom make targets for the installation phase. ```nix { installTargets = "install-bin install-doc"; } ``` -------------------------------- ### Usage examples for lib.fixedPoints.fix Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples showing fix applied to attribute sets and lists. ```nix fix (self: { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; }) => { bar = "bar"; foo = "foo"; foobar = "foobar"; } fix (self: [ 1 2 (elemAt self 0 + elemAt self 1) ]) => [ 1 2 3 ] ``` -------------------------------- ### Build and run a Docker image with nix-build Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates the workflow of building a Docker image using nix-build, loading it into Docker, and starting a shell container. ```bash $ nix-build (some output removed for clarity) /nix/store/rpf47f4z5b9qr4db4ach9yr4b85hjhxq-env-helpers.tar.gz $ docker image load -i /nix/store/rpf47f4z5b9qr4db4ach9yr4b85hjhxq-env-helpers.tar.gz (output removed for clarity) $ docker container run --rm -it env-helpers:latest /bin/sh sh-5.2# help GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu) (rest of output removed for clarity) ``` -------------------------------- ### lib.fixedPoints.fix Usage Examples Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples comparing recursive attribute sets with let-binding recursion. ```nix nix-repl> rec { foo = "foo"; bar = "bar"; foobar = foo + bar; } { bar = "bar"; foo = "foo"; foobar = "foobar"; } ``` ```nix nix-repl> let self = { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; }; in self { bar = "bar"; foo = "foo"; foobar = "foobar"; } ``` -------------------------------- ### Install an Octave package Source: https://nixos.org/manual/nixpkgs/unstable Install an Octave package into the user profile from the repository root. ```bash $ nix-env -f. -iA octavePackages.symbolic ``` -------------------------------- ### Install Manpage with Custom Name Source: https://nixos.org/manual/nixpkgs/unstable Installs a manpage file using a specific name. ```nix postInstall = '' installManPage -- --name ''; } ``` -------------------------------- ### Building the exportImage package Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example output showing the unpacking process during a nix-build of the exportImage function. ```bash $ nix-build (some output removed for clarity) Unpacking base image... From-image name or tag wasn't set. Reading the first ID. Unpacking layer 5731199219418f175d1580dbca05677e69144425b2d9ecb60f416cd57ca3ca42/layer.tar tar: Removing leading `/' from member names Unpacking layer e2897bf34bb78c4a65736510204282d9f7ca258ba048c183d665bd0f3d24c5ec/layer.tar tar: Removing leading `/' from member names Unpacking layer 420aa5876dca4128cd5256da7dea0948e30ef5971712f82601718cdb0a6b4cda/layer.tar tar: Removing leading `/' from member names Unpacking layer ea5f4e620e7906c8ecbc506b5e6f46420e68d4b842c3303260d5eb621b5942e5/layer.tar tar: Removing leading `/' from member names Unpacking layer 65807b9abe8ab753fa97da8fb74a21fcd4725cc51e1b679c7973c97acd47ebcf/layer.tar tar: Removing leading `/' from member names Unpacking layer b7da2076b60ebc0ea6824ef641978332b8ac908d47b2d07ff31b9cc362245605/layer.tar Executing post-mount steps... Packing raw image... [ 1.660036] reboot: Power down /nix/store/x6a5m7c6zdpqz1d8j7cnzpx9glzzvd2h-hello ``` -------------------------------- ### Profiling configuration overlay start Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Initial boilerplate for configuring global profiling settings via Nixpkgs overlays. ```nix let ``` -------------------------------- ### Install nix-generate-from-cpan Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Command to install the utility for generating Nix expressions from CPAN modules. ```bash $ nix-env -f "" -iA nix-generate-from-cpan ``` -------------------------------- ### Enter nix-shell with Idris libraries Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Start a shell environment with specific Idris libraries available. ```bash $ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])' ``` -------------------------------- ### Install custom Idris package Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Install the custom Idris package defined in an overlay. ```bash $ # On NixOS $ nix-env -iA nixos.myIdris $ # On non-NixOS $ nix-env -iA nixpkgs.myIdris ``` -------------------------------- ### Define meta.teams default and example Source: https://nixos.org/manual/nixpkgs/unstable Default value and example usage for the meta.teams attribute set. ```nix [ ] ``` ```nix [ lib.teams.acme lib.teams.haskell ] ``` -------------------------------- ### Build a Docker image using runAsRoot Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates using runAsRoot to perform filesystem operations during the image build process. ```nix { dockerTools, buildEnv, hello, }: dockerTools.buildImage { name = "hello"; tag = "latest"; copyToRoot = buildEnv { name = "image-root"; paths = [ hello ]; pathsToLink = [ "/bin" ]; }; runAsRoot = '' mkdir -p /data echo "some content" > my-file ''; config = { Cmd = [ "/bin/hello" ]; WorkingDir = "/data"; }; } ``` -------------------------------- ### Initialize Dotnet development environment Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Command to enter a nix-shell for Dotnet development. ```bash nix-shell -p dotnet-sdk ``` -------------------------------- ### Define meta.maintainers default and example Source: https://nixos.org/manual/nixpkgs/unstable Default value and example usage for the meta.maintainers attribute set. ```nix [ ] ``` ```nix [ lib.maintainers.alice lib.maintainers.bob ] ``` -------------------------------- ### Configure Project References Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example configuration for adding project and package references within a .NET project file. ```xml ``` -------------------------------- ### CPE Example for glibc Source: https://nixos.org/manual/nixpkgs/unstable A concrete example of a CPE 2.3 string for glibc version 2.40.1. ```text cpe:2.3:a:gnu:glibc:2.40.1:*:*:*:*:*:*:* ``` -------------------------------- ### Build and verify fetchurl output Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Shows how to trigger the download using nix-build and verify the resulting file content. ```bash $ nix-build (output removed for clarity) /nix/store/4g9y3x851wqrvim4zcz5x2v3zivmsq8n-version $ cat /nix/store/4g9y3x851wqrvim4zcz5x2v3zivmsq8n-version 23.11 ``` -------------------------------- ### Define a .NET Application Package Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example default.nix file demonstrating the use of buildDotnetModule with various configuration arguments. ```nix { lib, buildDotnetModule, dotnetCorePackages, ffmpeg, }: let referencedProject = import ../../bar { # ... }; in buildDotnetModule rec { pname = "someDotnetApplication"; version = "0.1"; src = ./.; projectFile = "src/project.sln"; nugetDeps = ./deps.json; # see "Generating and updating NuGet dependencies" section for details buildInputs = [ referencedProject ]; # `referencedProject` must contain `nupkg` in the folder structure. dotnet-sdk = dotnetCorePackages.sdk_8_0; dotnet-runtime = dotnetCorePackages.runtime_8_0; executables = [ "foo" ]; # This wraps "$out/lib/$pname/foo" to `$out/bin/foo`. executables = [ ]; # Don't install any executables. packNupkg = true; # This packs the project as "foo-0.1.nupkg" at `$out/share`. runtimeDeps = [ ffmpeg ]; # This will wrap ffmpeg's library path into `LD_LIBRARY_PATH`. } ``` -------------------------------- ### Install custom environment to profile Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Command to build and install the defined environment into the user profile. ```bash nix-env -iA myEnv ``` -------------------------------- ### Add build phase hooks Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates using preConfigure to generate files before the build script runs. ```nix (hello { }).override { preConfigure = '' echo "pub const PATH=\"${hi.out}\";" >> src/path.rs" ''; } ``` -------------------------------- ### Define Go build tags Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Examples of setting static and conditional build tags for Go projects. ```nix { tags = [ "production" "sqlite" ]; } ``` ```nix { tags = [ "production" ] ++ lib.optionals withSqlite [ "sqlite" ]; } ``` -------------------------------- ### Build and Install Octave Packages Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Commands to build or install Octave packages from the Nixpkgs repository. ```bash $ nix-build -A octavePackages.symbolic ``` ```bash $ nix-env -f. -iA octavePackages.symbolic ``` -------------------------------- ### Install Idris via nix-env Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Install the base Idris compiler using the nix-env command. ```bash $ nix-env -f "" -iA idris ``` -------------------------------- ### Include documentation outputs in environment Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Configure extraOutputsToInstall to ensure documentation files like man pages are included in the build environment. ```nix { packageOverrides = pkgs: with pkgs; { myPackages = pkgs.buildEnv { name = "my-packages"; paths = [ aspell bc coreutils ffmpeg nix emscripten jq nox silver-searcher ]; pathsToLink = [ "/share/man" "/share/doc" "/bin" ]; extraOutputsToInstall = [ "man" "doc" ]; }; }; } ``` -------------------------------- ### Join subpaths usage example Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of joining multiple subpath strings into a single normalized path. ```nix subpath.join [ "foo" "bar/baz" ] => "./foo/bar/baz" ``` -------------------------------- ### Create a desktop file with makeDesktopItem Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates the configuration of various XDG specification fields, including actions and extra configuration, to generate a desktop file. ```nix { makeDesktopItem }: makeDesktopItem { name = "my-program"; desktopName = "My Program"; genericName = "Video Player"; noDisplay = false; comment = "Cool video player"; icon = "/path/to/icon"; onlyShowIn = [ "KDE" ]; dbusActivatable = true; tryExec = "my-program"; exec = "my-program --someflag"; path = "/some/working/path"; terminal = false; actions.example = { name = "New Window"; exec = "my-program --new-window"; icon = "/some/icon"; }; mimeTypes = [ "video/mp4" ]; categories = [ "Utility" ]; implements = [ "org.my-program" ]; keywords = [ "Video" "Player" ]; startupNotify = false; startupWMClass = "MyProgram"; prefersNonDefaultGPU = false; extraConfig.X-SomeExtension = "somevalue"; } ``` -------------------------------- ### Configuring pnpm install flags Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Passing additional flags to the pnpm install process via pnpmInstallFlags. ```nix { # ... pnpmDeps = fetchPnpmDeps { # ... inherit (finalAttrs) pnpmInstallFlags; }; pnpmInstallFlags = [ "--shamefully-hoist" ]; } ``` -------------------------------- ### Manage plugins with Vim packages Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Define start and optional plugins within a package set using the native Vim package manager. ```nix vim-full.customize { vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { # loaded on launch start = [ youcompleteme fugitive ]; # manually loadable by calling `:packadd $plugin-name` # however, if a Vim plugin has a dependency that is not explicitly listed in # opt that dependency will always be added to start to avoid confusion. opt = [ phpCompletion elm-vim ]; # To automatically load a plugin when opening a filetype, add vimrc lines like: # autocmd FileType php :packadd phpCompletion }; } ``` -------------------------------- ### Create custom Emacs configuration file Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Inject a default.el configuration file into the Emacs site-start directory to automate package setup. ```nix { packageOverrides = pkgs: { myEmacsConfig = pkgs.writeText "default.el" '' (eval-when-compile (require 'use-package)) ;; load some packages (use-package company :bind ("" . company-complete) :diminish company-mode :commands (company-mode global-company-mode) :defer 1 :config (global-company-mode)) (use-package counsel :commands (counsel-descbinds) :bind (([remap execute-extended-command] . counsel-M-x) ("C-x C-f" . counsel-find-file) ("C-c g" . counsel-git) ("C-c j" . counsel-git-grep) ("C-c k" . counsel-ag) ("C-x l" . counsel-locate) ("M-y" . counsel-yank-pop))) (use-package flycheck :defer 2 :config (global-flycheck-mode)) (use-package ivy :defer 1 :bind (("C-c C-r" . ivy-resume) ("C-x C-b" . ivy-switch-buffer) :map ivy-minibuffer-map ("C-j" . ivy-call)) :diminish ivy-mode :commands ivy-mode :config (ivy-mode 1)) (use-package magit :defer :if (executable-find "git") :bind (("C-x g" . magit-status) ("C-x G" . magit-dispatch-popup)) :init (setq magit-completing-read-function 'ivy-completing-read)) (use-package projectile :commands projectile-mode :bind-keymap ("C-c p" . projectile-command-map) :defer 5 :config (projectile-global-mode)) ''; myEmacs = emacs.pkgs.withPackages ( epkgs: (with epkgs.melpaStablePackages; [ (runCommand "default.el" { } '' mkdir -p $out/share/emacs/site-lisp cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el '') company counsel flycheck ivy magit projectile use-package ]) ); }; } ``` -------------------------------- ### Install Cataclysm DDA via Nix Source: https://nixos.org/manual/nixpkgs/unstable Commands to install stable or curses-only builds of Cataclysm DDA to your profile. ```bash nix-env -f "" -iA cataclysm-dda ``` ```bash cataclysmDDA.stable.curses ``` -------------------------------- ### Build and use Common Lisp wrappers Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Create a shell environment with specific packages and load them using the Nixpkgs-provided ASDF. ```bash nix-shell -p 'sbcl.withPackages (ps: [ ps.alexandria ps.bordeaux-threads ])' ``` ```lisp $ sbcl * (load (sb-ext:posix-getenv "ASDF")) * (asdf:load-system 'alexandria) * (asdf:load-system 'bordeaux-threads) ``` -------------------------------- ### Build a D package with buildDubPackage Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example configuration for building a D project using the Dub package manager. ```nix { lib, buildDubPackage, fetchFromGitHub, ncurses, zlib, }: buildDubPackage rec { pname = "btdu"; version = "0.5.1"; src = fetchFromGitHub { owner = "CyberShadow"; repo = "btdu"; tag = "v${version}"; hash = "sha256-3sSZq+5UJH02IO0Y1yL3BLHDb4lk8k6awb5ZysBQciE="; }; ``` -------------------------------- ### Install Hy with Python Packages Source: https://nixos.org/manual/nixpkgs/unstable Install Hy with custom Python packages using nix-shell or by extending configuration.nix. ```bash $ nix-shell -p "hy.withPackages (ps: with ps; [ numpy matplotlib ])" ``` ```nix { ``` -------------------------------- ### Run binary with qemu Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Execute a cross-compiled binary using qemu in a nix-shell. ```bash $ nix-shell -p qemu --run 'qemu-aarch64 ./result/bin/hello' Hello, world! ``` -------------------------------- ### Install standalone Treesitter parsers Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Use this approach to install grammars and queries without the full nvim-treesitter plugin. ```nix (pkgs.neovim.override { configure = { packages.myPlugins = with pkgs.vimPlugins; let # Select the grammars you need treesitter-grammars = with nvim-treesitter-parsers; [ nix python ]; # Queries are needed for treesitter based syntax highlighting and folds. treesitter-queries = map (p: p.associatedQuery) treesitter-grammars; in { start = [ # regular plugins ] ++ treesitter-grammars ++ treesitter-queries; }; }; }) ``` -------------------------------- ### Install Custom Font Formats Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Uses the installFont function to install specific font formats like SVG. ```nix { nativeBuildInputs = [ installFonts ]; postInstall = '' installFont svg $out/share/fonts/svg ''; } ``` -------------------------------- ### Run an OCI container with runc Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates building the container package and executing it using the runc runtime. ```bash $ nix-build (some output removed for clarity) /nix/store/7f9hgx0arvhzp2a3qphp28rxbn748l25-join $ cd /nix/store/7f9hgx0arvhzp2a3qphp28rxbn748l25-join $ nix-shell -p runc [nix-shell:/nix/store/7f9hgx0arvhzp2a3qphp28rxbn748l25-join]$ sudo runc run ocitools-example help GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-gnu) (some output removed for clarity) ``` -------------------------------- ### Build and run Docker image Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Commands to build the image with nix-build, load it into Docker, and execute a shell. ```bash $ nix-build (some output removed for clarity) /nix/store/2p0i3i04cgjlk71hsn7ll4kxaxxiv4qg-docker-image-env-helpers.tar.gz $ docker image load -i /nix/store/2p0i3i04cgjlk71hsn7ll4kxaxxiv4qg-docker-image-env-helpers.tar.gz (output removed for clarity) $ docker container run --rm -it env-helpers:latest /bin/sh sh-5.2# help GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu) (rest of output removed for clarity) ``` -------------------------------- ### PIC hardening error example Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of an assembler error occurring when position independent code is enabled in an incompatible environment. ```text ccbLfRgg.s: Assembler messages: ccbLfRgg.s:33: Error: missing or invalid displacement expression `private_key_len@GOTOFF' ``` -------------------------------- ### Enter a Haskell Development Environment Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Shows how to use nix-shell to enter an environment pre-configured with package dependencies. ```bash $ cd ~/src/random $ nix-shell -A haskellPackages.random.env '' [nix-shell:~/src/random]$ ghc-pkg list /nix/store/a8hhl54xlzfizrhcf03c1l3f6l9l8qwv-ghc-9.2.4-with-packages/lib/ghc-9.2.4/package.conf.d Cabal-3.6.3.0 array-0.5.4.0 base-4.16.3.0 binary-0.8.9.0 … ghc-9.2.4 … ``` -------------------------------- ### Build a Dart application with buildDartApplication Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example derivation for building a Dart application using fetchFromGitHub and a pre-imported pubspec.lock.json file. ```nix { lib, buildDartApplication, fetchFromGitHub, }: buildDartApplication (finalAttrs: { pname = "dart-sass"; version = "1.62.1"; src = fetchFromGitHub { owner = "sass"; repo = "dart-sass"; tag = finalAttrs.version; hash = "sha256-U6enz8yJcc4Wf8m54eYIAnVg/jsGi247Wy8lp1r1wg4="; }; pubspecLock = lib.importJSON ./pubspec.lock.json; }) ``` -------------------------------- ### Format hardening error example Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of a build error caused by the format hardening flag when a format string is not a literal. ```text /tmp/nix-build-zynaddsubfx-2.5.2.drv-0/zynaddsubfx-2.5.2/src/UI/guimain.cpp:571:28: error: format not a string literal and no format arguments [-Werror=format-security] printf(help_message); ^ cc1plus: some warnings being treated as errors ``` -------------------------------- ### Build a Nim package with buildNimPackage Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Example of a Nim program build configuration using a lockfile and buildNimPackage. ```nix { lib, buildNimPackage, fetchFromGitHub, }: buildNimPackage (finalAttrs: { pname = "ttop"; version = "1.2.7"; src = fetchFromGitHub { owner = "inv2004"; repo = "ttop"; tag = "v${finalAttrs.version}"; hash = lib.fakeHash; }; lockFile = ./lock.json; nimFlags = [ "-d:NimblePkgVersion=${finalAttrs.version}" ]; }) ``` -------------------------------- ### Configure a development environment with shellFor Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage An example of using shellFor to create a development environment that includes multiple packages and their dependencies. ```nix { pkgs ? import { }, }: pkgs.haskellPackages.shellFor { packages = hpkgs: [ # reuse the nixpkgs for this package hpkgs.distribution-nixpkgs # call our generated Nix expression manually (hpkgs.callPackage ./my-project/my-project.nix { }) ]; ``` -------------------------------- ### Configure Idris2 prefix for installation Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Set IDRIS2_PREFIX to a writable directory to allow running idris2 --install successfully. ```nix { pkgs ? import { }, }: pkgs.mkShell { packages = [ (idris2.withPackages (p: [ p.idris2Api ])) ]; shellHook = '' IDRIS2_PREFIX="$HOME/.idris2" ''; } ``` -------------------------------- ### Create a custom Python environment Source: https://nixos.org/manual/nixpkgs/unstable/#javascript-buildNpmPackage Demonstrates how to define a custom package within a let expression and include it in a Python environment using withPackages. ```nix with import { }; ( let my_toolz = python313Packages.buildPythonPackage (finalAttrs: { pname = "toolz"; version = "0.10.0"; pyproject = true; src = fetchPypi { inherit (finalAttrs) pname version; hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA="; }; build-system = [ python313Packages.setuptools ]; # has no tests doCheck = false; meta = { homepage = "https://github.com/pytoolz/toolz/"; description = "List processing tools and functional utilities"; # [...] }; }); in python313Packages.python.withPackages ( ps: with ps; [ numpy my_toolz ] ) ).env ```