!FBuJyWXTGcGtHTPphC:nixos.org

Nix Rust

712 Members
Rust163 Servers

Load older messages


SenderMessageTime
19 Oct 2022
@aktaboot:tchncs.deaktaboot * there's fenix, naersk and oxalica for building with rust ? 18:29:24
@aktaboot:tchncs.deaktaboot * there's fenix, naersk and oxalica for building rust ? 18:29:33
@aktaboot:tchncs.deaktabootwill check naersk ig18:29:46
@charles:computer.surgeryCharles ⚡️i don't like overlays so i don't use oxalica18:29:52
@charles:computer.surgeryCharles ⚡️

steal this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";

    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    { self
    , nixpkgs
    , flake-utils

    , fenix
    }: flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = nixpkgs.legacyPackages.${system};
      rust = fenix.packages.${system};
      cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
    in
    {
      packages.default = (pkgs.makeRustPlatform {
        inherit (rust.stable) cargo rustc;
      }).buildRustPackage {
        pname = cargoToml.package.name;
        version = cargoToml.package.version;

        cargoLock.lockFile = ./Cargo.lock;

        src = builtins.filterSource
          # Exclude `target` because it's huge
          (path: type: !(type == "directory" && baseNameOf path == "target"))
          ./.;

        # This is disabled so CI can be impure and not break Nix builds
        doCheck = false;
      };

      devShells.default = self.packages.${system}.default.overrideAttrs (old: {
        # Rust Analyzer needs to be able to find the path to default crate
        # sources, and it can read this environment variable to do so
        RUST_SRC_PATH = "${rust.stable.rust-src}/lib/rustlib/src/rust/library";

        nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ (with pkgs; [
          file
          ncurses
          nixpkgs-fmt
          shellcheck
          shfmt
        ]) ++ (with rust; [
          latest.rustfmt
          stable.clippy
          stable.rust-src
        ]) ++ (with pkgs.nodePackages; [
          markdownlint-cli
        ]);
      });

      checks = {
        packagesDefault = self.packages.${system}.default;
        devShellsDefault = self.devShells.${system}.default;
      };
    });
}
18:30:24
@charles:computer.surgeryCharles ⚡️wait no18:30:37
@charles:computer.surgeryCharles ⚡️ *

steal this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";

    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    naersk = {
      url = "github:nix-community/naersk";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    { self
    , nixpkgs
    , flake-utils

    , fenix
    , naersk
    }: flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = nixpkgs.legacyPackages.${system};
      toolchain = fenix.packages.${system}.stable;
    in
    {
      packages.default = (pkgs.callPackage naersk {
        inherit (toolchain) rustc cargo;
      }).buildPackage {
        src = ./.;
      };

      devShells.default = pkgs.mkShell {
        # Rust Analyzer needs to be able to find the path to default crate
        # sources, and it can read this environment variable to do so
        RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library";

        # Development tools
        nativeBuildInputs = (with toolchain; [
          cargo
          clippy
          rust-src
          rustc

          # Always use nightly rustfmt because most of its options are unstable
          fenix.packages.${system}.latest.rustfmt
        ]) ++ (with pkgs; [
          file
          ncurses
          nixpkgs-fmt
          shellcheck
          shfmt
        ]) ++ (with pkgs.nodePackages; [
          markdownlint-cli
        ]);
      };

      checks = {
        packagesDefault = self.packages.${system}.default;
        devShellsDefault = self.devShells.${system}.default;
      };
    });
}
18:31:08
@charles:computer.surgeryCharles ⚡️okay now steal it18:31:12
@charles:computer.surgeryCharles ⚡️you'll just need to add your repo as an input, change line 33, and get rid of the devshell stuff18:32:09
@charles:computer.surgeryCharles ⚡️then it should work18:32:12
@charles:computer.surgeryCharles ⚡️except for the graphics stuff18:32:15
@charles:computer.surgeryCharles ⚡️you'll need to add other things for that18:32:19
@aktaboot:tchncs.deaktabootokay will try thanks18:35:26
@charles:computer.surgeryCharles ⚡️for graphics, maybe something like this will be a good start: https://or.computer.surgery/charles/maxels/-/blob/main/flake.nix#L38-5518:35:50
@aktaboot:tchncs.deaktabootwhat do you mean by graphics ?18:36:58
@charles:computer.surgeryCharles ⚡️well, it looks like the thing you're building depends on winit and such18:37:20
@charles:computer.surgeryCharles ⚡️so it's probably a graphical application18:37:35
@aktaboot:tchncs.deaktabootit is18:37:42
@charles:computer.surgeryCharles ⚡️and so you need to give it x11 libs so it can do graphics18:37:52
@charles:computer.surgeryCharles ⚡️and vulkan or whatever so it can bother the gpu to do stuff18:38:02
@aktaboot:tchncs.deaktabootI'm on wayland but Ig it doesn't matter18:38:18
@charles:computer.surgeryCharles ⚡️then you'll probably need to add wayland things18:38:31
@aktaboot:tchncs.deaktabootoh18:38:41
@charles:computer.surgeryCharles ⚡️unfortunately i have an nvidia gpu so i'm not allowed to run wayland and thus i won't be of much help there18:39:29
@aktaboot:tchncs.deaktabootno problemo, I'll figure it out :D18:40:03
@charles:computer.surgeryCharles ⚡️the linker errors should be pretty clear on what libraries you need18:40:17
@aktaboot:tchncs.deaktaboot does the flake have to be named flake.nix ? 18:42:58
@charles:computer.surgeryCharles ⚡️i believe so18:43:07
@benjamin:computer.surgerybenjamin ⚡️
In reply to @charles:computer.surgery
unfortunately i have an nvidia gpu so i'm not allowed to run wayland and thus i won't be of much help there
don't the proprietary drivers support dmabuf now?
19:04:57
@charles:computer.surgeryCharles ⚡️all i know is i still get sassy error messages from sway19:05:20

Show newer messages


Back to Room ListRoom Version: 6