about summary refs log tree commit diff
path: root/flake.nix
blob: 1d999f7237557a0aac6e3f21c6e41b0548470c27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs =
    { self, nixpkgs }:
    let
      systems = [
        "x86_64-linux"
        "x86_64-darwin"
        "aarch64-linux"
        "aarch64-darwin"
        "riscv64-linux"
      ];

      eachSystem =
        f:
        nixpkgs.lib.genAttrs systems (
          system:
          f {
            inherit system;
            pkgs = import nixpkgs { inherit system; };
          }
        );
    in
    {
      devShells = eachSystem (
        { system, pkgs }:
        let
          inherit (pkgs) tinycc pkg-config gnumake lldb clang bintools xxd;

          stdenv = pkgs.llvmPackages.stdenv;
          mkShell = pkgs.mkShell.override { inherit stdenv; };

          musl-src = pkgs.runCommand "musl-src" { } ''
            mkdir $out
            tar -xf ${pkgs.musl.src} -C $out
          '';

          musl = pkgs.musl.overrideAttrs (attrs: {
            # this HAS the be fixed in upstream nixpkgs one day, right?
            CFLAGS = attrs.CFLAGS ++ [
              "-fdebug-prefix-map=/build=${musl-src}"
            ];
            seperateDebugInfo = false;
            dontStrip = true;
          });
        in
        {
          default = mkShell {
            buildInputs = [
              musl
              tinycc
            ];

            nativeBuildInputs = [
              pkg-config
              gnumake
              lldb
              clang
              bintools
              xxd
            ];

            MUSL_LIB = "${musl}";
            MUSL_DEV = "${musl.dev}";
            MUSL_SRC = "${musl-src}";
          };
        }
      );
    };
}