shell.nix
2583 bytes
1let
2 # We specify sources via Niv: use "niv update nixpkgs" to update nixpkgs, for example.
3 sources = import ./util/nix/sources.nix { };
4in
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 }:
11with pkgs;
12let
13 avrlibc = pkgsCross.avr.libcCross;
14
15 avr_incflags = [
16 "-isystem ${avrlibc}/avr/include"
17 "-B${avrlibc}/avr/lib/avr5"
18 "-L${avrlibc}/avr/lib/avr5"
19 "-B${avrlibc}/avr/lib/avr35"
20 "-L${avrlibc}/avr/lib/avr35"
21 "-B${avrlibc}/avr/lib/avr51"
22 "-L${avrlibc}/avr/lib/avr51"
23 ];
24
25 # Builds the python env based on nix/pyproject.toml and
26 # nix/poetry.lock Use the "poetry update --lock", "poetry add
27 # --lock" etc. in the nix folder to adjust the contents of those
28 # files if the requirements*.txt files change
29 pythonEnv = poetry2nix.mkPoetryEnv {
30 projectDir = ./util/nix;
31 overrides = poetry2nix.overrides.withDefaults (self: super: {
32 qmk = super.qmk.overridePythonAttrs(old: {
33 # Allow QMK CLI to run "qmk" as a subprocess (the wrapper changes
34 # $PATH and breaks these invocations).
35 dontWrapPythonPrograms = true;
36
37 # Fix "qmk setup" to use the Python interpreter from the environment
38 # when invoking "qmk doctor" (sys.executable gets its value from
39 # $NIX_PYTHONEXECUTABLE, which is set by the "qmk" wrapper from the
40 # Python environment, so "qmk doctor" then runs with the proper
41 # $NIX_PYTHONPATH too, because sys.executable actually points to
42 # another wrapper from the same Python environment).
43 postPatch = ''
44 substituteInPlace qmk_cli/subcommands/setup.py \
45 --replace "[Path(sys.argv[0]).as_posix()" \
46 "[Path(sys.executable).as_posix(), Path(sys.argv[0]).as_posix()"
47 '';
48 });
49 });
50 };
51in
52mkShell {
53 name = "qmk-firmware";
54
55 buildInputs = [ clang-tools_11 dfu-programmer dfu-util diffutils git pythonEnv niv ]
56 ++ lib.optional avr [
57 pkgsCross.avr.buildPackages.binutils
58 pkgsCross.avr.buildPackages.gcc8
59 avrlibc
60 avrdude
61 ]
62 ++ lib.optional arm [ gcc-arm-embedded ]
63 ++ lib.optional teensy [ teensy-loader-cli ];
64
65 AVR_CFLAGS = lib.optional avr avr_incflags;
66 AVR_ASFLAGS = lib.optional avr avr_incflags;
67 shellHook = ''
68 # Prevent the avr-gcc wrapper from picking up host GCC flags
69 # like -iframework, which is problematic on Darwin
70 unset NIX_CFLAGS_COMPILE_FOR_TARGET
71 '';
72}