Skip to content

rewrite devshell with flake #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
result*
result-*
*~
.DS_Store
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# rust-for-linux/nix
# Rust for Linux Nix

Efforts for packaging the Rust for Linux project with the [Nix package manager](https://nixos.org/).

```
$ nix-build -A kernel
```
35 changes: 0 additions & 35 deletions default.nix

This file was deleted.

96 changes: 96 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
description = "A very basic flake";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "A very basic flake";
description = "Devshell for building the Linux kernel";


inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
oxalica.url = "github:oxalica/rust-overlay";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 (different) nixpkgs in flake.lock

Suggested change
oxalica.url = "github:oxalica/rust-overlay";
oxalica.url = "github:oxalica/rust-overlay";
oxalica.inputs.nixpkgs.follows = "nixpkgs";

};

outputs = inputs@{ self, nixpkgs, flake-utils, ... }: {
} // flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [ inputs.oxalica.overlays.default ];
};
in {
devShells = {
default = pkgs.callPackage ./nix/shell.nix { rustAttrs = pkgs.rust-bin.stable.latest; llvmPackages = pkgs.llvmPackages_18; };
clang = self.devShells.${system}.default.override { isClang = true; };
};
});
}
109 changes: 109 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{ lib
, mkShellNoCC
, writeShellScriptBin

, b4

, gnumake
, pkg-config
, ncurses
, rustAttrs
, rust-bindgen-unwrapped

, elfutils
, bison
, flex
, perl
, bc
, nettools
, openssl
, rsync
, gmp
, libmpc
, mpfr
, zstd
, python3Minimal
, kmod
, hexdump

, isClang ? false
, llvmPackages
, gcc ? null
}:

#assert !isClang -> gcc;

let
makeBinArg = package: name: bin: "${name}=${package}/bin/${bin}";
makeHostToolArg = package: unwrapped: name: bin: "${makeBinArg unwrapped name bin} ${makeBinArg package "HOST${name}" bin}";
makeMakeVars = vars: lib.concatStringsSep " \\\n " ((map (v:
if v ? package-unwrapped then
makeHostToolArg v.package v.package-unwrapped v.name v.bin
else
makeBinArg v.package v.name v.bin)) vars);
clangTool = { name, bin, hostPackage ? "clang", package ? "${hostPackage}-unwrapped" }: [
{ inherit name; value = "${llvmPackages.${package}}/bin/${bin}"; }
{ name = "HOST${name}"; value = "${llvmPackages.${hostPackage}}/bin/${bin}"; }
];

# Env variables that make wants
makeEnv = if isClang then ({
LLVM = "1";
NM = "${llvmPackages.libllvm}/bin/llvm-nm";
STRIP = "${llvmPackages.libllvm}/bin/llvm-strip";
OBJCOPY = "${llvmPackages.libllvm}/bin/llvm-objcopy";
READELF = "${llvmPackages.libllvm}/bin/llvm-readelf";
LLVM_AS = "${llvmPackages.libllvm}/bin/llvm-as";
LLVM_LINK = "${llvmPackages.libllvm}/bin/llvm-link";
KCFLAGS = "\"-isystem ${llvmPackages.clang}/resource-root/include\"";
} // (lib.listToAttrs (lib.flatten (map clangTool [
{ name = "CC"; bin = "clang"; }
{ name = "LD"; bin = "ld.lld"; hostPackage = "bintools"; }
{ name = "AR"; bin = "ar"; hostPackage = "bintools"; }
])))) else {
TODO = builtins.warn "TODO gcc build";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: attribute 'warn' missing

Suggested change
TODO = builtins.warn "TODO gcc build";
TODO = builtins.throw "TODO gcc build";

};

gnumake' = writeShellScriptBin "make" ''
${gnumake}/bin/make "$@" \
${lib.concatStringsSep " \\\n " (lib.mapAttrsToList (name: value: "${name}=${value}") makeEnv)}
'';
in mkShellNoCC {
name = "linux";

packages = [
b4

gnumake'
pkg-config
ncurses

elfutils
bison
flex
perl
bc
nettools
openssl
rsync
gmp
libmpc
mpfr
zstd
python3Minimal
kmod
hexdump

(rustAttrs.default.override {
extensions = [ "rust-src" "rust-analyzer" ];
})
rust-bindgen-unwrapped
];

env = makeEnv;

LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";

hardeningDisable =
[ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ];
}
38 changes: 0 additions & 38 deletions nix/sources.json

This file was deleted.

Loading