| 19 Oct 2022 |
aktaboot | I thought it woud be the other way around | 18:14:21 |
Charles ⚡️ | no, fenix.packages.${system}.${thing}.toolchain is a derivation that includes everything from ${thing} which is generally undesirable | 18:14:55 |
Charles ⚡️ | 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-49 | 18:15:46 |
aktaboot | oh okay, whereas using it in the Rust 'Platform' will only be used in the build Phase, correct ? | 18:16:26 |
aktaboot | * oh okay, whereas using it in the Rust 'Platform', it will only be used in the build Phase, correct ? | 18:16:54 |
Charles ⚡️ | yeah, your buildRustPackage only needs cargo and rustc to build your crates, it doesn't need clippy or rustfmt | 18:17:25 |
aktaboot | thanks, I'm pretty new still 😅 sorry for being an idiot :P | 18:17:44 |
Charles ⚡️ | nah it's fine i also went through this | 18:17:54 |
aktaboot | oh no :( | 18:18:46 |
aktaboot | collect2: fatal error: cannot find 'ld' | 18:19:11 |
Charles ⚡️ | bizarre | 18:19:55 |
Charles ⚡️ | 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 | ❯ 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 ⚡️ | one moment i'm just gonna send you a flake that works | 18:23:33 |
aktaboot | now it wants me to put all the outputHashes for some reason | 18:26:17 |
aktaboot | maybe because it's a pure build ? | 18:26:44 |
Charles ⚡️ | yes because it uses git dependencies | 18:26:58 |
Charles ⚡️ | and buildRustPackage does not use builtins.fetchGit but pkgs.fetchgit | 18:27:12 |
Charles ⚡️ | so you need to provide hashes | 18:27:15 |
Charles ⚡️ | or switch to naersk, which uses builtins.fetchGit | 18:27:25 |
aktaboot | there's fenix, naersk and oxalica for rust ? | 18:29:12 |
aktaboot | * there's fenix, naersk and oxalica for building with rust ? | 18:29:24 |
aktaboot | * there's fenix, naersk and oxalica for building rust ? | 18:29:33 |
aktaboot | will check naersk ig | 18:29:46 |
Charles ⚡️ | i don't like overlays so i don't use oxalica | 18:29:52 |
Charles ⚡️ | 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 ⚡️ | wait no | 18:30:37 |
Charles ⚡️ | * 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 ⚡️ | okay now steal it | 18:31:12 |
Charles ⚡️ | you'll just need to add your repo as an input, change line 33, and get rid of the devshell stuff | 18:32:09 |