mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
doc: fix various nix
snippets
This commit is contained in:
parent
58cdd4e315
commit
5d979e79ce
10 changed files with 64 additions and 30 deletions
|
@ -20,12 +20,12 @@ Converts Nix values to strings in the way the [`derivation` built-in function](h
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
devShellTools.valueToString (builtins.toFile "foo" "bar")
|
devShellTools.valueToString (builtins.toFile "foo" "bar")
|
||||||
=> "/nix/store/...-foo"
|
# => "/nix/store/...-foo"
|
||||||
```
|
```
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
devShellTools.valueToString false
|
devShellTools.valueToString false
|
||||||
=> ""
|
# => ""
|
||||||
```
|
```
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
@ -47,11 +47,11 @@ devShellTools.unstructuredDerivationInputEnv {
|
||||||
args = [ "-c" "${./builder.sh}" ];
|
args = [ "-c" "${./builder.sh}" ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
=> {
|
# => {
|
||||||
name = "foo";
|
# name = "foo";
|
||||||
buildInputs = "/nix/store/...-hello /nix/store/...-figlet";
|
# buildInputs = "/nix/store/...-hello /nix/store/...-figlet";
|
||||||
builder = "/nix/store/...-bash";
|
# builder = "/nix/store/...-bash";
|
||||||
}
|
#}
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that `args` is not included, because Nix does not added it to the builder process environment.
|
Note that `args` is not included, because Nix does not added it to the builder process environment.
|
||||||
|
|
|
@ -9,7 +9,7 @@ pkgs.makeSetupHook {
|
||||||
name = "something-hook";
|
name = "something-hook";
|
||||||
propagatedBuildInputs = [ pkgs.commandsomething ];
|
propagatedBuildInputs = [ pkgs.commandsomething ];
|
||||||
depsTargetTargetPropagated = [ pkgs.libsomething ];
|
depsTargetTargetPropagated = [ pkgs.libsomething ];
|
||||||
} ./script.sh;
|
} ./script.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
### setup hook that depends on the hello package and runs hello and @shell@ is substituted with path to bash {#sec-pkgs.makeSetupHook-usage-example}
|
### setup hook that depends on the hello package and runs hello and @shell@ is substituted with path to bash {#sec-pkgs.makeSetupHook-usage-example}
|
||||||
|
@ -42,7 +42,7 @@ pkgs.makeSetupHook
|
||||||
}
|
}
|
||||||
preConfigureHooks+=(_printHelloHook)
|
preConfigureHooks+=(_printHelloHook)
|
||||||
''
|
''
|
||||||
);
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Attributes {#sec-pkgs.makeSetupHook-attributes}
|
## Attributes {#sec-pkgs.makeSetupHook-attributes}
|
||||||
|
|
|
@ -20,13 +20,15 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
If you use a custom `checkPhase`, remember to add the `runHook` calls:
|
If you use a custom `checkPhase`, remember to add the `runHook` calls:
|
||||||
```nix
|
```nix
|
||||||
checkPhase ''
|
{
|
||||||
|
checkPhase = ''
|
||||||
runHook preCheck
|
runHook preCheck
|
||||||
|
|
||||||
# ... your tests
|
# ... your tests
|
||||||
|
|
||||||
runHook postCheck
|
runHook postCheck
|
||||||
''
|
'';
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Variables {#sec-memcachedTestHook-variables}
|
## Variables {#sec-memcachedTestHook-variables}
|
||||||
|
@ -48,6 +50,6 @@ stdenv.mkDerivation {
|
||||||
];
|
];
|
||||||
|
|
||||||
preCheck = ''
|
preCheck = ''
|
||||||
memcachedTestPort=1234
|
memcachedTestPort=1234;
|
||||||
''
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,15 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
If you use a custom `checkPhase`, remember to add the `runHook` calls:
|
If you use a custom `checkPhase`, remember to add the `runHook` calls:
|
||||||
```nix
|
```nix
|
||||||
checkPhase ''
|
{
|
||||||
|
checkPhase = ''
|
||||||
runHook preCheck
|
runHook preCheck
|
||||||
|
|
||||||
# ... your tests
|
# ... your tests
|
||||||
|
|
||||||
runHook postCheck
|
runHook postCheck
|
||||||
''
|
'';
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Variables {#sec-redisTestHook-variables}
|
## Variables {#sec-redisTestHook-variables}
|
||||||
|
@ -55,6 +57,6 @@ stdenv.mkDerivation {
|
||||||
];
|
];
|
||||||
|
|
||||||
preCheck = ''
|
preCheck = ''
|
||||||
redisTestPort=6390
|
redisTestPort=6390;
|
||||||
''
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,23 +8,29 @@ supporting features.
|
||||||
Use the `android-studio-full` attribute for a very complete Android SDK, including system images:
|
Use the `android-studio-full` attribute for a very complete Android SDK, including system images:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
buildInputs = [ android-studio-full ];
|
buildInputs = [ android-studio-full ];
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This is identical to:
|
This is identical to:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
buildInputs = [ androidStudioPackages.stable.full ];
|
buildInputs = [ androidStudioPackages.stable.full ];
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, you can pass composeAndroidPackages to the `withSdk` passthru:
|
Alternatively, you can pass composeAndroidPackages to the `withSdk` passthru:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(android-studio.withSdk (androidenv.composeAndroidPackages {
|
(android-studio.withSdk (androidenv.composeAndroidPackages {
|
||||||
includeNDK = true;
|
includeNDK = true;
|
||||||
}).androidsdk)
|
}).androidsdk)
|
||||||
];
|
];
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
These will export `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT` to the SDK and NDK directories
|
These will export `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT` to the SDK and NDK directories
|
||||||
|
|
|
@ -11,7 +11,9 @@ ags.bundle {
|
||||||
pname = "hyprpanel";
|
pname = "hyprpanel";
|
||||||
version = "1.0.0";
|
version = "1.0.0";
|
||||||
|
|
||||||
src = fetchFromGitHub { ... };
|
src = fetchFromGitHub {
|
||||||
|
#...
|
||||||
|
};
|
||||||
|
|
||||||
# change your entry file (default is `app.ts`)
|
# change your entry file (default is `app.ts`)
|
||||||
entry = "app.ts";
|
entry = "app.ts";
|
||||||
|
@ -32,7 +34,9 @@ ags.bundle {
|
||||||
# GTK 4 support is opt-in
|
# GTK 4 support is opt-in
|
||||||
enableGtk4 = true;
|
enableGtk4 = true;
|
||||||
|
|
||||||
meta = { ... };
|
meta = {
|
||||||
|
#...
|
||||||
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ factorPackages.buildFactorApplication (finalAttrs: {
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = "https://some-forge.org/foo-${finalAttrs.version}.tar.gz"
|
url = "https://some-forge.org/foo-${finalAttrs.version}.tar.gz";
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
@ -323,7 +323,7 @@ buildNpmPackage {
|
||||||
npmRoot = ./.;
|
npmRoot = ./.;
|
||||||
fetcherOpts = {
|
fetcherOpts = {
|
||||||
# Pass 'curlOptsList' to 'pkgs.fetchurl' while fetching 'axios'
|
# Pass 'curlOptsList' to 'pkgs.fetchurl' while fetching 'axios'
|
||||||
{ "node_modules/axios" = { curlOptsList = [ "--verbose" ]; }; }
|
"node_modules/axios" = { curlOptsList = [ "--verbose" ]; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -410,7 +410,9 @@ stdenv.mkDerivation (finalAttrs: {
|
||||||
pname = "foo";
|
pname = "foo";
|
||||||
version = "0-unstable-1980-01-01";
|
version = "0-unstable-1980-01-01";
|
||||||
|
|
||||||
src = ...;
|
src = {
|
||||||
|
#...
|
||||||
|
};
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
nodejs
|
nodejs
|
||||||
|
@ -439,7 +441,9 @@ stdenv.mkDerivation (finalAttrs: {
|
||||||
pname = "foo";
|
pname = "foo";
|
||||||
version = "0-unstable-1980-01-01";
|
version = "0-unstable-1980-01-01";
|
||||||
|
|
||||||
src = ...;
|
src = {
|
||||||
|
# ...
|
||||||
|
};
|
||||||
|
|
||||||
pnpmInstallFlags = [ "--shamefully-hoist" ];
|
pnpmInstallFlags = [ "--shamefully-hoist" ];
|
||||||
|
|
||||||
|
@ -466,14 +470,16 @@ Assuming the following directory structure, we can define `sourceRoot` and `pnpm
|
||||||
```
|
```
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
...
|
{
|
||||||
|
# ...
|
||||||
pnpmDeps = pnpm.fetchDeps {
|
pnpmDeps = pnpm.fetchDeps {
|
||||||
...
|
# ...
|
||||||
sourceRoot = "${finalAttrs.src.name}/frontend";
|
sourceRoot = "${finalAttrs.src.name}/frontend";
|
||||||
};
|
};
|
||||||
|
|
||||||
# by default the working directory is the extracted source
|
# by default the working directory is the extracted source
|
||||||
pnpmRoot = "frontend";
|
pnpmRoot = "frontend";
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### PNPM Workspaces {#javascript-pnpm-workspaces}
|
#### PNPM Workspaces {#javascript-pnpm-workspaces}
|
||||||
|
@ -484,11 +490,13 @@ which will make PNPM only install dependencies for those workspace packages.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
...
|
{
|
||||||
|
# ...
|
||||||
pnpmWorkspaces = [ "@astrojs/language-server" ];
|
pnpmWorkspaces = [ "@astrojs/language-server" ];
|
||||||
pnpmDeps = pnpm.fetchDeps {
|
pnpmDeps = pnpm.fetchDeps {
|
||||||
inherit (finalAttrs) pnpmWorkspaces;
|
inherit (finalAttrs) pnpmWorkspaces;
|
||||||
...
|
#...
|
||||||
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -498,6 +506,7 @@ Note that you do not need to set `sourceRoot` to make this work.
|
||||||
Usually in such cases, you'd want to use `pnpm --filter=<pnpm workspace name> build` to build your project, as `npmHooks.npmBuildHook` probably won't work. A `buildPhase` based on the following example will probably fit most workspace projects:
|
Usually in such cases, you'd want to use `pnpm --filter=<pnpm workspace name> build` to build your project, as `npmHooks.npmBuildHook` probably won't work. A `buildPhase` based on the following example will probably fit most workspace projects:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
|
|
||||||
|
@ -505,6 +514,7 @@ buildPhase = ''
|
||||||
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Additional PNPM Commands and settings {#javascript-pnpm-extraCommands}
|
#### Additional PNPM Commands and settings {#javascript-pnpm-extraCommands}
|
||||||
|
@ -513,13 +523,15 @@ If you require setting an additional PNPM configuration setting (such as `dedupe
|
||||||
set `prePnpmInstall` to the right commands to run. For example:
|
set `prePnpmInstall` to the right commands to run. For example:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
prePnpmInstall = ''
|
prePnpmInstall = ''
|
||||||
pnpm config set dedupe-peer-dependants false
|
pnpm config set dedupe-peer-dependants false
|
||||||
'';
|
'';
|
||||||
pnpmDeps = pnpm.fetchDeps {
|
pnpmDeps = pnpm.fetchDeps {
|
||||||
inherit (finalAttrs) prePnpmInstall;
|
inherit (finalAttrs) prePnpmInstall;
|
||||||
...
|
# ...
|
||||||
};
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, `prePnpmInstall` will be run by both `pnpm.configHook` and by the `pnpm.fetchDeps` builder.
|
In this example, `prePnpmInstall` will be run by both `pnpm.configHook` and by the `pnpm.fetchDeps` builder.
|
||||||
|
|
|
@ -91,7 +91,7 @@ jd-cli.overrideMavenAttrs (old: rec {
|
||||||
|
|
||||||
# old mvnHash of 1.2.0 maven dependencies
|
# old mvnHash of 1.2.0 maven dependencies
|
||||||
mvnHash = "sha256-N9XC1pg6Y4sUiBWIQUf16QSXCuiAPpXEHGlgApviF4I=";
|
mvnHash = "sha256-N9XC1pg6Y4sUiBWIQUf16QSXCuiAPpXEHGlgApviF4I=";
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ maven.buildMavenPackage rec {
|
||||||
"org.apache.maven.surefire:surefire-junit-platform:3.1.2"
|
"org.apache.maven.surefire:surefire-junit-platform:3.1.2"
|
||||||
"org.junit.platform:junit-platform-launcher:1.10.0"
|
"org.junit.platform:junit-platform-launcher:1.10.0"
|
||||||
];
|
];
|
||||||
};
|
}
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,11 @@ top-level while luarocks installs them in various subfolders by default.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
rtp-nvim = neovimUtils.buildNeovimPlugin {
|
rtp-nvim = neovimUtils.buildNeovimPlugin {
|
||||||
luaAttr = luaPackages.rtp-nvim;
|
luaAttr = luaPackages.rtp-nvim;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
To update these packages, you should use the lua updater rather than vim's.
|
To update these packages, you should use the lua updater rather than vim's.
|
||||||
|
|
||||||
|
@ -164,16 +166,19 @@ The check hook will fail the build if any modules cannot be loaded. This encoura
|
||||||
To only check a specific module, add it manually to the plugin definition [overrides](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/overrides.nix).
|
To only check a specific module, add it manually to the plugin definition [overrides](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/overrides.nix).
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
gitsigns-nvim = super.gitsigns-nvim.overrideAttrs {
|
gitsigns-nvim = super.gitsigns-nvim.overrideAttrs {
|
||||||
dependencies = [ self.plenary-nvim ];
|
dependencies = [ self.plenary-nvim ];
|
||||||
nvimRequireCheck = "gitsigns";
|
nvimRequireCheck = "gitsigns";
|
||||||
};
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
Some plugins will have lua modules that require a user configuration to function properly or can contain optional lua modules that we dont want to test requiring.
|
Some plugins will have lua modules that require a user configuration to function properly or can contain optional lua modules that we dont want to test requiring.
|
||||||
We can skip specific modules using `nvimSkipModules`. Similar to `nvimRequireCheck`, it accepts a list of strings.
|
We can skip specific modules using `nvimSkipModules`. Similar to `nvimRequireCheck`, it accepts a list of strings.
|
||||||
- `nvimSkipModules = [ MODULE1 MODULE2 ];`
|
- `nvimSkipModules = [ MODULE1 MODULE2 ];`
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
asyncrun-vim = super.asyncrun-vim.overrideAttrs {
|
asyncrun-vim = super.asyncrun-vim.overrideAttrs {
|
||||||
nvimSkipModules = [
|
nvimSkipModules = [
|
||||||
# vim plugin with optional toggleterm integration
|
# vim plugin with optional toggleterm integration
|
||||||
|
@ -181,14 +186,17 @@ We can skip specific modules using `nvimSkipModules`. Similar to `nvimRequireChe
|
||||||
"asyncrun.toggleterm2"
|
"asyncrun.toggleterm2"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In rare cases, we might not want to actually test loading lua modules for a plugin. In those cases, we can disable `neovimRequireCheck` with `doCheck = false;`.
|
In rare cases, we might not want to actually test loading lua modules for a plugin. In those cases, we can disable `neovimRequireCheck` with `doCheck = false;`.
|
||||||
|
|
||||||
This can be manually added through plugin definition overrides in the [overrides.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/overrides.nix).
|
This can be manually added through plugin definition overrides in the [overrides.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/overrides.nix).
|
||||||
```nix
|
```nix
|
||||||
|
{
|
||||||
vim-test = super.vim-test.overrideAttrs {
|
vim-test = super.vim-test.overrideAttrs {
|
||||||
# Vim plugin with a test lua file
|
# Vim plugin with a test lua file
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue