From dcb884549ad8dffcbea36175f6f4b912177993bd Mon Sep 17 00:00:00 2001 From: Leandro Santiago Date: Tue, 11 Feb 2025 15:59:47 +0100 Subject: [PATCH 1/6] Allow building when SELinux is not used Add `USE_SELINUX` variable to `make all` --- CONTRIBUTING.md | 6 ++++++ mk/podman.mk | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a891987..9b0e48f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -118,6 +118,12 @@ To start the compilation of the default recipes run the command below: make all ``` +In case your operating system does not use SELinux, you must set the `USE_SELINUX` to `0` when calling `make all`, otherwise you might experience errors: + +```sh +make all USE_SELINUX=0 +``` + You can find the build system organization and commands on the [Build System](https://doc.redox-os.org/book/build-system-reference.html) page. ## Developer FAQ diff --git a/mk/podman.mk b/mk/podman.mk index 3bea7df..abd2b1e 100644 --- a/mk/podman.mk +++ b/mk/podman.mk @@ -5,10 +5,19 @@ IMAGE_TAG?=redox-base ## Working Directory in Podman CONTAINER_WORKDIR?=/mnt/redox + +## Flag passed to the Podman volumes. :Z can be used only with SELinux +USE_SELINUX=1 +ifeq ($(USE_SELINUX),1) +PODMAN_VOLUME_FLAG=:Z +else +PODMAN_VOLUME_FLAG= +endif + ## Podman Home Directory PODMAN_HOME?=$(ROOT)/build/podman ## Podman command with its many arguments -PODMAN_VOLUMES?=--volume $(ROOT):$(CONTAINER_WORKDIR):Z --volume $(PODMAN_HOME):/home:Z +PODMAN_VOLUMES?=--volume $(ROOT):$(CONTAINER_WORKDIR)$(PODMAN_VOLUME_FLAG) --volume $(PODMAN_HOME):/home$(PODMAN_VOLUME_FLAG) PODMAN_ENV?=--env PATH=/home/poduser/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env PODMAN_BUILD=0 PODMAN_CONFIG?=--env ARCH=$(ARCH) --env BOARD=$(BOARD) --env CONFIG_NAME=$(CONFIG_NAME) --env FILESYSTEM_CONFIG=$(FILESYSTEM_CONFIG) PODMAN_OPTIONS?=--rm --workdir $(CONTAINER_WORKDIR) --userns keep-id --user `id -u` --interactive --tty --env TERM=$(TERM) From d055f25da955e21c39bf723a8b98807296880279 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 18 Feb 2025 15:22:02 -0700 Subject: [PATCH 2/6] Update cookbook and relibc --- cookbook | 2 +- relibc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbook b/cookbook index bff6ca4..69c6dd2 160000 --- a/cookbook +++ b/cookbook @@ -1 +1 @@ -Subproject commit bff6ca4d6881ff295be995653feb94f5357e8e19 +Subproject commit 69c6dd237a6cfca6ac5b81866cb18843b783f57a diff --git a/relibc b/relibc index 365ec7f..84f3d84 160000 --- a/relibc +++ b/relibc @@ -1 +1 @@ -Subproject commit 365ec7fe7cce10aa51197a605e4801b8780cf758 +Subproject commit 84f3d84ef94ca9d7df49c72e2b7d0d1a57620409 From 4573edcc16445b96c6ddbee3eebfb4aefa6d1d6b Mon Sep 17 00:00:00 2001 From: Vincent Berthier Date: Tue, 18 Feb 2025 22:23:42 +0000 Subject: [PATCH 3/6] Add shell and build environment for NixOS --- flake.lock | 98 ++++++++++++++++++++++++++++ flake.nix | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++ mk/depends.mk | 7 ++ mk/fstools.mk | 3 + 4 files changed, 284 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cda9bbe --- /dev/null +++ b/flake.lock @@ -0,0 +1,98 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1739638817, + "narHash": "sha256-pPiI27T416xAAUETorkLAgHQMiLT92moOrf0ItHhtPA=", + "owner": "ipetkov", + "repo": "crane", + "rev": "bef2b45cd1273a9e621fb5292de89f4ed59ad812", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1739512841, + "narHash": "sha256-Zc+K4AxAwFaWKK18nSl/3TKidGf46En7bfK8SL+Revg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fada727ee7c0bd487e311dede0a2b0725a0f7765", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1739673031, + "narHash": "sha256-Z/GT8ebbvc4goxN4A0A5ACj26G1HaGJO+VetrPuC5Mo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "538528d55318e0c8af1c307dcf10b7629b988fc3", + "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..fc709cc --- /dev/null +++ b/flake.nix @@ -0,0 +1,176 @@ +# Podman needs to be installed and configured on the system for all this to work: +# https://nixos.wiki/wiki/Podman +{ + description = "The Nix-flake for Redox development on NixOS"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + + crane = { + url = "github:ipetkov/crane"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + rust-overlay, + crane, + } @ inputs: + flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: let + overlays = [(import rust-overlay)]; + pkgs = import nixpkgs { + inherit system overlays; + }; + inherit (pkgs) lib; + + rust-bin = + pkgs.rust-bin.nightly."2025-01-12".default.override + { + extensions = ["rust-analyzer" "rust-src"]; + targets = ["x86_64-unknown-redox"]; + }; + craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust-bin; + + # Podman config taken from https://nixos.wiki/wiki/Podman and https://gist.github.com/adisbladis/187204cb772800489ee3dac4acdd9947 + # Provides a script that copies required files to ~/ + podmanSetupScript = let + registriesConf = pkgs.writeText "registries.conf" '' + [registries.search] + registries = ['docker.io'] + [registries.block] + registries = [] + ''; + in + pkgs.writeScript "podman-setup" '' + #!${pkgs.runtimeShell} + # Dont overwrite customised configuration + if ! test -f ~/.config/containers/policy.json; then + install -Dm555 ${pkgs.skopeo.src}/default-policy.json ~/.config/containers/policy.json + fi + if ! test -f ~/.config/containers/registries.conf; then + install -Dm555 ${registriesConf} ~/.config/containers/registries.conf + fi + systemctl --user start podman.socket || true + export PODMAN_SYSTEMD_UNIT=podman.socket + ''; + + # Provides a fake "docker" binary mapping to podman + dockerCompat = pkgs.runCommandNoCC "docker-podman-compat" {} '' + mkdir -p $out/bin + ln -s ${pkgs.podman}/bin/podman $out/bin/docker + ''; + + cargo-config = + craneLib.buildPackage + { + pname = "cargo-config"; + version = "0.1.1"; + cargoArtifacts = null; + + src = pkgs.fetchFromGitHub { + owner = "wesleywiser"; + repo = "cargo-config"; + rev = "cf576faf65913615ed424914daa960800ed3ebc4"; + sha256 = "sha256-HrITNTfjBppOH1MhfZHfzHc6N8ymcm7vaiBI94ctUOA="; + fetchSubmodules = true; + }; + }; + + buildInputs = with pkgs; [ + # Compilation + rust-bin + + # Utils + cowsay + lolcat + tokio-console + + # Cargo utilities + bacon + cargo-bloat # check binaries size (which is fun but not terriby useful?) + cargo-cache # cargo cache -a + cargo-config + cargo-expand # for macro expension + cargo-spellcheck # Spellcheck documentation + + # Podman + dockerCompat + podman # Docker compat + runc # Container runtime + conmon # Container runtime monitor + skopeo # Interact with container registry + slirp4netns # User-mode networking for unprivileged namespaces + fuse-overlayfs # CoW for images, much faster than default vfs + + # Build Redox + ant + autoconf + automake + bison + cmake + curl + doxygen + expat + expect + file + flex + fuse + gmp + gnumake + gnupatch + gperf + just + libjpeg + libpng + libtool + llvmPackages.clang + llvmPackages.llvm + lua + m4 + meson + nasm + perl + perl540Packages.HTMLParser + perl540Packages.Po4a + pkgconf + podman + protobuf + (python3.withPackages (ps: with ps; [mako])) + qemu_kvm + rust-cbindgen + scons + SDL + syslinux + texinfo + unzip + waf + wget + xdg-utils + zip + ]; + in { + devShells.default = with pkgs; + mkShell { + inherit buildInputs; + + LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; + NIX_SHELL_BUILD = "1"; + shellHook = '' + # Install required configuration + ${podmanSetupScript} + echo "Redox environment loaded" | cowsay | lolcat + ''; + }; + }); +} diff --git a/mk/depends.mk b/mk/depends.mk index ed80f56..68ed63b 100644 --- a/mk/depends.mk +++ b/mk/depends.mk @@ -3,10 +3,15 @@ # Don't check for Rust/Cargo if you will be using Podman ifneq ($(PODMAN_BUILD),1) +# don’t check for Rust and Cargo if building on a Nix system +ifneq ($(NIX_SHELL_BUILD),1) + ifeq ($(shell which rustup),) $(error rustup not found, install from "https://rustup.rs/") endif +endif + ifeq ($(shell which cbindgen),) $(error cbindgen not found, install from crates.io or from your package manager) endif @@ -19,9 +24,11 @@ ifeq ($(shell which just),) $(error 'just' not found, install from crates.io or from your package manager) endif +ifneq ($(NIX_SHELL_BUILD),1) CARGO_CONFIG_VERSION=0.1.1 ifeq ($(shell env -u RUSTUP_TOOLCHAIN cargo install --list | grep '^cargo-config v$(CARGO_CONFIG_VERSION):$$'),) $(error cargo-config $(CARGO_CONFIG_VERSION) not found, run "cargo install --force --version $(CARGO_CONFIG_VERSION) cargo-config") endif +endif endif diff --git a/mk/fstools.mk b/mk/fstools.mk index a3acde9..31f39f5 100644 --- a/mk/fstools.mk +++ b/mk/fstools.mk @@ -16,6 +16,9 @@ else touch $@ endif +$(INSTALLER): CC = +$(INSTALLER): TARGET = $(HOST_TARGET) +$(INSTALLER): RUSTUP_TOOLCHAIN = $(INSTALLER): installer $(HOST_CARGO) build --bin redox_installer --manifest-path installer/Cargo.toml --release From 099e04e77a0e78ae17144219f78cfa231637b11d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 18 Feb 2025 15:47:16 -0700 Subject: [PATCH 4/6] Update cookbook --- cookbook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook b/cookbook index 69c6dd2..9c54dac 160000 --- a/cookbook +++ b/cookbook @@ -1 +1 @@ -Subproject commit 69c6dd237a6cfca6ac5b81866cb18843b783f57a +Subproject commit 9c54dacdf3dd063b9a497f223757821996ce9619 From 0cecf5558d5ed85ac1842eb7ddec6ea065d2ef74 Mon Sep 17 00:00:00 2001 From: accessviolation Date: Wed, 19 Feb 2025 00:22:44 +0100 Subject: [PATCH 5/6] Add missing 'patchelf' dependency for platforms in 'native_bootstrap.sh' --- native_bootstrap.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/native_bootstrap.sh b/native_bootstrap.sh index c23904e..66f5555 100755 --- a/native_bootstrap.sh +++ b/native_bootstrap.sh @@ -150,6 +150,7 @@ osx_macports() install_macports_pkg "p5-html-parser" install_macports_pkg "doxygen" install_macports_pkg "gpatch" + install_macports_pkg "patchelf" install_macports_pkg "automake" install_macports_pkg "scons" install_macports_pkg "gmake" @@ -219,6 +220,7 @@ osx_homebrew() install_brew_pkg "llvm" install_brew_pkg "doxygen" install_brew_pkg "gpatch" + install_brew_pkg "patchelf" install_brew_pkg "automake" install_brew_pkg "scons" install_brew_pkg "lua" @@ -290,6 +292,7 @@ freebsd() install_freebsd_pkg "llvm" install_freebsd_pkg "doxygen" install_freebsd_pkg "patch" + install_freebsd_pkg "patchelf" install_freebsd_pkg "automake" install_freebsd_pkg "scons" install_freebsd_pkg "lua54" @@ -328,6 +331,7 @@ archLinux() curl \ file \ patch \ + patchelf \ automake \ scons \ waf \ @@ -442,6 +446,7 @@ ubuntu() nasm \ ninja-build \ patch \ + patchelf \ perl \ pkg-config \ po4a \ @@ -570,6 +575,7 @@ fedora() gcc-c++ \ openssl \ patch \ + patchelf \ automake \ perl-Pod-Html \ perl-FindBin \ @@ -636,6 +642,7 @@ suse() "perl-HTML-Parser" "m4" "patch" + "patchelf" "scons" "pkgconf" "syslinux-utils" @@ -832,6 +839,7 @@ solus() libtool-devel \ po4a \ patch \ + patchelf \ bison \ flex \ gperf \ From 7357d4aabfd926035349b3297252477436595406 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Wed, 19 Feb 2025 21:02:18 +0100 Subject: [PATCH 6/6] build cargo-config with nixpkg's rustPlatform instead of craneLib --- flake.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index fc709cc..495a30f 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,10 @@ extensions = ["rust-analyzer" "rust-src"]; targets = ["x86_64-unknown-redox"]; }; - craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust-bin; + rustPlatform = pkgs.makeRustPlatform { + cargo = rust-bin; + rustc = rust-bin; + }; # Podman config taken from https://nixos.wiki/wiki/Podman and https://gist.github.com/adisbladis/187204cb772800489ee3dac4acdd9947 # Provides a script that copies required files to ~/ @@ -71,12 +74,9 @@ ln -s ${pkgs.podman}/bin/podman $out/bin/docker ''; - cargo-config = - craneLib.buildPackage - { + cargo-config = rustPlatform.buildRustPackage rec { pname = "cargo-config"; version = "0.1.1"; - cargoArtifacts = null; src = pkgs.fetchFromGitHub { owner = "wesleywiser"; @@ -85,6 +85,9 @@ sha256 = "sha256-HrITNTfjBppOH1MhfZHfzHc6N8ymcm7vaiBI94ctUOA="; fetchSubmodules = true; }; + + # useFetchCargoVendor = true; # this is recommended, but fails in some python code? + cargoHash = "sha256-yQpIKclZ8KLE5JGkB/tjKZA8ezaD9SbUthDsuBXYZjQ="; }; buildInputs = with pkgs; [ @@ -162,7 +165,7 @@ in { devShells.default = with pkgs; mkShell { - inherit buildInputs; + packages = buildInputs; LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; NIX_SHELL_BUILD = "1";