mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-09-29 07:32:58 +00:00
buildNimPackage: refactor to use overlay-style overrideAttrs
Make buildNimPackage cleaner and more efficient. Also encourage the use of a "buildNimPackage (finalAttrs: {…})" pattern.
This commit is contained in:
parent
731c00a128
commit
077d8a3447
@ -15,32 +15,23 @@ case of packages not containing exported library code the attribute
|
|||||||
The following example shows a Nim program that depends only on Nim libraries:
|
The following example shows a Nim program that depends only on Nim libraries:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ lib, nimPackages, fetchurl }:
|
{ lib, nimPackages, fetchFromGitHub }:
|
||||||
|
|
||||||
nimPackages.buildNimPackage rec {
|
|
||||||
pname = "hottext";
|
|
||||||
version = "1.4";
|
|
||||||
|
|
||||||
|
nimPackages.buildNimPackage (finalAttrs: {
|
||||||
|
pname = "ttop";
|
||||||
|
version = "1.0.1";
|
||||||
nimBinOnly = true;
|
nimBinOnly = true;
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchFromGitHub {
|
||||||
url = "https://git.sr.ht/~ehmry/hottext/archive/v${version}.tar.gz";
|
owner = "inv2004";
|
||||||
hash = "sha256-hIUofi81zowSMbt1lUsxCnVzfJGN3FEiTtN8CEFpwzY=";
|
repo = "ttop";
|
||||||
|
rev = "v${finalAttrs.version}";
|
||||||
|
hash = "sha256-x4Uczksh6p3XX/IMrOFtBxIleVHdAPX9e8n32VAUTC4=";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = with nimPackages; [
|
buildInputs = with nimPackages; [ asciigraph illwill parsetoml zippy ];
|
||||||
bumpy
|
|
||||||
chroma
|
|
||||||
flatty
|
|
||||||
nimsimd
|
|
||||||
pixie
|
|
||||||
sdl2
|
|
||||||
typography
|
|
||||||
vmath
|
|
||||||
zippy
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Nim library packages in Nixpkgs {#nim-library-packages-in-nixpkgs}
|
## Nim library packages in Nixpkgs {#nim-library-packages-in-nixpkgs}
|
||||||
@ -60,15 +51,16 @@ non-Nim package:
|
|||||||
```nix
|
```nix
|
||||||
{ lib, buildNimPackage, fetchNimble, SDL2 }:
|
{ lib, buildNimPackage, fetchNimble, SDL2 }:
|
||||||
|
|
||||||
buildNimPackage rec {
|
buildNimPackage (finalAttrs: {
|
||||||
pname = "sdl2";
|
pname = "sdl2";
|
||||||
version = "2.0.4";
|
version = "2.0.4";
|
||||||
src = fetchNimble {
|
src = fetchNimble {
|
||||||
inherit pname version;
|
inherit (finalAttrs) pname version;
|
||||||
hash = "sha256-qDtVSnf+7rTq36WAxgsUZ8XoUk4sKwHyt8EJcY5WP+o=";
|
hash = "sha256-Vtcj8goI4zZPQs2TbFoBFlcR5UqDtOldaXSH/+/xULk=";
|
||||||
};
|
};
|
||||||
propagatedBuildInputs = [ SDL2 ];
|
propagatedBuildInputs = [ SDL2 ];
|
||||||
}
|
doCheck = true;
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## `buildNimPackage` parameters {#buildnimpackage-parameters}
|
## `buildNimPackage` parameters {#buildnimpackage-parameters}
|
||||||
|
@ -1,45 +1,44 @@
|
|||||||
{ lib, stdenv, nim, nim_builder }:
|
{ lib, stdenv, nim, nim_builder }:
|
||||||
|
pkgArgs:
|
||||||
|
|
||||||
{ strictDeps ? true, depsBuildBuild ? [ ], nativeBuildInputs ? [ ]
|
let
|
||||||
, configurePhase ? null, buildPhase ? null, checkPhase ? null
|
baseAttrs = {
|
||||||
, installPhase ? null, enableParallelBuilding ? true, meta ? { }, ... }@attrs:
|
strictDeps = true;
|
||||||
|
enableParallelBuilding = true;
|
||||||
stdenv.mkDerivation (attrs // {
|
configurePhase = ''
|
||||||
inherit strictDeps enableParallelBuilding;
|
runHook preConfigure
|
||||||
depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
|
export NIX_NIM_BUILD_INPUTS=''${pkgsHostTarget[@]} $NIX_NIM_BUILD_INPUTS
|
||||||
nativeBuildInputs = [ nim ] ++ nativeBuildInputs;
|
nim_builder --phase:configure
|
||||||
|
runHook postConfigure
|
||||||
configurePhase = if (configurePhase == null) then ''
|
'';
|
||||||
runHook preConfigure
|
buildPhase = ''
|
||||||
export NIX_NIM_BUILD_INPUTS=''${pkgsHostTarget[@]} $NIX_NIM_BUILD_INPUTS
|
runHook preBuild
|
||||||
nim_builder --phase:configure
|
nim_builder --phase:build
|
||||||
runHook postConfigure
|
runHook postBuild
|
||||||
'' else
|
'';
|
||||||
configurePhase;
|
checkPhase = ''
|
||||||
|
runHook preCheck
|
||||||
buildPhase = if (buildPhase == null) then ''
|
nim_builder --phase:check
|
||||||
runHook preBuild
|
runHook postCheck
|
||||||
nim_builder --phase:build
|
'';
|
||||||
runHook postBuild
|
installPhase = ''
|
||||||
'' else
|
runHook preInstall
|
||||||
buildPhase;
|
nim_builder --phase:install
|
||||||
|
runHook postInstall
|
||||||
checkPhase = if (checkPhase == null) then ''
|
'';
|
||||||
runHook preCheck
|
meta = { inherit (nim.meta) maintainers platforms; };
|
||||||
nim_builder --phase:check
|
|
||||||
runHook postCheck
|
|
||||||
'' else
|
|
||||||
checkPhase;
|
|
||||||
|
|
||||||
installPhase = if (installPhase == null) then ''
|
|
||||||
runHook preInstall
|
|
||||||
nim_builder --phase:install
|
|
||||||
runHook postInstall
|
|
||||||
'' else
|
|
||||||
installPhase;
|
|
||||||
|
|
||||||
meta = meta // {
|
|
||||||
platforms = meta.platforms or nim.meta.platforms;
|
|
||||||
maintainers = (meta.maintainers or [ ]) ++ [ lib.maintainers.ehmry ];
|
|
||||||
};
|
};
|
||||||
})
|
|
||||||
|
inputsOverride =
|
||||||
|
{ depsBuildBuild ? [ ], nativeBuildInputs ? [ ], meta, ... }: {
|
||||||
|
depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
|
||||||
|
nativeBuildInputs = [ nim ] ++ nativeBuildInputs;
|
||||||
|
};
|
||||||
|
|
||||||
|
composition = finalAttrs:
|
||||||
|
let
|
||||||
|
asFunc = x: if builtins.isFunction x then x else (_: x);
|
||||||
|
prev = baseAttrs // (asFunc ((asFunc pkgArgs) finalAttrs)) baseAttrs;
|
||||||
|
in prev // inputsOverride prev;
|
||||||
|
|
||||||
|
in stdenv.mkDerivation composition
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{ lib, buildNimPackage, fetchNimble, SDL2 }:
|
{ lib, buildNimPackage, fetchNimble, SDL2 }:
|
||||||
|
|
||||||
buildNimPackage rec {
|
buildNimPackage (finalAttrs: {
|
||||||
pname = "sdl2";
|
pname = "sdl2";
|
||||||
version = "2.0.4";
|
version = "2.0.4";
|
||||||
src = fetchNimble {
|
src = fetchNimble {
|
||||||
inherit pname version;
|
inherit (finalAttrs) pname version;
|
||||||
hash = "sha256-Vtcj8goI4zZPQs2TbFoBFlcR5UqDtOldaXSH/+/xULk=";
|
hash = "sha256-Vtcj8goI4zZPQs2TbFoBFlcR5UqDtOldaXSH/+/xULk=";
|
||||||
};
|
};
|
||||||
propagatedBuildInputs = [ SDL2 ];
|
propagatedBuildInputs = [ SDL2 ];
|
||||||
@ -14,4 +14,4 @@ buildNimPackage rec {
|
|||||||
platforms = lib.platforms.linux; # Problems with Darwin.
|
platforms = lib.platforms.linux; # Problems with Darwin.
|
||||||
license = [ lib.licenses.mit ];
|
license = [ lib.licenses.mit ];
|
||||||
};
|
};
|
||||||
}
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{ lib, nimPackages, fetchFromGitHub }:
|
{ lib, nimPackages, fetchFromGitHub }:
|
||||||
|
|
||||||
nimPackages.buildNimPackage rec {
|
nimPackages.buildNimPackage (finalAttrs: {
|
||||||
pname = "ttop";
|
pname = "ttop";
|
||||||
version = "1.0.1";
|
version = "1.0.1";
|
||||||
nimBinOnly = true;
|
nimBinOnly = true;
|
||||||
@ -8,17 +8,17 @@ nimPackages.buildNimPackage rec {
|
|||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "inv2004";
|
owner = "inv2004";
|
||||||
repo = "ttop";
|
repo = "ttop";
|
||||||
rev = "v${version}";
|
rev = "v${finalAttrs.version}";
|
||||||
hash = "sha256-x4Uczksh6p3XX/IMrOFtBxIleVHdAPX9e8n32VAUTC4=";
|
hash = "sha256-x4Uczksh6p3XX/IMrOFtBxIleVHdAPX9e8n32VAUTC4=";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = with nimPackages; [ asciigraph illwill parsetoml zippy ];
|
buildInputs = with nimPackages; [ asciigraph illwill parsetoml zippy ];
|
||||||
|
|
||||||
meta = with lib;
|
meta = with lib;
|
||||||
src.meta // {
|
finalAttrs.src.meta // {
|
||||||
description = "Top-like system monitoring tool";
|
description = "Top-like system monitoring tool";
|
||||||
license = licenses.mit;
|
license = licenses.mit;
|
||||||
platforms = platforms.linux;
|
platforms = platforms.linux;
|
||||||
maintainers = with maintainers; [ sikmir ];
|
maintainers = with maintainers; [ sikmir ];
|
||||||
};
|
};
|
||||||
}
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user