I wanted to create a simple project flake for a video with manim
. This doesn’t work on my mac for multiple reasons:
-
moderngl
is marked broken on darwin. Nix says it depends on X11, but I think libGL is sufficient. -
mesa
is marked broken on darwin, which is bad aslibGL
requires it as a substitute forlibglvnd
. -
screeninfo
is also marked broken on darwin. This makes sense, it requires libX11.
I wanted to look at fixing this, and quickly found that the mesa
issue is very recent, so I switched to 23.05, unstable has wait for upstream for mesa to be fixed. I then started creating an overlay for these issues, and ended up with this flake:
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/23.05";
outputs = { self, nixpkgs }:
let
supportedSystems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
overlay = (final: prev: {
python3 = prev.python3.override {
packageOverrides = self: super: {
moderngl = super.moderngl.overrideAttrs (old: rec {
buildInputs = [ prev.libGL ]; # Remove X11
meta = old.meta // { platforms = prev.lib.platforms.all; };
});
};
};
manim = prev.manim.overrideAttrs (old: {
propagatedBuildInputs = builtins.filter (x: x.pname != "screeninfo")
old.propagatedBuildInputs;
});
});
pkgs =
forAllSystems (system: nixpkgs.legacyPackages.${system}.extend overlay);
in {
devShells = forAllSystems (system: {
default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [ manim ];
};
});
};
}
Unfortunately, when I run nix develop
, I still get an error that moderngl
is not supported on my platform:
warning: Git tree '/Users/feuh/repos/manim-nix-intro' is dirty
error:
… while calling the 'derivationStrict' builtin
at //builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'nix-shell'
whose name attribute is located at /nix/store/vhq11h949l5zycaw07acphv53ifq4p2c-source/pkgs/stdenv/generic/make-derivation.nix:303:7
… while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'
at /nix/store/vhq11h949l5zycaw07acphv53ifq4p2c-source/pkgs/stdenv/generic/make-derivation.nix:347:7:
346| depsBuildBuild = lib.elemAt (lib.elemAt dependencies 0) 0;
347| nativeBuildInputs = lib.elemAt (lib.elemAt dependencies 0) 1;
| ^
348| depsBuildTarget = lib.elemAt (lib.elemAt dependencies 0) 2;
(stack trace truncated; use '--show-trace' to show the full trace)
error: Package ‘python3.10-moderngl-5.8.2’ in /nix/store/vhq11h949l5zycaw07acphv53ifq4p2c-source/pkgs/development/python-modules/moderngl/default.nix:39 is not available on the requested hostPlatform:
hostPlatform.config = "aarch64-apple-darwin"
package.meta.platforms = [
"aarch64-linux"
"armv5tel-linux"
"armv6l-linux"
"armv7a-linux"
"armv7l-linux"
"i686-linux"
"loongarch64-linux"
"m68k-linux"
"microblaze-linux"
"microblazeel-linux"
"mipsel-linux"
"mips64el-linux"
"powerpc64-linux"
"powerpc64le-linux"
"riscv32-linux"
"riscv64-linux"
"s390-linux"
"s390x-linux"
"x86_64-linux"
]
package.meta.badPlatforms = [ ]
, refusing to evaluate.
a) To temporarily allow packages that are unsupported for this system, you can use an environment variable
[ ... etc. ...]
So somehow, the line
meta = old.meta // { platforms = prev.lib.platforms.all; };
Doesn’t have the desired effect.
I tried the following:
- Remove
old.meta //
→ no effect - Use
overridePythonAttrs
instead ofoverrideAttrs
→ no effect - Chaging the filter function to
x: !builtins.elem x.pname ["screeninfo" "moderngl" "moderngl_window"]
→ allowed me to start the build, which has been running for over half an hour before I aborted it. Even if it works, the renderer will be broken as it relies onmoderngl
- Replace
prev.manim
with(prev.manim.override { inherit (final) python3; })
in an attempt to force the packageOverrides to be used → no effect
I think I don’t really understand how overlays work, and everything else I try is just throwing stuff at the wall to see if anything sticks. Could someone give me a bit of a direction?