Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
50 changes: 29 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,12 @@ If you have any problems with formatting, please ping the [formatting team](http
That is, write

```nix
{ stdenv, fetchurl, perl }: <...>
{
stdenv,
fetchurl,
perl,
}:
<...>
```

instead of
Expand All @@ -579,60 +584,63 @@ If you have any problems with formatting, please ping the [formatting team](http
or

```nix
{ stdenv, fetchurl, perl, ... }: <...>
{
stdenv,
fetchurl,
perl,
...
}:
<...>
```

For functions that are truly generic in the number of arguments, but have some required arguments, you should write them using an `@`-pattern:

```nix
{ stdenv, doCoverageAnalysis ? false, ... } @ args:
{
stdenv,
doCoverageAnalysis ? false,
...
}@args:

stdenv.mkDerivation (args // {
foo = if doCoverageAnalysis then "bla" else "";
})
stdenv.mkDerivation (args // { foo = if doCoverageAnalysis then "bla" else ""; })
```

instead of

```nix
args:

args.stdenv.mkDerivation (args // {
foo = if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "";
})
args.stdenv.mkDerivation (
args
// {
foo = if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "";
}
)
```

- Unnecessary string conversions should be avoided.
Do

```nix
{
rev = version;
}
{ rev = version; }
```

instead of

```nix
{
rev = "${version}";
}
{ rev = "${version}"; }
```

- Building lists conditionally _should_ be done with `lib.optional(s)` instead of using `if cond then [ ... ] else null` or `if cond then [ ... ] else [ ]`.

```nix
{
buildInputs = lib.optional stdenv.hostPlatform.isDarwin iconv;
}
{ buildInputs = lib.optional stdenv.hostPlatform.isDarwin iconv; }
```

instead of

```nix
{
buildInputs = if stdenv.hostPlatform.isDarwin then [ iconv ] else null;
}
{ buildInputs = if stdenv.hostPlatform.isDarwin then [ iconv ] else null; }
```

As an exception, an explicit conditional expression with null can be used when fixing a important bug without triggering a mass rebuild.
Expand Down
3 changes: 2 additions & 1 deletion ci/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ rec {
parse = pkgs.lib.recurseIntoAttrs {
latest = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.latest; };
lix = pkgs.callPackage ./parse.nix { nix = pkgs.lix; };
minimum = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.minimum; };
# TODO: Raise nixVersions.minimum to 2.24 and flip back to it.
minimum = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.nix_2_24; };
};
shell = import ../shell.nix { inherit nixpkgs system; };
tarball = import ../pkgs/top-level/make-tarball.nix {
Expand Down
12 changes: 6 additions & 6 deletions ci/pinned.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
},
"branch": "nixpkgs-unstable",
"submodules": false,
"revision": "6afe187897bef7933475e6af374c893f4c84a293",
"url": "https://github.com/NixOS/nixpkgs/archive/6afe187897bef7933475e6af374c893f4c84a293.tar.gz",
"hash": "1x3yas2aingswrw7hpn43d9anlb08bpyk42dqg6v8f3p3yk83p1b"
"revision": "2baf8e1658cba84a032c3a8befb1e7b06629242a",
"url": "https://github.com/NixOS/nixpkgs/archive/2baf8e1658cba84a032c3a8befb1e7b06629242a.tar.gz",
"hash": "0l48zkf2zs7r53fjq46j770vpb5avxihyfypra3fv429akqnsmm1"
},
"treefmt-nix": {
"type": "Git",
Expand All @@ -22,9 +22,9 @@
},
"branch": "main",
"submodules": false,
"revision": "a05be418a1af1198ca0f63facb13c985db4cb3c5",
"url": "https://github.com/numtide/treefmt-nix/archive/a05be418a1af1198ca0f63facb13c985db4cb3c5.tar.gz",
"hash": "1yadm9disc59an4a6c1zidq82530rd7i7idzzsirv6dlwirbqk3q"
"revision": "421b56313c65a0815a52b424777f55acf0b56ddf",
"url": "https://github.com/numtide/treefmt-nix/archive/421b56313c65a0815a52b424777f55acf0b56ddf.tar.gz",
"hash": "1l57hzz704s7izkkcl3xsg77xjfza57cl0fchs24rdpdhmry2dmp"
}
},
"version": 5
Expand Down
5 changes: 1 addition & 4 deletions doc/build-helpers/fixed-point-arguments.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ lib.extendMkDerivation {
}@args:
{
# Arguments to pass
inherit
preferLocalBuild
allowSubstitute
;
inherit preferLocalBuild allowSubstitute;
# Some expressions involving specialArg
greeting = if specialArg "hi" then "hi" else "hello";
};
Expand Down
8 changes: 2 additions & 6 deletions doc/build-helpers/images/appimagetools.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ let
hash = "sha256-he1uGC1M/nFcKpMM9JKY4oeexJcnzV0ZRxhTjtJz6xw=";
};
in
appimageTools.wrapType2 {
inherit pname version src;
}
appimageTools.wrapType2 { inherit pname version src; }
```

:::
Expand Down Expand Up @@ -104,9 +102,7 @@ let
hash = "sha256-/hMPvYdnVB1XjKgU2v47HnVvW4+uC3rhRjbucqin4iI=";
};

appimageContents = appimageTools.extract {
inherit pname version src;
};
appimageContents = appimageTools.extract { inherit pname version src; };
in
appimageTools.wrapType2 {
inherit pname version src;
Expand Down
5 changes: 1 addition & 4 deletions doc/build-helpers/images/binarycache.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ You may also want to consider [dockerTools](#sec-pkgs-dockerTools) for your cont
The following derivation will construct a flat-file binary cache containing the closure of `hello`.

```nix
{ mkBinaryCache, hello }:
mkBinaryCache {
rootPaths = [ hello ];
}
{ mkBinaryCache, hello }: mkBinaryCache { rootPaths = [ hello ]; }
```

Build the cache on a machine.
Expand Down
4 changes: 1 addition & 3 deletions doc/build-helpers/images/dockertools.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -1577,9 +1577,7 @@ This example uses [](#ex-dockerTools-streamNixShellImage-hello) as a starting po
dockerTools.streamNixShellImage {
tag = "latest";
drv = hello.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [
cowsay
];
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ cowsay ];
});
}
```
Expand Down
4 changes: 1 addition & 3 deletions doc/build-helpers/images/ocitools.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ This example uses `ociTools.buildContainer` to create a simple container that ru
bash,
}:
ociTools.buildContainer {
args = [
(lib.getExe bash)
];
args = [ (lib.getExe bash) ];

readonly = false;
}
Expand Down
31 changes: 13 additions & 18 deletions doc/build-helpers/special/checkpoint-build.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ For hermeticity, Nix derivations do not allow any state to be carried over betwe
However, we can tell Nix explicitly what the previous build state was, by representing that previous state as a derivation output. This allows the passed build state to be used for an incremental build.

To change a normal derivation to a checkpoint based build, these steps must be taken:
- apply `prepareCheckpointBuild` on the desired derivation, e.g.
```nix
{
checkpointArtifacts = (pkgs.checkpointBuildTools.prepareCheckpointBuild pkgs.virtualbox);
}
```
- change something you want in the sources of the package, e.g. use a source override:
```nix
{
changedVBox = pkgs.virtualbox.overrideAttrs (old: {
src = path/to/vbox/sources;
});
}
```
```nix
{
checkpointArtifacts = (pkgs.checkpointBuildTools.prepareCheckpointBuild pkgs.virtualbox);
}
```
```nix
{
changedVBox = pkgs.virtualbox.overrideAttrs (old: {
src = path/to/vbox/sources;
});
}
```
- use `mkCheckpointBuild changedVBox checkpointArtifacts`
- enjoy shorter build times

Expand All @@ -30,10 +28,7 @@ To change a normal derivation to a checkpoint based build, these steps must be t
pkgs ? import <nixpkgs> { },
}:
let
inherit (pkgs.checkpointBuildTools)
prepareCheckpointBuild
mkCheckpointBuild
;
inherit (pkgs.checkpointBuildTools) prepareCheckpointBuild mkCheckpointBuild;
helloCheckpoint = prepareCheckpointBuild pkgs.hello;
changedHello = pkgs.hello.overrideAttrs (_: {
doCheck = false;
Expand Down
12 changes: 3 additions & 9 deletions doc/build-helpers/testers.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ If the `moduleNames` argument is omitted, `hasPkgConfigModules` will use `meta.p

```nix
{
passthru.tests.pkg-config = testers.hasPkgConfigModules {
package = finalAttrs.finalPackage;
};
passthru.tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };

meta.pkgConfigModules = [ "libfoo" ];
}
Expand Down Expand Up @@ -74,9 +72,7 @@ If you have a static site that can be built with Nix, you can use `lycheeLinkChe
# Check hyperlinks in the `nix` documentation

```nix
testers.lycheeLinkCheck {
site = nix.doc + "/share/doc/nix/manual";
}
testers.lycheeLinkCheck { site = nix.doc + "/share/doc/nix/manual"; }
```

:::
Expand Down Expand Up @@ -269,9 +265,7 @@ The default argument to the command is `--version`, and the version to be checke
This example will run the command `hello --version`, and then check that the version of the `hello` package is in the output of the command.

```nix
{
passthru.tests.version = testers.testVersion { package = hello; };
}
{ passthru.tests.version = testers.testVersion { package = hello; }; }
```

:::
Expand Down
13 changes: 7 additions & 6 deletions doc/build-helpers/trivial-build-helpers.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ runCommandWith {

Likewise, `runCommandCC name derivationArgs buildCommand` is equivalent to
```nix
runCommandWith {
inherit name derivationArgs;
} buildCommand
runCommandWith { inherit name derivationArgs; } buildCommand
```
:::

Expand Down Expand Up @@ -713,7 +711,10 @@ concatTextFile
# Writes contents of files to /nix/store/<store path>
concatText
"my-file"
[ file1 file2 ]
[
file1
file2
]

# Writes contents of files to /nix/store/<store path>
concatScript
Expand Down Expand Up @@ -790,7 +791,7 @@ The result is equivalent to the output of `nix-store -q --requisites`.
For example,

```nix
writeClosure [ (writeScriptBin "hi" ''${hello}/bin/hello'') ]
writeClosure [ (writeScriptBin "hi" "${hello}/bin/hello") ]
```

produces an output path `/nix/store/<hash>-runtime-deps` containing
Expand All @@ -816,7 +817,7 @@ This produces the equivalent of `nix-store -q --references`.
For example,

```nix
writeDirectReferencesToFile (writeScriptBin "hi" ''${hello}/bin/hello'')
writeDirectReferencesToFile (writeScriptBin "hi" "${hello}/bin/hello")
```

produces an output path `/nix/store/<hash>-runtime-references` containing
Expand Down
2 changes: 1 addition & 1 deletion doc/functions/generators.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let
} ":";
};

# the INI file can now be given as plain old nix values
in
# the INI file can now be given as plain old nix values
customToINI {
main = {
pushinfo = true;
Expand Down
21 changes: 15 additions & 6 deletions doc/functions/nix-gitignore.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@
src = nix-gitignore.gitignoreSource [ ] ./source;
# Simplest version

src = nix-gitignore.gitignoreSource "supplemental-ignores\n" ./source;
src = nix-gitignore.gitignoreSource ''
supplemental-ignores
'' ./source;
# This one reads the ./source/.gitignore and concats the auxiliary ignores

src = nix-gitignore.gitignoreSourcePure "ignore-this\nignore-that\n" ./source;
src = nix-gitignore.gitignoreSourcePure ''
ignore-this
ignore-that
'' ./source;
# Use this string as gitignore, don't read ./source/.gitignore.

src = nix-gitignore.gitignoreSourcePure [ "ignore-this\nignore-that\n" ~/.gitignore ] ./source;
src = nix-gitignore.gitignoreSourcePure [
''
ignore-this
ignore-that
''
~/.gitignore
] ./source;
# It also accepts a list (of strings and paths) that will be concatenated
# once the paths are turned to strings via readFile.
}
Expand All @@ -41,9 +52,7 @@ Those filter functions accept the same arguments the `builtins.filterSource` fun
If you want to make your own filter from scratch, you may use

```nix
{
gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root;
}
{ gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root; }
```

## gitignore files in subdirectories {#sec-pkgs-nix-gitignore-usage-recursive}
Expand Down
4 changes: 1 addition & 3 deletions doc/hooks/breakpoint.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
This hook makes a build pause instead of stopping when a failure occurs. It prevents Nix from cleaning up the build environment immediately and allows the user to attach to the build environment. Upon a build error, it will print instructions that can be used to enter the environment for debugging. breakpointHook is only available on Linux. To use it, add `breakpointHook` to `nativeBuildInputs` in the package to be inspected.

```nix
{
nativeBuildInputs = [ breakpointHook ];
}
{ nativeBuildInputs = [ breakpointHook ]; }
```

When a build failure occurs, an instruction will be printed showing how to attach to the build sandbox.
Expand Down
Loading
Loading