mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 19:55:41 +03:00
doc: update Nix code snippets format
Command: `mdcr --config doc/tests/mdcr-config.toml doc/`
This commit is contained in:
parent
5d979e79ce
commit
bcea0cf344
86 changed files with 2485 additions and 1478 deletions
|
@ -99,10 +99,12 @@ There are several ways to tweak how Nix handles a package which has been marked
|
|||
|
||||
```nix
|
||||
{
|
||||
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
|
||||
"roon-server"
|
||||
"vscode"
|
||||
];
|
||||
allowUnfreePredicate =
|
||||
pkg:
|
||||
builtins.elem (lib.getName pkg) [
|
||||
"roon-server"
|
||||
"vscode"
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -112,7 +114,10 @@ There are several ways to tweak how Nix handles a package which has been marked
|
|||
|
||||
```nix
|
||||
{
|
||||
allowlistedLicenses = with lib.licenses; [ amd wtfpl ];
|
||||
allowlistedLicenses = with lib.licenses; [
|
||||
amd
|
||||
wtfpl
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -120,7 +125,10 @@ There are several ways to tweak how Nix handles a package which has been marked
|
|||
|
||||
```nix
|
||||
{
|
||||
blocklistedLicenses = with lib.licenses; [ agpl3Only gpl3Only ];
|
||||
blocklistedLicenses = with lib.licenses; [
|
||||
agpl3Only
|
||||
gpl3Only
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -158,9 +166,11 @@ There are several ways to tweak how Nix handles a package which has been marked
|
|||
|
||||
```nix
|
||||
{
|
||||
allowInsecurePredicate = pkg: builtins.elem (lib.getName pkg) [
|
||||
"ovftool"
|
||||
];
|
||||
allowInsecurePredicate =
|
||||
pkg:
|
||||
builtins.elem (lib.getName pkg) [
|
||||
"ovftool"
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -173,7 +183,9 @@ You can define a function called `packageOverrides` in your local `~/.config/nix
|
|||
```nix
|
||||
{
|
||||
packageOverrides = pkgs: rec {
|
||||
foo = pkgs.foo.override { /* ... */ };
|
||||
foo = pkgs.foo.override {
|
||||
# ...
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
@ -197,23 +209,24 @@ Using `packageOverrides`, it is possible to manage packages declaratively. This
|
|||
|
||||
```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
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -221,24 +234,28 @@ To install it into our environment, you can just run `nix-env -iA nixpkgs.myPack
|
|||
|
||||
```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"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -250,24 +267,32 @@ After building that new environment, look through `~/.nix-profile` to make sure
|
|||
|
||||
```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"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -275,33 +300,42 @@ This provides us with some useful documentation for using our packages. However
|
|||
|
||||
```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"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -326,43 +360,54 @@ Configuring GNU info is a little bit trickier than man pages. To work correctly,
|
|||
|
||||
```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
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -136,7 +136,12 @@ self: super:
|
|||
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);
|
||||
|
||||
|
|
|
@ -13,27 +13,38 @@ It is used to override the arguments passed to a function.
|
|||
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 {
|
||||
# ...
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
@ -55,9 +66,11 @@ Example usages:
|
|||
|
||||
```nix
|
||||
{
|
||||
helloBar = pkgs.hello.overrideAttrs (finalAttrs: previousAttrs: {
|
||||
pname = previousAttrs.pname + "-bar";
|
||||
});
|
||||
helloBar = pkgs.hello.overrideAttrs (
|
||||
finalAttrs: previousAttrs: {
|
||||
pname = previousAttrs.pname + "-bar";
|
||||
}
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -107,7 +120,7 @@ Example usage:
|
|||
url = "ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2";
|
||||
hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY=";
|
||||
};
|
||||
patches = [];
|
||||
patches = [ ];
|
||||
});
|
||||
}
|
||||
```
|
||||
|
@ -128,8 +141,15 @@ Example usage:
|
|||
|
||||
```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;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue