freecad-flake

Source: github.com/chrisppy/freecad-flake

A Nix Flake providing a custom, declarative FreeCAD wrapper module and packaging system with dynamic plugin discovery and XML configuration injection.

Usage & configuration options →

Features

  • Dynamic Plugin Discovery: Every pin in the plugins group of .tack/pins.toml (e.g., sheet-metal, fasteners, history) becomes a boolean toggle option, generated with lib.genAttrs. Pins are fetched lazily, so only enabled plugins are downloaded.

  • Configuration in Nix: Seed user.cfg and system.cfg from Nix attrsets (or existing .cfg files); see Configuration files.

  • Custom FreeCAD Wrapper: Utilizes pkgs.freecad.customize to produce a customized FreeCAD derivation (programs.freecad.package).

  • Flake Native: Seamless integration with NixOS system configurations and Home Manager environments.

  • Pinned with tack: nixpkgs, devfmt and the plugins are pinned in .tack/ instead of flake inputs, so the flake has no inputs and no flake.lock. Plugins follow upstream's newest versioned release tag, and a daily workflow commits the new lock when any pin moves.

Updating pins

just update                 # tack update: every pin
just update-input plugins   # only the plugins group
just look                   # what would move

To add a plugin, add a table to .tack/pins.toml and lock it with just update-input <name>:

[inputs.plugins.<name>]
tag  = "v{version}"
type = "fetch"
url  = "github:<owner>/<repo>"

Installation

Add freecad-flake to your flake.nix inputs:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    # No `inputs.*.follows` needed: freecad-flake has no flake inputs, and the
    # module builds with your own `pkgs`.
    freecad-flake.url = "github:chrisppy/freecad-flake";
  };

  outputs = { self, nixpkgs, freecad-flake, ... }@inputs: {
    # Your flake outputs...
  };
}

Usage

Import the module directly into your NixOS system configuration:

{ inputs, pkgs, ... }: {
  imports = [
    inputs.freecad-flake.nixosModules.default
  ];

  programs.freecad = {
    enable = true;

    # Workbench plugins: the `plugins` group in .tack/pins.toml
    plugins = {
      fasteners = true;
      sheet-metal = true;
      history = true;
    };

    # Seeds for ~/.config/FreeCAD/{user,system}.cfg: Nix attrsets, or paths
    # to existing .cfg files
    userCfg.BaseApp.Preferences.Units = {
      UserSchema = 5; # Building US
      Decimals = 3;
    };
    systemCfg = ./config/system.cfg;

    # Custom wrapper flags or extra python extension package mappings
    makeWrapperFlags = [
      "--set QT_QPA_PLATFORM wayland"
    ];
  };
}

Configuration Options

OptionTypeDefaultDescription
programs.freecad.enablebooleanfalseEnable customized FreeCAD installation wrapper.
programs.freecad.plugins.<name>booleanfalseEnable custom upstream plugin workbench (generated for each pin in the plugins group of .tack/pins.toml).
programs.freecad.userCfgnull, path or attrsetnullSeed for ~/.config/FreeCAD/user.cfg (see below).
programs.freecad.systemCfgnull, path or attrsetnullSeed for ~/.config/FreeCAD/system.cfg (see below).
programs.freecad.cfgMode"seed", "merge" or "overwrite""seed"How userCfg and systemCfg reach ~/.config/FreeCAD (see below).
programs.freecad.pythonslist of unspecified[ ]Python extensions package mappings passed directly to pkgs.freecad.customize.
programs.freecad.makeWrapperFlagslist of strings[ ]Flags passed directly to makeWrapper inside the customization derivation.
programs.freecad.packagepackage(read-only)The resulting customized FreeCAD package derivation generated by pkgs.freecad.customize.

Configuration files

userCfg and systemCfg take either a path to an existing .cfg file or an attrset of FreeCAD parameters, which is rendered to FreeCAD's XML. The top-level attrset is the Root group, so paths read like FreeCAD's parameter editor (Tools → Edit parameters):

NixFreeCAD
attrsetFCParamGroup
true / falseFCBool
integerFCInt
floatFCFloat
stringFCText
inputs.freecad-flake.lib.uint 4059297279FCUInt (colors)

Attrsets set in several modules merge, so settings can live next to whatever they belong to.

cfgMode decides how they reach ~/.config/FreeCAD/. The files there are always normal, writable copies, never symlinks into the Nix store, because FreeCAD rewrites them when it exits.

cfgModeOn each FreeCAD launch
seedCopies the file only if it doesn't exist yet. FreeCAD owns it from then on, so later Nix changes need the old file moved aside.
mergeWrites every value set in Nix into the existing file and keeps everything else (recent files, window layout, other preferences). Nix's values win at each launch.
overwriteReplaces the file, so anything not set in Nix goes back to FreeCAD's default, recent files and window layout included.

merge keeps a broken file as <name>.cfg.bak and starts from the Nix copy.

inputs.freecad-flake.lib.toCfg renders an attrset to .cfg text, for use outside the module.