summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 4b02b61f8047e595da89a7eea8c423a1490bf55a (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
  description = "Kernel development environments";

  inputs = {
    systems.url = "github:nix-systems/default-linux";

    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

    flake-utils = {
      url = "github:numtide/flake-utils";
      inputs.systems.follows = "systems";
    };

    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };

    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, rust-overlay, fenix, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages."${system}";

        # A set of scripts to simplify kernel development.
        kernelDevTools = pkgs.callPackage ./tools.nix { };

        linuxCommonDependencies = [
          kernelDevTools
        ] ++ (with pkgs; [
          gnumake
          perl
          bison
          flex
          gmp
          libmpc
          mpfr
          pahole
          nettools
          bc
          rsync
          openssl
          cpio
          elfutils
          zstd
          python3Minimal
          zlib
          kmod
          ubootTools

          # For make menuconfig
          ncurses

          # For make gtags
          global

          # For git send-email 🫠
          gitFull
        ]);

        linuxLlvmDependencies = [
          pkgs.llvmPackages.bintools
          pkgs.llvmPackages.llvm
          pkgs.llvmPackages.clang
        ];

        linuxGccDependencies = [
          pkgs.gcc
        ];

        rust-analyzer = fenix.packages."${system}".rust-analyzer;

        linuxRustDependencies = rustVersion:
          let
            rustc = rust-overlay.packages."${system}"."${rustVersion}".override {
              extensions = [
                "rust-src"
                "rustfmt"
                "clippy"
              ];
            };

            rustPlatform = pkgs.makeRustPlatform {
              cargo = rustc;
              rustc = rustc;
            };

            bindgenUnwrapped = pkgs.callPackage ./bindgen/0.65.1.nix {
              inherit rustPlatform;
            };

            bindgen = pkgs.rust-bindgen.override {
              rust-bindgen-unwrapped = bindgenUnwrapped;
            };
          in
          [
            rustc
            bindgen
            rust-analyzer
          ];
      in
      {
        devShells = {
          default = self.devShells."${system}".linux_6_8;

          # Linux 6.8
          linux_6_8 = pkgs.mkShell {
            packages =
              linuxLlvmDependencies
              ++ (linuxRustDependencies "rust_1_74_1")
              ++ linuxCommonDependencies;

            # To force LLVM build mode. This should create less problems
            # with Rust interop.
            LLVM = "1";

            # Disable all automatically applied hardening. The Linux
            # kernel will take care of itself.
            NIX_HARDENING_ENABLE = "";
          };

          linux_6_8_gcc = pkgs.mkShell {
            packages =
              linuxGccDependencies
              ++ linuxCommonDependencies;

            # Disable all automatically applied hardening. The Linux
            # kernel will take care of itself.
            NIX_HARDENING_ENABLE = "";
          };

          # Linux 6.9
          linux_6_9 = pkgs.mkShell {
            packages =
              linuxLlvmDependencies
              ++ (linuxRustDependencies "rust_1_76_0")
              ++ linuxCommonDependencies;

            # To force LLVM build mode. This should create less problems
            # with Rust interop.
            LLVM = "1";

            # Disable all automatically applied hardening. The Linux
            # kernel will take care of itself.
            NIX_HARDENING_ENABLE = "";
          };

          linux_6_9_gcc = self.devShells."${system}".linux_6_8_gcc;
        };
      });
}