From d7a681ef0d951ec5f3283df5d2f0bd73991b7c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Fri, 2 Aug 2024 13:13:10 +0200 Subject: [PATCH 1/3] add a flake.nix file for the development environment, add direnv-related files to .gitignore --- .gitignore | 3 +++ flake.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 36990affc73..829d3179cf9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ lib*.a *.iml ### macOS ### .DS_Store + +### direnv ### +/.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..e76a789238b --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "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": 1720633750, + "narHash": "sha256-N8apMO2pP/upWeH+JY5eM8VDp2qBAAzE+OY5LRW6qpw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "54bc082f5a7219d122e74fe52c021cf59fed9d6f", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "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 00000000000..b0d95ef2478 --- /dev/null +++ b/flake.nix @@ -0,0 +1,70 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + libselinuxPath = with pkgs; + lib.makeLibraryPath [ + libselinux + ]; + libaclPath = with pkgs; + lib.makeLibraryPath [ + acl + ]; + + build_deps = with pkgs; [ + clang + llvmPackages.bintools + rustup + + pre-commit + + # debugging + gdb + ]; + gnu_testing_deps = with pkgs; [ + autoconf + automake + bison + gnum4 + gperf + gettext + texinfo + ]; + in { + devShell = pkgs.mkShell { + buildInputs = build_deps ++ gnu_testing_deps; + + RUSTC_VERSION = "1.75"; + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [pkgs.llvmPackages_latest.libclang.lib]; + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ + ''; + + SELINUX_INCLUDE_DIR = ''${pkgs.libselinux.dev}/include''; + SELINUX_LIB_DIR = libselinuxPath; + SELINUX_STATIC = "0"; + + # Necessary to build GNU. + LDFLAGS = ''-L ${libselinuxPath} -L ${libaclPath}''; + + # Add precompiled library to rustc search path + RUSTFLAGS = + (builtins.map (a: ''-L ${a}/lib'') [ + ]) + ++ [ + ''-L ${libselinuxPath}'' + ''-L ${libaclPath}'' + ]; + }; + }); +} From 852161092185a41a7fd290063a7f84cc686ac0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Fri, 2 Aug 2024 13:23:08 +0200 Subject: [PATCH 2/3] patch build-gnu.sh for NixOS --- util/build-gnu.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 38df18daeb2..b004b9bd510 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -371,3 +371,8 @@ sed -i "s/color_code='0;31;42'/color_code='31;42'/" tests/ls/quote-align.sh # Slightly different error message sed -i 's/not supported/unexpected argument/' tests/mv/mv-exchange.sh +# Most tests check that `/usr/bin/tr` is working correctly before running. +# However in NixOS/Nix-based distros, the tr coreutil is located somewhere in +# /nix/store/xxxxxxxxxxxx...xxxx/bin/tr +# We just replace the references to `/usr/bin/tr` with the result of `$(which tr)` +sed -i 's/\/usr\/bin\/tr/$(which tr)/' tests/init.sh From f07db1b075410331037d09d133945c82f154bd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Wed, 23 Oct 2024 23:38:31 +0200 Subject: [PATCH 3/3] Add .envrc --- .envrc | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 00000000000..720e019335c --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +fi + +use flake