!FBuJyWXTGcGtHTPphC:nixos.org

Nix Rust

693 Members
Rust156 Servers

Load older messages


SenderMessageTime
20 Feb 2025
@charles:computer.surgeryCharlessince i would already have a nixpkgs at the point i would need to call this19:20:55
21 Feb 2025
@amihsekai:matrix.orgthou-vow joined the room.05:49:50
@niklaskorz:korz.devNiklas KorzConcerning https://github.com/NixOS/nixpkgs/pull/383717#issuecomment-2673988082 : Was the linker setting in .cargo/config.toml previously ignored and now it's somehow picked up by buildRustPackage?09:32:47
@niklaskorz:korz.devNiklas Korz Or was clang previously accidentally exposed to buildRustPackage? 🤔 09:36:47
@kraem:ne.bul.aekraem

i'm using crane to build dependencies and the finaly binary in two different steps.
after building the dependencies i'm exporting the closure using nix-store --export $(nix-store --query --requisites ./result).
since that doesn't include the cargo-deps-.drv-files and their outputs, when i run nix-store --import and building the final binary (on a different host for example) the final-binary-step builds them, creating double work.
when trying to export them as well, some of the drv-files aren't present:

export drvs=$(nix-store -q --requisites $(nix-store --query --deriver ./result/) | grep cargo-package)
export outputs$(nix-store -q --outputs $(nix-store -q --requisites $drvs)) # <- this errors since some of the drv-files aren't present in the nix store

how can i make sure to export all the drv-files and their outputs when exporting a nix store closure?

12:58:43
@kraem:ne.bul.aekraem *

i'm using crane to build dependencies and the finaly binary in two different steps.
after building the dependencies i'm exporting the closure using nix-store --export $(nix-store --query --requisites ./result).
since that doesn't include the cargo-deps-.drv-files and their outputs, when i run nix-store --import and building the final binary (on a different host for example) the final-binary-step builds them, creating double work.
when trying to export them as well, some of the drv-files aren't present:

export drvs=$(nix-store -q --requisites $(nix-store --query --deriver ./result/) | grep cargo-package)
export outputs$(nix-store -q --outputs $(nix-store -q --requisites $drvs)) 
# the line above errors since some of the drv-files aren't present in the nix store,
# even though i'm running this after building the final closure successfully

how can i make sure to export all the drv-files and their outputs when exporting a nix store closure?

13:00:04
@kraem:ne.bul.aekraem

oh. actually i might not need the drvs, just their outputs:

deps=$(nix-store -r $(nix-store -q --requisites $(nix-store -q --deriver ./result/) | rg cargo-package))
final_closure=$(nix-store -q --requisites ./result/)
nix-store --export $deps $final_closure > /tmp/deps_and_final_closure
13:35:18
@kraem:ne.bul.aekraemthat sped things up :) 13:36:00
@morj:morj.menMorj left the room.13:55:13
@rosssmyth:matrix.orgrosssmyth

I am getting an error from a derivation I made. Specifically:

Executing cargoInstallPostBuildHook
cp: missing destination file operand after 'target/x86_64-unknown-linux-gnu/dev-tmp/'

Has anyone seen this before?

18:33:46
@rosssmyth:matrix.orgrosssmyth

The derivation itself is pretty simple

{ pkgs, stdenv, rustPlatform, ... }:

let
fs = pkgs.lib.fileset;
src = fs.difference (fs.gitTracked ./.) (fs.unions [
  ./.gitignore
  ./flake.lock
  (fs.fileFilter (file: file.hasExt "nix") ./.)
]);
in
stdenv.mkDerivation (self: {
  cargoDeps = rustPlatform.importCargoLock {
    lockFile = ./Cargo.lock;
  };

  nativeBuildInputs = [
    rustPlatform.rust.rustc
    rustPlatform.rust.cargo
  ];

  cargoBuildType = "dev";
  buildInputs = let r = rustPlatform; in [
    r.cargoSetupHook
    r.cargoBuildHook
    r.cargoInstallHook
  ];

  name = let b = builtins; in (b.fromTOML (b.readFile ./Cargo.toml)).package.name;
  src = fs.toSource {
    root = ./.;
    fileset = src;
  };

  doCheck = false;
  meta.mainProgram = self.name;
})
18:37:44
@rosssmyth:matrix.orgrosssmythI saw this before when I was doing some refactoring but was able to just revert the change so I ignored it18:38:20
@rosssmyth:matrix.orgrosssmyth* I saw this before when I was doing some refactoring on another project but was able to just revert the change so I ignored it18:38:29
22 Feb 2025
@charles:computer.surgeryCharlesi got this to work fwiw: https://gitlab.computer.surgery/charles/dotfiles/-/blob/27483e3a0aca60882d731c271f57ea95dd8da3c2/nix/default.nix#L28-3902:25:47
@charles:computer.surgeryCharlesi opened an issue about this uh usability papercut with an explanation of how to do it so others can use it as a reference: https://github.com/oxalica/rust-overlay/issues/20902:36:24
23 Feb 2025
@linucifer:envs.net@linucifer:envs.net removed their profile picture.17:24:50
@linucifer:envs.net@linucifer:envs.net removed their display name linucifer.17:24:54
@linucifer:envs.net@linucifer:envs.net left the room.17:24:57
24 Feb 2025
@wilfredallyn:matrix.orgwilfredallyn set a profile picture.00:05:17
26 Feb 2025
@samw:fairydust.spacesamw joined the room.09:50:20
27 Feb 2025
@niklaskorz:korz.devNiklas Korz

Toma: I think I just found out why cargo-about has issues with git-fetched crates in nixpkgs, and wondered if you had any idea how/if fetchCargoVendor could accomodate this use-case.

The affected crates for which cargo-about fails to read the LICENSE are from a monorepo, where the LICENSE file is referenced in each crate's Cargo.toml but is located in the parent directory (the root of the repository). For fetchCargoVendor, the parent directory is the vendor directory itself, not the root of the crate's git repository, resulting in this error:

zed-editor> 2025-02-27 15:58:07.231029 +00:00:00 [WARN] failed to validate all files specified in clarification for crate pet-virtualenv 0.1.0: unable to read path '/private/tmp/nix-build-zed-editor-0.175.5.drv-0/zed-editor-0.175.5-vendor/pet-virtualenv-0.1.0/../../LICENSE': No such file or directory (os error 2)
16:08:10
@niklaskorz:korz.devNiklas Korz *

Toma: I think I just found out why cargo-about has issues with git-fetched crates in nixpkgs, and wondered if you had any idea how/if fetchCargoVendor could accomodate this use-case.

The affected crates for which cargo-about fails to read the LICENSE are from a Cargo workspace git repo, where the LICENSE file is referenced in each crate's Cargo.toml but is located in the parent directory (the root of the repository). For fetchCargoVendor, the parent directory is the vendor directory itself, not the root of the crate's git repository, resulting in this error:

zed-editor> 2025-02-27 15:58:07.231029 +00:00:00 [WARN] failed to validate all files specified in clarification for crate pet-virtualenv 0.1.0: unable to read path '/private/tmp/nix-build-zed-editor-0.175.5.drv-0/zed-editor-0.175.5-vendor/pet-virtualenv-0.1.0/../../LICENSE': No such file or directory (os error 2)
16:08:32
@niklaskorz:korz.devNiklas Korz

Ok minor correction, the LICENSE file is not referenced by the crate's Cargo.toml but by the cargo-about config of the project that depends on them (in this case, zed-editor):

[pet-virtualenv.clarify]
license = "MIT"
[[pet-virtualenv.clarify.files]]
path = '../../LICENSE'
checksum = 'c2cfccb812fe482101a8f04597dfc5a9991a6b2748266c47ac91b6a5aae15383'
16:11:18
@setthemfree:matrix.orgundltd Hi everyone. If I add cargo and rustc to system packages and try to run cargo run or cargo build, I'm getting error: linker \`cc\` not found. I do use nix develop with mkShell most of the time, where this problem does not appear. But I am also getting the same error from emacs when trying to use eglot, and I'm not sure how to counter that. 16:27:11
@setthemfree:matrix.orgundltd Preferably I would not even have cargo and rustc in global $PATH, but I want it to work in emacs when editing rust code with eglot. 16:28:20
@emilazy:matrix.orgemily I would suggest using direnv with a Nix-based .envrc 16:33:30
@emilazy:matrix.orgemily then you can make your editor inherit your nix develop environment 16:33:42
@emilazy:matrix.orgemily (and as a bonus, get it just by cding into a project directory in your shell) 16:33:50
@setthemfree:matrix.orgundltd I'm a little scared of code executing when I cd into things, though using $PATH from various nix develop in emacs would be interesting 16:38:19
@charles:computer.surgeryCharlesdirenv requires you to manually allow each .envrc before executing it, so you have a chance to read it before you run it. It re-requests if the file changes too16:44:26

Show newer messages


Back to Room ListRoom Version: 6