treewide: run treefmt with mdcr/nixfmt

This commit is contained in:
Wolfgang Walther 2025-07-22 16:14:50 +02:00
parent 6c47e7d5da
commit 62fe016519
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
195 changed files with 1919 additions and 2002 deletions

View File

@ -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
@ -579,17 +584,25 @@ 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
@ -597,42 +610,37 @@ If you have any problems with formatting, please ping the [formatting team](http
```nix
args:
args.stdenv.mkDerivation (args // {
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.

View File

@ -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";
};

View File

@ -37,9 +37,7 @@ let
hash = "sha256-he1uGC1M/nFcKpMM9JKY4oeexJcnzV0ZRxhTjtJz6xw=";
};
in
appimageTools.wrapType2 {
inherit pname version src;
}
appimageTools.wrapType2 { inherit pname version src; }
```
:::
@ -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;

View File

@ -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.

View File

@ -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 ];
});
}
```

View File

@ -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;
}

View File

@ -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
{
```nix
{
checkpointArtifacts = (pkgs.checkpointBuildTools.prepareCheckpointBuild pkgs.virtualbox);
}
```
- change something you want in the sources of the package, e.g. use a source override:
```nix
{
}
```
```nix
{
changedVBox = pkgs.virtualbox.overrideAttrs (old: {
src = path/to/vbox/sources;
});
}
```
}
```
- use `mkCheckpointBuild changedVBox checkpointArtifacts`
- enjoy shorter build times
@ -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;

View File

@ -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" ];
}
@ -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"; }
```
:::
@ -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; }; }
```
:::

View File

@ -152,9 +152,7 @@ runCommandWith {
Likewise, `runCommandCC name derivationArgs buildCommand` is equivalent to
```nix
runCommandWith {
inherit name derivationArgs;
} buildCommand
runCommandWith { inherit name derivationArgs; } buildCommand
```
:::
@ -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
@ -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
@ -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

View File

@ -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;

View File

@ -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.
}
@ -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}

View File

@ -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.

View File

@ -4,17 +4,12 @@
This hook starts a Memcached server during `checkPhase`. Example:
```nix
{
stdenv,
memcachedTestHook,
}:
{ stdenv, memcachedTestHook }:
stdenv.mkDerivation {
# ...
nativeCheckInputs = [
memcachedTestHook
];
nativeCheckInputs = [ memcachedTestHook ];
}
```
@ -45,11 +40,10 @@ stdenv.mkDerivation {
# ...
nativeCheckInputs = [
memcachedTestHook
];
nativeCheckInputs = [ memcachedTestHook ];
preCheck = ''
memcachedTestPort=1234;
'';
}
```

View File

@ -38,9 +38,7 @@ stdenv.mkDerivation {
# ...
nativeBuildInputs = [
patchRcPathFish
];
nativeBuildInputs = [ patchRcPathFish ];
postFixup = ''
patchRcPathFish $out/bin/this-foo.fish ${

View File

@ -13,9 +13,7 @@ stdenv.mkDerivation {
# ...
nativeCheckInputs = [
redisTestHook
];
nativeCheckInputs = [ redisTestHook ];
}
```
@ -56,9 +54,7 @@ stdenv.mkDerivation {
# ...
nativeCheckInputs = [
redisTestHook
];
nativeCheckInputs = [ redisTestHook ];
preCheck = ''
redisTestPort=6390;

View File

@ -35,8 +35,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
hash = "...";
};
nativeBuildInputs =
[
nativeBuildInputs = [
# Pull in our main hook
cargo-tauri.hook
@ -46,10 +45,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
# Make sure we can find our libraries
pkg-config
]
++ lib.optionals stdenv.hostPlatform.isLinux [
wrapGAppsHook4
];
] ++ lib.optionals stdenv.hostPlatform.isLinux [ wrapGAppsHook4 ];
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
glib-networking # Most Tauri apps need networking

View File

@ -16,9 +16,7 @@ The hook runs in `installCheckPhase`, requiring `doInstallCheck` is enabled for
stdenv.mkDerivation (finalAttrs: {
# ...
nativeInstallCheckInputs = [
udevCheckHook
];
nativeInstallCheckInputs = [ udevCheckHook ];
doInstallCheck = true;
# ...

View File

@ -15,9 +15,7 @@ You use it like this:
stdenv.mkDerivation (finalAttrs: {
# ...
nativeInstallCheckInputs = [
versionCheckHook
];
nativeInstallCheckInputs = [ versionCheckHook ];
doInstallCheck = true;
# ...

View File

@ -16,9 +16,7 @@ In Nixpkgs, `zig.hook` overrides the default build, check and install phases.
stdenv.mkDerivation {
# . . .
nativeBuildInputs = [
zig.hook
];
nativeBuildInputs = [ zig.hook ];
zigBuildFlags = [ "-Dman-pages=true" ];

View File

@ -79,9 +79,7 @@ let
sha256,
...
}:
pkgs.fetchzip {
inherit name url sha256;
};
pkgs.fetchzip { inherit name url sha256; };
};
in

View File

@ -144,9 +144,7 @@ agdaPackages.mkDerivation {
version = "1.0";
pname = "my-agda-lib";
src = ./.;
buildInputs = [
agdaPackages.standard-library
];
buildInputs = [ agdaPackages.standard-library ];
}
```

View File

@ -8,17 +8,13 @@ supporting features.
Use the `android-studio-full` attribute for a very complete Android SDK, including system images:
```nix
{
buildInputs = [ android-studio-full ];
}
{ buildInputs = [ android-studio-full ]; }
```
This is identical to:
```nix
{
buildInputs = [ androidStudioPackages.stable.full ];
}
{ buildInputs = [ androidStudioPackages.stable.full ]; }
```
Alternatively, you can pass composeAndroidPackages to the `withSdk` passthru:
@ -26,11 +22,7 @@ Alternatively, you can pass composeAndroidPackages to the `withSdk` passthru:
```nix
{
buildInputs = [
(android-studio.withSdk
(androidenv.composeAndroidPackages {
includeNDK = true;
}).androidsdk
)
(android-studio.withSdk (androidenv.composeAndroidPackages { includeNDK = true; }).androidsdk)
];
}
```
@ -58,9 +50,7 @@ let
"arm64-v8a"
];
includeNDK = true;
includeExtras = [
"extras;google;auto"
];
includeExtras = [ "extras;google;auto" ];
};
in
androidComposition.androidsdk

View File

@ -65,9 +65,7 @@ let
overlays = [ ];
};
in
pkgs.mkShell {
packages = [ pkgs.beamPackages.rebar3 ];
}
pkgs.mkShell { packages = [ pkgs.beamPackages.rebar3 ]; }
```
:::
@ -324,9 +322,7 @@ with pkgs;
let
elixir = beam.packages.erlang_27.elixir_1_18;
in
mkShell {
buildInputs = [ elixir ];
}
mkShell { buildInputs = [ elixir ]; }
```
### Using an overlay {#beam-using-overlays}
@ -348,11 +344,7 @@ let
pkgs = import <nixpkgs> { overlays = [ elixir_1_18_1_overlay ]; };
in
with pkgs;
mkShell {
buildInputs = [
elixir_1_18
];
}
mkShell { buildInputs = [ elixir_1_18 ]; }
```
#### Elixir - Phoenix project {#elixir---phoenix-project}

View File

@ -77,8 +77,8 @@ let
);
}
);
# Here, `myChickenPackages.chickenEggs.json-rpc`, which depends on `srfi-180` will use
# the local copy of `srfi-180`.
in
# Here, `myChickenPackages.chickenEggs.json-rpc`, which depends on `srfi-180` will use
# the local copy of `srfi-180`.
<...>
```

View File

@ -145,17 +145,13 @@ There are three distinct ways of changing a Coq package by overriding one of its
For example, assuming you have a special `mathcomp` dependency you want to use, here is how you could override the `mathcomp` dependency:
```nix
multinomials.override {
mathcomp = my-special-mathcomp;
}
multinomials.override { mathcomp = my-special-mathcomp; }
```
In Nixpkgs, all Coq derivations take a `version` argument. This can be overridden in order to easily use a different version:
```nix
coqPackages.multinomials.override {
version = "1.5.1";
}
coqPackages.multinomials.override { version = "1.5.1"; }
```
Refer to [](#coq-packages-attribute-sets-coqpackages) for all the different formats that you can potentially pass to `version`, as well as the restrictions.

View File

@ -146,9 +146,7 @@ These settings ensure that the CUDA setup hooks function as intended.
When using `callPackage`, you can choose to pass in a different variant, e.g. when a package requires a specific version of CUDA:
```nix
{
mypkg = callPackage { cudaPackages = cudaPackages_12_2; };
}
{ mypkg = callPackage { cudaPackages = cudaPackages_12_2; }; }
```
::: {.caution}
@ -208,9 +206,7 @@ It is possible to run Docker or Podman containers with CUDA support. The recomme
The NVIDIA Container Toolkit can be enabled in NixOS like follows:
```nix
{
hardware.nvidia-container-toolkit.enable = true;
}
{ hardware.nvidia-container-toolkit.enable = true; }
```
This will automatically enable a service that generates a CDI specification (located at `/var/run/cdi/nvidia-container-toolkit.json`) based on the auto-detected hardware of your machine. You can check this service by running:

View File

@ -94,9 +94,7 @@ let
hash = "sha256-B4Q3c6IvTLg3Q92qYa8y+i4uTaphtFdjp+Ir3QQjdN0=";
};
dhallOverlay = self: super: {
true = self.callPackage ./true.nix { };
};
dhallOverlay = self: super: { true = self.callPackage ./true.nix { }; };
overlay = self: super: {
dhallPackages = super.dhallPackages.override (old: {

View File

@ -10,9 +10,7 @@ with import <nixpkgs> { };
mkShell {
name = "dotnet-env";
packages = [
dotnet-sdk
];
packages = [ dotnet-sdk ];
}
```
@ -161,7 +159,9 @@ buildDotnetModule rec {
projectFile = "src/project.sln";
nugetDeps = ./deps.json; # see "Generating and updating NuGet dependencies" section for details
buildInputs = [ referencedProject ]; # `referencedProject` must contain `nupkg` in the folder structure.
buildInputs = [
referencedProject
]; # `referencedProject` must contain `nupkg` in the folder structure.
dotnet-sdk = dotnetCorePackages.sdk_8_0;
dotnet-runtime = dotnetCorePackages.runtime_8_0;

View File

@ -38,10 +38,7 @@ One advantage is that when `pkgs.zlib` is updated, it will automatically update
```nix
(pkgs.zlib.override {
stdenv = pkgs.emscriptenStdenv;
}).overrideAttrs
(old: {
(pkgs.zlib.override { stdenv = pkgs.emscriptenStdenv; }).overrideAttrs (old: {
buildInputs = old.buildInputs ++ [ pkg-config ];
# we need to reset this setting!
env = (old.env or { }) // {
@ -109,7 +106,7 @@ One advantage is that when `pkgs.zlib` is updated, it will automatically update
--replace-fail 'AR="libtool"' 'AR="ar"' \
--replace-fail 'ARFLAGS="-o"' 'ARFLAGS="-r"'
'';
})
})
```
:::{.example #usage-2-pkgs.buildemscriptenpackage}

View File

@ -81,10 +81,7 @@ The function understands several forms of source directory trees:
For instance, packaging the Bresenham algorithm for line interpolation looks like this, see `pkgs/development/compilers/factor-lang/vocabs/bresenham` for the complete file:
```nix
{
factorPackages,
fetchFromGitHub,
}:
{ factorPackages, fetchFromGitHub }:
factorPackages.buildFactorVocab {
pname = "bresenham";

View File

@ -48,9 +48,7 @@ In the rare case you need to use icons from dependencies (e.g. when an app force
```nix
{
buildInputs = [
pantheon.elementary-icon-theme
];
buildInputs = [ pantheon.elementary-icon-theme ];
preFixup = ''
gappsWrapperArgs+=(
# The icon theme is hardcoded.

View File

@ -147,9 +147,7 @@ A string list of [Go build tags (also called build constraints)](https://pkg.go.
Tags can also be set conditionally:
```nix
{
tags = [ "production" ] ++ lib.optionals withSqlite [ "sqlite" ];
}
{ tags = [ "production" ] ++ lib.optionals withSqlite [ "sqlite" ]; }
```
### `deleteVendor` {#var-go-deleteVendor}
@ -283,9 +281,7 @@ For example, only a selection of tests could be run with:
```nix
{
# -run and -skip accept regular expressions
checkFlags = [
"-run=^Test(Simple|Fast)$"
];
checkFlags = [ "-run=^Test(Simple|Fast)$" ];
}
```

View File

@ -783,9 +783,7 @@ need to build `nix-tree` with a more recent version of `brick` than the default
one provided by `haskellPackages`:
```nix
haskellPackages.nix-tree.override {
brick = haskellPackages.brick_0_67;
}
haskellPackages.nix-tree.override { brick = haskellPackages.brick_0_67; }
```
<!-- TODO(@sternenseemann): This belongs in the next section
@ -841,8 +839,8 @@ let
install -Dm644 man/${drv.pname}.1 -t "$out/share/man/man1"
'';
});
in
in
installManPage haskellPackages.pnbackup
```
@ -1310,8 +1308,8 @@ let
ghcName = "ghc92";
# Desired new setting
enableProfiling = true;
in
in
[
# The first overlay modifies the GHC derivation so that it does or does not
# build profiling versions of the core libraries bundled with it. It is
@ -1322,8 +1320,8 @@ in
final: prev:
let
inherit (final) lib;
in
in
{
haskell = prev.haskell // {
compiler = prev.haskell.compiler // {
@ -1341,8 +1339,8 @@ in
let
inherit (final) lib;
haskellLib = final.haskell.lib.compose;
in
in
{
haskell = prev.haskell // {
packages = prev.haskell.packages // {

View File

@ -31,9 +31,7 @@ Xcode.
let
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
};
xcodeenv = import ./xcodeenv { inherit (pkgs) stdenv; };
in
xcodeenv.composeXcodeWrapper {
version = "9.2";
@ -65,9 +63,7 @@ executing the `xcodeenv.buildApp {}` function:
let
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
};
xcodeenv = import ./xcodeenv { inherit (pkgs) stdenv; };
in
xcodeenv.buildApp {
name = "MyApp";
@ -161,9 +157,7 @@ instances:
let
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
};
xcodeenv = import ./xcodeenv { inherit (pkgs) stdenv; };
in
xcode.simulateApp {
name = "simulate";
@ -195,9 +189,7 @@ app in the requested simulator instance:
let
pkgs = import <nixpkgs> { };
xcodeenv = import ./xcodeenv {
inherit (pkgs) stdenv;
};
xcodeenv = import ./xcodeenv { inherit (pkgs) stdenv; };
in
xcode.simulateApp {
name = "simulate";

View File

@ -108,11 +108,7 @@ You can also specify what JDK your JRE should be based on, for example
selecting a 'headless' build to avoid including a link to GTK+:
```nix
{
my_jre = pkgs.jre_minimal.override {
jdk = jdk11_headless;
};
}
{ my_jre = pkgs.jre_minimal.override { jdk = jdk11_headless; }; }
```
Note all JDKs passthru `home`, so if your application requires

View File

@ -303,9 +303,7 @@ buildNpmPackage {
version = "0.1.0";
src = ./.;
npmDeps = importNpmLock {
npmRoot = ./.;
};
npmDeps = importNpmLock { npmRoot = ./.; };
npmConfigHook = importNpmLock.npmConfigHook;
}
@ -456,9 +454,7 @@ In case you are patching `package.json` or `pnpm-lock.yaml`, make sure to pass `
`pnpm.configHook` supports adding additional `pnpm install` flags via `pnpmInstallFlags` which can be set to a Nix string array:
```nix
{
pnpm,
}:
{ pnpm }:
stdenv.mkDerivation (finalAttrs: {
pname = "foo";
@ -470,9 +466,7 @@ stdenv.mkDerivation (finalAttrs: {
pnpmInstallFlags = [ "--shamefully-hoist" ];
pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pnpmInstallFlags;
};
pnpmDeps = pnpm.fetchDeps { inherit (finalAttrs) pnpmInstallFlags; };
})
```
@ -699,9 +693,7 @@ It's important to use the `--offline` flag. For example if you script is `"build
```nix
{
nativeBuildInputs = [
writableTmpDirAsHomeHook
];
nativeBuildInputs = [ writableTmpDirAsHomeHook ];
buildPhase = ''
runHook preBuild
@ -716,9 +708,7 @@ It's important to use the `--offline` flag. For example if you script is `"build
The `distPhase` is packing the package's dependencies in a tarball using `yarn pack`. You can disable it using:
```nix
{
doDist = false;
}
{ doDist = false; }
```
The configure phase can sometimes fail because it makes many assumptions which may not always apply. One common override is:
@ -837,8 +827,8 @@ It's recommended to ensure you're explicitly pinning the major version used, for
let
yarn-berry = yarn-berry_4;
in
in
stdenv.mkDerivation (finalAttrs: {
pname = "foo";
version = "0-unstable-1980-01-01";
@ -892,8 +882,8 @@ To compensate for this, the `yarn-berry-fetcher missing-hashes` subcommand can b
let
yarn-berry = yarn-berry_4;
in
in
stdenv.mkDerivation (finalAttrs: {
pname = "foo";
version = "0-unstable-1980-01-01";

View File

@ -49,9 +49,7 @@ Also one can create a `pkgs.mkShell` environment in `shell.nix`/`flake.nix`:
let
sbcl' = sbcl.withPackages (ps: [ ps.alexandria ]);
in
mkShell {
packages = [ sbcl' ];
}
mkShell { packages = [ sbcl' ]; }
```
Such a Lisp can be now used e.g. to compile your sources:
@ -192,11 +190,7 @@ let
hash = "sha256-1Hzxt65dZvgOFIljjjlSGgKYkj+YBLwJCACi5DZsKmQ=";
};
};
sbcl' = sbcl.withOverrides (
self: super: {
inherit alexandria;
}
);
sbcl' = sbcl.withOverrides (self: super: { inherit alexandria; });
in
sbcl'.pkgs.alexandria
```

View File

@ -117,9 +117,7 @@ top-level while luarocks installs them in various subfolders by default.
For instance:
```nix
{
rtp-nvim = neovimUtils.buildNeovimPlugin {
luaAttr = luaPackages.rtp-nvim;
};
rtp-nvim = neovimUtils.buildNeovimPlugin { luaAttr = luaPackages.rtp-nvim; };
}
```
To update these packages, you should use the lua updater rather than vim's.

View File

@ -26,9 +26,7 @@ buildNimPackage (finalAttrs: {
lockFile = ./lock.json;
nimFlags = [
"-d:NimblePkgVersion=${finalAttrs.version}"
];
nimFlags = [ "-d:NimblePkgVersion=${finalAttrs.version}" ];
})
```

View File

@ -44,9 +44,7 @@ This will also work in a `shell.nix` file.
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
(octave.withPackages (opkgs: with opkgs; [ symbolic ]))
];
nativeBuildInputs = with pkgs; [ (octave.withPackages (opkgs: with opkgs; [ symbolic ])) ];
}
```

View File

@ -267,13 +267,7 @@ php.buildComposerProject2 (finalAttrs: {
# 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

View File

@ -126,9 +126,7 @@ buildPythonPackage rec {
pluggy
];
nativeCheckInputs = [
hypothesis
];
nativeCheckInputs = [ hypothesis ];
meta = {
changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}";
@ -271,16 +269,8 @@ be used through out all of the Python package set:
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; });
};
};
}
@ -323,9 +313,7 @@ python3Packages.buildPythonApplication rec {
hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw=";
};
build-system = with python3Packages; [
setuptools
];
build-system = with python3Packages; [ setuptools ];
dependencies = with python3Packages; [
tornado
@ -357,9 +345,7 @@ the attribute in `python-packages.nix`, and the `toPythonApplication` shall be
applied to the reference:
```nix
{
python3Packages,
}:
{ python3Packages }:
python3Packages.toPythonApplication python3Packages.youtube-dl
```
@ -395,9 +381,7 @@ mkPythonMetaPackage {
pname = "psycopg2-binary";
inherit (psycopg2) optional-dependencies version;
dependencies = [ psycopg2 ];
meta = {
inherit (psycopg2.meta) description homepage;
};
meta = { inherit (psycopg2.meta) description homepage; };
}
```
@ -443,9 +427,7 @@ let
pythonEnv = myPython.withPackages (ps: [ ps.my-editable ]);
in
pkgs.mkShell {
packages = [ pythonEnv ];
}
pkgs.mkShell { packages = [ pythonEnv ]; }
```
#### `python.buildEnv` function {#python.buildenv-function}
@ -942,9 +924,7 @@ buildPythonPackage rec {
hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";
};
build-system = [
setuptools
];
build-system = [ setuptools ];
# has no tests
doCheck = false;
@ -1001,9 +981,7 @@ with import <nixpkgs> { };
hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";
};
build-system = [
python313.pkgs.setuptools
];
build-system = [ python313.pkgs.setuptools ];
# has no tests
doCheck = false;
@ -1080,9 +1058,7 @@ buildPythonPackage rec {
hash = "sha256-FLLvdm1MllKrgTGC6Gb0k0deZeVYvtCCLji/B7uhong=";
};
build-system = [
setuptools
];
build-system = [ setuptools ];
dependencies = [
multipledispatch
@ -1090,9 +1066,7 @@ buildPythonPackage rec {
python-dateutil
];
nativeCheckInputs = [
pytestCheckHook
];
nativeCheckInputs = [ pytestCheckHook ];
meta = {
changelog = "https://github.com/blaze/datashape/releases/tag/${version}";
@ -1133,9 +1107,7 @@ buildPythonPackage rec {
hash = "sha256-s9NiusRxFydHzaNRMjjxFcvWxfi45jGb9ql6eJJyQJk=";
};
build-system = [
setuptools
];
build-system = [ setuptools ];
buildInputs = [
libxml2
@ -1197,9 +1169,7 @@ buildPythonPackage rec {
hash = "sha256-9ru2r6kwhUCaskiFoaPNuJCfCVoUL01J40byvRt4kHQ=";
};
build-system = [
setuptools
];
build-system = [ setuptools ];
buildInputs = [
fftw
@ -1307,11 +1277,7 @@ To use `pytestCheckHook`, add it to `nativeCheckInputs`.
Adding `pytest` is not required, since it is included with `pytestCheckHook`.
```nix
{
nativeCheckInputs = [
pytestCheckHook
];
}
{ nativeCheckInputs = [ pytestCheckHook ]; }
```
`pytestCheckHook` recognizes the following attributes:
@ -1340,9 +1306,7 @@ The following example demonstrates usage of various `pytestCheckHook` attributes
```nix
{
nativeCheckInputs = [
pytestCheckHook
];
nativeCheckInputs = [ pytestCheckHook ];
# Allow running the following test paths and test objects.
enabledTestPaths = [
@ -1402,9 +1366,7 @@ by disabling tests that match both `"Foo"` **and** `"bar"`:
{
__structuredAttrs = true;
disabledTests = [
"Foo and bar"
];
disabledTests = [ "Foo and bar" ];
}
```
@ -1492,9 +1454,7 @@ we can do:
"pkg1"
"pkg3"
];
pythonRemoveDeps = [
"pkg2"
];
pythonRemoveDeps = [ "pkg2" ];
}
```
@ -1509,9 +1469,7 @@ Another option is to pass `true`, that will relax/remove all dependencies, for
example:
```nix
{
pythonRelaxDeps = true;
}
{ pythonRelaxDeps = true; }
```
which would result in the following `requirements.txt` file:
@ -1547,9 +1505,7 @@ automatically add `pythonRelaxDepsHook` if either `pythonRelaxDeps` or
```nix
{
nativeCheckInputs = [
unittestCheckHook
];
nativeCheckInputs = [ unittestCheckHook ];
unittestFlags = [
"-s"
@ -1575,9 +1531,7 @@ render them using the default `html` style.
"doc"
];
nativeBuildInputs = [
sphinxHook
];
nativeBuildInputs = [ sphinxHook ];
}
```
@ -1652,9 +1606,7 @@ buildPythonPackage rec {
hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";
};
build-system = [
setuptools
];
build-system = [ setuptools ];
meta = {
changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}";
@ -1717,14 +1669,10 @@ with import <nixpkgs> { };
});
};
in
pkgs.python310.override {
inherit packageOverrides;
};
pkgs.python310.override { inherit packageOverrides; };
in
python.withPackages (ps: [
ps.pandas
])
python.withPackages (ps: [ ps.pandas ])
).env
```
@ -1743,16 +1691,9 @@ with import <nixpkgs> { };
(
let
packageOverrides = self: super: {
scipy = super.scipy_0_17;
};
packageOverrides = self: super: { scipy = super.scipy_0_17; };
in
(pkgs.python310.override {
inherit packageOverrides;
}).withPackages
(ps: [
ps.blaze
])
(pkgs.python310.override { inherit packageOverrides; }).withPackages (ps: [ ps.blaze ])
).env
```
@ -2000,11 +1941,7 @@ this snippet:
```nix
{
myPythonPackages = python3Packages.override {
overrides = self: super: {
twisted = <...>;
};
};
myPythonPackages = python3Packages.override { overrides = self: super: { twisted = <...>; }; };
}
```

View File

@ -52,7 +52,7 @@ Add entries to `qtWrapperArgs` are to modify the wrappers created by
stdenv.mkDerivation {
# ...
nativeBuildInputs = [ qt6.wrapQtAppsHook ];
qtWrapperArgs = [ ''--prefix PATH : /path/to/bin'' ];
qtWrapperArgs = [ "--prefix PATH : /path/to/bin" ];
}
```

View File

@ -172,7 +172,9 @@ 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"
];
};
};
};
@ -193,7 +195,9 @@ let
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"
];
};
};
};

View File

@ -62,9 +62,7 @@ hash using `nix-hash --to-sri --type sha256 "<original sha256>"`.
:::
```nix
{
cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8=";
}
{ cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8="; }
```
If this method does not work, you can resort to copying the `Cargo.lock` file into nixpkgs
@ -77,9 +75,7 @@ then be taken from the failed build. A fake hash can be used for
`cargoHash` as follows:
```nix
{
cargoHash = lib.fakeHash;
}
{ cargoHash = lib.fakeHash; }
```
Per the instructions in the [Cargo Book](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html)
@ -478,11 +474,7 @@ and fetches every dependency as a separate fixed-output derivation.
`importCargoLock` can be used as follows:
```nix
{
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
}
{ cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; }; }
```
If the `Cargo.lock` file includes git dependencies, then their output
@ -1000,8 +992,8 @@ let
cargo = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
rustc = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
};
in
in
rustPlatform.buildRustPackage (finalAttrs: {
pname = "ripgrep";
version = "14.1.1";

View File

@ -25,7 +25,6 @@ primarily for Chez Scheme in a derivation, one might write:
akkuPackages.chez-srfi
];
}
```
The package index is located in `pkgs/tools/package-management/akku`

View File

@ -80,8 +80,8 @@ expression. The next step is to write that expression:
let
# Pass the generated files to the helper.
generated = swiftpm2nix.helpers ./nix;
in
in
stdenv.mkDerivation (finalAttrs: {
pname = "myproject";
version = "0.0.0";
@ -131,17 +131,13 @@ stdenv.mkDerivation (finalAttrs: {
If you'd like to build a different configuration than `release`:
```nix
{
swiftpmBuildConfig = "debug";
}
{ swiftpmBuildConfig = "debug"; }
```
It is also possible to provide additional flags to `swift build`:
```nix
{
swiftpmFlags = [ "--disable-dead-strip" ];
}
{ swiftpmFlags = [ "--disable-dead-strip" ]; }
```
The default `buildPhase` already passes `-j` for parallel building.
@ -155,9 +151,7 @@ Including `swiftpm` in your `nativeBuildInputs` also provides a default
`checkPhase`, but it must be enabled with:
```nix
{
doCheck = true;
}
{ doCheck = true; }
```
This essentially runs: `swift test -c release`

View File

@ -214,11 +214,7 @@ let
latex_with_foiltex = texliveSmall.withPackages (_: [ foiltex ]);
in
runCommand "test.pdf"
{
nativeBuildInputs = [ latex_with_foiltex ];
}
''
runCommand "test.pdf" { nativeBuildInputs = [ latex_with_foiltex ]; } ''
cat >test.tex <<EOF
\documentclass{foils}
@ -231,7 +227,7 @@ runCommand "test.pdf"
EOF
pdflatex test.tex
cp test.pdf $out
''
''
```
## LuaLaTeX font cache {#sec-language-texlive-lualatex-font-cache}
@ -239,15 +235,11 @@ runCommand "test.pdf"
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 ];
}
''
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).

View File

@ -25,9 +25,7 @@ typst.withPackages.override
typstPackages = old.typstPackages.extend (
_: previous: {
polylux_0_4_0 = previous.polylux_0_4_0.overrideAttrs (oldPolylux: {
src = oldPolylux.src.overrideAttrs {
outputHash = YourUpToDatePolyluxHash;
};
src = oldPolylux.src.overrideAttrs { outputHash = YourUpToDatePolyluxHash; };
});
}
);
@ -47,10 +45,7 @@ typst.withPackages.override
Here's how to define a custom Typst package:
```nix
{
buildTypstPackage,
typstPackages,
}:
{ buildTypstPackage, typstPackages }:
buildTypstPackage (finalAttrs: {
pname = "my-typst-package";

View File

@ -29,9 +29,7 @@ The default configuration directory is `~/.cataclysm-dda`. If you prefer
`$XDG_CONFIG_HOME/cataclysm-dda`, override the derivation:
```nix
cataclysm-dda.override {
useXdgDir = true;
}
cataclysm-dda.override { useXdgDir = true; }
```
## Important note for overriding packages {#important-note-for-overriding-packages}
@ -62,10 +60,10 @@ let
# or by using a helper function `attachPkgs`.
goodExample2 = attachPkgs pkgs myCDDA;
in
# badExample # parallel building disabled
# goodExample1.withMods (_: []) # parallel building enabled
# badExample # parallel building disabled
# goodExample1.withMods (_: []) # parallel building enabled
in
goodExample2.withMods (_: [ ]) # parallel building enabled
```
@ -75,11 +73,7 @@ To install Cataclysm DDA with mods of your choice, you can use `withMods`
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

View File

@ -8,9 +8,7 @@ To enable them, use an override on `inkscape-with-extensions`:
```nix
inkscape-with-extensions.override {
inkscapeExtensions = with inkscape-extensions; [
inkstitch
];
inkscapeExtensions = with inkscape-extensions; [ inkstitch ];
}
```

View File

@ -3,7 +3,5 @@
Kakoune can be built to autoload plugins:
```nix
(kakoune.override {
plugins = with pkgs.kakounePlugins; [ parinfer-rust ];
})
(kakoune.override { plugins = with pkgs.kakounePlugins; [ parinfer-rust ]; })
```

View File

@ -77,9 +77,7 @@ A plugin can be any kind of derivation, the only requirement is that it should a
If the plugin is itself a Perl package that needs to be imported from other plugins or scripts, add the following passthrough:
```nix
{
passthru.perlPackages = [ "self" ];
}
{ passthru.perlPackages = [ "self" ]; }
```
This will make the urxvt wrapper pick up the dependency and set up the Perl path accordingly.

View File

@ -496,8 +496,8 @@
```nix
let
pkgs = import <nixpkgs> { };
in
in
pkgs.caddy.withPlugins {
plugins = [
# tagged upstream

View File

@ -135,9 +135,7 @@ Some frequently encountered problems when packaging for cross-compilation should
Many packages assume that an unprefixed binutils (`cc`/`ar`/`ld` etc.) is available, but Nix doesn't provide one. It only provides a prefixed one, just as it only does for all the other binutils programs. It may be necessary to patch the package to fix the build system to use a prefix. For instance, instead of `cc`, use `${stdenv.cc.targetPrefix}cc`.
```nix
{
makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" ];
}
{ makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" ]; }
```
#### How do I avoid compiling a GCC cross-compiler from source? {#cross-qa-avoid-compiling-gcc-cross-compiler}
@ -152,9 +150,7 @@ $ nix-build '<nixpkgs>' -A pkgsCross.raspberryPi.hello
Add the following to your `mkDerivation` invocation.
```nix
{
depsBuildBuild = [ buildPackages.stdenv.cc ];
}
{ depsBuildBuild = [ buildPackages.stdenv.cc ]; }
```
#### My packages testsuite needs to run host platform code. {#cross-testsuite-runs-host-code}
@ -162,9 +158,7 @@ Add the following to your `mkDerivation` invocation.
Add the following to your `mkDerivation` invocation.
```nix
{
doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
}
{ doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; }
```
#### Package using Meson needs to run binaries for the host platform during build. {#cross-meson-runs-host-code}
@ -175,13 +169,9 @@ e.g.
```nix
{
nativeBuildInputs =
[
nativeBuildInputs = [
meson
]
++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
mesonEmulatorHook
];
] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ mesonEmulatorHook ];
}
```

View File

@ -108,9 +108,7 @@ The *priority* of the package, used by `nix-env` to resolve file name conflicts
The list of Nix platform types on which the package is supported. Hydra builds packages according to the platform specified. If no platform is specified, the package does not have prebuilt binaries. An example is:
```nix
{
meta.platforms = lib.platforms.linux;
}
{ meta.platforms = lib.platforms.linux; }
```
Attribute Set `lib.platforms` defines [various common lists](https://github.com/NixOS/nixpkgs/blob/master/lib/systems/doubles.nix) of platforms types.
@ -164,9 +162,7 @@ This means that `broken` can be used to express constraints, for example:
- Does not cross compile
```nix
{
meta.broken = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform);
}
{ meta.broken = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform); }
```
- Broken if all of a certain set of its dependencies are broken

View File

@ -541,11 +541,7 @@ let
# An example of an attribute containing a function
passthru.appendPackages =
packages':
finalAttrs.finalPackage.overrideAttrs (
newSelf: super: {
packages = super.packages ++ packages';
}
);
finalAttrs.finalPackage.overrideAttrs (newSelf: super: { packages = super.packages ++ packages'; });
# For illustration purposes; referenced as
# `(pkg.overrideAttrs(x)).finalAttrs` etc in the text below.
@ -787,9 +783,7 @@ The file name of the Makefile.
A list of strings passed as additional flags to `make`. These flags are also used by the default install and check phase. For setting make flags specific to the build phase, use `buildFlags` (see below).
```nix
{
makeFlags = [ "PREFIX=$(out)" ];
}
{ makeFlags = [ "PREFIX=$(out)" ]; }
```
::: {.note}
@ -839,9 +833,7 @@ It is highly recommended, for packages' sources that are not distributed with an
Controls whether the check phase is executed. By default it is skipped, but if `doCheck` is set to true, the check phase is usually executed. Thus you should set
```nix
{
doCheck = true;
}
{ doCheck = true; }
```
in the derivation to enable checks. The exception is cross compilation. Cross compiled builds never run tests, no matter how `doCheck` is set, as the newly-built program wont run on the platform used to build it.
@ -894,9 +886,7 @@ See the [build phase](#var-stdenv-makeFlags) for details.
The make targets that perform the installation. Defaults to `install`. Example:
```nix
{
installTargets = "install-bin install-doc";
}
{ installTargets = "install-bin install-doc"; }
```
##### `installFlags` / `installFlagsArray` {#var-stdenv-installFlags}
@ -1085,9 +1075,7 @@ It is often better to add tests that are not part of the source distribution to
Controls whether the installCheck phase is executed. By default it is skipped, but if `doInstallCheck` is set to true, the installCheck phase is usually executed. Thus you should set
```nix
{
doInstallCheck = true;
}
{ doInstallCheck = true; }
```
in the derivation to enable install checks. The exception is cross compilation. Cross compiled builds never run tests, no matter how `doInstallCheck` is set, as the newly-built program wont run on the platform used to build it.

View File

@ -21,9 +21,7 @@ In particular, all build-time dependencies are checked.
A user's Nixpkgs configuration is stored in a user-specific configuration file located at `~/.config/nixpkgs/config.nix`. For example:
```nix
{
allowUnfree = true;
}
{ allowUnfree = true; }
```
:::{.caution}
@ -44,9 +42,7 @@ There are two ways to try compiling a package which has been marked as broken.
- For permanently allowing broken packages to be built, you may add `allowBroken = true;` to your user's configuration file, like this:
```nix
{
allowBroken = true;
}
{ allowBroken = true; }
```
@ -63,9 +59,7 @@ There are also two ways to try compiling a package which has been marked as unsu
- For permanently allowing unsupported packages to be built, you may add `allowUnsupportedSystem = true;` to your user's configuration file, like this:
```nix
{
allowUnsupportedSystem = true;
}
{ allowUnsupportedSystem = true; }
```
The difference between a package being unsupported on some system and being broken is admittedly a bit fuzzy. If a program *ought* to work on a certain platform, but doesn't, the platform should be included in `meta.platforms`, but marked as broken with e.g. `meta.broken = !hostPlatform.isWindows`. Of course, this begs the question of what "ought" means exactly. That is left to the package maintainer.
@ -90,9 +84,7 @@ There are several ways to tweak how Nix handles a package which has been marked
This option is a function which accepts a package as a parameter, and returns a boolean. The following example configuration accepts a package and always returns false:
```nix
{
allowUnfreePredicate = (pkg: false);
}
{ allowUnfreePredicate = (pkg: false); }
```
For a more useful example, try the following. This configuration only allows unfree packages named roon-server and visual studio code:
@ -151,11 +143,7 @@ There are several ways to tweak how Nix handles a package which has been marked
The following example configuration permits the installation of the hypothetically insecure package `hello`, version `1.2.3`:
```nix
{
permittedInsecurePackages = [
"hello-1.2.3"
];
}
{ permittedInsecurePackages = [ "hello-1.2.3" ]; }
```
- It is also possible to create a custom policy around which insecure packages to allow and deny, by overriding the `allowInsecurePredicate` configuration option.
@ -165,13 +153,7 @@ There are several ways to tweak how Nix handles a package which has been marked
The following configuration example allows any version of the `ovftool` package:
```nix
{
allowInsecurePredicate =
pkg:
builtins.elem (lib.getName pkg) [
"ovftool"
];
}
{ allowInsecurePredicate = pkg: builtins.elem (lib.getName pkg) [ "ovftool" ]; }
```
Note that `permittedInsecurePackages` is only checked if `allowInsecurePredicate` is not specified.

View File

@ -48,12 +48,8 @@ Overlays are Nix functions which accept two arguments, conventionally called `se
self: super:
{
boost = super.boost.override {
python = self.python3;
};
rr = super.callPackage ./pkgs/rr {
stdenv = self.stdenv_32bit;
};
boost = super.boost.override { python = self.python3; };
rr = super.callPackage ./pkgs/rr { stdenv = self.stdenv_32bit; };
}
```
@ -99,13 +95,9 @@ Introduced in [PR #83888](https://github.com/NixOS/nixpkgs/pull/83888), we are a
self: super:
{
blas = super.blas.override {
blasProvider = self.mkl;
};
blas = super.blas.override { blasProvider = self.mkl; };
lapack = super.lapack.override {
lapackProvider = self.mkl;
};
lapack = super.lapack.override { lapackProvider = self.mkl; };
}
```
@ -123,13 +115,9 @@ To override `blas` and `lapack` with its reference implementations (i.e. for dev
self: super:
{
blas = super.blas.override {
blasProvider = self.lapack-reference;
};
blas = super.blas.override { blasProvider = self.lapack-reference; };
lapack = super.lapack.override {
lapackProvider = self.lapack-reference;
};
lapack = super.lapack.override { lapackProvider = self.lapack-reference; };
}
```

View File

@ -31,11 +31,7 @@ pkgs.foo.override (previous: {
```nix
import pkgs.path {
overlays = [
(self: super: {
foo = super.foo.override { barSupport = true; };
})
];
overlays = [ (self: super: { foo = super.foo.override { barSupport = true; }; }) ];
}
```
@ -67,9 +63,7 @@ Example usages:
```nix
{
helloBar = pkgs.hello.overrideAttrs (
finalAttrs: previousAttrs: {
pname = previousAttrs.pname + "-bar";
}
finalAttrs: previousAttrs: { pname = previousAttrs.pname + "-bar"; }
);
}
```
@ -85,11 +79,7 @@ If only a one-argument function is written, the argument has the meaning of `pre
Function arguments can be omitted entirely if there is no need to access `previousAttrs` or `finalAttrs`.
```nix
{
helloWithDebug = pkgs.hello.overrideAttrs {
separateDebugInfo = true;
};
}
{ helloWithDebug = pkgs.hello.overrideAttrs { separateDebugInfo = true; }; }
```
In the above example, the `separateDebugInfo` attribute is overridden to be true, thus building debug info for `helloWithDebug`.

View File

@ -86,14 +86,12 @@ When adding users to [`maintainer-list.nix`](./maintainer-list.nix), the followi
Given a maintainer entry like this:
``` nix
```nix
{
example = {
email = "user@example.com";
name = "Example User";
keys = [{
fingerprint = "0000 0000 2A70 6423 0AED 3C11 F04F 7A19 AAA6 3AFE";
}];
keys = [ { fingerprint = "0000 0000 2A70 6423 0AED 3C11 F04F 7A19 AAA6 3AFE"; } ];
};
}
```

View File

@ -28,7 +28,7 @@ can be accomplished using the following configuration on the host:
```nix
{
networking.nat.enable = true;
networking.nat.internalInterfaces = ["ve-+"];
networking.nat.internalInterfaces = [ "ve-+" ];
networking.nat.externalInterface = "eth0";
}
```
@ -40,9 +40,7 @@ If you are using Network Manager, you need to explicitly prevent it from
managing container interfaces:
```nix
{
networking.networkmanager.unmanaged = [ "interface-name:ve-*" ];
}
{ networking.networkmanager.unmanaged = [ "interface-name:ve-*" ]; }
```
You may need to restart your system for the changes to take effect.

View File

@ -39,9 +39,7 @@ they were in the same cgroup, then the PostgreSQL process would get
`configuration.nix`:
```nix
{
systemd.services.httpd.serviceConfig.CPUShares = 512;
}
{ systemd.services.httpd.serviceConfig.CPUShares = 512; }
```
By default, every cgroup has 1024 CPU shares, so this will halve the CPU
@ -54,9 +52,7 @@ limits can be specified in `configuration.nix`; for instance, to limit
`httpd.service` to 512 MiB of RAM (excluding swap):
```nix
{
systemd.services.httpd.serviceConfig.MemoryLimit = "512M";
}
{ systemd.services.httpd.serviceConfig.MemoryLimit = "512M"; }
```
The command `systemd-cgtop` shows a continuously updated list of all

View File

@ -6,10 +6,11 @@ shall be a container named `database` running PostgreSQL:
```nix
{
containers.database =
{ config =
containers.database = {
config =
{ config, pkgs, ... }:
{ services.postgresql.enable = true;
{
services.postgresql.enable = true;
services.postgresql.package = pkgs.postgresql_14;
};
};

View File

@ -82,9 +82,7 @@ In order to enable a systemd *system* service with provided upstream
package, use (e.g):
```nix
{
systemd.packages = [ pkgs.packagekit ];
}
{ systemd.packages = [ pkgs.packagekit ]; }
```
Usually NixOS modules written by the community do the above, plus take

View File

@ -4,8 +4,8 @@ If you find yourself repeating yourself over and over, its time to abstract.
```nix
{
services.httpd.virtualHosts =
{ "blog.example.org" = {
services.httpd.virtualHosts = {
"blog.example.org" = {
documentRoot = "/webroot/blog.example.org";
adminAddr = "alice@example.org";
forceSSL = true;
@ -24,15 +24,15 @@ If you find yourself repeating yourself over and over, its time to abstract.
It defines two virtual hosts with nearly identical configuration; the only difference is the document root directories. To prevent this duplication, we can use a `let`:
```nix
let
commonConfig =
{ adminAddr = "alice@example.org";
commonConfig = {
adminAddr = "alice@example.org";
forceSSL = true;
enableACME = true;
};
in
{
services.httpd.virtualHosts =
{ "blog.example.org" = (commonConfig // { documentRoot = "/webroot/blog.example.org"; });
services.httpd.virtualHosts = {
"blog.example.org" = (commonConfig // { documentRoot = "/webroot/blog.example.org"; });
"wiki.example.org" = (commonConfig // { documentRoot = "/webroot/wiki.example.org"; });
};
}
@ -45,9 +45,24 @@ You can write a `let` wherever an expression is allowed. Thus, you also could ha
```nix
{
services.httpd.virtualHosts =
let commonConfig = { /* ... */ }; in
{ "blog.example.org" = (commonConfig // { /* ... */ });
"wiki.example.org" = (commonConfig // { /* ... */ });
let
commonConfig = {
# ...
};
in
{
"blog.example.org" = (
commonConfig
// {
# ...
}
);
"wiki.example.org" = (
commonConfig
// {
# ...
}
);
};
}
```
@ -60,14 +75,15 @@ but not `{ let commonConfig = ...; in ...; }` since attributes (as opposed to at
{
services.httpd.virtualHosts =
let
makeVirtualHost = webroot:
{ documentRoot = webroot;
makeVirtualHost = webroot: {
documentRoot = webroot;
adminAddr = "alice@example.org";
forceSSL = true;
enableACME = true;
};
in
{ "example.org" = (makeVirtualHost "/webroot/example.org");
{
"example.org" = (makeVirtualHost "/webroot/example.org");
"example.com" = (makeVirtualHost "/webroot/example.com");
"example.gov" = (makeVirtualHost "/webroot/example.gov");
"example.nl" = (makeVirtualHost "/webroot/example.nl");

View File

@ -7,8 +7,7 @@ modules. For instance, to statically configure an IPv6 address:
```nix
{
networking.localCommands =
''
networking.localCommands = ''
ip -6 addr add 2001:610:685:1::1/64 dev eth0
'';
}

View File

@ -23,9 +23,7 @@ Then you write and test the package as described in the Nixpkgs manual.
Finally, you add it to [](#opt-environment.systemPackages), e.g.
```nix
{
environment.systemPackages = [ pkgs.my-package ];
}
{ environment.systemPackages = [ pkgs.my-package ]; }
```
and you run `nixos-rebuild`, specifying your own Nixpkgs tree:
@ -43,7 +41,9 @@ tree. For instance, here is how you specify a build of the
{
environment.systemPackages =
let
my-hello = with pkgs; stdenv.mkDerivation rec {
my-hello =
with pkgs;
stdenv.mkDerivation rec {
name = "hello-2.8";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
@ -59,15 +59,13 @@ Of course, you can also move the definition of `my-hello` into a
separate Nix expression, e.g.
```nix
{
environment.systemPackages = [ (import ./my-hello.nix) ];
}
{ environment.systemPackages = [ (import ./my-hello.nix) ]; }
```
where `my-hello.nix` contains:
```nix
with import <nixpkgs> {}; # bring all of Nixpkgs into scope
with import <nixpkgs> { }; # bring all of Nixpkgs into scope
stdenv.mkDerivation rec {
name = "hello-2.8";

View File

@ -5,7 +5,8 @@ The NixOS configuration file generally looks like this:
```nix
{ config, pkgs, ... }:
{ /* option definitions */
{
# option definitions
}
```
@ -19,7 +20,8 @@ name of an option and `value` is its value. For example,
```nix
{ config, pkgs, ... }:
{ services.httpd.enable = true;
{
services.httpd.enable = true;
services.httpd.adminAddr = "alice@example.org";
services.httpd.virtualHosts.localhost.documentRoot = "/webroot";
}
@ -38,7 +40,8 @@ example above can also be written as:
```nix
{ config, pkgs, ... }:
{ services = {
{
services = {
httpd = {
enable = true;
adminAddr = "alice@example.org";

View File

@ -41,14 +41,14 @@ You can use them like this:
{
environment.systemPackages = with pkgs; [
sl
(pass.withExtensions (subpkgs: with subpkgs; [
(pass.withExtensions (
subpkgs: with subpkgs; [
pass-audit
pass-otp
pass-genphrase
]))
(python3.withPackages (subpkgs: with subpkgs; [
requests
]))
]
))
(python3.withPackages (subpkgs: with subpkgs; [ requests ]))
cowsay
];
}
@ -62,9 +62,7 @@ dependency on GTK 2. If you want to build it against GTK 3, you can
specify that as follows:
```nix
{
environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ];
}
{ environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ]; }
```
The function `override` performs the call to the Nix function that
@ -109,8 +107,8 @@ your customised instance, you can apply a *global* override as follows:
```nix
{
nixpkgs.config.packageOverrides = pkgs:
{ emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
nixpkgs.config.packageOverrides = pkgs: {
emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
};
}
```

View File

@ -7,9 +7,7 @@ following line to `configuration.nix` enables the Mozilla Thunderbird
email application:
```nix
{
environment.systemPackages = [ pkgs.thunderbird ];
}
{ environment.systemPackages = [ pkgs.thunderbird ]; }
```
The effect of this specification is that the Thunderbird package from

View File

@ -7,8 +7,8 @@ point `/data`:
```nix
{
fileSystems."/data" =
{ device = "/dev/disk/by-label/data";
fileSystems."/data" = {
device = "/dev/disk/by-label/data";
fsType = "ext4";
};
}

View File

@ -5,9 +5,7 @@ and other unexpected packets. The firewall applies to both IPv4 and IPv6
traffic. It is enabled by default. It can be disabled as follows:
```nix
{
networking.firewall.enable = false;
}
{ networking.firewall.enable = false; }
```
If the firewall is enabled, you can open specific TCP ports to the
@ -15,7 +13,10 @@ outside world:
```nix
{
networking.firewall.allowedTCPPorts = [ 80 443 ];
networking.firewall.allowedTCPPorts = [
80
443
];
}
```
@ -28,8 +29,14 @@ To open ranges of TCP ports:
```nix
{
networking.firewall.allowedTCPPortRanges = [
{ from = 4000; to = 4007; }
{ from = 8000; to = 8010; }
{
from = 4000;
to = 4007;
}
{
from = 8000;
to = 8010;
}
];
}
```

View File

@ -55,11 +55,7 @@ supported through the rocmPackages.clr.icd package. Adding this package to
enables OpenCL support:
```nix
{
hardware.graphics.extraPackages = [
rocmPackages.clr.icd
];
}
{ hardware.graphics.extraPackages = [ rocmPackages.clr.icd ]; }
```
### Intel {#sec-gpu-accel-opencl-intel}
@ -75,11 +71,7 @@ to enable OpenCL support. For example, for Gen12 and later GPUs, the following
configuration can be used:
```nix
{
hardware.graphics.extraPackages = [
intel-compute-runtime
];
}
{ hardware.graphics.extraPackages = [ intel-compute-runtime ]; }
```
## Vulkan {#sec-gpu-accel-vulkan}
@ -145,20 +137,15 @@ A specific driver can be forced as follows:
```nix
{
hardware.graphics.extraPackages = [
pkgs.amdvlk
];
hardware.graphics.extraPackages = [ pkgs.amdvlk ];
# To enable Vulkan support for 32-bit applications, also add:
hardware.graphics.extraPackages32 = [
pkgs.driversi686Linux.amdvlk
];
hardware.graphics.extraPackages32 = [ pkgs.driversi686Linux.amdvlk ];
# Force radv
environment.variables.AMD_VULKAN_ICD = "RADV";
# Or
environment.variables.VK_ICD_FILENAMES =
"/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json";
environment.variables.VK_ICD_FILENAMES = "/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json";
}
```
@ -183,21 +170,13 @@ $ nix-shell -p libva-utils --run vainfo
Modern Intel GPUs use the iHD driver, which can be installed with:
```nix
{
hardware.graphics.extraPackages = [
intel-media-driver
];
}
{ hardware.graphics.extraPackages = [ intel-media-driver ]; }
```
Older Intel GPUs use the i965 driver, which can be installed with:
```nix
{
hardware.graphics.extraPackages = [
intel-vaapi-driver
];
}
{ hardware.graphics.extraPackages = [ intel-vaapi-driver ]; }
```
## Common issues {#sec-gpu-accel-common-issues}

View File

@ -6,10 +6,12 @@ manually as follows:
```nix
{
networking.interfaces.eth0.ipv4.addresses = [ {
networking.interfaces.eth0.ipv4.addresses = [
{
address = "192.168.1.2";
prefixLength = 24;
} ];
}
];
}
```
@ -32,9 +34,7 @@ configuration is performed by `network-setup.service`.
The host name is set using [](#opt-networking.hostName):
```nix
{
networking.hostName = "cartman";
}
{ networking.hostName = "cartman"; }
```
The default host name is `nixos`. Set it to the empty string (`""`) to

View File

@ -9,18 +9,14 @@ may be overridden on a per-interface basis by
IPv6 support globally by setting:
```nix
{
networking.enableIPv6 = false;
}
{ networking.enableIPv6 = false; }
```
You can disable IPv6 on a single interface using a normal sysctl (in
this example, we use interface `eth0`):
```nix
{
boot.kernel.sysctl."net.ipv6.conf.eth0.disable_ipv6" = true;
}
{ boot.kernel.sysctl."net.ipv6.conf.eth0.disable_ipv6" = true; }
```
As with IPv4 networking interfaces are automatically configured via
@ -28,10 +24,12 @@ DHCPv6. You can configure an interface manually:
```nix
{
networking.interfaces.eth0.ipv6.addresses = [ {
networking.interfaces.eth0.ipv6.addresses = [
{
address = "fe00:aa:bb:cc::2";
prefixLength = 64;
} ];
}
];
}
```

View File

@ -24,17 +24,13 @@ the host. This enables apiserver, controllerManager, scheduler,
addonManager, kube-proxy and etcd:
```nix
{
services.kubernetes.roles = [ "master" ];
}
{ services.kubernetes.roles = [ "master" ]; }
```
While this will enable the kubelet and kube-proxy only:
```nix
{
services.kubernetes.roles = [ "node" ];
}
{ services.kubernetes.roles = [ "node" ]; }
```
Assigning both the master and node roles is usable if you want a single
@ -42,7 +38,10 @@ node Kubernetes cluster for dev or testing purposes:
```nix
{
services.kubernetes.roles = [ "master" "node" ];
services.kubernetes.roles = [
"master"
"node"
];
}
```

View File

@ -5,9 +5,7 @@ option `boot.kernelPackages`. For instance, this selects the Linux 3.10
kernel:
```nix
{
boot.kernelPackages = pkgs.linuxKernel.packages.linux_3_10;
}
{ boot.kernelPackages = pkgs.linuxKernel.packages.linux_3_10; }
```
Note that this not only replaces the kernel, but also packages that are
@ -43,7 +41,9 @@ instance, to enable support for the kernel debugger KGDB:
```nix
{
nixpkgs.config.packageOverrides = pkgs: pkgs.lib.recursiveUpdate pkgs {
nixpkgs.config.packageOverrides =
pkgs:
pkgs.lib.recursiveUpdate pkgs {
linuxKernel.kernels.linux_5_10 = pkgs.linuxKernel.kernels.linux_5_10.override {
extraConfig = ''
KGDB y
@ -64,7 +64,11 @@ by `udev`. You can force a module to be loaded via
```nix
{
boot.kernelModules = [ "fuse" "kvm-intel" "coretemp" ];
boot.kernelModules = [
"fuse"
"kvm-intel"
"coretemp"
];
}
```
@ -72,9 +76,7 @@ If the module is required early during the boot (e.g. to mount the root
file system), you can use [](#opt-boot.initrd.kernelModules):
```nix
{
boot.initrd.kernelModules = [ "cifs" ];
}
{ boot.initrd.kernelModules = [ "cifs" ]; }
```
This causes the specified modules and their dependencies to be added to
@ -84,9 +86,7 @@ Kernel runtime parameters can be set through
[](#opt-boot.kernel.sysctl), e.g.
```nix
{
boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 120;
}
{ boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 120; }
```
sets the kernel's TCP keepalive time to 120 seconds. To see the
@ -99,9 +99,7 @@ Please refer to the Nixpkgs manual for the various ways of [building a custom ke
To use your custom kernel package in your NixOS configuration, set
```nix
{
boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel;
}
{ boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel; }
```
## Rust {#sec-linux-rust}

View File

@ -39,9 +39,7 @@ Should grub be used as bootloader, and `/boot` is located on an
encrypted partition, it is necessary to add the following grub option:
```nix
{
boot.loader.grub.enableCryptodisk = true;
}
{ boot.loader.grub.enableCryptodisk = true; }
```
## FIDO2 {#sec-luks-file-systems-fido2}
@ -74,7 +72,8 @@ key, add the following to `configuration.nix`:
```nix
{
boot.initrd.luks.fido2Support = true;
boot.initrd.luks.devices."/dev/sda2".fido2.credential = "f1d00200108b9d6e849a8b388da457688e3dd653b4e53770012d8f28e5d3b269865038c346802f36f3da7278b13ad6a3bb6a1452e24ebeeaa24ba40eef559b1b287d2a2f80b7";
boot.initrd.luks.devices."/dev/sda2".fido2.credential =
"f1d00200108b9d6e849a8b388da457688e3dd653b4e53770012d8f28e5d3b269865038c346802f36f3da7278b13ad6a3bb6a1452e24ebeeaa24ba40eef559b1b287d2a2f80b7";
}
```
@ -83,9 +82,7 @@ you might want to enable it only when your device is PIN protected, such
as [Trezor](https://trezor.io/).
```nix
{
boot.initrd.luks.devices."/dev/sda2".fido2.passwordLess = true;
}
{ boot.initrd.luks.devices."/dev/sda2".fido2.passwordLess = true; }
```
### systemd Stage 1 {#sec-luks-file-systems-fido2-systemd}

View File

@ -71,11 +71,9 @@ Here is an example with a prebuilt plugin tarball:
{
services.mattermost = {
plugins = with pkgs; [
/*
* todo
* 0.7.1
* https://github.com/mattermost/mattermost-plugin-todo/releases/tag/v0.7.1
*/
# todo
# 0.7.1
# https://github.com/mattermost/mattermost-plugin-todo/releases/tag/v0.7.1
(fetchurl {
# Note: Don't unpack the tarball; the NixOS module will repack it for you.
url = "https://github.com/mattermost-community/mattermost-plugin-todo/releases/download/v0.7.1/com.mattermost.plugin-todo-0.7.1.tar.gz";

View File

@ -13,7 +13,11 @@ including them from `configuration.nix`, e.g.:
```nix
{ config, pkgs, ... }:
{ imports = [ ./vpn.nix ./kde.nix ];
{
imports = [
./vpn.nix
./kde.nix
];
services.httpd.enable = true;
environment.systemPackages = [ pkgs.emacs ];
# ...
@ -26,7 +30,8 @@ Here, we include two modules from the same directory, `vpn.nix` and
```nix
{ config, pkgs, ... }:
{ services.xserver.enable = true;
{
services.xserver.enable = true;
services.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;
environment.systemPackages = [ pkgs.vim ];
@ -42,9 +47,7 @@ merged last, so for list-type options, it will appear at the end of the
merged list. If you want it to appear first, you can use `mkBefore`:
```nix
{
boot.kernelModules = mkBefore [ "kvm-intel" ];
}
{ boot.kernelModules = mkBefore [ "kvm-intel" ]; }
```
This causes the `kvm-intel` kernel module to be loaded before any other
@ -62,9 +65,7 @@ When that happens, it's possible to force one definition take precedence
over the others:
```nix
{
services.httpd.adminAddr = pkgs.lib.mkForce "bob@example.org";
}
{ services.httpd.adminAddr = pkgs.lib.mkForce "bob@example.org"; }
```
When using multiple modules, you may need to access configuration values
@ -84,9 +85,11 @@ For example, here is a module that adds some packages to
```nix
{ config, pkgs, ... }:
{ environment.systemPackages =
{
environment.systemPackages =
if config.services.xserver.enable then
[ pkgs.firefox
[
pkgs.firefox
pkgs.thunderbird
]
else
@ -126,12 +129,14 @@ have the same effect as importing a file which sets those options.
```nix
{ config, pkgs, ... }:
let netConfig = hostName: {
let
netConfig = hostName: {
networking.hostName = hostName;
networking.useDHCP = false;
};
};
in
{ imports = [ (netConfig "nixos.localdomain") ]; }
{
imports = [ (netConfig "nixos.localdomain") ];
}
```

View File

@ -4,9 +4,7 @@ To facilitate network configuration, some desktop environments use
NetworkManager. You can enable NetworkManager by setting:
```nix
{
networking.networkmanager.enable = true;
}
{ networking.networkmanager.enable = true; }
```
some desktop managers (e.g., GNOME) enable NetworkManager automatically
@ -16,9 +14,7 @@ All users that should have permission to change network settings must
belong to the `networkmanager` group:
```nix
{
users.users.alice.extraGroups = [ "networkmanager" ];
}
{ users.users.alice.extraGroups = [ "networkmanager" ]; }
```
NetworkManager is controlled using either `nmcli` or `nmtui`
@ -38,7 +34,9 @@ NetworkManager to ignore those interfaces like:
```nix
{
networking.networkmanager.unmanaged = [
"*" "except:type:wwan" "except:type:gsm"
"*"
"except:type:wwan"
"except:type:gsm"
];
}
```

View File

@ -8,11 +8,7 @@ is to say, expected usage is to add them to the imports list of your
`/etc/configuration.nix` as such:
```nix
{
imports = [
<nixpkgs/nixos/modules/profiles/profile-name.nix>
];
}
{ imports = [ <nixpkgs/nixos/modules/profiles/profile-name.nix> ]; }
```
Even if some of these profiles seem only useful in the context of

View File

@ -3,9 +3,7 @@
Secure shell (SSH) access to your machine can be enabled by setting:
```nix
{
services.openssh.enable = true;
}
{ services.openssh.enable = true; }
```
By default, root logins using a password are disallowed. They can be
@ -17,7 +15,6 @@ as follows:
```nix
{
users.users.alice.openssh.authorizedKeys.keys =
[ "ssh-ed25519 AAAAB3NzaC1kc3MAAACBAPIkGWVEt4..." ];
users.users.alice.openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAB3NzaC1kc3MAAACBAPIkGWVEt4..." ];
}
```

View File

@ -41,8 +41,8 @@ Here's a typical setup:
fileSystems."/mnt/my-dir" = {
device = "my-user@example.com:/my-dir/";
fsType = "sshfs";
options =
[ # Filesystem options
options = [
# Filesystem options
"allow_other" # for non-root access
"_netdev" # this is a network fs
"x-systemd.automount" # mount on demand
@ -58,8 +58,8 @@ Here's a typical setup:
More options from `ssh_config(5)` can be given as well, for example you can change the default SSH port or specify a jump proxy:
```nix
{
options =
[ "ProxyJump=bastion@example.com"
options = [
"ProxyJump=bastion@example.com"
"Port=22"
];
}
@ -68,9 +68,10 @@ It's also possible to change the `ssh` command used by SSHFS to connect to the s
For example:
```nix
{
options =
[ (builtins.replaceStrings [" "] ["\\040"]
"ssh_command=${pkgs.openssh}/bin/ssh -v -L 8080:localhost:80")
options = [
(builtins.replaceStrings [ " " ] [ "\\040" ]
"ssh_command=${pkgs.openssh}/bin/ssh -v -L 8080:localhost:80"
)
];
}

View File

@ -24,7 +24,10 @@ appropriately:
{
services.httpd.enable = true;
services.httpd.adminAddr = "...";
networking.firewall.allowedTCPPorts = [ 80 443 ];
networking.firewall.allowedTCPPorts = [
80
443
];
}
```
@ -39,8 +42,14 @@ the password file.
{
services.httpd.extraModules = [
# note that order is *super* important here
{ name = "dav_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so"; }
{ name = "authz_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so"; }
{
name = "dav_svn";
path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so";
}
{
name = "authz_svn";
path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so";
}
];
services.httpd.virtualHosts = {
"svn" = {

View File

@ -11,7 +11,10 @@ account named `alice` shall exist:
isNormalUser = true;
home = "/home/alice";
description = "Alice Foobar";
extraGroups = [ "wheel" "networkmanager" ];
extraGroups = [
"wheel"
"networkmanager"
];
openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... alice@foobar" ];
};
}
@ -40,9 +43,7 @@ A user ID (uid) is assigned automatically. You can also specify a uid
manually by adding
```nix
{
uid = 1000;
}
{ uid = 1000; }
```
to the user specification.
@ -51,9 +52,7 @@ Groups can be specified similarly. The following states that a group
named `students` shall exist:
```nix
{
users.groups.students.gid = 1000;
}
{ users.groups.students.gid = 1000; }
```
As with users, the group ID (gid) is optional and will be assigned
@ -109,9 +108,7 @@ Instead of using a custom perl script to create users and groups, you can use
systemd-sysusers:
```nix
{
systemd.sysusers.enable = true;
}
{ systemd.sysusers.enable = true; }
```
The primary benefit of this is to remove a dependency on perl.
@ -137,9 +134,7 @@ the Perl script. It aims to eventually replace the Perl script by default.
You can enable Userborn via:
```nix
{
services.userborn.enable = true;
}
{ services.userborn.enable = true; }
```
You can configure Userborn to store the password files
@ -147,9 +142,7 @@ You can configure Userborn to store the password files
location to `/etc`:
```nix
{
services.userborn.passwordFilesLocation = "/persistent/etc";
}
{ services.userborn.passwordFilesLocation = "/persistent/etc"; }
```
This is useful when you store `/etc` on a `tmpfs` or if `/etc` is immutable

View File

@ -9,9 +9,7 @@ a Wayland Compositor such as sway without separately enabling a Wayland
server:
```nix
{
programs.sway.enable = true;
}
{ programs.sway.enable = true; }
```
This installs the sway compositor along with some essential utilities.

View File

@ -7,9 +7,7 @@ skip the rest of this section on wireless networks.
NixOS will start wpa_supplicant for you if you enable this setting:
```nix
{
networking.wireless.enable = true;
}
{ networking.wireless.enable = true; }
```
NixOS lets you specify networks for wpa_supplicant declaratively:
@ -17,17 +15,20 @@ NixOS lets you specify networks for wpa_supplicant declaratively:
```nix
{
networking.wireless.networks = {
echelon = { # SSID with no spaces or special characters
echelon = {
# SSID with no spaces or special characters
psk = "abcdefgh";
};
"echelon's AP" = { # SSID with spaces and/or special characters
"echelon's AP" = {
# SSID with spaces and/or special characters
psk = "ijklmnop";
};
echelon = { # Hidden SSID
echelon = {
# Hidden SSID
hidden = true;
psk = "qrstuvwx";
};
free.wifi = {}; # Public wireless network
free.wifi = { }; # Public wireless network
};
}
```

View File

@ -4,9 +4,7 @@ The X Window System (X11) provides the basis of NixOS' graphical user
interface. It can be enabled as follows:
```nix
{
services.xserver.enable = true;
}
{ services.xserver.enable = true; }
```
The X server will automatically detect and use the appropriate video
@ -14,9 +12,7 @@ driver from a set of X.org drivers (such as `vesa` and `intel`). You can
also specify a driver manually, e.g.
```nix
{
services.xserver.videoDrivers = [ "r128" ];
}
{ services.xserver.videoDrivers = [ "r128" ]; }
```
to enable X.org's `xf86-video-r128` driver.
@ -63,9 +59,7 @@ The X server is started automatically at boot time. If you don't want
this to happen, you can set:
```nix
{
services.xserver.autorun = false;
}
{ services.xserver.autorun = false; }
```
The X server can then be started manually:
@ -78,9 +72,7 @@ On 64-bit systems, if you want OpenGL for 32-bit programs such as in
Wine, you should also set the following:
```nix
{
hardware.graphics.enable32Bit = true;
}
{ hardware.graphics.enable32Bit = true; }
```
## Auto-login {#sec-x11-auto-login}
@ -98,9 +90,7 @@ desktop environment. If you wanted no desktop environment and i3 as your
your window manager, you'd define:
```nix
{
services.displayManager.defaultSession = "none+i3";
}
{ services.displayManager.defaultSession = "none+i3"; }
```
Every display manager in NixOS supports auto-login, here is an example
@ -187,9 +177,7 @@ both drivers. Use the option
to set one. The recommended configuration for modern systems is:
```nix
{
services.xserver.videoDrivers = [ "modesetting" ];
}
{ services.xserver.videoDrivers = [ "modesetting" ]; }
```
::: {.note}
The `modesetting` driver doesn't currently provide a `TearFree` option (this
@ -221,9 +209,7 @@ better 3D performance than the X.org drivers. It is not enabled by
default because it's not free software. You can enable it as follows:
```nix
{
services.xserver.videoDrivers = [ "nvidia" ];
}
{ services.xserver.videoDrivers = [ "nvidia" ]; }
```
If you have an older card, you may have to use one of the legacy drivers:
@ -245,18 +231,14 @@ Support for Synaptics touchpads (found in many laptops such as the Dell
Latitude series) can be enabled as follows:
```nix
{
services.libinput.enable = true;
}
{ services.libinput.enable = true; }
```
The driver has many options (see [](#ch-options)).
For instance, the following disables tap-to-click behavior:
```nix
{
services.libinput.touchpad.tapping = false;
}
{ services.libinput.touchpad.tapping = false; }
```
Note: the use of `services.xserver.synaptics` is deprecated since NixOS

View File

@ -13,11 +13,15 @@ This is an example of using `warnings`.
{
config = lib.mkIf config.services.foo.enable {
warnings =
if config.services.foo.bar
then [ ''You have enabled the bar feature of the foo service.
if config.services.foo.bar then
[
''
You have enabled the bar feature of the foo service.
This is known to cause some specific problems in certain situations.
'' ]
else [];
''
]
else
[ ];
};
}
```
@ -30,8 +34,9 @@ This example, extracted from the [`syslogd` module](https://github.com/NixOS/nix
{ config, lib, ... }:
{
config = lib.mkIf config.services.syslogd.enable {
assertions =
[ { assertion = !config.services.rsyslogd.enable;
assertions = [
{
assertion = !config.services.rsyslogd.enable;
message = "rsyslogd conflicts with syslogd";
}
];

View File

@ -20,7 +20,8 @@ For this purpose, Bootspec offers a generic extension facility [`boot.bootspec.e
An example for SecureBoot is to get the Nix store path to `/etc/os-release` in order to bake it into a unified kernel image:
```nix
{ config, lib, ... }: {
{ config, lib, ... }:
{
boot.bootspec.extensions = {
"org.secureboot.osRelease" = config.environment.etc."os-release".source;
};

View File

@ -9,9 +9,7 @@ Instead of using a custom perl script to activate `/etc`, you activate it via an
overlay filesystem:
```nix
{
system.etc.overlay.enable = true;
}
{ system.etc.overlay.enable = true; }
```
Using an overlay has two benefits:
@ -24,9 +22,7 @@ upper layer). However, you can also mount `/etc` immutably (i.e. read-only) by
setting:
```nix
{
system.etc.overlay.mutable = false;
}
{ system.etc.overlay.mutable = false; }
```
The overlay is atomically replaced during system switch. However, files that

View File

@ -23,7 +23,8 @@ type-checked and assign a default value. See
for a more complete example.
```nix
{ lib, config, ... }: {
{ lib, config, ... }:
{
options.settings = lib.mkOption {
type = lib.types.submodule {

View File

@ -4,11 +4,16 @@ Sometimes NixOS modules need to be used in configuration but exist
outside of Nixpkgs. These modules can be imported:
```nix
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:
{
imports =
[ # Use a locally-available module definition in
imports = [
# Use a locally-available module definition in
# ./example-module/default.nix
./example-module
];

View File

@ -11,7 +11,12 @@ Each of the meta-attributes must be defined at most once per module
file.
```nix
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:
{
options = {
# ...

View File

@ -8,7 +8,8 @@ If you want to build such a system, you can use the `image-based-appliance`
profile:
```nix
{ modulesPath, ... }: {
{ modulesPath, ... }:
{
imports = [ "${modulesPath}/profiles/image-based-appliance.nix" ];
}
```

View File

@ -79,13 +79,14 @@ For example:
### `mkEnableOption` usage
```nix
lib.mkEnableOption "magic"
# is like
lib.mkOption {
# is like
lib.mkOption
{
type = lib.types.bool;
default = false;
example = true;
description = "Whether to enable magic.";
}
}
```
:::
@ -94,7 +95,14 @@ lib.mkOption {
Usage:
```nix
mkPackageOption pkgs "name" { default = [ "path" "in" "pkgs" ]; example = "literal example"; }
mkPackageOption pkgs "name" {
default = [
"path"
"in"
"pkgs"
];
example = "literal example";
}
```
Creates an Option attribute set for an option that specifies the package a module should use for some purpose.
@ -127,47 +135,52 @@ Examples:
### Simple `mkPackageOption` usage
```nix
lib.mkPackageOption pkgs "hello" { }
# is like
lib.mkOption {
# is like
lib.mkOption
{
type = lib.types.package;
default = pkgs.hello;
defaultText = lib.literalExpression "pkgs.hello";
description = "The hello package to use.";
}
}
```
:::
::: {#ex-options-declarations-util-mkPackageOption-ghc .example}
### `mkPackageOption` with explicit default and example
```nix
lib.mkPackageOption pkgs "GHC" {
lib.mkPackageOption pkgs "GHC"
{
default = [ "ghc" ];
example = "pkgs.haskell.packages.ghc92.ghc.withPackages (hkgs: [ hkgs.primes ])";
}
# is like
lib.mkOption {
}
# is like
lib.mkOption
{
type = lib.types.package;
default = pkgs.ghc;
defaultText = lib.literalExpression "pkgs.ghc";
example = lib.literalExpression "pkgs.haskell.packages.ghc92.ghc.withPackages (hkgs: [ hkgs.primes ])";
description = "The GHC package to use.";
}
}
```
:::
::: {#ex-options-declarations-util-mkPackageOption-extraDescription .example}
### `mkPackageOption` with additional description text
```nix
mkPackageOption pkgs [ "python312Packages" "torch" ] {
mkPackageOption pkgs [ "python312Packages" "torch" ]
{
extraDescription = "This is an example and doesn't actually do anything.";
}
# is like
lib.mkOption {
}
# is like
lib.mkOption
{
type = lib.types.package;
default = pkgs.python312Packages.torch;
defaultText = lib.literalExpression "pkgs.python312Packages.torch";
description = "The pytorch package to use. This is an example and doesn't actually do anything.";
}
}
```
:::
@ -233,9 +246,7 @@ enforces that there can only be a single display manager enabled.
### Extending `services.xserver.displayManager.enable` in the `gdm` module
```nix
{
services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ "gdm" ]);
};
services.xserver.displayManager.enable = mkOption { type = with types; nullOr (enum [ "gdm" ]); };
}
```
:::
@ -244,9 +255,7 @@ enforces that there can only be a single display manager enabled.
### Extending `services.xserver.displayManager.enable` in the `sddm` module
```nix
{
services.xserver.displayManager.enable = mkOption {
type = with types; nullOr (enum [ "sddm" ]);
};
services.xserver.displayManager.enable = mkOption { type = with types; nullOr (enum [ "sddm" ]); };
}
```
:::

View File

@ -21,10 +21,16 @@ option, you may need to use `mkIf`. Consider, for instance:
```nix
{
config = if config.services.httpd.enable then {
environment.systemPackages = [ /* ... */ ];
config =
if config.services.httpd.enable then
{
environment.systemPackages = [
# ...
} else {};
];
# ...
}
else
{ };
}
```
@ -35,9 +41,13 @@ clearly circular and contradictory:
```nix
{
config = if config.services.httpd.enable then {
config =
if config.services.httpd.enable then
{
services.httpd.enable = false;
} else {
}
else
{
services.httpd.enable = true;
};
}
@ -48,7 +58,9 @@ The solution is to write:
```nix
{
config = mkIf config.services.httpd.enable {
environment.systemPackages = [ /* ... */ ];
environment.systemPackages = [
# ...
];
# ...
};
}
@ -60,7 +72,13 @@ be "pushed down" into the individual definitions, as if you had written:
```nix
{
config = {
environment.systemPackages = if config.services.httpd.enable then [ /* ... */ ] else [];
environment.systemPackages =
if config.services.httpd.enable then
[
# ...
]
else
[ ];
# ...
};
}
@ -75,9 +93,7 @@ priority 100 and option defaults have priority 1500.
You can specify an explicit priority by using `mkOverride`, e.g.
```nix
{
services.openssh.enable = mkOverride 10 false;
}
{ services.openssh.enable = mkOverride 10 false; }
```
This definition causes all other definitions with priorities above 10 to
@ -92,9 +108,7 @@ The functions `mkBefore` and `mkAfter` are equal to `mkOrder 500` and `mkOrder 1
As an example,
```nix
{
hardware.firmware = mkBefore [ myFirmware ];
}
{ hardware.firmware = mkBefore [ myFirmware ]; }
```
This definition ensures that `myFirmware` comes before other unordered
@ -112,13 +126,18 @@ they were declared in separate modules. This can be done using
```nix
{
config = mkMerge
[ # Unconditional stuff.
{ environment.systemPackages = [ /* ... */ ];
config = mkMerge [
# Unconditional stuff.
{
environment.systemPackages = [
# ...
];
}
# Conditional stuff.
(mkIf config.services.bla.enable {
environment.systemPackages = [ /* ... */ ];
environment.systemPackages = [
# ...
];
})
];
}
@ -164,9 +183,7 @@ The following shows an example configuration that yields an error with the custo
```nix
{
_file = "file.nix";
options.foo = mkOption {
default = 13;
};
options.foo = mkOption { default = 13; };
config.foo = lib.mkDefinition {
file = "custom place";
# mkOptionDefault creates a conflict with the option foo's `default = 1` on purpose

View File

@ -495,14 +495,12 @@ if you want to allow users to leave it undefined.
{
options.mod = mkOption {
description = "submodule example";
type = with types; submodule {
type =
with types;
submodule {
options = {
foo = mkOption {
type = int;
};
bar = mkOption {
type = str;
};
foo = mkOption { type = int; };
bar = mkOption { type = str; };
};
};
};
@ -516,12 +514,8 @@ if you want to allow users to leave it undefined.
let
modOptions = {
options = {
foo = mkOption {
type = int;
};
bar = mkOption {
type = int;
};
foo = mkOption { type = int; };
bar = mkOption { type = int; };
};
};
in
@ -546,14 +540,12 @@ multiple definitions of the submodule option set
{
options.mod = mkOption {
description = "submodule example";
type = with types; listOf (submodule {
type =
with types;
listOf (submodule {
options = {
foo = mkOption {
type = int;
};
bar = mkOption {
type = str;
};
foo = mkOption { type = int; };
bar = mkOption { type = str; };
};
});
};
@ -566,8 +558,14 @@ multiple definitions of the submodule option set
```nix
{
config.mod = [
{ foo = 1; bar = "one"; }
{ foo = 2; bar = "two"; }
{
foo = 1;
bar = "one";
}
{
foo = 2;
bar = "two";
}
];
}
```
@ -584,14 +582,12 @@ multiple named definitions of the submodule option set
{
options.mod = mkOption {
description = "submodule example";
type = with types; attrsOf (submodule {
type =
with types;
attrsOf (submodule {
options = {
foo = mkOption {
type = int;
};
bar = mkOption {
type = str;
};
foo = mkOption { type = int; };
bar = mkOption { type = str; };
};
});
};
@ -603,8 +599,14 @@ multiple named definitions of the submodule option set
### Definition of attribute sets of submodules
```nix
{
config.mod.one = { foo = 1; bar = "one"; };
config.mod.two = { foo = 2; bar = "two"; };
config.mod.one = {
foo = 1;
bar = "one";
};
config.mod.two = {
foo = 2;
bar = "two";
};
}
```
:::

Some files were not shown because too many files have changed in this diff Show More