mirror of
https://codeberg.org/icewind/mill-scale.git
synced 2026-06-03 09:54:19 +02:00
autodep env variables
This commit is contained in:
parent
c8bab3321a
commit
6055ccecb6
4 changed files with 75 additions and 37 deletions
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"openssl-sys" = { build = [ "openssl" ]; };
|
|
||||||
"libudev-sys" = { build = [ "eudev" ]; };
|
|
||||||
"libdbus-sys" = { build = [ "dbus" ]; };
|
|
||||||
"expat-sys" = { build = [ "cmake" ]; };
|
|
||||||
"servo-fontconfig-sys" = { build = [ "fontconfig" ]; };
|
|
||||||
}
|
|
||||||
47
autodeps/default.nix
Normal file
47
autodeps/default.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
{ lib, src, config }:
|
||||||
|
let
|
||||||
|
inherit (builtins) readFile pathExists attrNames hasAttr;
|
||||||
|
inherit (lib) map intersectLists foldl splitString getAttrFromPath;
|
||||||
|
|
||||||
|
cargoLockDeps =
|
||||||
|
if pathExists (src + /Cargo.lock) then
|
||||||
|
let
|
||||||
|
cargoLock = fromTOML (readFile (src + /Cargo.lock));
|
||||||
|
in
|
||||||
|
map (package: package.name) cargoLock.package
|
||||||
|
else [ ];
|
||||||
|
availableAutoDeps = import ./deps.nix;
|
||||||
|
detectedDeps = intersectLists cargoLockDeps (attrNames availableAutoDeps);
|
||||||
|
mergedDetectedDeps =
|
||||||
|
if config.autodeps then
|
||||||
|
foldl
|
||||||
|
(merged: dep: {
|
||||||
|
build = merged.build ++ (availableAutoDeps.${dep}.build or [ ]);
|
||||||
|
native = merged.native ++ (availableAutoDeps.${dep}.native or [ ]);
|
||||||
|
env =
|
||||||
|
if (hasAttr "env" availableAutoDeps.${dep}) then
|
||||||
|
pkgs: (merged.env pkgs) // (availableAutoDeps.${dep}.env pkgs)
|
||||||
|
else merged.env;
|
||||||
|
})
|
||||||
|
{
|
||||||
|
build = [ ];
|
||||||
|
native = [ ];
|
||||||
|
env = pkgs: { };
|
||||||
|
}
|
||||||
|
detectedDeps else {
|
||||||
|
build = [ ];
|
||||||
|
native = [ ];
|
||||||
|
env = pkgs: { };
|
||||||
|
};
|
||||||
|
getPkgs = pkgs: deps:
|
||||||
|
let
|
||||||
|
depPaths = map (splitString ".") deps;
|
||||||
|
in
|
||||||
|
map (path: getAttrFromPath path pkgs) depPaths;
|
||||||
|
autoDeps = pkgs: {
|
||||||
|
buildInputs = getPkgs pkgs mergedDetectedDeps.build;
|
||||||
|
nativeBuildInputs = with pkgs; [ pkg-config ] ++ (getPkgs pkgs mergedDetectedDeps.native);
|
||||||
|
env = mergedDetectedDeps.env pkgs;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
autoDeps
|
||||||
15
autodeps/deps.nix
Normal file
15
autodeps/deps.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"openssl-sys" = { build = [ "openssl" ]; };
|
||||||
|
"libudev-sys" = { build = [ "eudev" ]; };
|
||||||
|
"libdbus-sys" = { build = [ "dbus" ]; };
|
||||||
|
"expat-sys" = { native = [ "cmake" ]; };
|
||||||
|
"servo-fontconfig-sys" = { build = [ "fontconfig" ]; };
|
||||||
|
"x11-dl" = { build = [ "xorg.libX11" "xorg.libXcursor" "xorg.libXrandr" "xorg.libXi" ]; };
|
||||||
|
"glutin_glx_sys" = {
|
||||||
|
build = [ "libGL" ];
|
||||||
|
env = pkgs: {
|
||||||
|
LD_LIBRARY_PATH = with pkgs; "/run/opengl-driver/lib/:${lib.makeLibraryPath ([libGL libGLU])}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
"wayland-egl" = { build = [ "egl-wayland" ]; };
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
{ lib, src, config, flakelight, inputs, ... }:
|
{ lib, src, config, flakelight, inputs, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) elem readFile pathExists isAttrs attrNames match any;
|
inherit (builtins) elem readFile pathExists isAttrs match any;
|
||||||
inherit (lib) map mkDefault mkIf mkMerge mkOption warnIf assertMsg optionalAttrs types optionalString genAttrs hasInfix intersectLists foldl attrVals;
|
inherit (lib) map mkDefault mkIf mkMerge mkOption warnIf assertMsg optionalAttrs types optionalString genAttrs hasInfix intersectLists attrVals;
|
||||||
inherit (lib.fileset) fileFilter toSource unions;
|
inherit (lib.fileset) fileFilter toSource unions;
|
||||||
inherit (flakelight.types) fileset function optFunctionTo;
|
inherit (flakelight.types) fileset function optFunctionTo;
|
||||||
|
|
||||||
|
|
@ -19,33 +19,11 @@ let
|
||||||
hasExamples = pathExists (src + /examples);
|
hasExamples = pathExists (src + /examples);
|
||||||
hasDefaultPackage = pathExists (src + /nix/package.nix);
|
hasDefaultPackage = pathExists (src + /nix/package.nix);
|
||||||
|
|
||||||
cargoLockDeps =
|
autoDeps = (import ./autodeps { inherit lib src config; });
|
||||||
if pathExists (src + /Cargo.lock) then
|
|
||||||
let
|
|
||||||
cargoLock = fromTOML (readFile (src + /Cargo.lock));
|
|
||||||
in
|
|
||||||
map (package: package.name) cargoLock.package
|
|
||||||
else [ ];
|
|
||||||
availableAutoDeps = import ./autodeps.nix;
|
|
||||||
detectedDeps = intersectLists cargoLockDeps (attrNames availableAutoDeps);
|
|
||||||
mergedDetectedDeps =
|
|
||||||
if config.autodeps then
|
|
||||||
foldl
|
|
||||||
(merged: dep: {
|
|
||||||
build = merged.build ++ (availableAutoDeps.${dep}.build or [ ]);
|
|
||||||
native = merged.native ++ (availableAutoDeps.${dep}.native or [ ]);
|
|
||||||
})
|
|
||||||
{
|
|
||||||
build = [ ];
|
|
||||||
native = [ ];
|
|
||||||
}
|
|
||||||
detectedDeps else {
|
|
||||||
build = [ ];
|
|
||||||
native = [ ];
|
|
||||||
};
|
|
||||||
buildDeps = pkgs: {
|
buildDeps = pkgs: {
|
||||||
buildInputs = (attrVals mergedDetectedDeps.build pkgs) ++ (config.buildInputs pkgs);
|
buildInputs = (autoDeps pkgs).buildInputs ++ (config.buildInputs pkgs);
|
||||||
nativeBuildInputs = with pkgs; [ pkg-config ] ++ (attrVals mergedDetectedDeps.native pkgs) ++ (config.nativeBuildInputs pkgs);
|
nativeBuildInputs = (autoDeps pkgs).nativeBuildInputs ++ (config.nativeBuildInputs pkgs);
|
||||||
|
env = (autoDeps pkgs).env // (config.buildEnv pkgs);
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
warnIf (! builtins ? readFileType) "Unsupported Nix version in use."
|
warnIf (! builtins ? readFileType) "Unsupported Nix version in use."
|
||||||
|
|
@ -87,6 +65,11 @@ warnIf (! builtins ? readFileType) "Unsupported Nix version in use."
|
||||||
default = pkgs: [ ];
|
default = pkgs: [ ];
|
||||||
description = "native build inputs for the package";
|
description = "native build inputs for the package";
|
||||||
};
|
};
|
||||||
|
buildEnv = mkOption {
|
||||||
|
type = function;
|
||||||
|
default = pkgs: { };
|
||||||
|
description = "build environent variables for the package";
|
||||||
|
};
|
||||||
tools = mkOption {
|
tools = mkOption {
|
||||||
type = function;
|
type = function;
|
||||||
default = pkgs: with pkgs; [ cargo-edit bacon ];
|
default = pkgs: with pkgs; [ cargo-edit bacon ];
|
||||||
|
|
@ -292,9 +275,9 @@ warnIf (! builtins ? readFileType) "Unsupported Nix version in use."
|
||||||
++ (buildDeps pkgs).buildInputs
|
++ (buildDeps pkgs).buildInputs
|
||||||
++ (buildDeps pkgs).nativeBuildInputs;
|
++ (buildDeps pkgs).nativeBuildInputs;
|
||||||
|
|
||||||
env = { rustPlatform, ... }: {
|
env = { rustPlatform, pkgs, ... }: {
|
||||||
RUST_SRC_PATH = toString rustPlatform.rustLibSrc;
|
RUST_SRC_PATH = toString rustPlatform.rustLibSrc;
|
||||||
};
|
} // (buildDeps pkgs).env;
|
||||||
};
|
};
|
||||||
miri = {
|
miri = {
|
||||||
packages = pkgs: with pkgs; [ miriRustToolchain ]
|
packages = pkgs: with pkgs; [ miriRustToolchain ]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue