diff options
| author | Julian Stecklina <julian.stecklina@cyberus-technology.de> | 2024-03-25 15:36:43 +0100 |
|---|---|---|
| committer | Julian Stecklina <julian.stecklina@cyberus-technology.de> | 2024-03-25 15:36:43 +0100 |
| commit | 6cc20b7e3c8d50bb03eb2706af21c4ae9a1d3a79 (patch) | |
| tree | 01f33fc0012cf9c6c9669a3b87bfe9fcc1e7ec55 | |
Initial import
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 58 | ||||
| -rw-r--r-- | bindgen/0.65.1.nix | 47 | ||||
| -rw-r--r-- | flake.lock | 124 | ||||
| -rw-r--r-- | flake.nix | 98 |
5 files changed, 328 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f6b899 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Linux Kernel Development Environment via Nix + +Welcome to a streamlined Linux kernel development setup using Nix +flakes. This project simplifies the process of setting up a +development environment for the Linux kernel, ensuring that you have +all the necessary dependencies, including specific versions of Rust +and bindgen, preinstalled in a devShell. + +## Quick Start + +Getting started with your kernel development environment is incredibly +simple. If you're aiming to develop for Linux version 6.8, all you +need is a single command: + +```shell +linux$ nix develop github:blitz/kernel-dev#linux_6_8 +``` + +This will drop you into a shell with all the dependencies required for +working on the Linux 6.8 kernel preinstalled. + +### Features + +- **Simplicity**: Forget about the hassle of managing multiple + dependencies and their versions. One command is all it takes. +- **Reproducibility**: With Nix flakes, your development environment + is reproducible, ensuring that your setup is always consistent and + predictable. +- **Version-specific environments**: Tailored development environments + for specific Linux kernel versions, starting with Linux 6.8. + +### Requirements + +- Nix package manager with flake support enabled. + +## Usage + +To start developing for a different version of the Linux kernel, use +the following pattern, replacing linux_6_8 with the target version +(note: versions are added based on community contributions and +demand): + +```shell +$ nix develop github:blitz/kernel-dev#linux_<major_version>_<minor_version> +``` + +If you don't find the exact version that you need, one that is close +_might_ work as well. + +## Contributing + +Contributions are welcome! Whether it's adding support for new kernel +versions, improving the setup process, or documentation - feel free to +fork the project and submit a pull request. + +## License + +This project is open source and available under the MIT License. diff --git a/bindgen/0.65.1.nix b/bindgen/0.65.1.nix new file mode 100644 index 0000000..fcc5edc --- /dev/null +++ b/bindgen/0.65.1.nix @@ -0,0 +1,47 @@ +{ lib, fetchCrate, rustPlatform, clang, rustfmt }: +let + # bindgen hardcodes rustfmt outputs that use nightly features + rustfmt-nightly = rustfmt.override { asNightly = true; }; +in rustPlatform.buildRustPackage rec { + pname = "rust-bindgen-unwrapped"; + version = "0.65.1"; + + src = fetchCrate { + pname = "bindgen-cli"; + inherit version; + sha256 = "sha256-9JJXQQSbCxTh3fIbVSrc6WAYGivwomkoB8ZIquUNr9o="; + }; + + cargoHash = "sha256-Kz6Y+4F9Yu5oKYI9LgZKLh0AkQTwerPS4A758TZrkoc="; + + buildInputs = [ clang.cc.lib ]; + + preConfigure = '' + export LIBCLANG_PATH="${clang.cc.lib}/lib" + ''; + + doCheck = true; + nativeCheckInputs = [ clang ]; + + RUSTFMT = "${rustfmt-nightly}/bin/rustfmt"; + + preCheck = '' + # for the ci folder, notably + patchShebangs . + ''; + + passthru = { inherit clang; }; + + meta = with lib; { + description = "Automatically generates Rust FFI bindings to C (and some C++) libraries"; + longDescription = '' + Bindgen takes a c or c++ header file and turns them into + rust ffi declarations. + ''; + homepage = "https://github.com/rust-lang/rust-bindgen"; + license = with licenses; [ bsd3 ]; + maintainers = with maintainers; [ johntitor ralith ]; + mainProgram = "bindgen"; + platforms = platforms.unix; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c83cf0a --- /dev/null +++ b/flake.lock @@ -0,0 +1,124 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1711347842, + "narHash": "sha256-NEu85M2kpGlEBPVNSIB0nOSLWg3x6R3px5Nd+vthdsU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "12619df460ea671b1e94a5c2c8c17ca91cb86ebe", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710806803, + "narHash": "sha256-qrxvLS888pNJFwJdK+hf1wpRCSQcqA6W5+Ox202NDa0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b06025f1533a1e07b6db3e75151caa155d1c7eb3", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1711304256, + "narHash": "sha256-4na1ZTc6Iknu6V1Wo6jnt6d3H0JdZfpKF4GX/WNa/Zc=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "6f6b03f9de783f91456080b3f6adc8d92903c1b0", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1710987136, + "narHash": "sha256-Q8GRdlAIKZ8tJUXrbcRO1pA33AdoPfTUirsSnmGQnOU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "97596b54ac34ad8184ca1eef44b1ec2e5c2b5f9e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..904be02 --- /dev/null +++ b/flake.nix @@ -0,0 +1,98 @@ +{ + description = "Kernel development environments"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + 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}"; + + linuxCommonDependencies = with pkgs; [ + gnumake + perl + bison + flex + gmp + libmpc + mpfr + pahole + nettools + bc + rsync + openssl + cpio + elfutils + zstd + python3Minimal + zlib + kmod + ubootTools + + llvmPackages.bintools + llvmPackages.clang + llvmPackages.llvm + + # For make menuconfig + ncurses + ]; + + rust-analyzer = fenix.packages."${system}".rust-analyzer; + + rustc_1_76 = rust-overlay.packages."${system}".rust_1_76_0.override { + extensions = [ + "rust-src" + "rustfmt" + "clippy" + ]; + }; + + rust-bindgen_0_65_1 = let + rustPlatform_1_76 = pkgs.makeRustPlatform { + cargo = rustc_1_76; + rustc = rustc_1_76; + }; + + rust-bindgen-unwrapped_0_65_1 = pkgs.callPackage ./bindgen/0.65.1.nix { + rustPlatform = rustPlatform_1_76; + }; + in + pkgs.rust-bindgen.override { + rust-bindgen-unwrapped = rust-bindgen-unwrapped_0_65_1; + }; + in + { + devShells.default = self.devShells."${system}".linux_6_8; + + devShells.linux_6_8 = pkgs.mkShell { + packages = [ + rustc_1_76 + rust-bindgen_0_65_1 + rust-analyzer + ] ++ 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 = ""; + }; + } + ); +} |
