shell.nix 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. let
  2. # We specify sources via Niv: use "niv update nixpkgs" to update nixpkgs, for example.
  3. sources = import ./util/nix/sources.nix { };
  4. in
  5. # However, if you want to override Niv's inputs, this will let you do that.
  6. { pkgs ? import sources.nixpkgs { }
  7. , poetry2nix ? pkgs.callPackage (import sources.poetry2nix) { }
  8. , avr ? true
  9. , arm ? true
  10. , teensy ? true }:
  11. with pkgs;
  12. let
  13. avrlibc = pkgsCross.avr.libcCross;
  14. avr_incflags = [
  15. "-isystem ${avrlibc}/avr/include"
  16. "-B${avrlibc}/avr/lib/avr5"
  17. "-L${avrlibc}/avr/lib/avr5"
  18. "-B${avrlibc}/avr/lib/avr35"
  19. "-L${avrlibc}/avr/lib/avr35"
  20. "-B${avrlibc}/avr/lib/avr51"
  21. "-L${avrlibc}/avr/lib/avr51"
  22. ];
  23. # Builds the python env based on nix/pyproject.toml and
  24. # nix/poetry.lock Use the "poetry update --lock", "poetry add
  25. # --lock" etc. in the nix folder to adjust the contents of those
  26. # files if the requirements*.txt files change
  27. pythonEnv = poetry2nix.mkPoetryEnv {
  28. projectDir = ./util/nix;
  29. overrides = poetry2nix.overrides.withDefaults (self: super: {
  30. pillow = super.pillow.overridePythonAttrs(old: {
  31. # Use preConfigure from nixpkgs to fix library detection issues and
  32. # impurities which can break the build process; this also requires
  33. # adding propagatedBuildInputs and buildInputs from the same source.
  34. propagatedBuildInputs = (old.buildInputs or []) ++ pkgs.python3.pkgs.pillow.propagatedBuildInputs;
  35. buildInputs = (old.buildInputs or []) ++ pkgs.python3.pkgs.pillow.buildInputs;
  36. preConfigure = (old.preConfigure or "") + pkgs.python3.pkgs.pillow.preConfigure;
  37. });
  38. qmk = super.qmk.overridePythonAttrs(old: {
  39. # Allow QMK CLI to run "qmk" as a subprocess (the wrapper changes
  40. # $PATH and breaks these invocations).
  41. dontWrapPythonPrograms = true;
  42. });
  43. });
  44. };
  45. in
  46. mkShell {
  47. name = "qmk-firmware";
  48. buildInputs = [ clang-tools dfu-programmer dfu-util diffutils git pythonEnv poetry niv ]
  49. ++ lib.optional avr [
  50. pkgsCross.avr.buildPackages.binutils
  51. pkgsCross.avr.buildPackages.gcc8
  52. avrlibc
  53. avrdude
  54. ]
  55. ++ lib.optional arm [ gcc-arm-embedded ]
  56. ++ lib.optional teensy [ teensy-loader-cli ];
  57. AVR_CFLAGS = lib.optional avr avr_incflags;
  58. AVR_ASFLAGS = lib.optional avr avr_incflags;
  59. shellHook = ''
  60. # Prevent the avr-gcc wrapper from picking up host GCC flags
  61. # like -iframework, which is problematic on Darwin
  62. unset NIX_CFLAGS_COMPILE_FOR_TARGET
  63. '';
  64. }