freecad: make customizable
FreeCad has addon system with various addons around the net. It has an addon-manager which allows to browse through registered addons and install them in runtime. But this is not nix-way, because you have to install addons again after system configuration moving. Additionally freecad allows you to manually install addons and put them to common folder or specify with command arguments. This patch introduces extra `customize` method to FreeCad derivation attrset (inspired from vim) which allows you to inject addons from nix configuration. ```nix { freecad , fetchFromGitHub }: let cad-exchanger = fetchFromGitHub { owner = "yorikvanhavre"; repo = "CADExchanger"; rev = "5c2cd792ddc4581b917ebe7add5ef960bf6c3e2a"; hash = "sha256-AST5bwhgMbvW3m8V1cv5PqKjJi2eSE1lbXpVLvRVzM8="; }; freecad-customized = freecad.customize { modules = [ cad-exchanger ]; }; in freecad-customized ``` Change-Id: I64cea3a5c7c5d08d153424b98dafec4117808d21
This commit is contained in:
parent
063fa684a4
commit
d3c8c86ac4
98
pkgs/by-name/fr/freecad/freecad-utils.nix
Normal file
98
pkgs/by-name/fr/freecad/freecad-utils.nix
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
runCommand,
|
||||
buildEnv,
|
||||
makeWrapper,
|
||||
lib,
|
||||
python311,
|
||||
writeShellScript,
|
||||
}:
|
||||
let
|
||||
wrapPathsStr =
|
||||
flag: values:
|
||||
builtins.concatStringsSep " " (
|
||||
builtins.concatMap (p: [
|
||||
"--add-flags"
|
||||
flag
|
||||
"--add-flags"
|
||||
p
|
||||
]) values
|
||||
);
|
||||
|
||||
wrapCfgStr =
|
||||
typ: val:
|
||||
let
|
||||
installer = writeShellScript "insteller-${typ}" ''
|
||||
dst="$HOME/.config/FreeCAD/${typ}.cfg"
|
||||
if [ ! -f "$dst" ]; then
|
||||
mkdir -p "$(dirname "$dst")"
|
||||
cp --no-preserve=mode,ownership '${val}' "$dst"
|
||||
fi
|
||||
'';
|
||||
in
|
||||
lib.optionalString (val != null) "--run ${installer}";
|
||||
|
||||
pythonsProcessed = builtins.map (
|
||||
pyt:
|
||||
if builtins.isString pyt then
|
||||
pyt
|
||||
else if builtins.isFunction pyt then
|
||||
"${(python311.withPackages pyt)}/lib/python3.11/site-packages"
|
||||
else
|
||||
throw "Expected string or function as python paths for freecad"
|
||||
);
|
||||
|
||||
makeCustomizable =
|
||||
freecad:
|
||||
freecad
|
||||
// {
|
||||
customize =
|
||||
{
|
||||
name ? freecad.name,
|
||||
modules ? [ ],
|
||||
pythons ? [ ],
|
||||
makeWrapperFlags ? [ ],
|
||||
userCfg ? null,
|
||||
systemCfg ? null,
|
||||
}:
|
||||
let
|
||||
modulesStr = wrapPathsStr "--module-path" modules;
|
||||
pythonsStr = wrapPathsStr "--python-path" (pythonsProcessed pythons);
|
||||
makeWrapperFlagsStr = builtins.concatStringsSep " " (builtins.map (f: "'${f}'") makeWrapperFlags);
|
||||
|
||||
userCfgStr = wrapCfgStr "user" userCfg;
|
||||
systemCfgStr = wrapCfgStr "system" systemCfg;
|
||||
|
||||
bin = runCommand "${name}-bin" { nativeBuildInputs = [ makeWrapper ]; } ''
|
||||
mkdir -p "$out/bin"
|
||||
for exe in FreeCAD{,Cmd}; do
|
||||
if [[ ! -e ${freecad}/bin/$exe ]]; then
|
||||
echo "No binary $exe in freecad package"
|
||||
false
|
||||
fi
|
||||
dest="$out/bin/$exe";
|
||||
makeWrapper "${freecad}/bin/$exe" "$dest" \
|
||||
--inherit-argv0 \
|
||||
${modulesStr} \
|
||||
${pythonsStr} \
|
||||
${userCfgStr} \
|
||||
${systemCfgStr} \
|
||||
${makeWrapperFlagsStr}
|
||||
done
|
||||
ln -s FreeCAD $out/bin/freecad
|
||||
ln -s FreeCADCmd $out/bin/freecadcmd
|
||||
'';
|
||||
in
|
||||
makeCustomizable (buildEnv {
|
||||
inherit name;
|
||||
paths = [
|
||||
(lib.lowPrio freecad)
|
||||
bin
|
||||
];
|
||||
});
|
||||
override = f: makeCustomizable (freecad.override f);
|
||||
overrideAttrs = f: makeCustomizable (freecad.overrideAttrs f);
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit makeCustomizable;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
{ lib
|
||||
, callPackage
|
||||
, cmake
|
||||
, coin3d
|
||||
, doxygen
|
||||
@ -60,8 +61,9 @@ let
|
||||
scipy
|
||||
shiboken2
|
||||
;
|
||||
freecad-utils = callPackage ./freecad-utils.nix { };
|
||||
in
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
freecad-utils.makeCustomizable (stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "freecad";
|
||||
version = "1.0rc4";
|
||||
|
||||
@ -215,4 +217,4 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
maintainers = with lib.maintainers; [ gebner srounce ];
|
||||
platforms = lib.platforms.linux;
|
||||
};
|
||||
})
|
||||
}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user