Skip to content

Commit d3c8c86

Browse files
committed
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
1 parent 063fa68 commit d3c8c86

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
runCommand,
3+
buildEnv,
4+
makeWrapper,
5+
lib,
6+
python311,
7+
writeShellScript,
8+
}:
9+
let
10+
wrapPathsStr =
11+
flag: values:
12+
builtins.concatStringsSep " " (
13+
builtins.concatMap (p: [
14+
"--add-flags"
15+
flag
16+
"--add-flags"
17+
p
18+
]) values
19+
);
20+
21+
wrapCfgStr =
22+
typ: val:
23+
let
24+
installer = writeShellScript "insteller-${typ}" ''
25+
dst="$HOME/.config/FreeCAD/${typ}.cfg"
26+
if [ ! -f "$dst" ]; then
27+
mkdir -p "$(dirname "$dst")"
28+
cp --no-preserve=mode,ownership '${val}' "$dst"
29+
fi
30+
'';
31+
in
32+
lib.optionalString (val != null) "--run ${installer}";
33+
34+
pythonsProcessed = builtins.map (
35+
pyt:
36+
if builtins.isString pyt then
37+
pyt
38+
else if builtins.isFunction pyt then
39+
"${(python311.withPackages pyt)}/lib/python3.11/site-packages"
40+
else
41+
throw "Expected string or function as python paths for freecad"
42+
);
43+
44+
makeCustomizable =
45+
freecad:
46+
freecad
47+
// {
48+
customize =
49+
{
50+
name ? freecad.name,
51+
modules ? [ ],
52+
pythons ? [ ],
53+
makeWrapperFlags ? [ ],
54+
userCfg ? null,
55+
systemCfg ? null,
56+
}:
57+
let
58+
modulesStr = wrapPathsStr "--module-path" modules;
59+
pythonsStr = wrapPathsStr "--python-path" (pythonsProcessed pythons);
60+
makeWrapperFlagsStr = builtins.concatStringsSep " " (builtins.map (f: "'${f}'") makeWrapperFlags);
61+
62+
userCfgStr = wrapCfgStr "user" userCfg;
63+
systemCfgStr = wrapCfgStr "system" systemCfg;
64+
65+
bin = runCommand "${name}-bin" { nativeBuildInputs = [ makeWrapper ]; } ''
66+
mkdir -p "$out/bin"
67+
for exe in FreeCAD{,Cmd}; do
68+
if [[ ! -e ${freecad}/bin/$exe ]]; then
69+
echo "No binary $exe in freecad package"
70+
false
71+
fi
72+
dest="$out/bin/$exe";
73+
makeWrapper "${freecad}/bin/$exe" "$dest" \
74+
--inherit-argv0 \
75+
${modulesStr} \
76+
${pythonsStr} \
77+
${userCfgStr} \
78+
${systemCfgStr} \
79+
${makeWrapperFlagsStr}
80+
done
81+
ln -s FreeCAD $out/bin/freecad
82+
ln -s FreeCADCmd $out/bin/freecadcmd
83+
'';
84+
in
85+
makeCustomizable (buildEnv {
86+
inherit name;
87+
paths = [
88+
(lib.lowPrio freecad)
89+
bin
90+
];
91+
});
92+
override = f: makeCustomizable (freecad.override f);
93+
overrideAttrs = f: makeCustomizable (freecad.overrideAttrs f);
94+
};
95+
in
96+
{
97+
inherit makeCustomizable;
98+
}

pkgs/by-name/fr/freecad/package.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{ lib
2+
, callPackage
23
, cmake
34
, coin3d
45
, doxygen
@@ -60,8 +61,9 @@ let
6061
scipy
6162
shiboken2
6263
;
64+
freecad-utils = callPackage ./freecad-utils.nix { };
6365
in
64-
stdenv.mkDerivation (finalAttrs: {
66+
freecad-utils.makeCustomizable (stdenv.mkDerivation (finalAttrs: {
6567
pname = "freecad";
6668
version = "1.0rc4";
6769

@@ -215,4 +217,4 @@ stdenv.mkDerivation (finalAttrs: {
215217
maintainers = with lib.maintainers; [ gebner srounce ];
216218
platforms = lib.platforms.linux;
217219
};
218-
})
220+
}))

0 commit comments

Comments
 (0)