Commit Graph

90 Commits

Author SHA1 Message Date
Ivan Petkov
a2dd1b8ad4
Allow configuring which cargo profile is selected 2022-07-23 11:10:45 -07:00
Ivan Petkov
bce972e03b
Add cargoHelperFunctionsHook
* It will automatically capture and log all `cargo` invocations
2022-07-23 11:11:36 -07:00
Ivan Petkov
7fc1a8fec3
Remove --workspace from all default commands
* This allows for fewer assumptions about the project structure
* The old behavior can easily be brought back by setting `cargoExtraArgs
  = "--workspace";` in any derivation
2022-07-20 19:27:52 -07:00
Ivan Petkov
9eb8357f53
Reformat nix files 2022-07-09 20:20:15 -07:00
Ivan Petkov
b9b1c322a5
mkDummySrc: fix handling when src is already filtered 2022-06-29 20:49:12 -07:00
Ivan Petkov
43aab4b7d8
Add .overrideToolchain convenience method 2022-06-26 11:25:40 -07:00
Ivan Petkov
49141d2b37
Import groupBy from lib not builtins
* lib.groupBy will default to builtins.groupBy if available, so it is
  safer to use
2022-06-07 14:51:20 -07:00
Yusuf Bera Ertan
8f0b89244f
fix(mkDummySrc): remove IFD trigger by not checking if cargo lock path exists, the build will fail if it doesnt 2022-06-05 14:04:20 +03:00
Ivan Petkov
6fd4d85dac
buildDepsOnly: remove (now unnecessary) cargoLock check
* Previously we would manually copy over any Cargo.lock file from the
  source to the dummified source
* Now, `mkDummySrc` will implicitly copy the file if it is present, or
  ignore it if missing, so this check is a bit overzealous now
* Loosening this check also allows callers to sneak in their own
  Cargo.lock file (e.g. through a patch phase) while still avoiding IFD
2022-06-02 20:51:28 -07:00
Ivan Petkov
c2acd4b443
Minor cleanup 2022-06-02 19:49:44 -07:00
adisbladis
a1e56fba69 Stop passing around fromTOML
It's a builtin that we can just use directly.
2022-06-03 02:01:02 +08:00
adisbladis
2491382d63 Remove internal dependency on toTOML 2022-06-03 02:01:02 +08:00
Ivan Petkov
4bd60ab128
Drop compatibility for Nix versions below 2.8.1 2022-06-01 17:05:52 -07:00
Ivan Petkov
4f2b1c43c9
mkDummySrc: fix cache invalidation if src is flake root 2022-05-16 20:10:38 -07:00
Ivan Petkov
c8b8597ecb
Merge pull request #26 from firestack/fix/relative-paths
fix(nix-relative-paths): quote relative paths to allow for external sources
2022-05-10 17:21:29 -07:00
Kayla Firestack
e908c1afea fix(nix-relative-paths): quote relative paths to allow for external sources
when trying to use crane with a non local src (eg, not `./.`) we get the error
```
$ nix flake show
<...>
error: access to absolute path '/Cargo.toml' is forbidden in pure eval mode (use '--impure' to override)
(use '--show-trace' to show detailed location information)
```

To fix this, we quote the relative paths so to properly append them to the base path.

https://nixos.wiki/wiki/Nix_Expression_Language#Coercing_a_relative_path_with_interpolated_variables_to_an_absolute_path_.28for_imports.29

## Reproduction flake
```
{
  description = "Build a cargo project without extra checks";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

    crane = {
      url = "github:ipetkov/crane";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    external-crate-source = {
      url = "github:ray-kast/empress";
      flake = false;
    };

    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, crane, flake-utils, external-crate-source, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};

        test-crate = crane.lib.${system}.buildPackage {
          src = external-crate-source.outPath;
        };
      in
      {
        packages.default = test-crate;
      });
}
```
2022-05-10 10:00:00 -04:00
Ivan Petkov
b47fafa717
buildDepsOnly: add --all-targets to default cargoCheckCommand
This allows caching all artifacts (including from dev-dependencies) such
that tools like clippy don't have to generate them every time they run.
2022-05-08 19:46:58 -07:00
Ivan Petkov
762784a8c5
Add compatibility fallback for builtins.groupBy 2022-02-20 14:20:21 -08:00
Ivan Petkov
f8d1e70dfc
Fix handling of git repos whose rev is not on the main branch
* When Nix fetches a git repo it will only look for the specified
  revision only starting from the main branch (apparently fetching
  arbitrary revisions from a repository has some security implications)
* If a ref (i.e. branch or tag) is not specified, Nix will only fetch
  the repo's main branch
* To remedy this we will supply Nix with the branch or tag (if specified
  in the Cargo.lock) to help it find the specified revision
* If cargo does not specify a branch or tag for us, we'll set `allRefs =
  true` so that Nix can try fetching all possible branches and tags
  before trying to check out the locked revision
2022-02-18 18:10:53 -08:00
Ivan Petkov
5c8e7f732f
Fix callPackage scopes for build hooks so cross compiling works
* Previously all build hooks were instantiated in a single
  `callPackages` call which led to several issues:
  - changes via `lib.overrideScope'` were ignored because the build
    hooks were only ever instantiated with the nixpkgs instance of our
    flake (not whatever overlays the caller may have made)
  - the pkgs splicing was not done quite right, meaning when we pull in
    the build hooks as nativeBuildInputs the splicing wasn't picking up
    the overridden versions of `cargo` but was instead trying to
    recompile the nixpkgs version each time
2022-02-14 18:31:45 -08:00
Ivan Petkov
78359792ae
Form paths by concatenating a string suffix not a path
* Seems like Nix can get unhappy if a path fragment is evaluated too
  eagerly, giving errors like
  `error: access to absolute path '/Cargo.toml' is forbidden in pure eval mode (use '--impure' to override)`
* Changing to using string manipulation seems to resolve the issue
2022-02-13 12:50:43 -08:00
Ivan Petkov
a56b6d1c56
cargoTarpaulin: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoTarpaulin` invocations with other
  derivations
2022-02-13 09:36:31 -08:00
Ivan Petkov
3024283855
cargoClippy: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoClippy` invocations with other
  derivations
2022-02-13 09:34:26 -08:00
Ivan Petkov
472d7ffc99
Handle case where a git repo contains multiple crates 2022-02-10 20:32:31 -08:00
Ivan Petkov
e2c665091e
Add test that source prefix remapping works 2022-02-09 20:54:56 -08:00
Ivan Petkov
469f4a5fde
Fix git dependency handling of overlapping repos 2022-02-09 20:22:07 -08:00
Ivan Petkov
ca73fc5305
Add support for git dependencies 2022-02-07 20:03:12 -08:00
Ivan Petkov
1ab0cad98c
Split out registry vendoring to vendorCargoRegistries 2022-02-06 17:16:49 -08:00
Ivan Petkov
90d5ad84c4
cargoFmt: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoFmt` invocations with other
  derivations
2022-02-10 21:02:48 -08:00
Ivan Petkov
d4b5f8abe6
chore: switch to runCommandLocal to reduce network pressure 2022-01-30 16:10:41 -08:00
Ivan Petkov
492076c765 Rename registryFromGitIndex input to indexUrl for consistency 2022-01-30 23:58:56 +00:00
Ivan Petkov
47fbae6dc3 Add support for alternative cargo registries 2022-01-30 23:58:56 +00:00
Ivan Petkov
5e44613211 Make crate downloads aware of alternative registries 2022-01-30 23:58:56 +00:00
Ivan Petkov
5bae4b91c1 Optimize searching for cargo configuration files
* Rather than recursively look up all paths in a given project and then
  filtering for cargo-specific files, we now use our own customized
  traversal method to only capture the results we want.
2022-01-30 23:58:56 +00:00
Ivan Petkov
8f6b608ca1
Inline Cargo.{toml,lock} checks in buildDepsOnly 2022-01-16 18:24:13 -08:00
Ivan Petkov
aeb598b174
Add cargoTarpaulin 2022-01-16 18:16:21 -08:00
Ivan Petkov
438154f265
Add cargoFmt 2022-01-16 17:49:39 -08:00
Ivan Petkov
13c6a4cdce
crateNameFromCargoToml: use 0.0.1 as fallback version 2022-01-15 19:58:31 -08:00
Ivan Petkov
92d185d877
Fix some formatting 2022-01-15 19:56:46 -08:00
Ivan Petkov
72bb21ee86
crateNameFromCargoToml: fix parameter validation
* Previously the check was overzealous and it was impossible to only
  specify `cargoToml` (since both other parameters would be null)
* Instead, we take advantage of Nix's laziness and only throw when
  needed
2022-01-09 15:50:21 -08:00
Ivan Petkov
3f82111135
Merge vendorCargoDepsFromArgs into vendorCargoDeps 2022-01-08 17:52:10 -08:00
Ivan Petkov
bd27ed8f73
cargoClippy: remove unused parameter 2022-01-08 17:24:57 -08:00
Ivan Petkov
49ef407216
Rename doCopyTargetToOutput to doInstallCargoArtifacts
* Similarly rename `installCargoTargetDirHook` to
  `installCargoArtifactsHook`
* The intention is to highlight that "install" implies "copy to output"
  and not anywhere else
* Also avoids the potential confusion of "cargo target dir" (location of
  cargo's artifacts) with "cargo target" (which is the target
  architecture/platform we want cargo to build for)
2022-01-08 17:14:05 -08:00
Ivan Petkov
4099e352b8
cargoClippy: do not force cargo target dir to be installed
* Just having the derivation succeed is evidence enough and copying the
  artifacts isn't strictly necessary
2022-01-08 17:03:06 -08:00
Ivan Petkov
263fe7c78f
Fix operator precedence typo
* In Nix the `or` operator has higher precedence than function
  application, therefore `x or y z` parses as `(x or y) z`
2022-01-08 16:57:45 -08:00
Ivan Petkov
1c9633f4aa
mkDummySrc: allow cargoLock location to be passed in by caller
* This can potentially allow callers to build crates which may not have
  a Cargo.lock in their source but needs to be passed in from
  _elsewhere_
2022-01-07 20:54:07 -08:00
Ivan Petkov
44e9060497
Print cargo version before building
* Just for the benefit of being able to tell at which cargo version is
  used at a glance
2022-01-07 20:48:52 -08:00
Ivan Petkov
abc2c8c418
mkDummySrc: drop dummy lib.rs by default, not main.rs
* There are some edge cases where cargo will allow a lib.rs file to be
  present but not a main.rs (e.g. a binary cannot be called "examples",
  which will happen if the crate is called that and a main.rs file is
  present)
2022-01-07 20:42:24 -08:00
Ivan Petkov
1c8034c0d9
Update mkDummySrc to support cargo workspaces 2022-01-07 17:36:31 -08:00
Ivan Petkov
791f1b2241
Add tests for mkDummySrc
* Also fix a bug with copying over .cargo/config files
2022-01-05 20:46:05 -08:00