diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000000..77158bafbf90b --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1714253743, + "narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1708475490, + "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0e74ca98a74bc7270d28838369593635a5db3260", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1714058656, + "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000000..fe7b499bdcb8a --- /dev/null +++ b/flake.nix @@ -0,0 +1,200 @@ +{ + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + # Dev tools + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + + outputs = inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + imports = [ + inputs.treefmt-nix.flakeModule + ]; + perSystem = { config, self', pkgs, lib, system, ... }: + let + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + nonRustDeps = [ + pkgs.pkg-config + pkgs.stdenv.cc.cc + pkgs.zlib + pkgs.openssl + pkgs.protobuf + ]; + rust-toolchain = pkgs.symlinkJoin { + name = "rust-toolchain"; + paths = [ + pkgs.rustc + pkgs.cargo + pkgs.clippy + pkgs.cargo-watch + pkgs.rust-analyzer + pkgs.rustPlatform.rustcSrc + (pkgs.python3.withPackages (python-pkgs: [ + python-pkgs.numpy + python-pkgs.pyarrow + ])) + pkgs.maturin + ]; + }; + NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + pkgs.stdenv.cc.cc + pkgs.zlib + pkgs.openssl + pkgs.protobuf + ]; + + + # see: https://gist.github.com/ChadSki/926e5633961c9b48131eabd32e57adb2 + # Conda installs it's packages and environments under this directory + installationPath = "~/.conda"; + miniconda-version = "4.3.11"; + + # Downloaded Miniconda installer + minicondaScript = pkgs.stdenv.mkDerivation rec { + name = "miniconda-${miniconda-version}"; + version = miniconda-version; + src = pkgs.fetchurl { + url = "https://repo.continuum.io/miniconda/Miniconda3-${miniconda-version}-Linux-x86_64.sh"; + sha256 = "1f2g8x1nh8xwcdh09xcra8vd15xqb5crjmpvmc2xza3ggg771zmr"; + }; + # Nothing to unpack. + unpackPhase = "true"; + # Rename the file so it's easier to use. The file needs to have .sh ending + # because the installation script does some checks based on that assumption. + # However, don't add it under $out/bin/ becase we don't really want to use + # it within our environment. It is called by "conda-install" defined below. + installPhase = '' + mkdir -p $out + cp $src $out/miniconda.sh + ''; + # Add executable mode here after the fixup phase so that no patching will be + # done by nix because we want to use this miniconda installer in the FHS + # user env. + fixupPhase = '' + chmod +x $out/miniconda.sh + ''; + }; + + # Wrap miniconda installer so that it is non-interactive and installs into the + # path specified by installationPath + conda = pkgs.runCommand "conda-install" + { buildInputs = [ pkgs.makeWrapper minicondaScript ]; } + '' + mkdir -p $out/bin + makeWrapper \ + ${minicondaScript}/miniconda.sh \ + $out/bin/conda-install \ + --add-flags "-p ${installationPath}" \ + --add-flags "-b" + ''; + + in + { + # Rust package + packages.default = pkgs.rustPlatform.buildRustPackage { + inherit (cargoToml.package) name version; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + }; + + # Rust dev environment + devShells.default = pkgs.mkShell { + inherit NIX_LD_LIBRARY_PATH; + inputsFrom = [ + config.treefmt.build.devShell + ]; + shellHook = '' + # For rust-analyzer 'hover' tooltips to work. + export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} + + echo + echo "🍎🍎 Run 'just ' to get started" + just + ''; + buildInputs = nonRustDeps; + nativeBuildInputs = with pkgs; [ + just + rust-toolchain + (pkgs.hiPrio pkgs.bashInteractive) # needed so it doesn't mangle terminal in vscode + python311 + pre-commit + ]; + # RUST_BACKTRACE = 1; + }; + + # NIXPKGS_ALLOW_UNFREE=1 nix develop '.#conda' --impure + # conda install -c conda-forge boa conda-verify + # NOTE: conda env create fails probably because I am not on nvidia + # conda env create -f ./conda/environments/datafusion-dev.yaml -n datafusion-dev + # > ResolvePackageNotFound: cudf + devShells.conda = (pkgs.buildFHSUserEnv { + name = "conda"; + targetPkgs = pkgs: ( + with pkgs; [ + autoconf + binutils + conda + cudatoolkit + curl + freeglut + gcc11 + git + gitRepo + gnumake + gnupg + gperf + libGLU libGL + libselinux + linuxPackages.nvidia_x11 + m4 + ncurses5 + procps + stdenv.cc + unzip + util-linux + wget + xorg.libICE + xorg.libSM + xorg.libX11 + xorg.libXext + xorg.libXi + xorg.libXmu + xorg.libXrandr + xorg.libXrender + xorg.libXv + zlib + ] + ); + profile = '' + # cuda + export CUDA_PATH=${pkgs.cudatoolkit} + # export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib + export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib" + export EXTRA_CCFLAGS="-I/usr/include" + # conda + export PATH=${installationPath}/bin:$PATH + # Paths for gcc if compiling some C sources with pip + export NIX_CFLAGS_COMPILE="-I${installationPath}/include" + export NIX_CFLAGS_LINK="-L${installationPath}lib" + # Some other required environment variables + export FONTCONFIG_FILE=/etc/fonts/fonts.conf + export QTCOMPOSE=${pkgs.xorg.libX11}/share/X11/locale + ''; + }).env; + + # Add your auto-formatters here. + # cf. https://numtide.github.io/treefmt/ + treefmt.config = { + projectRootFile = "flake.nix"; + programs = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + }; + }; + }; + }; +}