!FBuJyWXTGcGtHTPphC:nixos.org

Nix Rust

700 Members
Rust155 Servers

Load older messages


SenderMessageTime
19 Oct 2022
@aktaboot:tchncs.deaktabootI thought it woud be the other way around18:14:21
@charles:computer.surgeryCharles ⚡️ no, fenix.packages.${system}.${thing}.toolchain is a derivation that includes everything from ${thing} which is generally undesirable 18:14:55
@charles:computer.surgeryCharles ⚡️here's how to include devtools in your devshell using my methodology, plus a hack to always use nightly rustfmt because of all the "unstable" options: https://or.computer.surgery/charles/engage/-/blob/main/flake.nix#L42-4918:15:46
@aktaboot:tchncs.deaktabootoh okay, whereas using it in the Rust 'Platform' will only be used in the build Phase, correct ?18:16:26
@aktaboot:tchncs.deaktaboot* oh okay, whereas using it in the Rust 'Platform', it will only be used in the build Phase, correct ?18:16:54
@charles:computer.surgeryCharles ⚡️ yeah, your buildRustPackage only needs cargo and rustc to build your crates, it doesn't need clippy or rustfmt 18:17:25
@aktaboot:tchncs.deaktabootthanks, I'm pretty new still 😅 sorry for being an idiot :P18:17:44
@charles:computer.surgeryCharles ⚡️nah it's fine i also went through this18:17:54
@aktaboot:tchncs.deaktabootoh no :(18:18:46
@aktaboot:tchncs.deaktaboot collect2: fatal error: cannot find 'ld' 18:19:11
@charles:computer.surgeryCharles ⚡️bizarre18:19:55
@charles:computer.surgeryCharles ⚡️

one other change i would recommend as well:

--- flake.nix	2022-10-19 11:10:47.604364787 -0700
+++ fixed.nix	2022-10-19 11:19:38.387891737 -0700
@@ -39,6 +39,8 @@
           version = "0.5.1";

           src = uad;
+
+          cargoLock.lockFile = "${uad}/Cargo.lock";

 #          src = pkgs.fetchFromGitHub {
 #            owner = "0x192";
@@ -46,7 +48,6 @@
 #            rev = "0.5.1";
 #            sha256 = "0ByB/jRJze9B2o4S1nevy+uIvEpjMszAVB0pB6WWocU=";
 #          };
-  cargoSha256 = "D2PsUoL1v9RWV1GNGHVQWvrY8I/hNaGvSZSsQJSh08w=";

         };
     });

makes it less annoying to pull updates

18:20:23
@aktaboot:tchncs.deaktaboot
❯ nix build .#
error: No hash was found while vendoring the git dependency glutin-0.28.0. You can add
       a hash through the `outputHashes` argument of `importCargoLock`:

       outputHashes = {
         "glutin-0.28.0" = "<hash>";
       };

       If you use `buildRustPackage`, you can add this attribute to the `cargoLock`
       attribute set.
(use '--show-trace' to show detailed location information)
18:23:19
@charles:computer.surgeryCharles ⚡️one moment i'm just gonna send you a flake that works18:23:33
@aktaboot:tchncs.deaktabootnow it wants me to put all the outputHashes for some reason18:26:17
@aktaboot:tchncs.deaktaboot maybe because it's a pure build ? 18:26:44
@charles:computer.surgeryCharles ⚡️yes because it uses git dependencies18:26:58
@charles:computer.surgeryCharles ⚡️ and buildRustPackage does not use builtins.fetchGit but pkgs.fetchgit 18:27:12
@charles:computer.surgeryCharles ⚡️so you need to provide hashes18:27:15
@charles:computer.surgeryCharles ⚡️ or switch to naersk, which uses builtins.fetchGit 18:27:25
@aktaboot:tchncs.deaktaboot there's fenix, naersk and oxalica for rust ? 18:29:12
@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

There are no newer messages yet.


Back to Room ListRoom Version: 6