doc: update Nix code snippets format

Command: `mdcr --config doc/tests/mdcr-config.toml doc/`

Changed files
+2478 -1471
doc
build-helpers
functions
hooks
interoperability
languages-frameworks
packages
stdenv
using
+12 -3
doc/build-helpers/dev-shell-tools.chapter.md
···
devShellTools.unstructuredDerivationInputEnv {
drvAttrs = {
name = "foo";
-
buildInputs = [ hello figlet ];
+
buildInputs = [
+
hello
+
figlet
+
];
builder = bash;
-
args = [ "-c" "${./builder.sh}" ];
+
args = [
+
"-c"
+
"${./builder.sh}"
+
];
};
}
# => {
···
let
pkg = hello;
in
-
devShellTools.derivationOutputEnv { outputList = pkg.outputs; outputMap = pkg; }
+
devShellTools.derivationOutputEnv {
+
outputList = pkg.outputs;
+
outputMap = pkg;
+
}
```
:::
+12 -5
doc/build-helpers/fetchers.chapter.md
···
In this example, we'll adapt [](#ex-fetchers-fetchurl-nixpkgs-version) to append the result of running the `hello` package to the contents we download, purely to illustrate how to manipulate the content.
```nix
-
{ fetchurl, hello, lib }:
+
{
+
fetchurl,
+
hello,
+
lib,
+
}:
fetchurl {
url = "https://raw.githubusercontent.com/NixOS/nixpkgs/23.11/.version";
···
Here is an example of `fetchDebianPatch` in action:
```nix
-
{ lib
-
, fetchDebianPatch
-
, buildPythonPackage
+
{
+
lib,
+
fetchDebianPatch,
+
buildPythonPackage,
}:
buildPythonPackage rec {
···
{ fetchtorrent }:
fetchtorrent {
-
config = { peer-limit-global = 100; };
+
config = {
+
peer-limit-global = 100;
+
};
url = "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c";
hash = "";
}
+6 -3
doc/build-helpers/images/appimagetools.section.md
···
url = "https://github.com/irccloud/irccloud-desktop/releases/download/v${version}/IRCCloud-${version}-linux-x86_64.AppImage";
hash = "sha256-/hMPvYdnVB1XjKgU2v47HnVvW4+uC3rhRjbucqin4iI=";
};
-
in appimageTools.wrapType2 {
+
in
+
appimageTools.wrapType2 {
inherit pname version src;
extraPkgs = pkgs: [ pkgs.at-spi2-core ];
}
···
appimageContents = appimageTools.extract {
inherit pname version src;
};
-
in appimageTools.wrapType2 {
+
in
+
appimageTools.wrapType2 {
inherit pname version src;
extraPkgs = pkgs: [ pkgs.at-spi2-core ];
···
substituteInPlace $out/irccloud.desktop --replace-fail 'Exec=AppRun' 'Exec=${pname}'
'';
};
-
in appimageTools.wrapType2 {
+
in
+
appimageTools.wrapType2 {
inherit pname version src;
extraPkgs = pkgs: [ pkgs.at-spi2-core ];
+1 -1
doc/build-helpers/images/binarycache.section.md
···
```nix
{ mkBinaryCache, hello }:
mkBinaryCache {
-
rootPaths = [hello];
+
rootPaths = [ hello ];
}
```
+34 -8
doc/build-helpers/images/dockertools.section.md
···
The Docker image will have name `redis` and tag `latest`.
```nix
-
{ dockerTools, buildEnv, redis }:
+
{
+
dockerTools,
+
buildEnv,
+
redis,
+
}:
dockerTools.buildImage {
name = "redis";
tag = "latest";
···
config = {
Cmd = [ "/bin/redis-server" ];
WorkingDir = "/data";
-
Volumes = { "/data" = { }; };
+
Volumes = {
+
"/data" = { };
+
};
};
}
```
···
This works the same as [](#ex-dockerTools-buildImage-extraCommands), but uses `runAsRoot` instead of `extraCommands`.
```nix
-
{ dockerTools, buildEnv, hello }:
+
{
+
dockerTools,
+
buildEnv,
+
hello,
+
}:
dockerTools.buildImage {
name = "hello";
tag = "latest";
···
Note that with `extraCommands`, we can't directly reference `/` and must create files and directories as if we were already on `/`.
```nix
-
{ dockerTools, buildEnv, hello }:
+
{
+
dockerTools,
+
buildEnv,
+
hello,
+
}:
dockerTools.buildImage {
name = "hello";
tag = "latest";
···
Note that using a value of `"now"` in the `created` attribute will break reproducibility.
```nix
-
{ dockerTools, buildEnv, hello }:
+
{
+
dockerTools,
+
buildEnv,
+
hello,
+
}:
dockerTools.buildImage {
name = "hello";
tag = "latest";
···
The following package shows a more compact way to create the same output generated in [](#ex-dockerTools-streamLayeredImage-hello).
```nix
-
{ dockerTools, hello, lib }:
+
{
+
dockerTools,
+
hello,
+
lib,
+
}:
dockerTools.streamLayeredImage {
name = "hello";
tag = "latest";
···
This example uses [](#ex-dockerTools-streamNixShellImage-hello) as a starting point.
```nix
-
{ dockerTools, cowsay, hello }:
+
{
+
dockerTools,
+
cowsay,
+
hello,
+
}:
dockerTools.streamNixShellImage {
tag = "latest";
drv = hello.overrideAttrs (old: {
-
nativeBuildInputs = old.nativeBuildInputs or [] ++ [
+
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [
cowsay
];
});
+37 -30
doc/build-helpers/images/makediskimage.section.md
···
To produce a Nix-store only image:
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
lib = pkgs.lib;
make-disk-image = import <nixpkgs/nixos/lib/make-disk-image.nix>;
in
-
make-disk-image {
-
inherit pkgs lib;
-
config = {};
-
additionalPaths = [ ];
-
format = "qcow2";
-
onlyNixStore = true;
-
partitionTableType = "none";
-
installBootLoader = false;
-
touchEFIVars = false;
-
diskSize = "auto";
-
additionalSpace = "0M"; # Defaults to 512M.
-
copyChannel = false;
-
}
+
make-disk-image {
+
inherit pkgs lib;
+
config = { };
+
additionalPaths = [ ];
+
format = "qcow2";
+
onlyNixStore = true;
+
partitionTableType = "none";
+
installBootLoader = false;
+
touchEFIVars = false;
+
diskSize = "auto";
+
additionalSpace = "0M"; # Defaults to 512M.
+
copyChannel = false;
+
}
```
Some arguments can be left out, they are shown explicitly for the sake of the example.
···
To produce a NixOS installation image disk with UEFI and bootloader installed:
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
lib = pkgs.lib;
make-disk-image = import <nixpkgs/nixos/lib/make-disk-image.nix>;
evalConfig = import <nixpkgs/nixos/lib/eval-config.nix>;
in
-
make-disk-image {
-
inherit pkgs lib;
-
inherit (evalConfig {
+
make-disk-image {
+
inherit pkgs lib;
+
inherit
+
(evalConfig {
modules = [
{
-
fileSystems."/" = { device = "/dev/vda"; fsType = "ext4"; autoFormat = true; };
+
fileSystems."/" = {
+
device = "/dev/vda";
+
fsType = "ext4";
+
autoFormat = true;
+
};
boot.grub.device = "/dev/vda";
}
];
-
}) config;
-
format = "qcow2";
-
onlyNixStore = false;
-
partitionTableType = "legacy+gpt";
-
installBootLoader = true;
-
touchEFIVars = true;
-
diskSize = "auto";
-
additionalSpace = "0M"; # Defaults to 512M.
-
copyChannel = false;
-
memSize = 2048; # Qemu VM memory size in megabytes. Defaults to 1024M.
-
}
+
})
+
config
+
;
+
format = "qcow2";
+
onlyNixStore = false;
+
partitionTableType = "legacy+gpt";
+
installBootLoader = true;
+
touchEFIVars = true;
+
diskSize = "auto";
+
additionalSpace = "0M"; # Defaults to 512M.
+
copyChannel = false;
+
memSize = 2048; # Qemu VM memory size in megabytes. Defaults to 1024M.
+
}
```
+5 -1
doc/build-helpers/images/ocitools.section.md
···
This example uses `ociTools.buildContainer` to create a simple container that runs `bash`.
```nix
-
{ ociTools, lib, bash }:
+
{
+
ociTools,
+
lib,
+
bash,
+
}:
ociTools.buildContainer {
args = [
(lib.getExe bash)
+17 -3
doc/build-helpers/images/portableservice.section.md
···
The following example builds a Portable Service image with the `hello` package, along with a service unit that runs it.
```nix
-
{ lib, writeText, portableService, hello }:
+
{
+
lib,
+
writeText,
+
portableService,
+
hello,
+
}:
let
hello-service = writeText "hello.service" ''
[Unit]
···
The following package builds on the package from [](#ex-portableService-hello) to make `/etc/ssl` available globally (this is only for illustrative purposes, because `hello` doesn't use `/etc/ssl`).
```nix
-
{ lib, writeText, portableService, hello, cacert }:
+
{
+
lib,
+
writeText,
+
portableService,
+
hello,
+
cacert,
+
}:
let
hello-service = writeText "hello.service" ''
[Unit]
···
inherit (hello) version;
units = [ hello-service ];
symlinks = [
-
{ object = "${cacert}/etc/ssl"; symlink = "/etc/ssl"; }
+
{
+
object = "${cacert}/etc/ssl";
+
symlink = "/etc/ssl";
+
}
];
}
```
+5 -2
doc/build-helpers/special/checkpoint-build.section.md
···
## Example {#sec-checkpoint-build-example}
```nix
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
let
inherit (pkgs.checkpointBuildTools)
prepareCheckpointBuild
···
sed -i 's/Hello, world!/Hello, Nix!/g' src/hello.c
'';
});
-
in mkCheckpointBuild changedHello helloCheckpoint
+
in
+
mkCheckpointBuild changedHello helloCheckpoint
```
+11 -4
doc/build-helpers/special/fakenss.section.md
···
This example includes the `hello` binary in the image so it can do something besides just have the extra files.
```nix
-
{ dockerTools, fakeNss, hello }:
+
{
+
dockerTools,
+
fakeNss,
+
hello,
+
}:
dockerTools.buildImage {
name = "image-with-passwd";
tag = "latest";
-
copyToRoot = [ fakeNss hello ];
+
copyToRoot = [
+
fakeNss
+
hello
+
];
config = {
Cmd = [ "/bin/hello" ];
···
```nix
{ fakeNss }:
fakeNss.override {
-
extraPasswdLines = ["newuser:x:9001:9001:new user:/var/empty:/bin/sh"];
-
extraGroupLines = ["newuser:x:9001:"];
+
extraPasswdLines = [ "newuser:x:9001:9001:new user:/var/empty:/bin/sh" ];
+
extraGroupLines = [ "newuser:x:9001:" ];
}
```
:::
+20 -13
doc/build-helpers/special/fhs-environments.section.md
···
You can create a simple environment using a `shell.nix` like this:
```nix
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
(pkgs.buildFHSEnv {
name = "simple-x11-env";
-
targetPkgs = pkgs: (with pkgs; [
-
udev
-
alsa-lib
-
]) ++ (with pkgs.xorg; [
-
libX11
-
libXcursor
-
libXrandr
-
]);
-
multiPkgs = pkgs: (with pkgs; [
-
udev
-
alsa-lib
-
]);
+
targetPkgs =
+
pkgs:
+
(with pkgs; [
+
udev
+
alsa-lib
+
])
+
++ (with pkgs.xorg; [
+
libX11
+
libXcursor
+
libXrandr
+
]);
+
multiPkgs =
+
pkgs:
+
(with pkgs; [
+
udev
+
alsa-lib
+
]);
runScript = "bash";
}).env
```
+7 -2
doc/build-helpers/special/mkshell.section.md
···
Here is a common usage example:
```nix
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
pkgs.mkShell {
packages = [ pkgs.gnumake ];
-
inputsFrom = [ pkgs.hello pkgs.gnutar ];
+
inputsFrom = [
+
pkgs.hello
+
pkgs.gnutar
+
];
shellHook = ''
export DEBUG=1
+30 -19
doc/build-helpers/special/vm-tools.section.md
···
Build the derivation hello inside a VM:
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
runInLinuxVM hello
+
{ pkgs }: with pkgs; with vmTools; runInLinuxVM hello
```
Build inside a VM with extra memory:
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
runInLinuxVM (hello.overrideAttrs (_: { memSize = 1024; }))
+
{ pkgs }:
+
with pkgs;
+
with vmTools;
+
runInLinuxVM (
+
hello.overrideAttrs (_: {
+
memSize = 1024;
+
})
+
)
```
Use VM with a disk image (implicitly sets `diskImage`, see [`vmTools.createEmptyImage`](#vm-tools-createEmptyImage)):
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
runInLinuxVM (hello.overrideAttrs (_: {
-
preVM = createEmptyImage {
-
size = 1024;
-
fullName = "vm-image";
-
};
-
}))
+
{ pkgs }:
+
with pkgs;
+
with vmTools;
+
runInLinuxVM (
+
hello.overrideAttrs (_: {
+
preVM = createEmptyImage {
+
size = 1024;
+
fullName = "vm-image";
+
};
+
})
+
)
```
## `vmTools.extractFs` {#vm-tools-extractFs}
···
Extract the contents of an ISO file:
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
extractFs { file = ./image.iso; }
+
{ pkgs }: with pkgs; with vmTools; extractFs { file = ./image.iso; }
```
## `vmTools.extractMTDfs` {#vm-tools-extractMTDfs}
···
Create a script for running a Fedora 27 VM:
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
makeImageTestScript diskImages.fedora27x86_64
+
{ pkgs }: with pkgs; with vmTools; makeImageTestScript diskImages.fedora27x86_64
```
Create a script for running an Ubuntu 20.04 VM:
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
makeImageTestScript diskImages.ubuntu2004x86_64
+
{ pkgs }: with pkgs; with vmTools; makeImageTestScript diskImages.ubuntu2004x86_64
```
## `vmTools.diskImageFuns` {#vm-tools-diskImageFuns}
···
8GiB image containing Firefox in addition to the default packages:
```nix
-
{ pkgs }: with pkgs; with vmTools;
-
diskImageFuns.ubuntu2004x86_64 { extraPackages = [ "firefox" ]; size = 8192; }
+
{ pkgs }:
+
with pkgs;
+
with vmTools;
+
diskImageFuns.ubuntu2004x86_64 {
+
extraPackages = [ "firefox" ];
+
size = 8192;
+
}
```
## `vmTools.diskImageExtraFuns` {#vm-tools-diskImageExtraFuns}
+64 -40
doc/build-helpers/testers.chapter.md
···
```nix
{
"https://nix\\.dev/manual/nix/[a-z0-9.-]*" = "${nix.doc}/share/doc/nix/manual";
-
"https://nixos\\.org/manual/nix/(un)?stable" = "${emptyDirectory}/placeholder-to-disallow-old-nix-docs-urls";
+
"https://nixos\\.org/manual/nix/(un)?stable" =
+
"${emptyDirectory}/placeholder-to-disallow-old-nix-docs-urls";
}
```
···
# Check that a build fails, and verify the changes made during build
```nix
-
runCommand "example" {
-
failed = testers.testBuildFailure (runCommand "fail" {} ''
-
echo ok-ish >$out
-
echo failing though
-
exit 3
-
'');
-
} ''
-
grep -F 'ok-ish' $failed/result
-
grep -F 'failing though' $failed/testBuildFailure.log
-
[[ 3 = $(cat $failed/testBuildFailure.exit) ]]
-
touch $out
-
''
+
runCommand "example"
+
{
+
failed = testers.testBuildFailure (
+
runCommand "fail" { } ''
+
echo ok-ish >$out
+
echo failing though
+
exit 3
+
''
+
);
+
}
+
''
+
grep -F 'ok-ish' $failed/result
+
grep -F 'failing though' $failed/testBuildFailure.log
+
[[ 3 = $(cat $failed/testBuildFailure.exit) ]]
+
touch $out
+
''
```
:::
···
expected = writeText "expected" ''
foo baz baz
'';
-
actual = runCommand "actual" {
-
# not really necessary for a package that's in stdenv
-
nativeBuildInputs = [ gnused ];
-
base = writeText "base" ''
-
foo bar baz
-
'';
-
} ''
-
sed -e 's/bar/baz/g' $base >$out
-
'';
+
actual =
+
runCommand "actual"
+
{
+
# not really necessary for a package that's in stdenv
+
nativeBuildInputs = [ gnused ];
+
base = writeText "base" ''
+
foo bar baz
+
'';
+
}
+
''
+
sed -e 's/bar/baz/g' $base >$out
+
'';
}
```
···
# Check that two packages produce the same derivation
```nix
-
testers.testEqualDerivation
-
"The hello package must stay the same when enabling checks."
-
hello
-
(hello.overrideAttrs(o: { doCheck = true; }))
+
testers.testEqualDerivation "The hello package must stay the same when enabling checks." hello (
+
hello.overrideAttrs (o: {
+
doCheck = true;
+
})
+
)
```
:::
···
curl -o /dev/null https://example.com
touch $out
'';
-
nativeBuildInputs = with pkgs; [ cacert curl ];
+
nativeBuildInputs = with pkgs; [
+
cacert
+
curl
+
];
}
```
···
# Run a NixOS test using `runNixOSTest`
```nix
-
pkgs.testers.runNixOSTest ({ lib, ... }: {
-
name = "hello";
-
nodes.machine = { pkgs, ... }: {
-
environment.systemPackages = [ pkgs.hello ];
-
};
-
testScript = ''
-
machine.succeed("hello")
-
'';
-
})
+
pkgs.testers.runNixOSTest (
+
{ lib, ... }:
+
{
+
name = "hello";
+
nodes.machine =
+
{ pkgs, ... }:
+
{
+
environment.systemPackages = [ pkgs.hello ];
+
};
+
testScript = ''
+
machine.succeed("hello")
+
'';
+
}
+
)
```
:::
···
{
name = "my-test";
nodes = {
-
machine1 = { lib, pkgs, nodes, ... }: {
-
environment.systemPackages = [ pkgs.hello ];
-
services.foo.enable = true;
-
};
+
machine1 =
+
{
+
lib,
+
pkgs,
+
nodes,
+
...
+
}:
+
{
+
environment.systemPackages = [ pkgs.hello ];
+
services.foo.enable = true;
+
};
# machine2 = ...;
};
testScript = ''
+84 -57
doc/build-helpers/trivial-build-helpers.chapter.md
···
# Invocation of `runCommandWith`
```nix
-
runCommandWith {
-
name = "example";
-
derivationArgs.nativeBuildInputs = [ cowsay ];
-
} ''
-
cowsay > $out <<EOMOO
-
'runCommandWith' is a bit cumbersome,
-
so we have more ergonomic wrappers.
-
EOMOO
-
''
+
runCommandWith
+
{
+
name = "example";
+
derivationArgs.nativeBuildInputs = [ cowsay ];
+
}
+
''
+
cowsay > $out <<EOMOO
+
'runCommandWith' is a bit cumbersome,
+
so we have more ergonomic wrappers.
+
EOMOO
+
''
```
:::
···
# Invocation of `runCommand`
```nix
-
runCommand "my-example" {} ''
+
runCommand "my-example" { } ''
echo My example command is running
mkdir $out
···
Write a desktop file `/nix/store/<store path>/my-program.desktop` to the Nix store.
```nix
-
{makeDesktopItem}:
+
{ makeDesktopItem }:
makeDesktopItem {
name = "my-program";
desktopName = "My Program";
···
mimeTypes = [ "video/mp4" ];
categories = [ "Utility" ];
implements = [ "org.my-program" ];
-
keywords = [ "Video" "Player" ];
+
keywords = [
+
"Video"
+
"Player"
+
];
startupNotify = false;
startupWMClass = "MyProgram";
prefersNonDefaultGPU = false;
···
Override the `hello` package to add a desktop item.
```nix
-
{ copyDesktopItems
-
, hello
-
, makeDesktopItem }:
+
{
+
copyDesktopItems,
+
hello,
+
makeDesktopItem,
+
}:
hello.overrideAttrs {
nativeBuildInputs = [ copyDesktopItems ];
-
desktopItems = [(makeDesktopItem {
-
name = "hello";
-
desktopName = "Hello";
-
exec = "hello";
-
})];
+
desktopItems = [
+
(makeDesktopItem {
+
name = "hello";
+
desktopName = "Hello";
+
exec = "hello";
+
})
+
];
}
```
···
Write the string `Contents of File` to `/nix/store/<store path>`:
```nix
-
writeText "my-file"
-
''
+
writeText "my-file" ''
Contents of File
-
''
+
''
```
:::
···
Write the string `Contents of File` to `/nix/store/<store path>/share/my-file`:
```nix
-
writeTextDir "share/my-file"
-
''
+
writeTextDir "share/my-file" ''
Contents of File
-
''
+
''
```
:::
···
Write the string `Contents of File` to `/nix/store/<store path>` and make the file executable.
```nix
-
writeScript "my-file"
-
''
+
writeScript "my-file" ''
Contents of File
-
''
+
''
```
This is equivalent to:
···
# Usage of `writeScriptBin`
```nix
-
writeScriptBin "my-script"
-
''
+
writeScriptBin "my-script" ''
echo "hi"
-
''
+
''
```
:::
···
# Usage of `writeShellScript`
```nix
-
writeShellScript "my-script"
-
''
+
writeShellScript "my-script" ''
echo "hi"
-
''
+
''
```
:::
···
# Usage of `writeShellScriptBin`
```nix
-
writeShellScriptBin "my-script"
-
''
+
writeShellScriptBin "my-script" ''
echo "hi"
-
''
+
''
```
:::
···
Here are a few examples:
```nix
-
# Writes my-file to /nix/store/<store path>
-
concatTextFile {
-
name = "my-file";
-
files = [ drv1 "${drv2}/path/to/file" ];
-
}
-
# See also the `concatText` helper function below.
+
concatTextFile
+
{
+
name = "my-file";
+
files = [
+
drv1
+
"${drv2}/path/to/file"
+
];
+
}
+
# See also the `concatText` helper function below.
-
# Writes executable my-file to /nix/store/<store path>/bin/my-file
-
concatTextFile {
-
name = "my-file";
-
files = [ drv1 "${drv2}/path/to/file" ];
-
executable = true;
-
destination = "/bin/my-file";
-
}
-
# Writes contents of files to /nix/store/<store path>
-
concatText "my-file" [ file1 file2 ]
+
# Writes executable my-file to /nix/store/<store path>/bin/my-file
+
concatTextFile
+
{
+
name = "my-file";
+
files = [
+
drv1
+
"${drv2}/path/to/file"
+
];
+
executable = true;
+
destination = "/bin/my-file";
+
}
+
# Writes contents of files to /nix/store/<store path>
+
concatText
+
"my-file"
+
[ file1 file2 ]
-
# Writes contents of files to /nix/store/<store path>
-
concatScript "my-file" [ file1 file2 ]
+
# Writes contents of files to /nix/store/<store path>
+
concatScript
+
"my-file"
+
[
+
file1
+
file2
+
]
```
## `writeShellApplication` {#trivial-builder-writeShellApplication}
···
writeShellApplication {
name = "show-nixos-org";
-
runtimeInputs = [ curl w3m ];
+
runtimeInputs = [
+
curl
+
w3m
+
];
text = ''
curl -s 'https://nixos.org' | w3m -dump -T text/html
···
Here is an example:
```nix
# adds symlinks of hello and stack to current build and prints "links added"
-
symlinkJoin { name = "myexample"; paths = [ pkgs.hello pkgs.stack ]; postBuild = "echo links added"; }
+
symlinkJoin {
+
name = "myexample";
+
paths = [
+
pkgs.hello
+
pkgs.stack
+
];
+
postBuild = "echo links added";
+
}
```
This creates a derivation with a directory structure like the following:
```
+13 -7
doc/functions/generators.section.md
···
# specifies how to format a key/value pair
mkKeyValue = generators.mkKeyValueDefault {
# specifies the generated string for a subset of nix values
-
mkValueString = v:
-
if v == true then ''"yes"''
-
else if v == false then ''"no"''
-
else if isString v then ''"${v}"''
+
mkValueString =
+
v:
+
if v == true then
+
''"yes"''
+
else if v == false then
+
''"no"''
+
else if isString v then
+
''"${v}"''
# and delegates all other values to the default generator
-
else generators.mkValueStringDefault {} v;
+
else
+
generators.mkValueStringDefault { } v;
} ":";
};
-
# the INI file can now be given as plain old nix values
-
in customToINI {
+
# the INI file can now be given as plain old nix values
+
in
+
customToINI {
main = {
pushinfo = true;
autopush = false;
+13 -10
doc/functions/nix-gitignore.section.md
···
`pkgs.nix-gitignore` exports a number of functions, but you'll most likely need either `gitignoreSource` or `gitignoreSourcePure`. As their first argument, they both accept either 1. a file with gitignore lines or 2. a string with gitignore lines, or 3. a list of either of the two. They will be concatenated into a single big string.
```nix
-
{ pkgs ? import <nixpkgs> {} }: {
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
+
{
-
src = nix-gitignore.gitignoreSource [] ./source;
-
# Simplest version
+
src = nix-gitignore.gitignoreSource [ ] ./source;
+
# Simplest version
-
src = nix-gitignore.gitignoreSource "supplemental-ignores\n" ./source;
-
# This one reads the ./source/.gitignore and concats the auxiliary ignores
+
src = nix-gitignore.gitignoreSource "supplemental-ignores\n" ./source;
+
# This one reads the ./source/.gitignore and concats the auxiliary ignores
-
src = nix-gitignore.gitignoreSourcePure "ignore-this\nignore-that\n" ./source;
-
# Use this string as gitignore, don't read ./source/.gitignore.
+
src = nix-gitignore.gitignoreSourcePure "ignore-this\nignore-that\n" ./source;
+
# Use this string as gitignore, don't read ./source/.gitignore.
-
src = nix-gitignore.gitignoreSourcePure ["ignore-this\nignore-that\n" ~/.gitignore] ./source;
-
# It also accepts a list (of strings and paths) that will be concatenated
-
# once the paths are turned to strings via readFile.
+
src = nix-gitignore.gitignoreSourcePure [ "ignore-this\nignore-that\n" ~/.gitignore ] ./source;
+
# It also accepts a list (of strings and paths) that will be concatenated
+
# once the paths are turned to strings via readFile.
}
```
+1 -2
doc/functions/prefer-remote-fetch.section.md
···
`prefer-remote-fetch` is an overlay that download sources on remote builder. This is useful when the evaluating machine has a slow upload while the builder can fetch faster directly from the source. To use it, put the following snippet as a new overlay:
```nix
-
self: super:
-
(super.prefer-remote-fetch self super)
+
self: super: (super.prefer-remote-fetch self super)
```
A full configuration example for that sets the overlay up for your own account, could look like this
+8 -8
doc/hooks/mpi-check-hook.section.md
···
Example:
```nix
-
{ mpiCheckPhaseHook, mpi, ... }:
-
{
-
# ...
+
{ mpiCheckPhaseHook, mpi, ... }:
+
{
+
# ...
-
nativeCheckInputs = [
-
openssh
-
mpiCheckPhaseHook
-
];
-
}
+
nativeCheckInputs = [
+
openssh
+
mpiCheckPhaseHook
+
];
+
}
```
+12 -2
doc/hooks/patch-rc-path-hooks.section.md
···
patch the init script for users to source without having the above dependencies in their `PATH`:
```nix
-
{ lib, stdenv, patchRcPathFish}:
+
{
+
lib,
+
stdenv,
+
patchRcPathFish,
+
}:
stdenv.mkDerivation {
# ...
···
];
postFixup = ''
-
patchRcPathFish $out/bin/this-foo.fish ${lib.makeBinPath [ coreutils man which ]}
+
patchRcPathFish $out/bin/this-foo.fish ${
+
lib.makeBinPath [
+
coreutils
+
man
+
which
+
]
+
}
'';
}
```
+10 -6
doc/hooks/postgresql-test-hook.section.md
···
This hook starts a PostgreSQL server during the `checkPhase`. Example:
```nix
-
{ stdenv, postgresql, postgresqlTestHook }:
+
{
+
stdenv,
+
postgresql,
+
postgresqlTestHook,
+
}:
stdenv.mkDerivation {
# ...
···
If you use a custom `checkPhase`, remember to add the `runHook` calls:
```nix
-
checkPhase ''
-
runHook preCheck
+
checkPhase ''
+
runHook preCheck
-
# ... your tests
+
# ... your tests
-
runHook postCheck
-
''
+
runHook postCheck
+
''
```
## Variables {#sec-postgresqlTestHook-variables}
+7 -2
doc/hooks/redis-test-hook.section.md
···
{
stdenv,
redis,
-
redisTestHook
+
redisTestHook,
}:
stdenv.mkDerivation {
···
Example usage:
```nix
-
{ stdenv, redis, redisTestHook }:
+
{
+
stdenv,
+
redis,
+
redisTestHook,
+
}:
stdenv.mkDerivation {
# ...
···
redisTestPort=6390;
'';
}
+
```
+1 -1
doc/hooks/versionCheckHook.section.md
···
lib,
stdenv,
versionCheckHook,
-
# ...
+
# ...
}:
stdenv.mkDerivation (finalAttrs: {
+4 -3
doc/hooks/zig.section.md
···
## Example code snippet {#zig-hook-example-code-snippet}
```nix
-
{ lib
-
, stdenv
-
, zig
+
{
+
lib,
+
stdenv,
+
zig,
}:
stdenv.mkDerivation {
+13 -3
doc/interoperability/cyclonedx.md
···
`nix:fod` properties may be extracted and evaluated to a derivation using code similar to the following, assuming a fictitious function `filterPropertiesToAttrs`:
```nix
-
{ pkgs, filterPropertiesToAttrs, properties }:
+
{
+
pkgs,
+
filterPropertiesToAttrs,
+
properties,
+
}:
let
fodProps = filterPropertiesToAttrs "nix:fod:" properties;
methods = {
fetchzip =
-
{ name, url, sha256, ... }:
+
{
+
name,
+
url,
+
sha256,
+
...
+
}:
pkgs.fetchzip {
inherit name url sha256;
};
};
-
in methods.${fodProps.method} fodProps
+
in
+
methods.${fodProps.method} fodProps
```
+14 -6
doc/languages-frameworks/agda.section.md
···
agda.withPackages (p: [
(p.standard-library.overrideAttrs (oldAttrs: {
version = "1.5";
-
src = fetchFromGitHub {
+
src = fetchFromGitHub {
repo = "agda-stdlib";
owner = "agda";
rev = "v1.5";
···
```nix
agda.withPackages {
-
pkgs = [ /* ... */ ];
+
pkgs = [
+
# ...
+
];
ghc = haskell.compiler.ghcHEAD;
}
```
···
Here is an example `default.nix`
```nix
-
{ nixpkgs ? <nixpkgs> }:
-
with (import nixpkgs {});
+
{
+
nixpkgs ? <nixpkgs>,
+
}:
+
with (import nixpkgs { });
agdaPackages.mkDerivation {
version = "1.0";
pname = "my-agda-lib";
···
To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the top line of the `default.nix` can look like:
```nix
-
{ mkDerivation, standard-library, fetchFromGitHub }:
-
{}
+
{
+
mkDerivation,
+
standard-library,
+
fetchFromGitHub,
+
}:
+
{ }
```
Note that the derivation function is called with `mkDerivation` set to `agdaPackages.mkDerivation`, therefore you
+24 -16
doc/languages-frameworks/android.section.md
···
```nix
{
-
buildInputs = [ android-studio-full ];
+
buildInputs = [ android-studio-full ];
}
```
···
```nix
{
-
buildInputs = [ androidStudioPackages.stable.full ];
+
buildInputs = [ androidStudioPackages.stable.full ];
}
```
···
```nix
{
-
buildInputs = [
-
(android-studio.withSdk (androidenv.composeAndroidPackages {
-
includeNDK = true;
-
}).androidsdk)
-
];
+
buildInputs = [
+
(android-studio.withSdk
+
(androidenv.composeAndroidPackages {
+
includeNDK = true;
+
}).androidsdk
+
)
+
];
}
```
···
Alternatively, you can deploy the SDK separately with a desired set of plugins, or subsets of an SDK.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
let
androidComposition = androidenv.composeAndroidPackages {
-
platformVersions = [ "34" "35" ];
+
platformVersions = [
+
"34"
+
"35"
+
];
systemImageTypes = [ "google_apis_playstore" ];
-
abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
+
abiVersions = [
+
"armeabi-v7a"
+
"arm64-v8a"
+
];
includeNDK = true;
includeExtras = [
"extras;google;auto"
···
`platform-tools` package, you can evaluate the following expression:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
let
androidComposition = androidenv.composeAndroidPackages {
···
The following Nix expression can be used to deploy the entire SDK:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
androidenv.androidPkgs.androidsdk
```
···
It is also possible to use one plugin only:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
androidenv.androidPkgs.platform-tools
```
···
function:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
androidenv.emulateApp {
name = "emulate-MyAndroidApp";
···
and the package and activity names to launch it:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
androidenv.emulateApp {
name = "emulate-MyAndroidApp";
···
purposes.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
androidenv.buildApp {
name = "MyAndroidApp";
+67 -33
doc/languages-frameworks/beam.section.md
···
```nix
let
-
pkgs = import <nixpkgs> { config = {}; overlays = []; };
+
pkgs = import <nixpkgs> {
+
config = { };
+
overlays = [ ];
+
};
in
pkgs.mkShell {
packages = [ pkgs.beamPackages.rebar3 ];
···
{
mixNixDeps = import ./mix.nix {
inherit beamPackages lib;
-
overrides = (final: prev: {
-
# mix2nix does not support git dependencies yet,
-
# so we need to add them manually
-
prometheus_ex = beamPackages.buildMix rec {
-
name = "prometheus_ex";
-
version = "3.0.5";
+
overrides = (
+
final: prev: {
+
# mix2nix does not support git dependencies yet,
+
# so we need to add them manually
+
prometheus_ex = beamPackages.buildMix rec {
+
name = "prometheus_ex";
+
version = "3.0.5";
-
# Change the argument src with the git src that you actually need
-
src = fetchFromGitLab {
-
domain = "git.pleroma.social";
-
group = "pleroma";
-
owner = "elixir-libraries";
-
repo = "prometheus.ex";
-
rev = "a4e9beb3c1c479d14b352fd9d6dd7b1f6d7deee5";
-
hash = "sha256-U17LlN6aGUKUFnT4XyYXppRN+TvUBIBRHEUsfeIiGOw=";
+
# Change the argument src with the git src that you actually need
+
src = fetchFromGitLab {
+
domain = "git.pleroma.social";
+
group = "pleroma";
+
owner = "elixir-libraries";
+
repo = "prometheus.ex";
+
rev = "a4e9beb3c1c479d14b352fd9d6dd7b1f6d7deee5";
+
hash = "sha256-U17LlN6aGUKUFnT4XyYXppRN+TvUBIBRHEUsfeIiGOw=";
+
};
+
# you can re-use the same beamDeps argument as generated
+
beamDeps = with final; [ prometheus ];
};
-
# you can re-use the same beamDeps argument as generated
-
beamDeps = with final; [ prometheus ];
-
};
-
});
+
}
+
);
};
}
```
···
hash = lib.fakeHash;
mixEnv = ""; # default is "prod", when empty includes all dependencies, such as "dev", "test".
# if you have build time environment variables add them here
-
MY_ENV_VAR="my_value";
+
MY_ENV_VAR = "my_value";
};
nodeDependencies = (pkgs.callPackage ./assets/default.nix { }).shell.nodeDependencies;
-
in packages.mixRelease {
-
inherit src pname version mixFodDeps;
+
in
+
packages.mixRelease {
+
inherit
+
src
+
pname
+
version
+
mixFodDeps
+
;
# if you have build time environment variables add them here
-
MY_ENV_VAR="my_value";
+
MY_ENV_VAR = "my_value";
postBuild = ''
ln -sf ${nodeDependencies}/lib/node_modules assets/node_modules
···
in your project with the following
```nix
-
{config, pkgs, lib, ...}:
+
{
+
config,
+
pkgs,
+
lib,
+
...
+
}:
let
release = pkgs.callPackage ./default.nix;
···
{
systemd.services.${release_name} = {
wantedBy = [ "multi-user.target" ];
-
after = [ "network.target" "postgresql.service" ];
+
after = [
+
"network.target"
+
"postgresql.service"
+
];
# note that if you are connecting to a postgres instance on a different host
# postgresql.service should not be included in the requires.
-
requires = [ "network-online.target" "postgresql.service" ];
+
requires = [
+
"network-online.target"
+
"postgresql.service"
+
];
description = "my app";
environment = {
# RELEASE_TMP is used to write the state of the
···
Usually, we need to create a `shell.nix` file and do our development inside of the environment specified therein. Just install your version of Erlang and any other interpreters, and then use your normal build tools. As an example with Elixir:
```nix
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
with pkgs;
let
···
```nix
let
-
elixir_1_18_1_overlay = (self: super: {
+
elixir_1_18_1_overlay = (
+
self: super: {
elixir_1_18 = super.elixir_1_18.override {
version = "1.18.1";
sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
-
});
+
}
+
);
pkgs = import <nixpkgs> { overlays = [ elixir_1_18_1_overlay ]; };
in
with pkgs;
···
nodePackages.prettier
];
-
inputs = basePackages ++ lib.optionals stdenv.hostPlatform.isLinux [ inotify-tools ]
-
++ lib.optionals stdenv.hostPlatform.isDarwin
-
(with darwin.apple_sdk.frameworks; [ CoreFoundation CoreServices ]);
+
inputs =
+
basePackages
+
++ lib.optionals stdenv.hostPlatform.isLinux [ inotify-tools ]
+
++ lib.optionals stdenv.hostPlatform.isDarwin (
+
with darwin.apple_sdk.frameworks;
+
[
+
CoreFoundation
+
CoreServices
+
]
+
);
# define shell startup command
hooks = ''
···
export ENV_VAR="your_env_var"
'';
-
in mkShell {
+
in
+
mkShell {
buildInputs = inputs;
shellHook = hooks;
}
+17 -8
doc/languages-frameworks/bower.section.md
···
```nix
{ fetchbower, buildEnv }:
-
buildEnv { name = "bower-env"; ignoreCollisions = true; paths = [
-
(fetchbower "angular" "1.5.3" "~1.5.0" "1749xb0firxdra4rzadm4q9x90v6pzkbd7xmcyjk6qfza09ykk9y")
-
(fetchbower "bootstrap" "3.3.6" "~3.3.6" "1vvqlpbfcy0k5pncfjaiskj3y6scwifxygfqnw393sjfxiviwmbv")
-
(fetchbower "jquery" "2.2.2" "1.9.1 - 2" "10sp5h98sqwk90y4k6hbdviwqzvzwqf47r3r51pakch5ii2y7js1")
-
]; }
+
buildEnv {
+
name = "bower-env";
+
ignoreCollisions = true;
+
paths = [
+
(fetchbower "angular" "1.5.3" "~1.5.0" "1749xb0firxdra4rzadm4q9x90v6pzkbd7xmcyjk6qfza09ykk9y")
+
(fetchbower "bootstrap" "3.3.6" "~3.3.6" "1vvqlpbfcy0k5pncfjaiskj3y6scwifxygfqnw393sjfxiviwmbv")
+
(fetchbower "jquery" "2.2.2" "1.9.1 - 2" "10sp5h98sqwk90y4k6hbdviwqzvzwqf47r3r51pakch5ii2y7js1")
+
];
+
}
```
Using the `bower2nix` command line arguments, the output can be redirected to a file. A name like `bower-packages.nix` would be fine.
···
### Example Full example — default.nix {#ex-buildBowerComponentsDefaultNix}
```nix
-
{ myWebApp ? { outPath = ./.; name = "myWebApp"; }
-
, pkgs ? import <nixpkgs> {}
+
{
+
myWebApp ? {
+
outPath = ./.;
+
name = "myWebApp";
+
},
+
pkgs ? import <nixpkgs> { },
}:
pkgs.stdenv.mkDerivation {
···
buildInputs = [ pkgs.nodePackages.gulp ];
-
bowerComponents = pkgs.buildBowerComponents { # note 1
+
bowerComponents = pkgs.buildBowerComponents {
+
# note 1
name = "my-web-app";
generated = ./bower-packages.nix;
src = myWebApp;
+12 -8
doc/languages-frameworks/chicken.section.md
···
```nix
let
-
myChickenPackages = pkgs.chickenPackages.overrideScope (self: super: {
+
myChickenPackages = pkgs.chickenPackages.overrideScope (
+
self: super: {
# The chicken package itself can be overridden to effect the whole ecosystem.
# chicken = super.chicken.overrideAttrs {
# src = ...
# };
-
chickenEggs = super.chickenEggs.overrideScope (eggself: eggsuper: {
-
srfi-180 = eggsuper.srfi-180.overrideAttrs {
-
# path to a local copy of srfi-180
-
src = <...>;
-
};
-
});
-
});
+
chickenEggs = super.chickenEggs.overrideScope (
+
eggself: eggsuper: {
+
srfi-180 = eggsuper.srfi-180.overrideAttrs {
+
# path to a local copy of srfi-180
+
src = <...>;
+
};
+
}
+
);
+
}
+
);
in
# Here, `myChickenPackages.chickenEggs.json-rpc`, which depends on `srfi-180` will use
# the local copy of `srfi-180`.
+70 -27
doc/languages-frameworks/coq.section.md
···
Here is a simple package example. It is a pure Coq library, thus it depends on Coq. It builds on the Mathematical Components library, thus it also takes some `mathcomp` derivations as `extraBuildInputs`.
```nix
-
{ lib, mkCoqDerivation, version ? null
-
, coq, mathcomp, mathcomp-finmap, mathcomp-bigenough }:
+
{
+
lib,
+
mkCoqDerivation,
+
version ? null,
+
coq,
+
mathcomp,
+
mathcomp-finmap,
+
mathcomp-bigenough,
+
}:
mkCoqDerivation {
-
/* namePrefix leads to e.g. `name = coq8.11-mathcomp1.11-multinomials-1.5.2` */
-
namePrefix = [ "coq" "mathcomp" ];
+
# namePrefix leads to e.g. `name = coq8.11-mathcomp1.11-multinomials-1.5.2`
+
namePrefix = [
+
"coq"
+
"mathcomp"
+
];
pname = "multinomials";
owner = "math-comp";
inherit version;
-
defaultVersion = with lib.versions; lib.switch [ coq.version mathcomp.version ] [
-
{ cases = [ (range "8.7" "8.12") (isEq "1.11") ]; out = "1.5.2"; }
-
{ cases = [ (range "8.7" "8.11") (range "1.8" "1.10") ]; out = "1.5.0"; }
-
{ cases = [ (range "8.7" "8.10") (range "1.8" "1.10") ]; out = "1.4"; }
-
{ cases = [ (isEq "8.6") (range "1.6" "1.7") ]; out = "1.1"; }
-
] null;
+
defaultVersion =
+
with lib.versions;
+
lib.switch
+
[ coq.version mathcomp.version ]
+
[
+
{
+
cases = [
+
(range "8.7" "8.12")
+
(isEq "1.11")
+
];
+
out = "1.5.2";
+
}
+
{
+
cases = [
+
(range "8.7" "8.11")
+
(range "1.8" "1.10")
+
];
+
out = "1.5.0";
+
}
+
{
+
cases = [
+
(range "8.7" "8.10")
+
(range "1.8" "1.10")
+
];
+
out = "1.4";
+
}
+
{
+
cases = [
+
(isEq "8.6")
+
(range "1.6" "1.7")
+
];
+
out = "1.1";
+
}
+
]
+
null;
release = {
"1.5.2".hash = "sha256-mjCx9XKa38Nz9E6wNK7YSqHdJ7YTua5fD3d6J4e7WpU=";
"1.5.1".hash = "sha256-Q8tm0y2FQAt2V1kZYkDlHWRia/lTvXAMVjdmzEV11I4=";
"1.5.0".hash = "sha256-HIK0f21G69oEW8JG46gSBde/Q2LR3GiBCv680gHbmRg=";
-
"1.5.0".rev = "1.5";
-
"1.4".hash = "sha256-F9g3MSIr3B6UZ3p8QWjz3/Jpw9sudJ+KRlvjiHSO024=";
-
"1.3".hash = "sha256-BPJTlAL0ETHvLMBslE0KFVt3DNoaGuMrHt2SBGyJe1A=";
-
"1.2".hash = "sha256-mHXBXSLYO4BN+jfN50y/+XCx0Qq5g4Ac2Y/qlsbgAdY=";
-
"1.1".hash = "sha256-ejAsMQbB/LtU9j+g160VdGXULrCe9s0gBWzyhKqmCuE=";
-
"1.0".hash = "sha256-tZTOltEBBKWciDxDMs/Ye4Jnq/33CANrHJ4FBMPtq+I=";
+
"1.5.0".rev = "1.5";
+
"1.4".hash = "sha256-F9g3MSIr3B6UZ3p8QWjz3/Jpw9sudJ+KRlvjiHSO024=";
+
"1.3".hash = "sha256-BPJTlAL0ETHvLMBslE0KFVt3DNoaGuMrHt2SBGyJe1A=";
+
"1.2".hash = "sha256-mHXBXSLYO4BN+jfN50y/+XCx0Qq5g4Ac2Y/qlsbgAdY=";
+
"1.1".hash = "sha256-ejAsMQbB/LtU9j+g160VdGXULrCe9s0gBWzyhKqmCuE=";
+
"1.0".hash = "sha256-tZTOltEBBKWciDxDMs/Ye4Jnq/33CANrHJ4FBMPtq+I=";
};
-
propagatedBuildInputs =
-
[ mathcomp.ssreflect mathcomp.algebra mathcomp-finmap mathcomp-bigenough ];
+
propagatedBuildInputs = [
+
mathcomp.ssreflect
+
mathcomp.algebra
+
mathcomp-finmap
+
mathcomp-bigenough
+
];
meta = {
description = "Coq/SSReflect Library for Monoidal Rings and Multinomials";
···
For example, here is how you could locally add a new release of the `multinomials` library, and set the `defaultVersion` to use this release:
```nix
-
coqPackages.lib.overrideCoqDerivation
-
{
-
defaultVersion = "2.0";
-
release."2.0".hash = "sha256-czoP11rtrIM7+OLdMisv2EF7n/IbGuwFxHiPtg3qCNM=";
-
}
-
coqPackages.multinomials
+
coqPackages.lib.overrideCoqDerivation {
+
defaultVersion = "2.0";
+
release."2.0".hash = "sha256-czoP11rtrIM7+OLdMisv2EF7n/IbGuwFxHiPtg3qCNM=";
+
} coqPackages.multinomials
```
### `.overrideAttrs` {#coq-overrideAttrs}
···
```nix
coqPackages.multinomials.overrideAttrs (oldAttrs: {
-
postInstall = oldAttrs.postInstall or "" + ''
-
echo "you can do anything you want here"
-
'';
+
postInstall =
+
oldAttrs.postInstall or ""
+
+ ''
+
echo "you can do anything you want here"
+
'';
})
```
+6 -3
doc/languages-frameworks/crystal.section.md
···
Next create a Nix file for your derivation and use `pkgs.crystal.buildCrystalPackage` as follows:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
crystal.buildCrystalPackage rec {
pname = "mint";
version = "0.5.0";
···
```nix
{
-
crystalBinaries.mint.options = [ "--release" "--verbose" ];
+
crystalBinaries.mint.options = [
+
"--release"
+
"--verbose"
+
];
}
```
Depending on the project, you might need additional steps to get it to compile successfully. In Mint's case, we need to link against openssl, so in the end the Nix file looks as follows:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
crystal.buildCrystalPackage rec {
version = "0.5.0";
pname = "mint";
+16 -10
doc/languages-frameworks/cuda.section.md
···
To use one or more CUDA packages in an expression, give the expression a `cudaPackages` parameter, and in case CUDA is optional
```nix
-
{ config
-
, cudaSupport ? config.cudaSupport
-
, cudaPackages ? { }
-
, ...
-
}: {}
+
{
+
config,
+
cudaSupport ? config.cudaSupport,
+
cudaPackages ? { },
+
...
+
}:
+
{ }
```
When using `callPackage`, you can choose to pass in a different variant, e.g.
···
set.
```nix
{
-
mypkg = let
-
cudaPackages = cudaPackages_11_5.overrideScope (final: prev: {
-
cudnn = prev.cudnn_8_3;
-
});
-
in callPackage { inherit cudaPackages; };
+
mypkg =
+
let
+
cudaPackages = cudaPackages_11_5.overrideScope (
+
final: prev: {
+
cudnn = prev.cudnn_8_3;
+
}
+
);
+
in
+
callPackage { inherit cudaPackages; };
}
```
+12 -14
doc/languages-frameworks/cuelang.section.md
···
Here is an example:
```nix
-
pkgs.writeCueValidator
-
(pkgs.writeText "schema.cue" ''
-
#Def1: {
-
field1: string
-
}
-
'')
-
{ document = "#Def1"; }
+
pkgs.writeCueValidator (pkgs.writeText "schema.cue" ''
+
#Def1: {
+
field1: string
+
}
+
'') { document = "#Def1"; }
```
- The first parameter is the Cue schema file.
···
Another example, given the following `validator.nix` :
```nix
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
let
-
genericValidator = version:
-
pkgs.writeCueValidator
-
(pkgs.writeText "schema.cue" ''
+
genericValidator =
+
version:
+
pkgs.writeCueValidator (pkgs.writeText "schema.cue" ''
#Version1: {
field1: string
}
#Version2: #Version1 & {
field1: "unused"
-
}''
-
)
-
{ document = "#Version${toString version}"; };
+
}'') { document = "#Version${toString version}"; };
in
{
validateV1 = genericValidator 1;
+6 -2
doc/languages-frameworks/dart.section.md
···
Dart supports multiple [outputs types](https://dart.dev/tools/dart-compile#types-of-output), you can choose between them using `dartOutputType` (defaults to `exe`). If you want to override the binaries path or the source path they come from, you can use `dartEntryPoints`. Outputs that require a runtime will automatically be wrapped with the relevant runtime (`dartaotruntime` for `aot-snapshot`, `dart run` for `jit-snapshot` and `kernel`, `node` for `js`), this can be overridden through `dartRuntimeCommand`.
```nix
-
{ lib, buildDartApplication, fetchFromGitHub }:
+
{
+
lib,
+
buildDartApplication,
+
fetchFromGitHub,
+
}:
buildDartApplication rec {
pname = "dart-sass";
···
`flutter` in Nixpkgs always points to `flutterPackages.stable`, which is the latest packaged version. To avoid unforeseen breakage during upgrade, packages in Nixpkgs should use a specific flutter version, such as `flutter319` and `flutter322`, instead of using `flutter` directly.
```nix
-
{ flutter322, fetchFromGitHub }:
+
{ flutter322, fetchFromGitHub }:
flutter322.buildFlutterApplication {
pname = "firmware-updater";
+8 -7
doc/languages-frameworks/dhall.section.md
···
let
nixpkgs = builtins.fetchTarball {
-
url = "https://github.com/NixOS/nixpkgs/archive/94b2848559b12a8ed1fe433084686b2a81123c99.tar.gz";
+
url = "https://github.com/NixOS/nixpkgs/archive/94b2848559b12a8ed1fe433084686b2a81123c99.tar.gz";
hash = "sha256-B4Q3c6IvTLg3Q92qYa8y+i4uTaphtFdjp+Ir3QQjdN0=";
};
···
overlay = self: super: {
dhallPackages = super.dhallPackages.override (old: {
-
overrides =
-
self.lib.composeExtensions (old.overrides or (_: _: {})) dhallOverlay;
+
overrides = self.lib.composeExtensions (old.overrides or (_: _: { })) dhallOverlay;
});
};
-
pkgs = import nixpkgs { config = {}; overlays = [ overlay ]; };
+
pkgs = import nixpkgs {
+
config = { };
+
overlays = [ overlay ];
+
};
in
-
pkgs
+
pkgs
```
… which we can then build using this command:
···
{
dhallOverrides = self: super: {
# Enable source for all Dhall packages
-
buildDhallPackage =
-
args: super.buildDhallPackage (args // { source = true; });
+
buildDhallPackage = args: super.buildDhallPackage (args // { source = true; });
true = self.callPackage ./true.nix { };
};
+21 -10
doc/languages-frameworks/dotnet.section.md
···
```nix
# shell.nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
mkShell {
name = "dotnet-env";
···
It's very likely that more than one sdk will be needed on a given project. Dotnet provides several different frameworks (E.g dotnetcore, aspnetcore, etc.) as well as many versions for a given framework. Normally, dotnet is able to fetch a framework and install it relative to the executable. However, this would mean writing to the nix store in nixpkgs, which is read-only. To support the many-sdk use case, one can compose an environment using `dotnetCorePackages.combinePackages`:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
mkShell {
name = "dotnet-env";
packages = [
-
(with dotnetCorePackages; combinePackages [
-
sdk_8_0
-
sdk_9_0
-
])
+
(
+
with dotnetCorePackages;
+
combinePackages [
+
sdk_8_0
+
sdk_9_0
+
]
+
)
];
}
```
···
Here is an example `default.nix`, using some of the previously discussed arguments:
```nix
-
{ lib, buildDotnetModule, dotnetCorePackages, ffmpeg }:
+
{
+
lib,
+
buildDotnetModule,
+
dotnetCorePackages,
+
ffmpeg,
+
}:
let
-
referencedProject = import ../../bar { /* ... */ };
-
in buildDotnetModule rec {
+
referencedProject = import ../../bar {
+
# ...
+
};
+
in
+
buildDotnetModule rec {
pname = "someDotnetApplication";
version = "0.1";
···
dotnet-runtime = dotnetCorePackages.runtime_8_0;
executables = [ "foo" ]; # This wraps "$out/lib/$pname/foo" to `$out/bin/foo`.
-
executables = []; # Don't install any executables.
+
executables = [ ]; # Don't install any executables.
packNupkg = true; # This packs the project as "foo-0.1.nupkg" at `$out/share`.
+65 -47
doc/languages-frameworks/emscripten.section.md
···
(pkgs.zlib.override {
stdenv = pkgs.emscriptenStdenv;
}).overrideAttrs
-
(old: rec {
-
buildInputs = old.buildInputs ++ [ pkg-config ];
-
# 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
+
(old: rec {
+
buildInputs = old.buildInputs ++ [ pkg-config ];
+
# 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
+
#export EMCC_DEBUG=2
+
emconfigure ./configure --prefix=$out --shared
-
runHook postConfigure
-
'';
-
dontStrip = true;
-
outputs = [ "out" ];
-
buildPhase = ''
-
emmake make
-
'';
-
installPhase = ''
-
emmake make install
-
'';
-
checkPhase = ''
-
echo "================= testing zlib using node ================="
+
runHook postConfigure
+
'';
+
dontStrip = true;
+
outputs = [ "out" ];
+
buildPhase = ''
+
emmake make
+
'';
+
installPhase = ''
+
emmake make install
+
'';
+
checkPhase = ''
+
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 "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
+
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 ================="
-
'';
+
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 ================="
+
'';
-
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"'
-
'';
-
})
+
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"'
+
'';
+
})
```
:::{.example #usage-2-pkgs.buildemscriptenpackage}
···
pkgs.buildEmscriptenPackage rec {
name = "xmlmirror";
-
buildInputs = [ pkg-config autoconf automake libtool gnumake libxml2 nodejs openjdk json_c ];
-
nativeBuildInputs = [ pkg-config zlib ];
+
buildInputs = [
+
pkg-config
+
autoconf
+
automake
+
libtool
+
gnumake
+
libxml2
+
nodejs
+
openjdk
+
json_c
+
];
+
nativeBuildInputs = [
+
pkg-config
+
zlib
+
];
src = pkgs.fetchgit {
url = "https://gitlab.com/odfplugfest/xmlmirror.git";
···
make -f Makefile.emEnv
'';
-
outputs = [ "out" "doc" ];
+
outputs = [
+
"out"
+
"doc"
+
];
installPhase = ''
mkdir -p $out/share
+6 -1
doc/languages-frameworks/gnome.section.md
···
--prefix XDG_DATA_DIRS : "$out/share/gsettings-schemas/${name}" \
--prefix XDG_DATA_DIRS : "${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}" \
--prefix XDG_DATA_DIRS : "${hicolor-icon-theme}/share" \
-
--prefix GI_TYPELIB_PATH : "${lib.makeSearchPath "lib/girepository-1.0" [ pango json-glib ]}"
+
--prefix GI_TYPELIB_PATH : "${
+
lib.makeSearchPath "lib/girepository-1.0" [
+
pango
+
json-glib
+
]
+
}"
done
'';
}
+10 -6
doc/languages-frameworks/gradle.section.md
···
hash = "sha256-ciKotTHSEcITfQYKFZ6sY2LZnXGChBJy0+eno8B3YHY=";
};
-
nativeBuildInputs = [ gradle makeWrapper ];
+
nativeBuildInputs = [
+
gradle
+
makeWrapper
+
];
# if the package has dependencies, mitmCache must be set
mitmCache = gradle.fetchDeps {
···
package. Using the pdftk example above:
```nix
-
{ lib
-
, stdenv
-
, gradle
-
# ...
-
, pdftk
+
{
+
lib,
+
stdenv,
+
gradle,
+
# ...
+
pdftk,
}:
stdenv.mkDerivation (finalAttrs: {
+2 -1
doc/languages-frameworks/hare.section.md
···
hareHook,
lib,
stdenv,
-
}: stdenv.mkDerivation {
+
}:
+
stdenv.mkDerivation {
pname = "<name>";
version = "<version>";
src = "<src>";
+85 -63
doc/languages-frameworks/haskell.section.md
···
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
inherit (pkgs) haskell;
inherit (haskell.lib.compose) overrideCabal;
···
previousIntermediates = turtle-full-build-with-incremental-output.intermediates;
}) turtle;
in
-
turtle-incremental-build
+
turtle-incremental-build
```
## Development environments {#haskell-development-environments}
···
```nix
# Retrieve nixpkgs impurely from NIX_PATH for now, you can pin it instead, of course.
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
# use the nixpkgs default haskell package set
pkgs.haskellPackages.callPackage ./my-project.nix { }
···
file set up for both, we can add the following `shell.nix` expression:
```nix
-
{ pkgs ? import <nixpkgs> {} }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
pkgs.haskellPackages.shellFor {
packages = hpkgs: [
···
with e.g.
```nix
-
pkgs.haskell-language-server.override { supportedGhcVersions = [ "90" "94" ]; }
+
pkgs.haskell-language-server.override {
+
supportedGhcVersions = [
+
"90"
+
"94"
+
];
+
}
```
Where all strings `version` are allowed such that
`haskell.packages.ghc${version}` is an existing package set.
···
derivation:
```nix
-
pkgs.haskell.lib.overrideCabal
-
(pkgs.haskell.lib.justStaticExecutables my-haskell-package)
-
(drv: {
-
disallowGhcReference = false;
-
})
+
pkgs.haskell.lib.overrideCabal (pkgs.haskell.lib.justStaticExecutables my-haskell-package) (drv: {
+
disallowGhcReference = false;
+
})
```
Then use `strings` to determine which libraries are responsible:
···
Finally, use `remove-references-to` to delete those store paths from the produced output:
```nix
-
pkgs.haskell.lib.overrideCabal
-
(pkgs.haskell.lib.justStaticExecutables my-haskell-package)
-
(drv: {
-
postInstall = ''
-
${drv.postInstall or ""}
-
remove-references-to -t ${pkgs.haskellPackages.hs-opentelemetry-sdk}
-
'';
-
})
+
pkgs.haskell.lib.overrideCabal (pkgs.haskell.lib.justStaticExecutables my-haskell-package) (drv: {
+
postInstall = ''
+
${drv.postInstall or ""}
+
remove-references-to -t ${pkgs.haskellPackages.hs-opentelemetry-sdk}
+
'';
+
})
```
[164630]: https://github.com/NixOS/nixpkgs/issues/164630
···
```nix
# cabal get mtl-2.2.1 && cd mtl-2.2.1 && cabal2nix .
-
{ mkDerivation, base, lib, transformers }:
+
{
+
mkDerivation,
+
base,
+
lib,
+
transformers,
+
}:
mkDerivation {
pname = "mtl";
version = "2.2.1";
src = ./.;
-
libraryHaskellDepends = [ base transformers ];
+
libraryHaskellDepends = [
+
base
+
transformers
+
];
homepage = "http://github.com/ekmett/mtl";
description = "Monad classes, using functional dependencies";
license = lib.licenses.bsd3;
···
# recommended to only use such an overlay if you are enabling profiling on a
# platform that doesn't by default, because compiling GHC from scratch is
# quite expensive.
-
(final: prev:
-
let
-
inherit (final) lib;
-
in
+
(
+
final: prev:
+
let
+
inherit (final) lib;
+
in
-
{
-
haskell = prev.haskell // {
-
compiler = prev.haskell.compiler // {
-
${ghcName} = prev.haskell.compiler.${ghcName}.override {
-
# Unfortunately, the GHC setting is named differently for historical reasons
-
enableProfiledLibs = enableProfiling;
+
{
+
haskell = prev.haskell // {
+
compiler = prev.haskell.compiler // {
+
${ghcName} = prev.haskell.compiler.${ghcName}.override {
+
# Unfortunately, the GHC setting is named differently for historical reasons
+
enableProfiledLibs = enableProfiling;
+
};
};
};
-
};
-
})
+
}
+
)
-
(final: prev:
-
let
-
inherit (final) lib;
-
haskellLib = final.haskell.lib.compose;
-
in
+
(
+
final: prev:
+
let
+
inherit (final) lib;
+
haskellLib = final.haskell.lib.compose;
+
in
-
{
-
haskell = prev.haskell // {
-
packages = prev.haskell.packages // {
-
${ghcName} = prev.haskell.packages.${ghcName}.override {
-
overrides = hfinal: hprev: {
-
mkDerivation = args: hprev.mkDerivation (args // {
-
# Since we are forcing our ideas upon mkDerivation, this change will
-
# affect every package in the package set.
-
enableLibraryProfiling = enableProfiling;
+
{
+
haskell = prev.haskell // {
+
packages = prev.haskell.packages // {
+
${ghcName} = prev.haskell.packages.${ghcName}.override {
+
overrides = hfinal: hprev: {
+
mkDerivation =
+
args:
+
hprev.mkDerivation (
+
args
+
// {
+
# Since we are forcing our ideas upon mkDerivation, this change will
+
# affect every package in the package set.
+
enableLibraryProfiling = enableProfiling;
-
# To actually use profiling on an executable, executable profiling
-
# needs to be enabled for the executable you want to profile. You
-
# can either do this globally or…
-
enableExecutableProfiling = enableProfiling;
-
});
+
# To actually use profiling on an executable, executable profiling
+
# needs to be enabled for the executable you want to profile. You
+
# can either do this globally or…
+
enableExecutableProfiling = enableProfiling;
+
}
+
);
-
# …only for the package that contains an executable you want to profile.
-
# That saves on unnecessary rebuilds for packages that you only depend
-
# on for their library, but also contain executables (e.g. pandoc).
-
my-executable = haskellLib.enableExecutableProfiling hprev.my-executable;
+
# …only for the package that contains an executable you want to profile.
+
# That saves on unnecessary rebuilds for packages that you only depend
+
# on for their library, but also contain executables (e.g. pandoc).
+
my-executable = haskellLib.enableExecutableProfiling hprev.my-executable;
-
# If you are disabling profiling to save on build time, but want to
-
# retain the ability to substitute from the binary cache. Drop the
-
# override for mkDerivation above and instead have an override like
-
# this for the specific packages you are building locally and want
-
# to make cheaper to build.
-
my-library = haskellLib.disableLibraryProfiling hprev.my-library;
+
# If you are disabling profiling to save on build time, but want to
+
# retain the ability to substitute from the binary cache. Drop the
+
# override for mkDerivation above and instead have an override like
+
# this for the specific packages you are building locally and want
+
# to make cheaper to build.
+
my-library = haskellLib.disableLibraryProfiling hprev.my-library;
+
};
};
};
};
-
};
-
})
+
}
+
)
```
+8 -2
doc/languages-frameworks/hy.section.md
···
Or if you want to extend your `configuration.nix`:
```nix
-
{ # ...
+
{
+
# ...
environment.systemPackages = with pkgs; [
-
(hy.withPackages (py-packages: with py-packages; [ numpy matplotlib ]))
+
(hy.withPackages (
+
py-packages: with py-packages; [
+
numpy
+
matplotlib
+
]
+
))
];
}
```
+24 -11
doc/languages-frameworks/idris.section.md
···
```nix
self: super: {
-
myIdris = with self.idrisPackages; with-packages [ contrib pruviloj ];
+
myIdris =
+
with self.idrisPackages;
+
with-packages [
+
contrib
+
pruviloj
+
];
}
```
···
As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`:
```nix
-
{ lib
-
, build-idris-package
-
, fetchFromGitHub
-
, contrib
-
, lightyear
+
{
+
lib,
+
build-idris-package,
+
fetchFromGitHub,
+
contrib,
+
lightyear,
}:
-
build-idris-package {
+
build-idris-package {
name = "yaml";
version = "2018-01-25";
···
# different from its package name here.
ipkgName = "Yaml";
# Idris dependencies to provide for the build
-
idrisDeps = [ contrib lightyear ];
+
idrisDeps = [
+
contrib
+
lightyear
+
];
src = fetchFromGitHub {
owner = "Heather";
···
Or it's possible to use
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
{
-
yaml = idrisPackages.callPackage ./yaml.nix {};
+
yaml = idrisPackages.callPackage ./yaml.nix { };
}
```
···
```nix
build-idris-package {
-
idrisBuildOptions = [ "--log" "1" "--verbose" ];
+
idrisBuildOptions = [
+
"--log"
+
"1"
+
"--verbose"
+
];
# ...
}
+34 -23
doc/languages-frameworks/idris2.section.md
···
A simple example of a fully packaged library would be the [`LSP-lib`](https://github.com/idris-community/LSP-lib) found in the `idris-community` GitHub organization.
```nix
{ fetchFromGitHub, idris2Packages }:
-
let lspLibPkg = idris2Packages.buildIdris {
-
ipkgName = "lsp-lib";
-
src = fetchFromGitHub {
-
owner = "idris-community";
-
repo = "LSP-lib";
-
rev = "main";
-
hash = "sha256-EvSyMCVyiy9jDZMkXQmtwwMoLaem1GsKVFqSGNNHHmY=";
+
let
+
lspLibPkg = idris2Packages.buildIdris {
+
ipkgName = "lsp-lib";
+
src = fetchFromGitHub {
+
owner = "idris-community";
+
repo = "LSP-lib";
+
rev = "main";
+
hash = "sha256-EvSyMCVyiy9jDZMkXQmtwwMoLaem1GsKVFqSGNNHHmY=";
+
};
+
idrisLibraries = [ ];
};
-
idrisLibraries = [ ];
-
};
-
in lspLibPkg.library { withSource = true; }
+
in
+
lspLibPkg.library { withSource = true; }
```
The above results in a derivation with the installed library results (with sourcecode).
A slightly more involved example of a fully packaged executable would be the [`idris2-lsp`](https://github.com/idris-community/idris2-lsp) which is an Idris2 language server that uses the `LSP-lib` found above.
```nix
-
{ callPackage, fetchFromGitHub, idris2Packages }:
+
{
+
callPackage,
+
fetchFromGitHub,
+
idris2Packages,
+
}:
# Assuming the previous example lives in `lsp-lib.nix`:
-
let lspLib = callPackage ./lsp-lib.nix { };
-
inherit (idris2Packages) idris2Api;
-
lspPkg = idris2Packages.buildIdris {
-
ipkgName = "idris2-lsp";
-
src = fetchFromGitHub {
-
owner = "idris-community";
-
repo = "idris2-lsp";
-
rev = "main";
-
hash = "sha256-vQTzEltkx7uelDtXOHc6QRWZ4cSlhhm5ziOqWA+aujk=";
-
};
-
idrisLibraries = [idris2Api lspLib];
+
let
+
lspLib = callPackage ./lsp-lib.nix { };
+
inherit (idris2Packages) idris2Api;
+
lspPkg = idris2Packages.buildIdris {
+
ipkgName = "idris2-lsp";
+
src = fetchFromGitHub {
+
owner = "idris-community";
+
repo = "idris2-lsp";
+
rev = "main";
+
hash = "sha256-vQTzEltkx7uelDtXOHc6QRWZ4cSlhhm5ziOqWA+aujk=";
};
-
in lspPkg.executable
+
idrisLibraries = [
+
idris2Api
+
lspLib
+
];
+
};
+
in
+
lspPkg.executable
```
The above uses the default value of `withSource = false` for the `idris2Api` but could be modified to include that library's source by passing `(idris2Api { withSource = true; })` to `idrisLibraries` instead. `idris2Api` in the above derivation comes built in with `idris2Packages`. This library exposes many of the otherwise internal APIs of the Idris2 compiler.
+4 -4
doc/languages-frameworks/ios.section.md
···
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
···
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
···
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
···
```nix
let
-
pkgs = import <nixpkgs> {};
+
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
+8 -3
doc/languages-frameworks/java.section.md
···
pname = "...";
version = "...";
-
src = fetchurl { /* ... */ };
+
src = fetchurl {
+
# ...
+
};
nativeBuildInputs = [
ant
···
something = (pkgs.something.override { jre = my_jre; });
other = (pkgs.other.override { jre = my_jre; });
in
-
<...>
+
<...>
```
You can also specify what JDK your JRE should be based on, for example
···
```nix
{
-
nativeBuildInputs = [ gcj ant ];
+
nativeBuildInputs = [
+
gcj
+
ant
+
];
}
```
+45 -28
doc/languages-frameworks/javascript.section.md
···
For example, `dat` requires `node-gyp-build`, so we override its expression in [pkgs/development/node-packages/overrides.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/node-packages/overrides.nix):
```nix
-
{
-
dat = prev.dat.override (oldAttrs: {
-
buildInputs = [ final.node-gyp-build pkgs.libtool pkgs.autoconf pkgs.automake ];
-
meta = oldAttrs.meta // { broken = since "12"; };
-
});
-
}
+
{
+
dat = prev.dat.override (oldAttrs: {
+
buildInputs = [
+
final.node-gyp-build
+
pkgs.libtool
+
pkgs.autoconf
+
pkgs.automake
+
];
+
meta = oldAttrs.meta // {
+
broken = since "12";
+
};
+
});
+
}
```
### Adding and Updating Javascript packages in nixpkgs {#javascript-adding-or-updating-packages}
···
Here's an example:
```nix
-
{ lib, buildNpmPackage, fetchFromGitHub }:
+
{
+
lib,
+
buildNpmPackage,
+
fetchFromGitHub,
+
}:
buildNpmPackage rec {
pname = "flood";
···
npmRoot = ./.;
fetcherOpts = {
# Pass 'curlOptsList' to 'pkgs.fetchurl' while fetching 'axios'
-
"node_modules/axios" = { curlOptsList = [ "--verbose" ]; };
+
"node_modules/axios" = {
+
curlOptsList = [ "--verbose" ];
+
};
};
};
···
stdenv,
nodejs,
# This is pinned as { pnpm = pnpm_9; }
-
pnpm
+
pnpm,
}:
stdenv.mkDerivation (finalAttrs: {
···
```nix
{
-
# ...
-
pnpmWorkspaces = [ "@astrojs/language-server" ];
-
pnpmDeps = pnpm.fetchDeps {
-
inherit (finalAttrs) pnpmWorkspaces;
-
#...
-
};
+
# ...
+
pnpmWorkspaces = [ "@astrojs/language-server" ];
+
pnpmDeps = pnpm.fetchDeps {
+
inherit (finalAttrs) pnpmWorkspaces;
+
#...
+
};
}
```
···
```nix
{
-
buildPhase = ''
-
runHook preBuild
+
buildPhase = ''
+
runHook preBuild
-
pnpm --filter=@astrojs/language-server build
+
pnpm --filter=@astrojs/language-server build
-
runHook postBuild
-
'';
+
runHook postBuild
+
'';
}
```
···
```nix
{
-
prePnpmInstall = ''
-
pnpm config set dedupe-peer-dependants false
-
'';
-
pnpmDeps = pnpm.fetchDeps {
-
inherit (finalAttrs) prePnpmInstall;
-
# ...
-
};
+
prePnpmInstall = ''
+
pnpm config set dedupe-peer-dependants false
+
'';
+
pnpmDeps = pnpm.fetchDeps {
+
inherit (finalAttrs) prePnpmInstall;
+
# ...
+
};
}
```
···
mkYarnPackage rec {
pkgConfig = {
node-sass = {
-
buildInputs = with final;[ python libsass pkg-config ];
+
buildInputs = with final; [
+
python
+
libsass
+
pkg-config
+
];
postInstall = ''
LIBSASS_EXT=auto yarn --offline run build
rm build/config.gypi
+3 -2
doc/languages-frameworks/julia.section.md
···
For example, you can build a Julia environment with the `Plots` package as follows.
```nix
-
julia.withPackages ["Plots"]
+
julia.withPackages [ "Plots" ]
```
Arguments can be passed using `.override`.
···
```nix
(julia.withPackages.override {
precompile = false; # Turn off precompilation
-
}) ["Plots"]
+
})
+
[ "Plots" ]
```
Here's a nice way to run a Julia environment with a shell one-liner:
+13 -6
doc/languages-frameworks/lisp.section.md
···
```nix
let
sbcl' = sbcl.withPackages (ps: [ ps.alexandria ]);
-
in mkShell {
+
in
+
mkShell {
packages = [ sbcl' ];
}
```
···
hash = "sha256-1Hzxt65dZvgOFIljjjlSGgKYkj+YBLwJCACi5DZsKmQ=";
};
};
-
sbcl' = sbcl.withOverrides (self: super: {
-
inherit alexandria;
-
});
-
in sbcl'.pkgs.alexandria
+
sbcl' = sbcl.withOverrides (
+
self: super: {
+
inherit alexandria;
+
}
+
);
+
in
+
sbcl'.pkgs.alexandria
```
## Overriding package attributes {#lisp-overriding-package-attributes}
···
wrapLisp {
pkg = clisp;
faslExt = "fas";
-
flags = ["-E" "UTF8"];
+
flags = [
+
"-E"
+
"UTF8"
+
];
}
```
+45 -17
doc/languages-frameworks/lua.section.md
···
Create a file, e.g. `build.nix`, with the following expression
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
lua5_2.withPackages (ps: with ps; [ busted luafilesystem ])
+
lua5_2.withPackages (
+
ps: with ps; [
+
busted
+
luafilesystem
+
]
+
)
```
and install it in your profile with
···
using `config.nix`,
```nix
-
{ # ...
+
{
+
# ...
-
packageOverrides = pkgs: with pkgs; {
-
myLuaEnv = lua5_2.withPackages (ps: with ps; [ busted luafilesystem ]);
-
};
+
packageOverrides =
+
pkgs: with pkgs; {
+
myLuaEnv = lua5_2.withPackages (
+
ps: with ps; [
+
busted
+
luafilesystem
+
]
+
);
+
};
}
```
···
For the sake of completeness, here's another example how to install the environment system-wide.
```nix
-
{ # ...
+
{
+
# ...
environment.systemPackages = with pkgs; [
-
(lua.withPackages(ps: with ps; [ busted luafilesystem ]))
+
(lua.withPackages (
+
ps: with ps; [
+
busted
+
luafilesystem
+
]
+
))
];
}
```
···
Use the following overlay template:
```nix
-
final: prev:
-
{
+
final: prev: {
lua = prev.lua.override {
packageOverrides = luaself: luaprev: {
-
luarocks-nix = luaprev.luarocks-nix.overrideAttrs(oa: {
+
luarocks-nix = luaprev.luarocks-nix.overrideAttrs (oa: {
pname = "luarocks-nix";
src = /home/my_luarocks/repository;
});
···
```nix
{
-
mynewlib = toLuaModule ( stdenv.mkDerivation { /* ... */ });
+
mynewlib = toLuaModule (
+
stdenv.mkDerivation {
+
# ...
+
}
+
);
}
```
···
version = "34.0.4-1";
src = fetchurl {
-
url = "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luaposix-34.0.4-1.src.rock";
+
url = "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luaposix-34.0.4-1.src.rock";
hash = "sha256-4mLJG8n4m6y4Fqd0meUDfsOb9RHSR0qa/KD5KCwrNXs=";
};
disabled = (luaOlder "5.1") || (luaAtLeast "5.4");
-
propagatedBuildInputs = [ bit32 lua std_normalize ];
+
propagatedBuildInputs = [
+
bit32
+
lua
+
std_normalize
+
];
meta = {
homepage = "https://github.com/luaposix/luaposix/";
description = "Lua bindings for POSIX";
-
maintainers = with lib.maintainers; [ vyp lblasc ];
+
maintainers = with lib.maintainers; [
+
vyp
+
lblasc
+
];
license.fullName = "MIT/X11";
};
};
···
Using the `withPackages` function, the previous example for the luafilesystem environment can be written like this:
```nix
-
lua.withPackages (ps: [ps.luafilesystem])
+
lua.withPackages (ps: [ ps.luafilesystem ])
```
`withPackages` passes the correct package set for the specific interpreter version as an argument to the function. In the above example, `ps` equals `luaPackages`.
But you can also easily switch to using `lua5_1`:
```nix
-
lua5_1.withPackages (ps: [ps.lua])
+
lua5_1.withPackages (ps: [ ps.lua ])
```
Now, `ps` is set to `lua5_1.pkgs`, matching the version of the interpreter.
+46 -15
doc/languages-frameworks/maven.section.md
···
Consider the following package:
```nix
-
{ lib, fetchFromGitHub, jre, makeWrapper, maven }:
+
{
+
lib,
+
fetchFromGitHub,
+
jre,
+
makeWrapper,
+
maven,
+
}:
maven.buildMavenPackage rec {
pname = "jd-cli";
···
Here is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/build-maven-repository.nix) of building the Maven repository
```nix
-
{ pkgs ? import <nixpkgs> { } }:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
with pkgs;
(buildMaven ./project-info.json).repo
```
···
:::
```nix
-
{ lib, stdenv, maven }:
+
{
+
lib,
+
stdenv,
+
maven,
+
}:
stdenv.mkDerivation {
name = "maven-repository";
buildInputs = [ maven ];
···
Regardless of which strategy is chosen above, the step to build the derivation is the same.
```nix
-
{ stdenv, maven, callPackage }:
+
{
+
stdenv,
+
maven,
+
callPackage,
+
}:
# pick a repository derivation, here we will use buildMaven
-
let repository = callPackage ./build-maven-repository.nix { };
-
in stdenv.mkDerivation rec {
+
let
+
repository = callPackage ./build-maven-repository.nix { };
+
in
+
stdenv.mkDerivation rec {
pname = "maven-demo";
version = "1.0";
···
We make sure to provide this classpath to the `makeWrapper`.
```nix
-
{ stdenv, maven, callPackage, makeWrapper, jre }:
+
{
+
stdenv,
+
maven,
+
callPackage,
+
makeWrapper,
+
jre,
+
}:
let
repository = callPackage ./build-maven-repository.nix { };
-
in stdenv.mkDerivation rec {
+
in
+
stdenv.mkDerivation rec {
pname = "maven-demo";
version = "1.0";
-
src = builtins.fetchTarball
-
"https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
+
src = builtins.fetchTarball "https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ maven ];
···
We will modify the derivation above to add a symlink to our repository so that it's accessible to our JAR during the `installPhase`.
```nix
-
{ stdenv, maven, callPackage, makeWrapper, jre }:
+
{
+
stdenv,
+
maven,
+
callPackage,
+
makeWrapper,
+
jre,
+
}:
# pick a repository derivation, here we will use buildMaven
-
let repository = callPackage ./build-maven-repository.nix { };
-
in stdenv.mkDerivation rec {
+
let
+
repository = callPackage ./build-maven-repository.nix { };
+
in
+
stdenv.mkDerivation rec {
pname = "maven-demo";
version = "1.0";
-
src = builtins.fetchTarball
-
"https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
+
src = builtins.fetchTarball "https://github.com/fzakaria/nixos-maven-example/archive/main.tar.gz";
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ maven ];
+4 -4
doc/languages-frameworks/neovim.section.md
···
You can explore the configuration with`nix repl` to discover these options and
override them. For instance:
```nix
-
neovim.overrideAttrs(oldAttrs: {
-
autowrapRuntimeDeps = false;
+
neovim.overrideAttrs (oldAttrs: {
+
autowrapRuntimeDeps = false;
})
```
···
For instance:
```nix
{
-
rtp-nvim = neovimUtils.buildNeovimPlugin {
+
rtp-nvim = neovimUtils.buildNeovimPlugin {
luaAttr = luaPackages.rtp-nvim;
-
};
+
};
}
```
To update these packages, you should use the lua updater rather than vim's.
+29 -13
doc/languages-frameworks/nim.section.md
···
The following example shows a Nim program that depends only on Nim libraries:
```nix
-
{ lib, buildNimPackage, fetchFromGitHub }:
+
{
+
lib,
+
buildNimPackage,
+
fetchFromGitHub,
+
}:
buildNimPackage (finalAttrs: {
pname = "ttop";
···
```nix
pkgs.nitter.overrideNimAttrs {
# using a different source which has different dependencies from the standard package
-
src = pkgs.fetchFromGithub { /* … */ };
+
src = pkgs.fetchFromGithub {
+
# …
+
};
# new lock file generated from the source
lockFile = ./custom-lock.json;
}
···
For example, to propagate a dependency on SDL2 for lockfiles that select the Nim `sdl2` library, an overlay is added to the set in the `nim-overrides.nix` file:
```nix
-
{ lib
-
/* … */
-
, SDL2
-
/* … */
+
{
+
lib,
+
# …
+
SDL2,
+
# …
}:
{
-
/* … */
+
# …
sdl2 =
lockAttrs:
-
{ buildInputs ? [ ], ... }:
+
{
+
buildInputs ? [ ],
+
...
+
}:
{
buildInputs = buildInputs ++ [ SDL2 ];
};
-
/* … */
+
# …
}
```
···
Override a package internal to its definition:
```nix
-
{ lib, buildNimPackage, nimOverrides, libressl }:
+
{
+
lib,
+
buildNimPackage,
+
nimOverrides,
+
libressl,
+
}:
let
buildNimPackage' = buildNimPackage.override {
nimOverrides = nimOverrides.override { openssl = libressl; };
};
-
in buildNimPackage' (finalAttrs: {
+
in
+
buildNimPackage' (finalAttrs: {
pname = "foo";
# …
})
-
```
Override a package externally:
```nix
-
{ pkgs }: {
+
{ pkgs }:
+
{
foo = pkgs.foo.override {
buildNimPackage = pkgs.buildNimPackage.override {
nimOverrides = pkgs.nimOverrides.override { openssl = libressl; };
+30 -13
doc/languages-frameworks/ocaml.section.md
···
For example:
```nix
let
-
pkgs = import <nixpkgs> {};
-
# choose the ocaml version you want to use
-
ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12;
+
pkgs = import <nixpkgs> { };
+
# choose the ocaml version you want to use
+
ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12;
in
pkgs.mkShell {
# build tools
-
nativeBuildInputs = with ocamlPackages; [ ocaml findlib dune_2 ocaml-lsp ];
+
nativeBuildInputs = with ocamlPackages; [
+
ocaml
+
findlib
+
dune_2
+
ocaml-lsp
+
];
# dependencies
buildInputs = with ocamlPackages; [ ocamlgraph ];
}
···
generates.
```nix
-
{ lib,
+
{
+
lib,
fetchFromGitHub,
buildDunePackage,
ocaml,
···
alcotest,
result,
bigstringaf,
-
ppx_let }:
+
ppx_let,
+
}:
buildDunePackage rec {
pname = "angstrom";
···
minimalOCamlVersion = "4.04";
src = fetchFromGitHub {
-
owner = "inhabitedtype";
-
repo = pname;
-
rev = version;
-
hash = "sha256-MK8o+iPGANEhrrTc1Kz9LBilx2bDPQt7Pp5P2libucI=";
+
owner = "inhabitedtype";
+
repo = pname;
+
rev = version;
+
hash = "sha256-MK8o+iPGANEhrrTc1Kz9LBilx2bDPQt7Pp5P2libucI=";
};
-
checkInputs = [ alcotest ppx_let ];
+
checkInputs = [
+
alcotest
+
ppx_let
+
];
buildInputs = [ ocaml-syntax-shims ];
-
propagatedBuildInputs = [ bigstringaf result ];
+
propagatedBuildInputs = [
+
bigstringaf
+
result
+
];
doCheck = lib.versionAtLeast ocaml.version "4.05";
meta = {
···
Here is a second example, this time using a source archive generated with `dune-release`. It is a good idea to use this archive when it is available as it will usually contain substituted variables such as a `%%VERSION%%` field. This library does not depend on any other OCaml library and no tests are run after building it.
```nix
-
{ lib, fetchurl, buildDunePackage }:
+
{
+
lib,
+
fetchurl,
+
buildDunePackage,
+
}:
buildDunePackage rec {
pname = "wtf8";
+3 -1
doc/languages-frameworks/octave.section.md
···
This will also work in a `shell.nix` file.
```nix
-
{ pkgs ? import <nixpkgs> { }}:
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
+20 -4
doc/languages-frameworks/perl.section.md
···
```nix
{
foo = import ../path/to/foo.nix {
-
inherit stdenv fetchurl /* ... */;
+
inherit
+
stdenv
+
fetchurl # ...
+
;
inherit (perlPackages) ClassC3;
};
}
···
`buildPerlPackage` is built on top of `stdenv`, so everything can be customised in the usual way. For instance, the `BerkeleyDB` module has a `preConfigure` hook to generate a configuration file used by `Makefile.PL`:
```nix
-
{ buildPerlPackage, fetchurl, db }:
+
{
+
buildPerlPackage,
+
fetchurl,
+
db,
+
}:
buildPerlPackage rec {
pname = "BerkeleyDB";
···
hash = "sha256-ASO9rV/FzJYZ0BH572Fxm2ZrFLMZLFATJng1NuU4FHc=";
};
propagatedBuildInputs = [
-
ClassC3 ClassInspector TestException MROCompat
+
ClassC3
+
ClassInspector
+
TestException
+
MROCompat
];
};
}
···
On Darwin, if a script has too many `-Idir` flags in its first line (its “shebang line”), it will not run. This can be worked around by calling the `shortenPerlShebang` function from the `postInstall` phase:
```nix
-
{ lib, stdenv, buildPerlPackage, fetchurl, shortenPerlShebang }:
+
{
+
lib,
+
stdenv,
+
buildPerlPackage,
+
fetchurl,
+
shortenPerlShebang,
+
}:
{
ImageExifTool = buildPerlPackage {
+91 -48
doc/languages-frameworks/php.section.md
···
ImageMagick enabled:
```nix
-
php.withExtensions ({ enabled, all }:
-
enabled ++ [ all.imagick ])
+
php.withExtensions ({ enabled, all }: enabled ++ [ all.imagick ])
```
To exclude some, but not all, of the default extensions, you can
filter the `enabled` list like this:
```nix
-
php.withExtensions ({ enabled, all }:
-
(lib.filter (e: e != php.extensions.opcache) enabled)
-
++ [ all.imagick ])
+
php.withExtensions (
+
{ enabled, all }: (lib.filter (e: e != php.extensions.opcache) enabled) ++ [ all.imagick ]
+
)
```
To build your list of extensions from the ground up, you can
ignore `enabled`:
```nix
-
php.withExtensions ({ all, ... }: with all; [ imagick opcache ])
+
php.withExtensions (
+
{ all, ... }:
+
with all;
+
[
+
imagick
+
opcache
+
]
+
)
```
`php.withExtensions` provides extensions by wrapping a minimal php
···
```nix
php.buildEnv {
-
extensions = { all, ... }: with all; [ imagick opcache ];
+
extensions =
+
{ all, ... }:
+
with all;
+
[
+
imagick
+
opcache
+
];
extraConfig = "memory_limit=256M";
}
```
···
```nix
let
-
myPhp = php.withExtensions ({ all, ... }: with all; [ imagick opcache ]);
-
in {
+
myPhp = php.withExtensions (
+
{ all, ... }:
+
with all;
+
[
+
imagick
+
opcache
+
]
+
);
+
in
+
{
services.phpfpm.pools."foo".phpPackage = myPhp;
}
```
···
```nix
let
myPhp = php.buildEnv {
-
extensions = { all, ... }: with all; [ imagick opcache ];
+
extensions =
+
{ all, ... }:
+
with all;
+
[
+
imagick
+
opcache
+
];
extraConfig = "memory_limit=256M";
};
-
in {
+
in
+
{
services.phpfpm.pools."foo".phpPackage = myPhp;
}
```
···
Example of building `composer` with additional extensions:
```nix
-
(php.withExtensions ({ all, enabled }:
-
enabled ++ (with all; [ imagick redis ]))
-
).packages.composer
+
(php.withExtensions (
+
{ all, enabled }:
+
enabled
+
++ (with all; [
+
imagick
+
redis
+
])
+
)).packages.composer
```
### Overriding PHP packages {#ssec-php-user-guide-overriding-packages}
···
packageOverrides = final: prev: {
extensions = prev.extensions // {
mysqlnd = prev.extensions.mysqlnd.overrideAttrs (attrs: {
-
patches = attrs.patches or [] ++ [
+
patches = attrs.patches or [ ] ++ [
# ...
];
});
···
# PHP version containing the `ast` extension enabled
php = php.buildEnv {
-
extensions = ({ enabled, all }: enabled ++ (with all; [
-
ast
-
]));
+
extensions = (
+
{ enabled, all }:
+
enabled
+
++ (with all; [
+
ast
+
])
+
);
};
# The composer vendor hash
···
separate functions and hooks:
```nix
-
{ stdenvNoCC, fetchFromGitHub, php }:
+
{
+
stdenvNoCC,
+
fetchFromGitHub,
+
php,
+
}:
-
stdenvNoCC.mkDerivation (finalAttrs:
-
let
-
src = fetchFromGitHub {
-
owner = "git-owner";
-
repo = "git-repo";
-
rev = finalAttrs.version;
-
hash = "sha256-VcQRSss2dssfkJ+iUb5qT+FJ10GHiFDzySigcmuVI+8=";
-
};
-
in {
-
inherit src;
-
pname = "php-app";
-
version = "1.0.0";
+
stdenvNoCC.mkDerivation (
+
finalAttrs:
+
let
+
src = fetchFromGitHub {
+
owner = "git-owner";
+
repo = "git-repo";
+
rev = finalAttrs.version;
+
hash = "sha256-VcQRSss2dssfkJ+iUb5qT+FJ10GHiFDzySigcmuVI+8=";
+
};
+
in
+
{
+
inherit src;
+
pname = "php-app";
+
version = "1.0.0";
-
buildInputs = [ php ];
+
buildInputs = [ php ];
-
nativeBuildInputs = [
-
php.packages.composer
-
# This hook will use the attribute `composerRepository`
-
php.composerHooks.composerInstallHook
-
];
+
nativeBuildInputs = [
+
php.packages.composer
+
# This hook will use the attribute `composerRepository`
+
php.composerHooks.composerInstallHook
+
];
-
composerRepository = php.mkComposerRepository {
-
inherit (finalAttrs) pname version src;
-
composerNoDev = true;
-
composerNoPlugins = true;
-
composerNoScripts = true;
-
# Specifying a custom composer.lock since it is not present in the sources.
-
composerLock = ./composer.lock;
-
# The composer vendor hash
-
vendorHash = "sha256-86s/F+/5cBAwBqZ2yaGRM5rTGLmou5//aLRK5SA0WiQ=";
-
};
-
})
+
composerRepository = php.mkComposerRepository {
+
inherit (finalAttrs) pname version src;
+
composerNoDev = true;
+
composerNoPlugins = true;
+
composerNoScripts = true;
+
# Specifying a custom composer.lock since it is not present in the sources.
+
composerLock = ./composer.lock;
+
# The composer vendor hash
+
vendorHash = "sha256-86s/F+/5cBAwBqZ2yaGRM5rTGLmou5//aLRK5SA0WiQ=";
+
};
+
}
+
)
```
+6 -3
doc/languages-frameworks/pkg-config.section.md
···
{ pkg-config, testers, ... }:
stdenv.mkDerivation (finalAttrs: {
-
/* ... */
+
# ...
-
nativeBuildInputs = [ pkg-config validatePkgConfig ];
+
nativeBuildInputs = [
+
pkg-config
+
validatePkgConfig
+
];
passthru.tests.pkg-config = testers.hasPkgConfigModules {
package = finalAttrs.finalPackage;
···
};
meta = {
-
/* ... */
+
# ...
pkgConfigModules = [ "miniz" ];
};
})
+234 -160
doc/languages-frameworks/python.section.md
···
The following is an example:
```nix
-
{ lib
-
, buildPythonPackage
-
, fetchPypi
+
{
+
lib,
+
buildPythonPackage,
+
fetchPypi,
-
# build-system
-
, setuptools
-
, setuptools-scm
+
# build-system
+
setuptools,
+
setuptools-scm,
-
# dependencies
-
, attrs
-
, pluggy
-
, py
-
, setuptools
-
, six
+
# dependencies
+
attrs,
+
pluggy,
+
py,
+
setuptools,
+
six,
-
# tests
-
, hypothesis
-
}:
+
# tests
+
hypothesis,
+
}:
buildPythonPackage rec {
pname = "pytest";
···
description = "Framework for writing tests";
homepage = "https://github.com/pytest-dev/pytest";
license = lib.licenses.mit;
-
maintainers = with lib.maintainers; [ domenkozar lovek323 madjar lsix ];
+
maintainers = with lib.maintainers; [
+
domenkozar
+
lovek323
+
madjar
+
lsix
+
];
};
}
```
···
the overrides for packages in the package set.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
(let
-
python = let
-
packageOverrides = self: super: {
-
pandas = super.pandas.overridePythonAttrs(old: rec {
-
version = "0.19.1";
-
src = fetchPypi {
-
pname = "pandas";
-
inherit version;
-
hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE=";
+
(
+
let
+
python =
+
let
+
packageOverrides = self: super: {
+
pandas = super.pandas.overridePythonAttrs (old: rec {
+
version = "0.19.1";
+
src = fetchPypi {
+
pname = "pandas";
+
inherit version;
+
hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE=";
+
};
+
});
};
-
});
-
};
-
in pkgs.python3.override {inherit packageOverrides; self = python;};
+
in
+
pkgs.python3.override {
+
inherit packageOverrides;
+
self = python;
+
};
-
in python.withPackages(ps: [ ps.blaze ])).env
+
in
+
python.withPackages (ps: [ ps.blaze ])
+
).env
```
The next example shows a non trivial overriding of the `blas` implementation to
···
python3MyBlas = pkgs.python3.override {
packageOverrides = self: super: {
# We need toPythonModule for the package set to evaluate this
-
blas = super.toPythonModule(super.pkgs.blas.override {
-
blasProvider = super.pkgs.mkl;
-
});
-
lapack = super.toPythonModule(super.pkgs.lapack.override {
-
lapackProvider = super.pkgs.mkl;
-
});
+
blas = super.toPythonModule (
+
super.pkgs.blas.override {
+
blasProvider = super.pkgs.mkl;
+
}
+
);
+
lapack = super.toPythonModule (
+
super.pkgs.lapack.override {
+
lapackProvider = super.pkgs.mkl;
+
}
+
);
};
};
}
···
specifying an interpreter version), like this:
```nix
-
{ lib
-
, python3Packages
-
, fetchPypi
+
{
+
lib,
+
python3Packages,
+
fetchPypi,
}:
python3Packages.buildPythonApplication rec {
···
src = fetchPypi {
inherit pname version;
-
hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw=";
+
hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw=";
};
build-system = with python3Packages; [
···
```nix
{
-
opencv = toPythonModule (pkgs.opencv.override {
-
enablePython = true;
-
pythonPackages = self;
-
});
+
opencv = toPythonModule (
+
pkgs.opencv.override {
+
enablePython = true;
+
pythonPackages = self;
+
}
+
);
}
```
···
Note that overriding packages deeper in the dependency graph _can_ work, but it's not the primary use case and overriding existing packages can make others break in unexpected ways.
-
``` nix
-
{ pkgs ? import <nixpkgs> { } }:
+
```nix
+
{
+
pkgs ? import <nixpkgs> { },
+
}:
let
pyproject = pkgs.lib.importTOML ./pyproject.toml;
···
};
};
-
pythonEnv = myPython.withPackages (ps: [ ps.my-editable ]);
+
pythonEnv = myPython.withPackages (ps: [ ps.my-editable ]);
-
in pkgs.mkShell {
+
in
+
pkgs.mkShell {
packages = [ pythonEnv ];
}
```
···
Saving the following as `default.nix`
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
python3.buildEnv.override {
extraLibs = [ python3Packages.pyramid ];
···
running `nix-shell` with the following `shell.nix`
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
(python3.buildEnv.override {
extraLibs = with python3Packages; [
···
example for the Pyramid Web Framework environment can be written like this:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
python.withPackages (ps: [ ps.pyramid ])
```
···
`pythonPackages`. But you can also easily switch to using python3:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
python3.withPackages (ps: [ ps.pyramid ])
```
···
thus be also written like this:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
(python3.withPackages (ps: with ps; [
-
numpy
-
requests
-
])).env
+
(python3.withPackages (
+
ps: with ps; [
+
numpy
+
requests
+
]
+
)).env
```
In contrast to [`python.buildEnv`](#python.buildenv-function), [`python.withPackages`](#python.withpackages-function) does not support the
···
in an environment. We can add a `shell.nix` file describing our dependencies:
```nix
-
with import <nixpkgs> {};
-
(python312.withPackages (ps: with ps; [
-
numpy
-
toolz
-
])).env
+
with import <nixpkgs> { };
+
(python312.withPackages (
+
ps: with ps; [
+
numpy
+
toolz
+
]
+
)).env
```
And then at the command line, just typing `nix-shell` produces the same
···
To combine this with `mkShell` you can:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
let
pythonEnv = python312.withPackages (ps: [
ps.numpy
ps.toolz
]);
-
in mkShell {
+
in
+
mkShell {
packages = [
pythonEnv
···
on NixOS.
```nix
-
{ # ...
+
{
+
# ...
environment.systemPackages = with pkgs; [
-
(python310.withPackages(ps: with ps; [ numpy toolz ]))
+
(python310.withPackages (
+
ps: with ps; [
+
numpy
+
toolz
+
]
+
))
];
}
```
···
`toolz` package.
```nix
-
{ lib
-
, buildPythonPackage
-
, fetchPypi
-
, setuptools
+
{
+
lib,
+
buildPythonPackage,
+
fetchPypi,
+
setuptools,
}:
buildPythonPackage rec {
···
and adds it along with a `numpy` package to a Python environment.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
( let
+
(
+
let
my_toolz = python312.pkgs.buildPythonPackage rec {
pname = "toolz";
version = "0.10.0";
···
};
};
-
in python312.withPackages (ps: with ps; [
-
numpy
-
my_toolz
-
])
+
in
+
python312.withPackages (
+
ps: with ps; [
+
numpy
+
my_toolz
+
]
+
)
).env
```
···
order to build [`datashape`](https://github.com/blaze/datashape).
```nix
-
{ lib
-
, buildPythonPackage
-
, fetchPypi
+
{
+
lib,
+
buildPythonPackage,
+
fetchPypi,
-
# build dependencies
-
, setuptools
+
# build dependencies
+
setuptools,
-
# dependencies
-
, numpy, multipledispatch, python-dateutil
+
# dependencies
+
numpy,
+
multipledispatch,
+
python-dateutil,
-
# tests
-
, pytestCheckHook
+
# tests
+
pytestCheckHook,
}:
buildPythonPackage rec {
···
when building the bindings and are therefore added as [`buildInputs`](#var-stdenv-buildInputs).
```nix
-
{ lib
-
, buildPythonPackage
-
, fetchPypi
-
, setuptools
-
, libxml2
-
, libxslt
+
{
+
lib,
+
buildPythonPackage,
+
fetchPypi,
+
setuptools,
+
libxml2,
+
libxslt,
}:
buildPythonPackage rec {
···
therefore we have to set `LDFLAGS` and `CFLAGS`.
```nix
-
{ lib
-
, buildPythonPackage
-
, fetchPypi
+
{
+
lib,
+
buildPythonPackage,
+
fetchPypi,
-
# build dependencies
-
, setuptools
+
# build dependencies
+
setuptools,
-
# dependencies
-
, fftw
-
, fftwFloat
-
, fftwLongDouble
-
, numpy
-
, scipy
+
# dependencies
+
fftw,
+
fftwFloat,
+
fftwLongDouble,
+
numpy,
+
scipy,
}:
buildPythonPackage rec {
···
changelog = "https://github.com/pyFFTW/pyFFTW/releases/tag/v${version}";
description = "Pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms";
homepage = "http://hgomersall.github.com/pyFFTW";
-
license = with lib.licenses; [ bsd2 bsd3 ];
+
license = with lib.licenses; [
+
bsd2
+
bsd3
+
];
};
```
···
```nix
-
disabledTests = [
-
# touches network
-
"download"
-
"update"
-
] ++ lib.optionals (pythonAtLeast "3.8") [
-
# broken due to python3.8 async changes
-
"async"
-
] ++ lib.optionals stdenv.buildPlatform.isDarwin [
-
# can fail when building with other packages
-
"socket"
-
];
+
disabledTests =
+
[
+
# touches network
+
"download"
+
"update"
+
]
+
++ lib.optionals (pythonAtLeast "3.8") [
+
# broken due to python3.8 async changes
+
"async"
+
]
+
++ lib.optionals stdenv.buildPlatform.isDarwin [
+
# can fail when building with other packages
+
"socket"
+
];
```
···
];
unittestFlags = [
-
"-s" "tests" "-v"
+
"-s"
+
"tests"
+
"-v"
];
```
···
We first create a function that builds `toolz` in `~/path/to/toolz/release.nix`
```nix
-
{ lib
-
, buildPythonPackage
-
, fetchPypi
-
, setuptools
+
{
+
lib,
+
buildPythonPackage,
+
fetchPypi,
+
setuptools,
}:
buildPythonPackage rec {
···
`callPackage` in the definition of our environment
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
( let
+
(
+
let
toolz = callPackage /path/to/toolz/release.nix {
buildPythonPackage = python3Packages.buildPythonPackage;
};
-
in python3.withPackages (ps: [
+
in
+
python3.withPackages (ps: [
ps.numpy
toolz
])
···
example we rename the `pandas` package and build it.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
(let
-
python = let
-
packageOverrides = self: super: {
-
pandas = super.pandas.overridePythonAttrs(old: {name="foo";});
-
};
-
in pkgs.python310.override {
-
inherit packageOverrides;
-
};
+
(
+
let
+
python =
+
let
+
packageOverrides = self: super: {
+
pandas = super.pandas.overridePythonAttrs (old: {
+
name = "foo";
+
});
+
};
+
in
+
pkgs.python310.override {
+
inherit packageOverrides;
+
};
-
in python.withPackages (ps: [
-
ps.pandas
-
])).env
+
in
+
python.withPackages (ps: [
+
ps.pandas
+
])
+
).env
```
Using `nix-build` on this expression will build an environment that contains the
···
the updated `scipy` version.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
-
( let
+
(
+
let
packageOverrides = self: super: {
scipy = super.scipy_0_17;
};
-
in (pkgs.python310.override {
+
in
+
(pkgs.python310.override {
inherit packageOverrides;
-
}).withPackages (ps: [
-
ps.blaze
-
])
+
}).withPackages
+
(ps: [
+
ps.blaze
+
])
).env
```
···
```nix
let
-
pkgs = import <nixpkgs> {};
-
newpkgs = import pkgs.path { overlays = [ (self: super: {
-
python310 = let
-
packageOverrides = python-self: python-super: {
-
numpy = python-super.numpy_1_18;
-
};
-
in super.python310.override {inherit packageOverrides;};
-
} ) ]; };
-
in newpkgs.inkscape
+
pkgs = import <nixpkgs> { };
+
newpkgs = import pkgs.path {
+
overlays = [
+
(self: super: {
+
python310 =
+
let
+
packageOverrides = python-self: python-super: {
+
numpy = python-super.numpy_1_18;
+
};
+
in
+
super.python310.override { inherit packageOverrides; };
+
})
+
];
+
};
+
in
+
newpkgs.inkscape
```
### `python setup.py bdist_wheel` cannot create .whl {#python-setup.py-bdist_wheel-cannot-create-.whl}
···
let
pythonPackages = python3Packages;
-
in pkgs.mkShell rec {
+
in
+
pkgs.mkShell rec {
name = "impurePythonEnv";
venvDir = "./.venv";
buildInputs = [
···
let
venvDir = "./.venv";
pythonPackages = python3Packages;
-
in pkgs.mkShell rec {
+
in
+
pkgs.mkShell rec {
name = "impurePythonEnv";
buildInputs = [
pythonPackages.python
···
```nix
final: prev: {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
-
(
-
python-final: python-prev: {
-
foo = python-prev.foo.overridePythonAttrs (oldAttrs: {
-
# ...
-
});
-
}
-
)
+
(python-final: python-prev: {
+
foo = python-prev.foo.overridePythonAttrs (oldAttrs: {
+
# ...
+
});
+
})
];
```
···
```nix
let
-
pkgs = import ./. {};
+
pkgs = import ./. { };
mypython = pkgs.python3.override {
enableOptimizations = true;
reproducibleBuild = false;
self = mypython;
};
-
in mypython
+
in
+
mypython
```
### How to add optional dependencies? {#python-optional-dependencies}
+6 -2
doc/languages-frameworks/qt.section.md
···
The `makeWrapper` arguments required for Qt are also exposed in the environment as `$qtWrapperArgs`.
```nix
-
{ stdenv, lib, wrapQtAppsHook }:
+
{
+
stdenv,
+
lib,
+
wrapQtAppsHook,
+
}:
stdenv.mkDerivation {
# ...
nativeBuildInputs = [ wrapQtAppsHook ];
dontWrapQtApps = true;
preFixup = ''
-
wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin
+
wrapQtApp "$out/bin/myapp" --prefix PATH : /path/to/bin
'';
}
```
+34 -22
doc/languages-frameworks/r.section.md
···
```nix
{
-
packageOverrides = super: let self = super.pkgs; in
+
packageOverrides =
+
super:
+
let
+
self = super.pkgs;
+
in
{
-
rEnv = super.rWrapper.override {
-
packages = with self.rPackages; [
-
devtools
-
ggplot2
-
reshape2
-
yaml
-
optparse
-
];
-
};
+
rEnv = super.rWrapper.override {
+
packages = with self.rPackages; [
+
devtools
+
ggplot2
+
reshape2
+
yaml
+
optparse
+
];
+
};
};
}
```
···
file like so:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
{
myProject = stdenv.mkDerivation {
name = "myProject";
···
```nix
{
-
packageOverrides = super: let self = super.pkgs; in
+
packageOverrides =
+
super:
+
let
+
self = super.pkgs;
+
in
{
-
rstudioEnv = super.rstudioWrapper.override {
-
packages = with self.rPackages; [
-
dplyr
-
ggplot2
-
reshape2
-
];
-
};
+
rstudioEnv = super.rstudioWrapper.override {
+
packages = with self.rPackages; [
+
dplyr
+
ggplot2
+
reshape2
+
];
+
};
};
}
```
···
modify any configuration files:
```nix
-
{ pkgs ? import <nixpkgs> {}
+
{
+
pkgs ? import <nixpkgs> { },
}:
pkgs.rstudioWrapper.override {
-
packages = with pkgs.rPackages; [ dplyr ggplot2 reshape2 ];
+
packages = with pkgs.rPackages; [
+
dplyr
+
ggplot2
+
reshape2
+
];
}
-
```
Executing `nix-shell` will then drop you into an environment equivalent to the
+59 -16
doc/languages-frameworks/ruby.section.md
···
Say we want to have Ruby, `nokogori`, and `pry`. Consider a `shell.nix` file with:
```nix
-
with import <nixpkgs> {};
-
ruby.withPackages (ps: with ps; [ nokogiri pry ])
+
with import <nixpkgs> { };
+
ruby.withPackages (
+
ps: with ps; [
+
nokogiri
+
pry
+
]
+
)
```
What's happening here?
···
name = "gems-for-some-project";
gemdir = ./.;
};
-
in mkShell { packages = [ gems gems.wrappedRuby ]; }
+
in
+
mkShell {
+
packages = [
+
gems
+
gems.wrappedRuby
+
];
+
}
```
With this file in your directory, you can run `nix-shell` to build and use the gems. The important parts here are `bundlerEnv` and `wrappedRuby`.
···
```nix
# ...
-
mkShell { buildInputs = [ gems (lowPrio gems.wrappedRuby) ]; }
+
mkShell {
+
buildInputs = [
+
gems
+
(lowPrio gems.wrappedRuby)
+
];
+
}
```
Sometimes a Gemfile references other files. Such as `.ruby-version` or vendored gems. When copying the Gemfile to the nix store we need to copy those files alongside. This can be done using `extraConfigPaths`. For example:
···
Here's the `ruby` one:
```nix
-
{ pg_version ? "10", pkgs ? import <nixpkgs> { } }:
+
{
+
pg_version ? "10",
+
pkgs ? import <nixpkgs> { },
+
}:
let
myRuby = pkgs.ruby.override {
defaultGemConfig = pkgs.defaultGemConfig // {
pg = attrs: {
-
buildFlags =
-
[ "--with-pg-config=${pkgs."postgresql_${pg_version}".pg_config}/bin/pg_config" ];
+
buildFlags = [ "--with-pg-config=${pkgs."postgresql_${pg_version}".pg_config}/bin/pg_config" ];
};
};
};
-
in myRuby.withPackages (ps: with ps; [ pg ])
+
in
+
myRuby.withPackages (ps: with ps; [ pg ])
```
And an example with `bundlerEnv`:
```nix
-
{ pg_version ? "10", pkgs ? import <nixpkgs> { } }:
+
{
+
pg_version ? "10",
+
pkgs ? import <nixpkgs> { },
+
}:
let
gems = pkgs.bundlerEnv {
name = "gems-for-some-project";
gemdir = ./.;
gemConfig = pkgs.defaultGemConfig // {
pg = attrs: {
-
buildFlags =
-
[ "--with-pg-config=${pkgs."postgresql_${pg_version}".pg_config}/bin/pg_config" ];
+
buildFlags = [ "--with-pg-config=${pkgs."postgresql_${pg_version}".pg_config}/bin/pg_config" ];
};
};
};
-
in mkShell { buildInputs = [ gems gems.wrappedRuby ]; }
+
in
+
mkShell {
+
buildInputs = [
+
gems
+
gems.wrappedRuby
+
];
+
}
```
And finally via overlays:
```nix
-
{ pg_version ? "10" }:
+
{
+
pg_version ? "10",
+
}:
let
pkgs = import <nixpkgs> {
overlays = [
···
})
];
};
-
in pkgs.ruby.withPackages (ps: with ps; [ pg ])
+
in
+
pkgs.ruby.withPackages (ps: with ps; [ pg ])
```
Then we can get whichever postgresql version we desire and the `pg` gem will always reference it correctly:
···
Here's another example:
```nix
-
{ lib, bundlerApp, makeWrapper, git, gnutar, gzip }:
+
{
+
lib,
+
bundlerApp,
+
makeWrapper,
+
git,
+
gnutar,
+
gzip,
+
}:
bundlerApp {
pname = "r10k";
···
nativeBuildInputs = [ makeWrapper ];
postBuild = ''
-
wrapProgram $out/bin/r10k --prefix PATH : ${lib.makeBinPath [ git gnutar gzip ]}
+
wrapProgram $out/bin/r10k --prefix PATH : ${
+
lib.makeBinPath [
+
git
+
gnutar
+
gzip
+
]
+
}
'';
}
```
+127 -92
doc/languages-frameworks/rust.section.md
···
Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`:
```nix
-
{ lib, fetchFromGitHub, rustPlatform }:
+
{
+
lib,
+
fetchFromGitHub,
+
rustPlatform,
+
}:
rustPlatform.buildRustPackage rec {
pname = "ripgrep";
···
pname = "myproject";
version = "1.0.0";
-
cargoLock = let
-
fixupLockFile = path: f (builtins.readFile path);
-
in {
-
lockFileContents = fixupLockFile ./Cargo.lock;
-
};
+
cargoLock =
+
let
+
fixupLockFile = path: f (builtins.readFile path);
+
in
+
{
+
lockFileContents = fixupLockFile ./Cargo.lock;
+
};
# ...
}
···
version = "1.0.0";
buildNoDefaultFeatures = true;
-
buildFeatures = [ "color" "net" ];
+
buildFeatures = [
+
"color"
+
"net"
+
];
# disable network features in tests
checkFeatures = [ "color" ];
···
import <nixpkgs> {
crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
rust.rustcTarget = "thumb-crazy";
-
rust.platform = { foo = ""; bar = ""; };
+
rust.platform = {
+
foo = "";
+
bar = "";
+
};
};
}
```
···
```nix
rustPlatform.buildRustPackage {
-
/* ... */
+
# ...
checkType = "debug";
}
```
···
```nix
rustPlatform.buildRustPackage {
-
/* ... */
+
# ...
checkFlags = [
# reason for disabling test
"--skip=example::tests:example_test"
···
```nix
rustPlatform.buildRustPackage {
-
/* ... */
+
# ...
useNextest = true;
}
```
···
```nix
rustPlatform.buildRustPackage {
-
/* ... */
+
# ...
dontUseCargoParallelTests = true;
}
```
···
```nix
rustPlatform.buildRustPackage {
-
/* ... */
+
# ...
buildType = "debug";
}
```
···
`sourceRoot` to point the tooling to this directory:
```nix
-
{ fetchFromGitHub
-
, buildPythonPackage
-
, cargo
-
, rustPlatform
-
, rustc
-
, setuptools-rust
+
{
+
fetchFromGitHub,
+
buildPythonPackage,
+
cargo,
+
rustPlatform,
+
rustc,
+
setuptools-rust,
}:
buildPythonPackage rec {
···
};
cargoDeps = rustPlatform.fetchCargoVendor {
-
inherit pname version src sourceRoot;
+
inherit
+
pname
+
version
+
src
+
sourceRoot
+
;
hash = "sha256-RO1m8wEd5Ic2M9q+zFHeCJWhCr4Sv3CEWd08mkxsBec=";
};
···
path for `fetchCargoVendor`.
```nix
-
-
{ buildPythonPackage
-
, fetchPypi
-
, rustPlatform
-
, setuptools-rust
-
, openssl
+
{
+
buildPythonPackage,
+
fetchPypi,
+
rustPlatform,
+
setuptools-rust,
+
openssl,
}:
buildPythonPackage rec {
···
`maturinBuildHook` is used to perform the build.
```nix
-
{ lib
-
, buildPythonPackage
-
, rustPlatform
-
, fetchFromGitHub
+
{
+
lib,
+
buildPythonPackage,
+
rustPlatform,
+
fetchFromGitHub,
}:
buildPythonPackage rec {
···
hash = "sha256-QsPCQhNZKYCAogQriQX6pBYQUDAIUsEdRX/63dAqTzg=";
};
-
nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ];
+
nativeBuildInputs = with rustPlatform; [
+
cargoSetupHook
+
maturinBuildHook
+
];
# ...
}
···
Some projects, especially GNOME applications, are built with the Meson Build System instead of calling Cargo directly. Using `rustPlatform.buildRustPackage` may successfully build the main program, but related files will be missing. Instead, you need to set up Cargo dependencies with `fetchCargoVendor` and `cargoSetupHook` and leave the rest to Meson. `rust` and `cargo` are still needed in `nativeBuildInputs` for Meson to use.
```nix
-
{ lib
-
, stdenv
-
, fetchFromGitLab
-
, meson
-
, ninja
-
, pkg-config
-
, rustPlatform
-
, rustc
-
, cargo
-
, wrapGAppsHook4
-
, blueprint-compiler
-
, libadwaita
-
, libsecret
-
, tinysparql
+
{
+
lib,
+
stdenv,
+
fetchFromGitLab,
+
meson,
+
ninja,
+
pkg-config,
+
rustPlatform,
+
rustc,
+
cargo,
+
wrapGAppsHook4,
+
blueprint-compiler,
+
libadwaita,
+
libsecret,
+
tinysparql,
}:
stdenv.mkDerivation rec {
···
or build inputs by overriding the hello crate in a separate file.
```nix
-
with import <nixpkgs> {};
-
((import ./hello.nix).hello {}).override {
+
with import <nixpkgs> { };
+
((import ./hello.nix).hello { }).override {
crateOverrides = defaultCrateOverrides // {
hello = attrs: { buildInputs = [ openssl ]; };
};
···
patches the derivation:
```nix
-
with import <nixpkgs> {};
-
((import ./hello.nix).hello {}).override {
+
with import <nixpkgs> { };
+
((import ./hello.nix).hello { }).override {
crateOverrides = defaultCrateOverrides // {
-
hello = attrs: lib.optionalAttrs (lib.versionAtLeast attrs.version "1.0") {
-
postPatch = ''
-
substituteInPlace lib/zoneinfo.rs \
-
--replace-fail "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo"
-
'';
-
};
+
hello =
+
attrs:
+
lib.optionalAttrs (lib.versionAtLeast attrs.version "1.0") {
+
postPatch = ''
+
substituteInPlace lib/zoneinfo.rs \
+
--replace-fail "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo"
+
'';
+
};
};
}
```
···
crate, we could do:
```nix
-
with import <nixpkgs> {};
-
((import hello.nix).hello {}).override {
+
with import <nixpkgs> { };
+
((import hello.nix).hello { }).override {
crateOverrides = defaultCrateOverrides // {
-
libc = attrs: { buildInputs = []; };
+
libc = attrs: { buildInputs = [ ]; };
};
}
```
···
- The version of `rustc` used to compile the crate:
```nix
-
(hello {}).override { rust = pkgs.rust; }
+
(hello { }).override { rust = pkgs.rust; }
```
- Whether to build in release mode or debug mode (release mode by
default):
```nix
-
(hello {}).override { release = false; }
+
(hello { }).override { release = false; }
```
- Whether to print the commands sent to `rustc` when building
(equivalent to `--verbose` in cargo:
```nix
-
(hello {}).override { verbose = false; }
+
(hello { }).override { verbose = false; }
```
- Extra arguments to be passed to `rustc`:
```nix
-
(hello {}).override { extraRustcOpts = "-Z debuginfo=2"; }
+
(hello { }).override { extraRustcOpts = "-Z debuginfo=2"; }
```
- Phases, just like in any other derivation, can be specified using
···
before running the build script:
```nix
-
(hello {}).override {
+
(hello { }).override {
preConfigure = ''
-
echo "pub const PATH=\"${hi.out}\";" >> src/path.rs"
+
echo "pub const PATH=\"${hi.out}\";" >> src/path.rs"
'';
}
```
···
A typical `shell.nix` might look like:
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
stdenv.mkDerivation {
name = "rust-env";
nativeBuildInputs = [
-
rustc cargo
+
rustc
+
cargo
# Example Build-time Additional Dependencies
pkg-config
···
```nix
with import <nixpkgs> { };
let
-
fenix = callPackage
-
(fetchFromGitHub {
-
owner = "nix-community";
-
repo = "fenix";
-
# commit from: 2023-03-03
-
rev = "e2ea04982b892263c4d939f1cc3bf60a9c4deaa1";
-
hash = "sha256-AsOim1A8KKtMWIxG+lXh5Q4P2bhOZjoUhFWJ1EuZNNk=";
-
})
-
{ };
+
fenix = callPackage (fetchFromGitHub {
+
owner = "nix-community";
+
repo = "fenix";
+
# commit from: 2023-03-03
+
rev = "e2ea04982b892263c4d939f1cc3bf60a9c4deaa1";
+
hash = "sha256-AsOim1A8KKtMWIxG+lXh5Q4P2bhOZjoUhFWJ1EuZNNk=";
+
}) { };
in
mkShell {
name = "rust-env";
···
The below snippet demonstrates invoking `buildRustPackage` with a Rust toolchain from oxalica's overlay:
```nix
-
with import <nixpkgs>
-
{
+
with import <nixpkgs> {
overlays = [
(import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"))
];
···
meta = {
description = "Fast line-oriented regex search tool, similar to ag and ack";
homepage = "https://github.com/BurntSushi/ripgrep";
-
license = with lib.licenses; [ mit unlicense ];
-
maintainers = with lib.maintainers; [];
+
license = with lib.licenses; [
+
mit
+
unlicense
+
];
+
maintainers = with lib.maintainers; [ ];
};
```
···
repository:
```nix
-
(final: prev: /*lib.optionalAttrs prev.stdenv.targetPlatform.isAarch64*/ {
-
rust_1_72 =
-
lib.updateManyAttrsByPath [{
-
path = [ "packages" "stable" ];
-
update = old: old.overrideScope(final: prev: {
-
rustc-unwrapped = prev.rustc-unwrapped.overrideAttrs (_: {
-
src = lib.cleanSource /git/scratch/rust;
-
# do *not* put passthru.isReleaseTarball=true here
-
});
-
});
-
}]
-
prev.rust_1_72;
-
})
+
(
+
final: prev: # lib.optionalAttrs prev.stdenv.targetPlatform.isAarch64
+
{
+
rust_1_72 = lib.updateManyAttrsByPath [
+
{
+
path = [
+
"packages"
+
"stable"
+
];
+
update =
+
old:
+
old.overrideScope (
+
final: prev: {
+
rustc-unwrapped = prev.rustc-unwrapped.overrideAttrs (_: {
+
src = lib.cleanSource /git/scratch/rust;
+
# do *not* put passthru.isReleaseTarball=true here
+
});
+
}
+
);
+
}
+
] prev.rust_1_72;
+
})
```
If the problem you're troubleshooting only manifests when
+11 -2
doc/languages-frameworks/swift.section.md
···
expression. The next step is to write that expression:
```nix
-
{ stdenv, swift, swiftpm, swiftpm2nix, fetchFromGitHub }:
+
{
+
stdenv,
+
swift,
+
swiftpm,
+
swiftpm2nix,
+
fetchFromGitHub,
+
}:
let
# Pass the generated files to the helper.
···
# Including SwiftPM as a nativeBuildInput provides a buildPhase for you.
# This by default performs a release build using SwiftPM, essentially:
# swift build -c release
-
nativeBuildInputs = [ swift swiftpm ];
+
nativeBuildInputs = [
+
swift
+
swiftpm
+
];
# The helper provides a configure snippet that will prepare all dependencies
# in the correct place, where SwiftPM expects them.
+59 -33
doc/languages-frameworks/texlive.section.md
···
- Packages cannot be used directly but must be assembled in an environment. To create or add packages to an environment, use
```nix
-
texliveSmall.withPackages (ps: with ps; [ collection-langkorean algorithms cm-super ])
+
texliveSmall.withPackages (
+
ps: with ps; [
+
collection-langkorean
+
algorithms
+
cm-super
+
]
+
)
```
The function `withPackages` can be called multiple times to add more packages.
···
- `texlive.withPackages` uses the same logic as `buildEnv`. Only parts of a package are installed in an environment: its 'runtime' files (`tex` output), binaries (`out` output), and support files (`tlpkg` output). Moreover, man and info pages are assembled into separate `man` and `info` outputs. To add only the TeX files of a package, or its documentation (`texdoc` output), just specify the outputs:
```nix
-
texlive.withPackages (ps: with ps; [
-
texdoc # recommended package to navigate the documentation
-
perlPackages.LaTeXML.tex # tex files of LaTeXML, omit binaries
-
cm-super
-
cm-super.texdoc # documentation of cm-super
-
])
+
texlive.withPackages (
+
ps: with ps; [
+
texdoc # recommended package to navigate the documentation
+
perlPackages.LaTeXML.tex # tex files of LaTeXML, omit binaries
+
cm-super
+
cm-super.texdoc # documentation of cm-super
+
]
+
)
```
- All packages distributed by TeX Live, which contains most of CTAN, are available and can be found under `texlive.pkgs`:
···
```nix
texlive.combine {
-
inherit (texlive) scheme-small collection-langkorean algorithms cm-super;
+
inherit (texlive)
+
scheme-small
+
collection-langkorean
+
algorithms
+
cm-super
+
;
}
```
···
```nix
texlive.combine {
# inherit (texlive) whatever-you-want;
-
pkgFilter = pkg:
-
pkg.tlType == "run" || pkg.tlType == "bin" || pkg.hasManpages || pkg.pname == "cm-super";
+
pkgFilter =
+
pkg: pkg.tlType == "run" || pkg.tlType == "bin" || pkg.hasManpages || pkg.pname == "cm-super";
# elem tlType [ "run" "bin" "doc" "source" ]
# there are also other attributes: version, name
}
···
Here is a (very verbose) example. See also the packages `auctex`, `eukleides`, `mftrace` for more examples.
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
let
foiltex = stdenvNoCC.mkDerivation {
pname = "latex-foiltex";
version = "2.1.4b";
-
outputs = [ "tex" "texdoc" ];
+
outputs = [
+
"tex"
+
"texdoc"
+
];
passthru.tlDeps = with texlive; [ latex ];
srcs = [
···
'';
nativeBuildInputs = [
-
(texliveSmall.withPackages (ps: with ps; [ cm-super hypdoc latexmk ]))
+
(texliveSmall.withPackages (
+
ps: with ps; [
+
cm-super
+
hypdoc
+
latexmk
+
]
+
))
# multiple-outputs.sh fails if $out is not defined
(writeShellScript "force-tex-output.sh" ''
out="''${tex-}"
···
latex_with_foiltex = texliveSmall.withPackages (_: [ foiltex ]);
in
-
runCommand "test.pdf" {
+
runCommand "test.pdf"
+
{
nativeBuildInputs = [ latex_with_foiltex ];
-
} ''
-
cat >test.tex <<EOF
-
\documentclass{foils}
+
}
+
''
+
cat >test.tex <<EOF
+
\documentclass{foils}
-
\title{Presentation title}
-
\date{}
+
\title{Presentation title}
+
\date{}
-
\begin{document}
-
\maketitle
-
\end{document}
-
EOF
-
pdflatex test.tex
-
cp test.pdf $out
-
''
+
\begin{document}
+
\maketitle
+
\end{document}
+
EOF
+
pdflatex test.tex
+
cp test.pdf $out
+
''
```
## LuaLaTeX font cache {#sec-language-texlive-lualatex-font-cache}
···
The font cache for LuaLaTeX is written to `$HOME`.
Therefore, it is necessary to set `$HOME` to a writable path, e.g. [before using LuaLaTeX in nix derivations](https://github.com/NixOS/nixpkgs/issues/180639):
```nix
-
runCommandNoCC "lualatex-hello-world" {
-
buildInputs = [ texliveFull ];
-
} ''
-
mkdir $out
-
echo '\documentclass{article} \begin{document} Hello world \end{document}' > main.tex
-
env HOME=$(mktemp -d) lualatex -interaction=nonstopmode -output-format=pdf -output-directory=$out ./main.tex
-
''
+
runCommandNoCC "lualatex-hello-world"
+
{
+
buildInputs = [ texliveFull ];
+
}
+
''
+
mkdir $out
+
echo '\documentclass{article} \begin{document} Hello world \end{document}' > main.tex
+
env HOME=$(mktemp -d) lualatex -interaction=nonstopmode -output-format=pdf -output-directory=$out ./main.tex
+
''
```
Additionally, [the cache of a user can diverge from the nix store](https://github.com/NixOS/nixpkgs/issues/278718).
+36 -25
doc/languages-frameworks/vim.section.md
···
vim-full.customize {
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
# loaded on launch
-
start = [ youcompleteme fugitive ];
+
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 ];
+
opt = [
+
phpCompletion
+
elm-vim
+
];
# To automatically load a plugin when opening a filetype, add vimrc lines like:
# autocmd FileType php :packadd phpCompletion
};
···
```nix
{
-
packageOverrides = pkgs: with pkgs; {
-
myVim = vim-full.customize {
-
# `name` specifies the name of the executable and package
-
name = "vim-with-plugins";
-
# add here code from the example section
-
};
-
myNeovim = neovim.override {
-
configure = {
-
# add code from the example section here
+
packageOverrides =
+
pkgs: with pkgs; {
+
myVim = vim-full.customize {
+
# `name` specifies the name of the executable and package
+
name = "vim-with-plugins";
+
# add here code from the example section
+
};
+
myNeovim = neovim.override {
+
configure = {
+
# add code from the example section here
+
};
};
};
-
};
}
```
···
in
{
environment.systemPackages = [
-
(
-
pkgs.neovim.override {
-
configure = {
-
packages.myPlugins = with pkgs.vimPlugins; {
+
(pkgs.neovim.override {
+
configure = {
+
packages.myPlugins = with pkgs.vimPlugins; {
start = [
vim-go # already packaged plugin
easygrep # custom package
];
-
opt = [];
+
opt = [ ];
};
# ...
};
-
}
-
)
+
})
];
}
```
···
vim-full.customize {
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
# loaded on launch
-
plug.plugins = [ youcompleteme fugitive phpCompletion elm-vim ];
+
plug.plugins = [
+
youcompleteme
+
fugitive
+
phpCompletion
+
elm-vim
+
];
};
}
```
···
```nix
{
-
deoplete-fish = super.deoplete-fish.overrideAttrs(old: {
-
dependencies = with super; [ deoplete-nvim vim-fish ];
+
deoplete-fish = super.deoplete-fish.overrideAttrs (old: {
+
dependencies = with super; [
+
deoplete-nvim
+
vim-fish
+
];
});
}
```
···
```nix
{
-
myVimPlugins = pkgs.vimPlugins.extend (
-
(pkgs.callPackage ./generated.nix {})
-
);
+
myVimPlugins = pkgs.vimPlugins.extend ((pkgs.callPackage ./generated.nix { }));
}
```
+43 -37
doc/packages/cataclysm-dda.section.md
···
# Unfortunately, this refers to the package before overriding and
# parallel building is still disabled.
-
badExample = myCDDA.withMods (_: []);
+
badExample = myCDDA.withMods (_: [ ]);
inherit (cataclysmDDA) attachPkgs pkgs wrapCDDA;
···
# badExample # parallel building disabled
# goodExample1.withMods (_: []) # parallel building enabled
-
goodExample2.withMods (_: []) # parallel building enabled
+
goodExample2.withMods (_: [ ]) # parallel building enabled
```
## Customizing with mods {#customizing-with-mods}
···
attribute:
```nix
-
cataclysm-dda.withMods (mods: with mods; [
-
tileset.UndeadPeople
-
])
+
cataclysm-dda.withMods (
+
mods: with mods; [
+
tileset.UndeadPeople
+
]
+
)
```
All mods, soundpacks, and tilesets available in nixpkgs are found in
···
```nix
let
-
customMods = self: super: lib.recursiveUpdate super {
-
# Modify existing mod
-
tileset.UndeadPeople = super.tileset.UndeadPeople.overrideAttrs (old: {
-
# If you like to apply a patch to the tileset for example
-
patches = [ ./path/to/your.patch ];
-
});
+
customMods =
+
self: super:
+
lib.recursiveUpdate super {
+
# Modify existing mod
+
tileset.UndeadPeople = super.tileset.UndeadPeople.overrideAttrs (old: {
+
# If you like to apply a patch to the tileset for example
+
patches = [ ./path/to/your.patch ];
+
});
-
# Add another mod
-
mod.Awesome = cataclysmDDA.buildMod {
-
modName = "Awesome";
-
version = "0.x";
-
src = fetchFromGitHub {
-
owner = "Someone";
-
repo = "AwesomeMod";
-
rev = "...";
-
hash = "...";
+
# Add another mod
+
mod.Awesome = cataclysmDDA.buildMod {
+
modName = "Awesome";
+
version = "0.x";
+
src = fetchFromGitHub {
+
owner = "Someone";
+
repo = "AwesomeMod";
+
rev = "...";
+
hash = "...";
+
};
+
# Path to be installed in the unpacked source (default: ".")
+
modRoot = "contents/under/this/path/will/be/installed";
};
-
# Path to be installed in the unpacked source (default: ".")
-
modRoot = "contents/under/this/path/will/be/installed";
-
};
-
# Add another soundpack
-
soundpack.Fantastic = cataclysmDDA.buildSoundPack {
-
# ditto
-
};
+
# Add another soundpack
+
soundpack.Fantastic = cataclysmDDA.buildSoundPack {
+
# ditto
+
};
-
# Add another tileset
-
tileset.SuperDuper = cataclysmDDA.buildTileSet {
-
# ditto
+
# Add another tileset
+
tileset.SuperDuper = cataclysmDDA.buildTileSet {
+
# ditto
+
};
};
-
};
in
-
cataclysm-dda.withMods (mods: with mods.extend customMods; [
-
tileset.UndeadPeople
-
mod.Awesome
-
soundpack.Fantastic
-
tileset.SuperDuper
-
])
+
cataclysm-dda.withMods (
+
mods: with mods.extend customMods; [
+
tileset.UndeadPeople
+
mod.Awesome
+
soundpack.Fantastic
+
tileset.SuperDuper
+
]
+
)
```
+2 -1
doc/packages/citrix.section.md
···
./custom-cert-1.pem
./custom-cert-2.pem # ...
];
-
in citrix_workspace.override { inherit extraCerts; }
+
in
+
citrix_workspace.override { inherit extraCerts; }
```
+72 -58
doc/packages/darwin-builder.section.md
···
darwin.inputs.nixpkgs.follows = "nixpkgs";
};
-
outputs = { self, darwin, nixpkgs, ... }@inputs:
-
let
+
outputs =
+
{
+
self,
+
darwin,
+
nixpkgs,
+
...
+
}@inputs:
+
let
-
inherit (darwin.lib) darwinSystem;
-
system = "aarch64-darwin";
-
pkgs = nixpkgs.legacyPackages."${system}";
-
linuxSystem = builtins.replaceStrings [ "darwin" ] [ "linux" ] system;
+
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;
+
darwin-builder = nixpkgs.lib.nixosSystem {
+
system = linuxSystem;
modules = [
+
"${nixpkgs}/nixos/modules/profiles/nix-builder-vm.nix"
{
-
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";
-
};
+
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";
+
};
+
};
+
}
+
];
+
};
+
};
+
+
};
}
```
···
in the example below and rebuild.
```nix
-
{
-
darwin-builder = nixpkgs.lib.nixosSystem {
-
system = linuxSystem;
-
modules = [
-
"${nixpkgs}/nixos/modules/profiles/nix-builder-vm.nix"
-
{
-
virtualisation.host.pkgs = pkgs;
-
virtualisation.darwin-builder.diskSize = 5120;
-
virtualisation.darwin-builder.memorySize = 1024;
-
virtualisation.darwin-builder.hostPort = 33022;
-
virtualisation.darwin-builder.workingDirectory = "/var/lib/darwin-builder";
-
}
-
];
-
};
-
}
+
{
+
darwin-builder = nixpkgs.lib.nixosSystem {
+
system = linuxSystem;
+
modules = [
+
"${nixpkgs}/nixos/modules/profiles/nix-builder-vm.nix"
+
{
+
virtualisation.host.pkgs = pkgs;
+
virtualisation.darwin-builder.diskSize = 5120;
+
virtualisation.darwin-builder.memorySize = 1024;
+
virtualisation.darwin-builder.hostPort = 33022;
+
virtualisation.darwin-builder.workingDirectory = "/var/lib/darwin-builder";
+
}
+
];
+
};
+
}
```
You may make any other changes to your VM in this attribute set. For example,
+35 -31
doc/packages/eclipse.section.md
···
```nix
{
packageOverrides = pkgs: {
-
myEclipse = with pkgs.eclipses; eclipseWithPlugins {
-
eclipse = eclipse-platform;
-
jvmArgs = [ "-Xmx2048m" ];
-
plugins = [ plugins.color-theme ];
-
};
+
myEclipse =
+
with pkgs.eclipses;
+
eclipseWithPlugins {
+
eclipse = eclipse-platform;
+
jvmArgs = [ "-Xmx2048m" ];
+
plugins = [ plugins.color-theme ];
+
};
};
}
```
···
```nix
{
packageOverrides = pkgs: {
-
myEclipse = with pkgs.eclipses; eclipseWithPlugins {
-
eclipse = eclipse-platform;
-
jvmArgs = [ "-Xmx2048m" ];
-
plugins = [
-
plugins.color-theme
-
(plugins.buildEclipsePlugin {
-
name = "myplugin1-1.0";
-
srcFeature = fetchurl {
-
url = "http://…/features/myplugin1.jar";
-
hash = "sha256-123…";
-
};
-
srcPlugin = fetchurl {
-
url = "http://…/plugins/myplugin1.jar";
-
hash = "sha256-123…";
-
};
-
})
-
(plugins.buildEclipseUpdateSite {
-
name = "myplugin2-1.0";
-
src = fetchurl {
-
stripRoot = false;
-
url = "http://…/myplugin2.zip";
-
hash = "sha256-123…";
-
};
-
})
-
];
-
};
+
myEclipse =
+
with pkgs.eclipses;
+
eclipseWithPlugins {
+
eclipse = eclipse-platform;
+
jvmArgs = [ "-Xmx2048m" ];
+
plugins = [
+
plugins.color-theme
+
(plugins.buildEclipsePlugin {
+
name = "myplugin1-1.0";
+
srcFeature = fetchurl {
+
url = "http://…/features/myplugin1.jar";
+
hash = "sha256-123…";
+
};
+
srcPlugin = fetchurl {
+
url = "http://…/plugins/myplugin1.jar";
+
hash = "sha256-123…";
+
};
+
})
+
(plugins.buildEclipseUpdateSite {
+
name = "myplugin2-1.0";
+
src = fetchurl {
+
stripRoot = false;
+
url = "http://…/myplugin2.zip";
+
hash = "sha256-123…";
+
};
+
})
+
];
+
};
};
}
```
+85 -76
doc/packages/emacs.section.md
···
```nix
{
-
packageOverrides = pkgs: with pkgs; {
-
myEmacs = emacs.pkgs.withPackages (epkgs: (with epkgs.melpaStablePackages; [
-
company
-
counsel
-
flycheck
-
ivy
-
magit
-
projectile
-
use-package
-
]));
-
};
+
packageOverrides =
+
pkgs: with pkgs; {
+
myEmacs = emacs.pkgs.withPackages (
+
epkgs:
+
(with epkgs.melpaStablePackages; [
+
company
+
counsel
+
flycheck
+
ivy
+
magit
+
projectile
+
use-package
+
])
+
);
+
};
}
```
···
```nix
{
-
packageOverrides = pkgs: with pkgs; rec {
-
myEmacsConfig = writeText "default.el" ''
-
(eval-when-compile
-
(require 'use-package))
+
packageOverrides =
+
pkgs: with pkgs; rec {
+
myEmacsConfig = writeText "default.el" ''
+
(eval-when-compile
+
(require 'use-package))
-
;; load some packages
+
;; load some packages
-
(use-package company
-
:bind ("<C-tab>" . company-complete)
-
:diminish company-mode
-
:commands (company-mode global-company-mode)
-
:defer 1
-
:config
-
(global-company-mode))
+
(use-package company
+
:bind ("<C-tab>" . 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 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 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 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 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))
-
'';
+
(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
-
]));
-
};
+
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
+
])
+
);
+
};
}
```
···
# ...
};
in
-
((emacsPackagesFor emacs).overrideScope overrides).withPackages
-
(p: with p; [
+
((emacsPackagesFor emacs).overrideScope overrides).withPackages (
+
p: with p; [
# here both these package will use haskell-mode of our own choice
ghc-mod
dante
-
])
+
]
+
)
```
}
+6 -3
doc/packages/fish.section.md
···
```nix
wrapFish {
-
pluginPkgs = with fishPlugins; [ pure foreign-env ];
-
completionDirs = [];
-
functionDirs = [];
+
pluginPkgs = with fishPlugins; [
+
pure
+
foreign-env
+
];
+
completionDirs = [ ];
+
functionDirs = [ ];
confDirs = [ "/path/to/some/fish/init/dir/" ];
}
```
+10 -3
doc/packages/ibus.section.md
···
On NixOS, you need to explicitly enable `ibus` with given engines before customizing your desktop to use `typing-booster`. This can be achieved using the `ibus` module:
```nix
-
{ pkgs, ... }: {
+
{ pkgs, ... }:
+
{
i18n.inputMethod = {
enable = true;
type = "ibus";
···
The IBus engine is based on `hunspell` to support completion in many languages. By default, the dictionaries `de-de`, `en-us`, `fr-moderne` `es-es`, `it-it`, `sv-se` and `sv-fi` are in use. To add another dictionary, the package can be overridden like this:
```nix
-
ibus-engines.typing-booster.override { langs = [ "de-at" "en-gb" ]; }
+
ibus-engines.typing-booster.override {
+
langs = [
+
"de-at"
+
"en-gb"
+
];
+
}
```
_Note: each language passed to `langs` must be an attribute name in `pkgs.hunspellDicts`._
···
On NixOS, it can be installed using the following expression:
```nix
-
{ pkgs, ... }: {
+
{ pkgs, ... }:
+
{
fonts.packages = with pkgs; [ noto-fonts-color-emoji ];
}
```
+1 -1
doc/packages/krita.section.md
···
```nix
(pkgs.krita.override (old: {
-
binaryPlugins = old.binaryPlugins ++ [ your-plugin ];
+
binaryPlugins = old.binaryPlugins ++ [ your-plugin ];
}))
```
+9 -5
doc/packages/python-tree-sitter.section.md
···
For example, to experiment with the Rust grammar, you can create a shell environment with the following configuration:
```nix
-
{ pkgs ? <nixpkgs> {} }:
+
{
+
pkgs ? <nixpkgs> { },
+
}:
pkgs.mkShell {
name = "py-tree-sitter-dev-shell";
buildInputs = with pkgs; [
-
(python3.withPackages (ps: with ps; [
-
tree-sitter
-
tree-sitter-grammars.tree-sitter-rust
-
]))
+
(python3.withPackages (
+
ps: with ps; [
+
tree-sitter
+
tree-sitter-grammars.tree-sitter-rust
+
]
+
))
];
}
```
+24 -12
doc/packages/urxvt.section.md
···
```nix
rxvt-unicode.override {
-
configure = { availablePlugins, ... }: {
-
plugins = with availablePlugins; [ perls resize-font vtwheel ];
-
};
+
configure =
+
{ availablePlugins, ... }:
+
{
+
plugins = with availablePlugins; [
+
perls
+
resize-font
+
vtwheel
+
];
+
};
}
```
···
```nix
rxvt-unicode.override {
-
configure = { availablePlugins, ... }: {
-
plugins = (builtins.attrValues availablePlugins) ++ [ custom-plugin ];
-
};
+
configure =
+
{ availablePlugins, ... }:
+
{
+
plugins = (builtins.attrValues availablePlugins) ++ [ custom-plugin ];
+
};
}
```
···
```nix
rxvt-unicode.override {
-
configure = { availablePlugins, ... }: {
-
pluginsDeps = [ xsel ];
-
};
+
configure =
+
{ availablePlugins, ... }:
+
{
+
pluginsDeps = [ xsel ];
+
};
}
```
···
```nix
rxvt-unicode.override {
-
configure = { availablePlugins, ... }: {
-
perlDeps = with perlPackages; [ AnyEvent ];
-
};
+
configure =
+
{ availablePlugins, ... }:
+
{
+
perlDeps = with perlPackages; [ AnyEvent ];
+
};
}
```
+63 -27
doc/packages/weechat.section.md
···
WeeChat can be configured to include your choice of plugins, reducing its closure size from the default configuration which includes all available plugins. To make use of this functionality, install an expression that overrides its configuration, such as:
```nix
-
weechat.override {configure = ({availablePlugins, ...}: {
-
plugins = with availablePlugins; [ python perl ];
-
});
+
weechat.override {
+
configure = (
+
{ availablePlugins, ... }:
+
{
+
plugins = with availablePlugins; [
+
python
+
perl
+
];
+
}
+
);
}
```
···
The Python and Perl plugins allows the addition of extra libraries. For instance, the `inotify.py` script in `weechat-scripts` requires D-Bus or libnotify, and the `fish.py` script requires `pycrypto`. To use these scripts, use the plugin's `withPackages` attribute:
```nix
-
weechat.override { configure = {availablePlugins, ...}: {
-
plugins = with availablePlugins; [
-
(python.withPackages (ps: with ps; [ pycrypto python-dbus ]))
-
];
+
weechat.override {
+
configure =
+
{ availablePlugins, ... }:
+
{
+
plugins = with availablePlugins; [
+
(python.withPackages (
+
ps: with ps; [
+
pycrypto
+
python-dbus
+
]
+
))
+
];
};
}
```
···
In order to also keep all default plugins installed, it is possible to use the following method:
```nix
-
weechat.override { configure = { availablePlugins, ... }: {
-
plugins = builtins.attrValues (availablePlugins // {
-
python = availablePlugins.python.withPackages (ps: with ps; [ pycrypto python-dbus ]);
-
});
-
}; }
+
weechat.override {
+
configure =
+
{ availablePlugins, ... }:
+
{
+
plugins = builtins.attrValues (
+
availablePlugins
+
// {
+
python = availablePlugins.python.withPackages (
+
ps: with ps; [
+
pycrypto
+
python-dbus
+
]
+
);
+
}
+
);
+
};
+
}
```
WeeChat allows to set defaults on startup using the `--run-command`. The `configure` method can be used to pass commands to the program:
```nix
weechat.override {
-
configure = { availablePlugins, ... }: {
-
init = ''
-
/set foo bar
-
/server add libera irc.libera.chat
-
'';
-
};
+
configure =
+
{ availablePlugins, ... }:
+
{
+
init = ''
+
/set foo bar
+
/server add libera irc.libera.chat
+
'';
+
};
}
```
···
```nix
weechat.override {
-
configure = { availablePlugins, ... }: {
-
scripts = with pkgs.weechatScripts; [
-
weechat-xmpp weechat-matrix-bridge wee-slack
-
];
-
init = ''
-
/set plugins.var.python.jabber.key "val"
-
'';
-
};
+
configure =
+
{ availablePlugins, ... }:
+
{
+
scripts = with pkgs.weechatScripts; [
+
weechat-xmpp
+
weechat-matrix-bridge
+
wee-slack
+
];
+
init = ''
+
/set plugins.var.python.jabber.key "val"
+
'';
+
};
}
```
···
url = "https://scripts.tld/your-scripts.tar.gz";
hash = "...";
};
-
passthru.scripts = [ "foo.py" "bar.lua" ];
+
passthru.scripts = [
+
"foo.py"
+
"bar.lua"
+
];
installPhase = ''
mkdir $out/share
cp foo.py $out/share
+14 -6
doc/stdenv/cross-compilation.chapter.md
···
In Nixpkgs, these three platforms are defined as attribute sets under the names `buildPlatform`, `hostPlatform`, and `targetPlatform`. They are always defined as attributes in the standard environment. That means one can access them like:
```nix
-
{ stdenv, fooDep, barDep, ... }: {
+
{
+
stdenv,
+
fooDep,
+
barDep,
+
...
+
}:
+
{
# ...stdenv.buildPlatform...
}
```
···
```nix
{
-
nativeBuildInputs = [
-
meson
-
] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
-
mesonEmulatorHook
-
];
+
nativeBuildInputs =
+
[
+
meson
+
]
+
++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
+
mesonEmulatorHook
+
];
}
```
+7 -2
doc/stdenv/meta.chapter.md
···
```nix
{
meta.platforms = lib.platforms.linux;
-
meta.hydraPlatforms = [];
+
meta.hydraPlatforms = [ ];
}
```
···
```nix
{
-
meta.broken = lib.all (map (p: p.meta.broken) [ glibc musl ]);
+
meta.broken = lib.all (
+
map (p: p.meta.broken) [
+
glibc
+
musl
+
]
+
);
}
```
+6 -1
doc/stdenv/multiple-output.chapter.md
···
```nix
{
-
outputs = [ "bin" "dev" "out" "doc" ];
+
outputs = [
+
"bin"
+
"dev"
+
"out"
+
"doc"
+
];
}
```
+3 -1
doc/stdenv/passthru.chapter.md
···
let
hello = stdenv.mkDerivation {
pname = "hello";
-
src = fetchGit { /* ... */ };
+
src = fetchGit {
+
# ...
+
};
passthru = {
foo = "bar";
+47 -27
doc/stdenv/stdenv.chapter.md
···
pname = "libfoo";
version = "1.2.3";
# ...
-
buildInputs = [libbar perl ncurses];
+
buildInputs = [
+
libbar
+
perl
+
ncurses
+
];
}
```
···
hash = "sha256-viwrS9lnaU8sTGuzK/+L/PlMM/xRRtgVuK5pixVeDEw=";
};
-
nativeBuildInputs = [ makeWrapper pkg-config ];
+
nativeBuildInputs = [
+
makeWrapper
+
pkg-config
+
];
buildInputs = [ libseccomp ];
postInstall = ''
···
--replace-fail "cp " "cp --no-preserve=mode "
wrapProgram $out/bin/solo5-virtio-mkimage \
-
--prefix PATH : ${lib.makeBinPath [ dosfstools mtools parted syslinux ]}
+
--prefix PATH : ${
+
lib.makeBinPath [
+
dosfstools
+
mtools
+
parted
+
syslinux
+
]
+
}
'';
doCheck = true;
-
nativeCheckInputs = [ util-linux qemu ];
-
checkPhase = '' [elided] '';
+
nativeCheckInputs = [
+
util-linux
+
qemu
+
];
+
checkPhase = ''[elided] '';
}
```
···
# A propagated dependency
```nix
-
with import <nixpkgs> {};
+
with import <nixpkgs> { };
let
bar = stdenv.mkDerivation {
name = "bar";
···
mkDerivation (finalAttrs: {
pname = "hello";
withFeature = true;
-
configureFlags =
-
lib.optionals finalAttrs.withFeature ["--with-feature"];
+
configureFlags = lib.optionals finalAttrs.withFeature [ "--with-feature" ];
})
```
···
```nix
# `pkg` is the _original_ definition (for illustration purposes)
-
let pkg =
-
mkDerivation (finalAttrs: {
+
let
+
pkg = mkDerivation (finalAttrs: {
# ...
# An example attribute
-
packages = [];
+
packages = [ ];
# `passthru.tests` is a commonly defined attribute.
passthru.tests.simple = f finalAttrs.finalPackage;
# An example of an attribute containing a function
-
passthru.appendPackages = packages':
-
finalAttrs.finalPackage.overrideAttrs (newSelf: super: {
-
packages = super.packages ++ packages';
-
});
+
passthru.appendPackages =
+
packages':
+
finalAttrs.finalPackage.overrideAttrs (
+
newSelf: super: {
+
packages = super.packages ++ packages';
+
}
+
);
# For illustration purposes; referenced as
# `(pkg.overrideAttrs(x)).finalAttrs` etc in the text below.
passthru.finalAttrs = finalAttrs;
passthru.original = pkg;
});
-
in pkg
+
in
+
pkg
```
Unlike the `pkg` binding in the above example, the `finalAttrs` parameter always references the final attributes. For instance `(pkg.overrideAttrs(x)).finalAttrs.finalPackage` is identical to `pkg.overrideAttrs(x)`, whereas `(pkg.overrideAttrs(x)).original` is the same as the original `pkg`.
···
```nix
let
pkgs = import ./. {
-
config = {};
+
config = { };
overlays = [
(final: prev: {
ncurses = prev.ncurses.overrideAttrs { separateDebugInfo = true; };
···
];
};
in
-
pkgs.mkShell {
+
pkgs.mkShell {
-
NIX_DEBUG_INFO_DIRS = "${pkgs.lib.getLib myDebugInfoDirs}/lib/debug";
+
NIX_DEBUG_INFO_DIRS = "${pkgs.lib.getLib myDebugInfoDirs}/lib/debug";
-
packages = [
-
pkgs.gdb
-
pkgs.socat
-
];
+
packages = [
+
pkgs.gdb
+
pkgs.socat
+
];
-
shellHook = ''
-
${pkgs.lib.getBin pkgs.gdb}/bin/gdb ${pkgs.lib.getBin pkgs.socat}/bin/socat
-
'';
-
}
+
shellHook = ''
+
${pkgs.lib.getBin pkgs.gdb}/bin/gdb ${pkgs.lib.getBin pkgs.socat}/bin/socat
+
'';
+
}
```
This setup works as follows:
+166 -121
doc/using/configuration.chapter.md
···
```nix
{
-
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
-
"roon-server"
-
"vscode"
-
];
+
allowUnfreePredicate =
+
pkg:
+
builtins.elem (lib.getName pkg) [
+
"roon-server"
+
"vscode"
+
];
}
```
···
```nix
{
-
allowlistedLicenses = with lib.licenses; [ amd wtfpl ];
+
allowlistedLicenses = with lib.licenses; [
+
amd
+
wtfpl
+
];
}
```
···
```nix
{
-
blocklistedLicenses = with lib.licenses; [ agpl3Only gpl3Only ];
+
blocklistedLicenses = with lib.licenses; [
+
agpl3Only
+
gpl3Only
+
];
}
```
···
```nix
{
-
allowInsecurePredicate = pkg: builtins.elem (lib.getName pkg) [
-
"ovftool"
-
];
+
allowInsecurePredicate =
+
pkg:
+
builtins.elem (lib.getName pkg) [
+
"ovftool"
+
];
}
```
···
```nix
{
packageOverrides = pkgs: rec {
-
foo = pkgs.foo.override { /* ... */ };
+
foo = pkgs.foo.override {
+
# ...
+
};
};
}
```
···
```nix
{
-
packageOverrides = pkgs: with pkgs; {
-
myPackages = pkgs.buildEnv {
-
name = "my-packages";
-
paths = [
-
aspell
-
bc
-
coreutils
-
gdb
-
ffmpeg
-
nix
-
emscripten
-
jq
-
nox
-
silver-searcher
-
];
+
packageOverrides =
+
pkgs: with pkgs; {
+
myPackages = pkgs.buildEnv {
+
name = "my-packages";
+
paths = [
+
aspell
+
bc
+
coreutils
+
gdb
+
ffmpeg
+
nix
+
emscripten
+
jq
+
nox
+
silver-searcher
+
];
+
};
};
-
};
}
```
···
```nix
{
-
packageOverrides = pkgs: with pkgs; {
-
myPackages = pkgs.buildEnv {
-
name = "my-packages";
-
paths = [
-
aspell
-
bc
-
coreutils
-
gdb
-
ffmpeg
-
nix
-
emscripten
-
jq
-
nox
-
silver-searcher
-
];
-
pathsToLink = [ "/share" "/bin" ];
+
packageOverrides =
+
pkgs: with pkgs; {
+
myPackages = pkgs.buildEnv {
+
name = "my-packages";
+
paths = [
+
aspell
+
bc
+
coreutils
+
gdb
+
ffmpeg
+
nix
+
emscripten
+
jq
+
nox
+
silver-searcher
+
];
+
pathsToLink = [
+
"/share"
+
"/bin"
+
];
+
};
};
-
};
}
```
···
```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" ];
+
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"
+
];
+
};
};
-
};
}
```
···
```nix
{
-
packageOverrides = pkgs: with pkgs; rec {
-
myProfile = writeText "my-profile" ''
-
export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
-
export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man
-
'';
-
myPackages = pkgs.buildEnv {
-
name = "my-packages";
-
paths = [
-
(runCommand "profile" {} ''
-
mkdir -p $out/etc/profile.d
-
cp ${myProfile} $out/etc/profile.d/my-profile.sh
-
'')
-
aspell
-
bc
-
coreutils
-
ffmpeg
-
man
-
nix
-
emscripten
-
jq
-
nox
-
silver-searcher
-
];
-
pathsToLink = [ "/share/man" "/share/doc" "/bin" "/etc" ];
-
extraOutputsToInstall = [ "man" "doc" ];
+
packageOverrides =
+
pkgs: with pkgs; rec {
+
myProfile = writeText "my-profile" ''
+
export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man
+
'';
+
myPackages = pkgs.buildEnv {
+
name = "my-packages";
+
paths = [
+
(runCommand "profile" { } ''
+
mkdir -p $out/etc/profile.d
+
cp ${myProfile} $out/etc/profile.d/my-profile.sh
+
'')
+
aspell
+
bc
+
coreutils
+
ffmpeg
+
man
+
nix
+
emscripten
+
jq
+
nox
+
silver-searcher
+
];
+
pathsToLink = [
+
"/share/man"
+
"/share/doc"
+
"/bin"
+
"/etc"
+
];
+
extraOutputsToInstall = [
+
"man"
+
"doc"
+
];
+
};
};
-
};
}
```
···
```nix
{
-
packageOverrides = pkgs: with pkgs; rec {
-
myProfile = writeText "my-profile" ''
-
export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
-
export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man
-
export INFOPATH=$HOME/.nix-profile/share/info:/nix/var/nix/profiles/default/share/info:/usr/share/info
-
'';
-
myPackages = pkgs.buildEnv {
-
name = "my-packages";
-
paths = [
-
(runCommand "profile" {} ''
-
mkdir -p $out/etc/profile.d
-
cp ${myProfile} $out/etc/profile.d/my-profile.sh
-
'')
-
aspell
-
bc
-
coreutils
-
ffmpeg
-
man
-
nix
-
emscripten
-
jq
-
nox
-
silver-searcher
-
texinfoInteractive
-
];
-
pathsToLink = [ "/share/man" "/share/doc" "/share/info" "/bin" "/etc" ];
-
extraOutputsToInstall = [ "man" "doc" "info" ];
-
postBuild = ''
-
if [ -x $out/bin/install-info -a -w $out/share/info ]; then
-
shopt -s nullglob
-
for i in $out/share/info/*.info $out/share/info/*.info.gz; do
-
$out/bin/install-info $i $out/share/info/dir
-
done
-
fi
+
packageOverrides =
+
pkgs: with pkgs; rec {
+
myProfile = writeText "my-profile" ''
+
export PATH=$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
export MANPATH=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man
+
export INFOPATH=$HOME/.nix-profile/share/info:/nix/var/nix/profiles/default/share/info:/usr/share/info
'';
+
myPackages = pkgs.buildEnv {
+
name = "my-packages";
+
paths = [
+
(runCommand "profile" { } ''
+
mkdir -p $out/etc/profile.d
+
cp ${myProfile} $out/etc/profile.d/my-profile.sh
+
'')
+
aspell
+
bc
+
coreutils
+
ffmpeg
+
man
+
nix
+
emscripten
+
jq
+
nox
+
silver-searcher
+
texinfoInteractive
+
];
+
pathsToLink = [
+
"/share/man"
+
"/share/doc"
+
"/share/info"
+
"/bin"
+
"/etc"
+
];
+
extraOutputsToInstall = [
+
"man"
+
"doc"
+
"info"
+
];
+
postBuild = ''
+
if [ -x $out/bin/install-info -a -w $out/share/info ]; then
+
shopt -s nullglob
+
for i in $out/share/info/*.info $out/share/info/*.info.gz; do
+
$out/bin/install-info $i $out/share/info/dir
+
done
+
fi
+
'';
+
};
};
-
};
}
```
+6 -1
doc/using/overlays.chapter.md
···
For BLAS/LAPACK switching to work correctly, all packages must depend on `blas` or `lapack`. This ensures that only one BLAS/LAPACK library is used at one time. There are two versions of BLAS/LAPACK currently in the wild, `LP64` (integer size = 32 bits) and `ILP64` (integer size = 64 bits). The attributes `blas` and `lapack` are `LP64` by default. Their `ILP64` version are provided through the attributes `blas-ilp64` and `lapack-ilp64`. Some software needs special flags or patches to work with `ILP64`. You can check if `ILP64` is used in Nixpkgs with `blas.isILP64` and `lapack.isILP64`. Some software does NOT work with `ILP64`, and derivations need to specify an assertion to prevent this. You can prevent `ILP64` from being used with the following:
```nix
-
{ stdenv, blas, lapack, ... }:
+
{
+
stdenv,
+
blas,
+
lapack,
+
...
+
}:
assert (!blas.isILP64) && (!lapack.isILP64);
+32 -12
doc/using/overrides.chapter.md
···
Example usages:
```nix
-
pkgs.foo.override { arg1 = val1; arg2 = val2; /* ... */ }
+
pkgs.foo.override {
+
arg1 = val1;
+
arg2 = val2; # ...
+
}
```
It's also possible to access the previous arguments.
```nix
-
pkgs.foo.override (previous: { arg1 = previous.arg1; /* ... */ })
+
pkgs.foo.override (previous: {
+
arg1 = previous.arg1; # ...
+
})
```
<!-- TODO: move below programlisting to a new section about extending and overlays and reference it -->
```nix
-
import pkgs.path { overlays = [ (self: super: {
-
foo = super.foo.override { barSupport = true ; };
-
})];}
+
import pkgs.path {
+
overlays = [
+
(self: super: {
+
foo = super.foo.override { barSupport = true; };
+
})
+
];
+
}
```
```nix
{
mypkg = pkgs.callPackage ./mypkg.nix {
-
mydep = pkgs.mydep.override { /* ... */ };
+
mydep = pkgs.mydep.override {
+
# ...
+
};
};
}
```
···
```nix
{
-
helloBar = pkgs.hello.overrideAttrs (finalAttrs: previousAttrs: {
-
pname = previousAttrs.pname + "-bar";
-
});
+
helloBar = pkgs.hello.overrideAttrs (
+
finalAttrs: previousAttrs: {
+
pname = previousAttrs.pname + "-bar";
+
}
+
);
}
```
···
url = "ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2";
hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY=";
};
-
patches = [];
+
patches = [ ];
});
}
```
···
```nix
{
-
f = { a, b }: { result = a+b; };
-
c = lib.makeOverridable f { a = 1; b = 2; };
+
f =
+
{ a, b }:
+
{
+
result = a + b;
+
};
+
c = lib.makeOverridable f {
+
a = 1;
+
b = 2;
+
};
}
```