redbadger / crux

Cross-platform app development in Rust
https://redbadger.github.io/crux/
Apache License 2.0
1.74k stars 63 forks source link

Nix package manager support #83

Open interroobang opened 1 year ago

interroobang commented 1 year ago

Hi there! Is there any plan about nix support? Thanks in advance.

obmarg commented 1 year ago

Hi @interroobang

I don't think we've got any specific plans to do things with nix. I've not used nix for a while, but I would have thought crux would just work if you were using nix? Is there some specific functionality we'd need to add to make that the case?

interroobang commented 1 year ago

Thanks for reply. There is bunch of framework and tools. Also platforms to support. I really love that ffi approach you build, I just don't want to install and define them one by one.

If there could be an universal configuration, installation file for needs, it will be good. Just nix first come to in my mind :)

Thanks again this work and project. It's very promising in my opinion.

I could close issue if you want.

obmarg commented 1 year ago

Ah, I see. So are you imagining nix as a way of scaffolding out a project or managing that scaffolding as you maintain the project?

interroobang commented 1 year ago

Ah, I see. So are you imagining nix as a way of scaffolding out a project or managing that scaffolding as you maintain the project?

Let me share something.

{
  description = "Nix flake for CRUX Hello World";

  # Flake inputs
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs"; # also valid: "nixpkgs"
    rust-overlay.url = "github:oxalica/rust-overlay"; # A helper for Rust + Nix
  };

  # Flake outputs
  outputs = { self, nixpkgs, rust-overlay }:
    let
      # Overlays enable you to customize the Nixpkgs attribute set
      overlays = [
        # Makes a `rust-bin` attribute available in Nixpkgs
        (import rust-overlay)
        # Provides a `rustToolchain` attribute for Nixpkgs that we can use to
        # create a Rust environment
        (self: super: {
          rustToolchain = super.rust-bin.stable.latest.default;
        })
      ];

      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
        "aarch64-apple-darwin"
        "aarch64-apple-ios"
        "aarch64-apple-ios-sim"
        "aarch64-linux-android"
        "wasm32-unknown-unknown"
        "x86_64-apple-ios"
      ];

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit overlays system; };
      });
    in
    {
      # Development environment output
      devShells = forAllSystems ({ pkgs }: {
        default = pkgs.mkShell {
          # The Nix packages provided in the environment
          packages = (with pkgs; [
            # The package provided by our custom overlay. Includes cargo, Clippy, cargo-fmt,
            # rustdoc, rustfmt, and other tools.
            rustToolchain
            rustup
            nodejs-18_x
            nodePackages_latest.pnpm
            trunk
            deno
          ]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
        };
      });
    };
}

Just a copy of a configuration that I found for being an example. I tried and it works.

For trial, just copy the code, fill into flake.nix file on project root and type nix develop

I just don't want to install and configure all tools one by one, as I said before. By the way, I will try to make a flake file for all dependencies for all targets....

Thanks for reply.

Thanks for the crux project and your effort's.

Edit: Please init git repo in working directory and add flake.nix file to local repo.

ahirner commented 1 year ago

Thanks for the flake.nix @interroobang.

I just don't want to install and configure all tools one by one

Is your intent to only build the core for crux or also a "shell" around it with nix? If the aim is an end-to-end solution, I think one could create some great flake.nix templates, e.g. with https://github.com/tadfisher/android-nixpkgs.

Disclaimer: just got into crux and evaluating a few options for the best e2e developer experience.