shell.nix 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. # `tomlkit` >= 0.8.0 is required to build `jsonschema` >= 4.11.0 (older
  5. # version do not support some valid TOML syntax: sdispater/tomlkit#148). The
  6. # updated `tomlkit` must be used by `makeRemoveSpecialDependenciesHook`
  7. # inside `poetry2nix`, therefore just providing the updated version through
  8. # our `nix/pyproject.toml` does not work, and using an overlay is required.
  9. pythonOverlay = final: prev: {
  10. python3 = prev.python3.override {
  11. packageOverrides = self: super: {
  12. tomlkit = super.tomlkit.overridePythonAttrs(old: rec {
  13. version = "0.11.4";
  14. src = super.fetchPypi {
  15. inherit (old) pname;
  16. inherit version;
  17. sha256 = "sha256-MjWpAQ+uVDI+cnw6wG+3IHUv5mNbNCbjedrsYPvUSoM=";
  18. };
  19. });
  20. };
  21. };
  22. };
  23. in
  24. # However, if you want to override Niv's inputs, this will let you do that.
  25. { pkgs ? import sources.nixpkgs { overlays = [ pythonOverlay ]; }
  26. , poetry2nix ? pkgs.callPackage (import sources.poetry2nix) { }
  27. , avr ? true
  28. , arm ? true
  29. , teensy ? true }:
  30. with pkgs;
  31. let
  32. avrlibc = pkgsCross.avr.libcCross;
  33. avr_incflags = [
  34. "-isystem ${avrlibc}/avr/include"
  35. "-B${avrlibc}/avr/lib/avr5"
  36. "-L${avrlibc}/avr/lib/avr5"
  37. "-B${avrlibc}/avr/lib/avr35"
  38. "-L${avrlibc}/avr/lib/avr35"
  39. "-B${avrlibc}/avr/lib/avr51"
  40. "-L${avrlibc}/avr/lib/avr51"
  41. ];
  42. # Builds the python env based on nix/pyproject.toml and
  43. # nix/poetry.lock Use the "poetry update --lock", "poetry add
  44. # --lock" etc. in the nix folder to adjust the contents of those
  45. # files if the requirements*.txt files change
  46. pythonEnv = poetry2nix.mkPoetryEnv {
  47. projectDir = ./util/nix;
  48. overrides = poetry2nix.overrides.withDefaults (self: super: {
  49. pillow = super.pillow.overridePythonAttrs(old: {
  50. # Use preConfigure from nixpkgs to fix library detection issues and
  51. # impurities which can break the build process; this also requires
  52. # adding propagatedBuildInputs and buildInputs from the same source.
  53. propagatedBuildInputs = (old.buildInputs or []) ++ pkgs.python3.pkgs.pillow.propagatedBuildInputs;
  54. buildInputs = (old.buildInputs or []) ++ pkgs.python3.pkgs.pillow.buildInputs;
  55. preConfigure = (old.preConfigure or "") + pkgs.python3.pkgs.pillow.preConfigure;
  56. });
  57. qmk = super.qmk.overridePythonAttrs(old: {
  58. # Allow QMK CLI to run "qmk" as a subprocess (the wrapper changes
  59. # $PATH and breaks these invocations).
  60. dontWrapPythonPrograms = true;
  61. });
  62. });
  63. };
  64. in
  65. mkShell {
  66. name = "qmk-firmware";
  67. buildInputs = [ clang-tools dfu-programmer dfu-util diffutils git pythonEnv niv ]
  68. ++ lib.optional avr [
  69. pkgsCross.avr.buildPackages.binutils
  70. pkgsCross.avr.buildPackages.gcc8
  71. avrlibc
  72. avrdude
  73. ]
  74. ++ lib.optional arm [ gcc-arm-embedded ]
  75. ++ lib.optional teensy [ teensy-loader-cli ];
  76. AVR_CFLAGS = lib.optional avr avr_incflags;
  77. AVR_ASFLAGS = lib.optional avr avr_incflags;
  78. shellHook = ''
  79. # Prevent the avr-gcc wrapper from picking up host GCC flags
  80. # like -iframework, which is problematic on Darwin
  81. unset NIX_CFLAGS_COMPILE_FOR_TARGET
  82. '';
  83. }