Code Monkey home page Code Monkey logo

nix-cargo-integration's Introduction

nix-cargo-integration

Easily and effortlessly integrate Cargo projects with Nix.

  • Uses dream2nix to build Cargo packages and provide a development shell.
  • Has sensible defaults, and strives to be compatible with Cargo.
  • Aims to offload work from the user; comes with useful configuration options.
  • It's a flake-parts module, so you can easily include it in existing Nix code that also use flake-parts.

Documentation

Documentation for master branch is on https://flake.parts/options/nix-cargo-integration.html (alternatively, read options directly in src/interface.nix and src/modules)

Examples can be found at examples directory.

Important (mostly breaking) changes can be found in CHANGELOG.md.

Installation

Run nix flake init -t github:yusdacra/nix-cargo-integration to initialize a simple flake.nix.

You can also run nix flake init -t github:yusdacra/nix-cargo-integration#simple-crate to initialize a Cargo crate alongside the flake.nix, or nix flake init -t github:yusdacra/nix-cargo-integration#simple-workspace for a Cargo workspace with a flake.nix.

If you already have a flake.nix with flake-parts setup, just add NCI to inputs:

{
  # ...
  inputs.nci.url = "github:yusdacra/nix-cargo-integration";
  # ...
}

and then inside the mkFlake:

{
  imports = [
    inputs.nci.flakeModule
  ];
}

Tips and tricks

Ignoring Cargo.lock in Rust libraries

The official recommendation for Rust libraries used to say to add Cargo.lock to the .gitignore. This is now no longer the case, however older projects may still do this, which will cause conflicts with the way paths are evaluated when using a flake.nix. Only files tracked by the version control system (i.e. git) can be accessed during evaluation. This will manifest in the following warning:

$ nix build
trace: Cargo.lock not found for project at path path/to/project.
Please ensure the lockfile exists for your project.
If you are using a VCS, ensure the lockfile is added to the VCS and not ignored (eg. run `git add path/to/project/Cargo.lock` for git).

This project will be skipped and won't have any outputs generated.
Run `nix run .#generate-lockfiles` to generate lockfiles for projects that don't have one.

A neat fix for that is to track the path to Cargo.lock without staging it (thanks to @bew).

$ git add --intent-to-add Cargo.lock

Add --force if your Cargo.lock is listed in .gitignore.

nix-cargo-integration's People

Contributors

austreelis avatar blm768 avatar dieracdelta avatar florianfranzen avatar maltet avatar mtoohey31 avatar nickhu avatar stupremee avatar urso avatar yusdacra avatar zyansheep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nix-cargo-integration's Issues

fix(crate2nix): crate2nix not working anymore on later nixpkgs versions

Fyi with recent nixpkgs updates, I'm not able to build helix from a flake anymore, I get the following error

error: store path '/nix/store/31wx97s28zgfj8whz7xzjcqrlgc5q3jh-hrixilsnngw4wxg0fvqa3jjq3ibrkb2p-source-cra
te2nix' is not allowed to have references

I'm guessing the errors are linked somehow.
I've reverted to the latest nixpkgs released version.

Originally posted by @happysalada in #38 (comment)

Provide debug apps as packages

Additional manipulations could benefit from having the various builds available as packages (not just as apps) in the flake output.

For example, to place the derivations into a container:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixCargoIntegration = {
      url = "github:yusdacra/nix-cargo-integration";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs:
    let
      outputs = inputs.nixCargoIntegration.lib.makeOutputs {
        root = ./.;
      };
    in
    outputs // {
      packages.x86_64-linux.container =
        let pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
            mkContainer = drv:
              pkgs.dockerTools.buildImage {
                name = "${drv.name}";
                config = {
                  Cmd = [ "${drv}/bin/hello" ];
                };
              };
        in
        mkContainer outputs.defaultPackage.x86_64-linux;
    };
}

crate2nix doesn't respect the toolchain file

When using the crate2nix build platform in this test repo https://github.com/JCapucho/cargo-nix-bug the build fails with the error

 error[E0554]: `#![feature]` may not be used on the stable release channel
   --> src/main.rs:1:1
    |
  1 | #![feature( try_trait)]
    | ^^^^^^^^^^^^^^^^^^^^^^^
  
  error: aborting due to previous error
  
  For more information about this error, try `rustc --explain E0554`.
cannot build derivation '/nix/store/whlyx870515cdarmc2ib0zyg0gxpg6mk-rust_nix-bug-0.1.0-linked.drv': 1 dependencies couldn't be built

This seems to be a problem with crate2nix itself but it would be nice to at least add a note in the readme.

use crate2nix from nixpkgs ?

First of all, thank you for the software!

Just a small problem I've been running on. When using a flake that uses nix-cargo-integration (I use helix for example). When I need to build the system, it uses a custom version of crate2nix that needs to be rebuilt everytime. That crate2nix version downloads and builds 300 rust crates. If I run the garbage collectors, those crates are deleted, and need to be redownloaded and built, which is a littlle unintuitive.

I'm not sure what the best solution for this is. I think crate2nix is pretty stable, but I understand your concern of using a specific version.

Override stdenv version

Is it possible to override the stdenv version? I see this but it looks like the version isn't possible to set. I have a use-case in helix where some C compiler flags are used that may only be supported in clang > 11 versions.

dream-lock.json doesn't exist

When I build my app with nix build, I get

trace:

The dream-lock.json for input 'app' doesn't exist or is outdated.
...Falling back to on-the-fly evaluation (possibly slow).
To speed up future evalutations run once:
  nix run .#resolve

(this doesn't terminate the build, and it works fine)

Running nix run .#resolve shows that an output called resolve doesn't exist

error: cannot find flake attribute 'git+file:///<the-app-directory>/app#resolve'

nixos-install fails because toolchain file is not prefixed with `/nix/store`

nixos-install fails with this:

error: attribute '/mnt/nix/store/hms1avnvdx54i5il4hcx0hky5srng2dx-source/rust-toolchain.toml' missing

       at /mnt/nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/pkgs-set.nix:50:12:

           49|       then rust-lib.rust-bin.fromRustupToolchainFile toolchainChannel
           50|       else rust-lib.rust-bin.${toolchainChannel}.latest.default;
             |            ^
           51|     toolchain = baseToolchain.override {

       … while evaluating the attribute 'rust-bin."/mnt/nix/store/hms1avnvdx54i5il4hcx0hky5srng2dx-source/rust-toolchain.toml".latest.default'

With nixos-install the prefix is usually /mnt/nix/store

if l.hasPrefix "/nix/store/" toolchainChannel

I think it's safer to just check the suffix with .toml or use builtins.pathExists to check if the file exists (which could clash though with files that are named like the channel that are in the repo I guess...)

error: The option `disableIfdWarning' does not exist

when running nix develop
i have no clue why this is happening, here is full trace

Full trace
error: The option `disableIfdWarning' does not exist. Definition values:
       - In `<unknown-file>': true

       … while evaluating the attribute 'config'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:330:9:

          329|         options = checked options;
          330|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          331|         _module = checked (config._module);

       … while evaluating anonymous lambda

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/modules/config.nix:1:1:

            1| {
             | ^
            2|   rawConfig,

       … from call site

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/lib.nix:22:15:

           21|   loadConfig = config'': let
           22|     config' = import ./modules/config.nix {
             |               ^
           23|       rawConfig = config'';

       … while evaluating 'loadConfig'

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/lib.nix:21:16:

           20|
           21|   loadConfig = config'': let
             |                ^
           22|     config' = import ./modules/config.nix {

       … from call site

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/lib.nix:74:20:

           73|   }:
           74|     initDream2nix (loadConfig config) pkgs;
             |                    ^
           75|

       … while evaluating 'imap1'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/lists.nix:117:14:

          116|   */
          117|   imap1 = f: list: genList (n: f (n + 1) (elemAt list n)) (length list);
             |              ^
          118|

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:382:73:

          381|           };
          382|         in parentFile: parentKey: initialModules: args: collectResults (imap1 (n: x:
             |                                                                         ^
          383|           let

       … while evaluating 'filterModules'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:397:36:

          396|       # modules recursively. It returns the final list of unique-by-key modules
          397|       filterModules = modulesPath: { disabled, modules }:
             |                                    ^
          398|         let

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:410:7:

          409|     in modulesPath: initialModules: args:
          410|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
             |       ^
          411|

       … while evaluating anonymous lambda

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:409:37:

          408|
          409|     in modulesPath: initialModules: args:
             |                                     ^
          410|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:253:25:

          252|       merged =
          253|         let collected = collectModules
             |                         ^
          254|           (specialArgs.modulesPath or "")

       … while evaluating 'reverseList'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/lists.nix:394:17:

          393|   */
          394|   reverseList = xs:
             |                 ^
          395|     let l = length xs; in genList (n: elemAt xs (l - n - 1)) l;

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:257:33:

          256|           ({ inherit lib options config specialArgs; } // specialArgs);
          257|         in mergeModules prefix (reverseList collected);
             |                                 ^
          258|

       … while evaluating 'byName'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:526:25:

          525|       */
          526|       byName = attr: f: modules:
             |                         ^
          527|         zipAttrsWith (n: concatLists)

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:543:21:

          542|       # an attrset 'name' => list of submodules that declare ‘name’.
          543|       declsByName = byName "options" (module: option:
             |                     ^
          544|           [{ inherit (module) _file; options = option; }]

       … while evaluating the attribute 'matchedOptions'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:621:14:

          620|     in {
          621|       inherit matchedOptions;
             |              ^
          622|

       … while evaluating 'mapAttrsRecursiveCond'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/attrsets.nix:393:36:

          392|   */
          393|   mapAttrsRecursiveCond = cond: f: set:
             |                                    ^
          394|     let

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:265:28:

          264|           # For definitions that have an associated option
          265|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                            ^
          266|

       … while evaluating the attribute 'config'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/modules.nix:330:9:

          329|         options = checked options;
          330|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          331|         _module = checked (config._module);

       … while evaluating anonymous lambda

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/modules/framework.nix:1:1:

            1| {
             | ^
            2|   lib,

       … from call site

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/default.nix:67:15:

           66|
           67|   framework = import ./modules/framework.nix {
             |               ^
           68|     inherit

       … while evaluating 'realizeProjects'

       at /nix/store/91fyfw2cyd4bffir6iydd7856sq7xwmv-source/src/default.nix:542:21:

          541|   # transform a list of resolved projects to buildable outputs
          542|   realizeProjects = {
             |                     ^
          543|     inject ? {},

       … from call site

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/build/default.nix:208:32:

          207|
          208|   _outputs = l.dbgX "outputs" (utils.mkCrateOutputs baseConfig);
             |                                ^
          209|   unwrappedPackage = _outputs.packages.${cargoPkg.name};

       … while evaluating 'dbgXY'

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/lib/default.nix:13:21:

           12|     dbgX = msg: x: dbgXY msg x x;
           13|     dbgXY = msg: x: y:
             |                     ^
           14|       if doDbg

       … from call site

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/lib/default.nix:12:20:

           11|       else x;
           12|     dbgX = msg: x: dbgXY msg x x;
             |                    ^
           13|     dbgXY = msg: x: y:

       … while evaluating 'dbgX'

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/lib/default.nix:12:17:

           11|       else x;
           12|     dbgX = msg: x: dbgXY msg x x;
             |                 ^
           13|     dbgXY = msg: x: y:

       … from call site

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/build/default.nix:208:14:

          207|
          208|   _outputs = l.dbgX "outputs" (utils.mkCrateOutputs baseConfig);
             |              ^
          209|   unwrappedPackage = _outputs.packages.${cargoPkg.name};

       … while evaluating anonymous lambda

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/build/default.nix:215:8:

          214|     wrapped = l.pipe unwrappedPackage [
          215|       (old:
             |        ^
          216|         old

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/trivial.nix:62:30:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                              ^
           63|     in builtins.foldl' reverseApply val functions;

       … while evaluating 'reverseApply'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/trivial.nix:62:27:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                           ^
           63|     in builtins.foldl' reverseApply val functions;

       … from call site

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/trivial.nix:63:8:

           62|     let reverseApply = x: f: f x;
           63|     in builtins.foldl' reverseApply val functions;
             |        ^
           64|

       … while evaluating 'pipe'

       at /nix/store/p6xfpp6i1a2h4ia3v81d1r414v6a603i-source/lib/trivial.nix:61:15:

           60|   */
           61|   pipe = val: functions:
             |               ^
           62|     let reverseApply = x: f: f x;

       … from call site

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/build/default.nix:214:15:

          213|   package = let
          214|     wrapped = l.pipe unwrappedPackage [
             |               ^
          215|       (old:

       … while evaluating the attribute 'package'

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/build/default.nix:213:3:

          212|   config = baseConfig // {inherit profile features doCheck;};
          213|   package = let
             |   ^
          214|     wrapped = l.pipe unwrappedPackage [

       … while evaluating anonymous lambda

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/makeOutput.nix:119:30:

          118|   # Packages set to be put in the outputs.
          119|   _packages = l.mapAttrs (_: v: v.package) packagesRaw;
             |                              ^
          120|   packages = {

       … from call site

       … while evaluating anonymous lambda

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/shell.nix:1:1:

            1| {
             | ^
            2|   common,

       … from call site

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/makeOutput.nix:154:25:

          153|   devShells = {
          154|     ${system}.${name} = mkShell {
             |                         ^
          155|       inherit common;

       … while evaluating 'mergeShells'

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/makeOutputs.nix:144:17:

          143|
          144|   mergeShells = shellAttrs: let
             |                 ^
          145|     shells = l.attrValues shellAttrs;

       … from call site

       at /nix/store/lxg16nxdr2km2xb0dix2fy4wxvzv9p0v-source/src/makeOutputs.nix:187:32:

          186|         l.mapAttrs
          187|         (_: s: s // {default = mergeShells s;})
             |                                ^
          188|         combinedOutputs.devShells;

edit, sorry here is actual flake:

# This file is pretty general, and you can adapt it in your project replacing
# only `name` and `description` below.

{
  description = "Hyprland-rs dev shell";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
		#rust-overlay = {
    #  url = "github:oxalica/rust-overlay";
    #  inputs.nixpkgs.follows = "nixpkgs";
    #};
    nci.url = "github:yusdacra/nix-cargo-integration";
    nci.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs:
    inputs.nci.lib.makeOutputs {
      root = ./.;
      config = common: {
        shell = {
          packages = with common.pkgs; [ rust-analyzer cargo-watch ];
        };
      };
    };
}
[package.metadata.nix]
#app = true
build = true
#systems = [
#    "aarch64-linux",
#    "i686-linux",
#    "x86_64-linux",
#]

How to use it ? i get the error `cargo: command not found`

Hello,

i'm trying to use this projet but i have this issue

/nix/store/lwcfw5vyjlzrs35k1hanv21j1q2s5c5w-stdenv-linux/setup: line 1364: cargo: command not found

What am i doing wrong ? How to use it ?

i tryied with a fresh crate using this script

#!/usr/bin/env sh
cd /tmp

rm -rf nix-cargo-integration-test
mkdir nix-cargo-integration-test
cd nix-cargo-integration-test

nix --version

nix_flake="nix --experimental-features 'nix-command flakes'"

nix-shell --pure --packages \
    cargo \
    nixUnstable \
    curl \
    cacert \
    git \
    --command "
cargo init
cargo run

echo '[package.metadata.nix]' >> Cargo.toml
echo 'build = true' >> Cargo.toml
echo 'app = true' >> Cargo.toml

${nix_flake} --version
${nix_flake} run github:yusdacra/nix-cargo-integration -- run

curl -sSL https://github.com/yusdacra/nix-cargo-integration/raw/66a357f6b17dd22f216dfd4373678deddbfe03fc/docs/example_flake.nix >flake.nix
git init
git config user.name name
git config user.email [email protected]
git add .
git commit --allow-empty-message --no-edit
${nix_flake} run
"

i get this output

bash nix-cargo-integration-test.sh
nix (Nix) 2.3.16
     Created binary (application) package
   Compiling nix-cargo-integration-test v0.1.0 (/tmp/nix-cargo-integration-test)
    Finished dev [unoptimized + debuginfo] target(s) in 0.52s
     Running `target/debug/nix-cargo-integration-test`
Hello, world!
nix (Nix) 2.5.0pre20211206_d1aaa7e
building '/nix/store/3rwmkjl42bab1jzdzgga5aw5lm6vdpic-nci-cli-0.1.0.drv'...
builder for '/nix/store/3rwmkjl42bab1jzdzgga5aw5lm6vdpic-nci-cli-0.1.0.drv' failed with exit code 1; last 6 log lines:
  unpacking sources
  unpacking source archive /nix/store/ayqnydsis8n1cx4mwc3b469qyy9wdfq7-source
  source root is source
  patching sources
  configuring
  /nix/store/lwcfw5vyjlzrs35k1hanv21j1q2s5c5w-stdenv-linux/setup: line 1364: cargo: command not found
error: build of '/nix/store/3rwmkjl42bab1jzdzgga5aw5lm6vdpic-nci-cli-0.1.0.drv' failed
Reinitialized existing Git repository in /tmp/nix-cargo-integration-test/.git/
[main (root-commit) bca910b] 
 5 files changed, 157 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.lock
 create mode 100644 Cargo.toml
 create mode 100644 flake.nix
 create mode 100644 src/main.rs
warning: creating lock file '/tmp/nix-cargo-integration-test/flake.lock'
warning: Git tree '/tmp/nix-cargo-integration-test' is dirty
building '/nix/store/rhqnmzdjgr394s78l2y0d4831wnvsl7p-nix-cargo-integration-test-0.1.0.drv'...
builder for '/nix/store/rhqnmzdjgr394s78l2y0d4831wnvsl7p-nix-cargo-integration-test-0.1.0.drv' failed with exit code 1; last 6 log lines:
  unpacking sources
  unpacking source archive /nix/store/yhq9ahw7zx7l34c8crd0h2g89zdbc9jz-source
  source root is source
  patching sources
  configuring
  /nix/store/lwcfw5vyjlzrs35k1hanv21j1q2s5c5w-stdenv-linux/setup: line 1364: cargo: command not found
error: build of '/nix/store/rhqnmzdjgr394s78l2y0d4831wnvsl7p-nix-cargo-integration-test-0.1.0.drv' failed

Refactor to integrate more tightly with dream2nix

We want to remove most of the logic from NCI by moving it to dream2nix:

  • move devshell logic to dream2nix
  • remove all override code from NCI, just directly pass overrides to dream2nix. This is a breaking change since overrides will no longer be "collected" if you define an override for a dependency.
  • remove build and app options from Cargo.toml metadata. By default all detected packages will be available, but the user will be able to specify names in flake.nix to only enable the specified packages in outputs. The reasoning for this one is that it's too much of a hassle to "just" get something started. Ideally you should be able to init the template and be ready to go.

These changes will allow NCI to just be a lightweight wrapper around dream2nix, mostly only providing configuration from Cargo.toml and a few other goodies that we already have that are Cargo specific / too opinionated.

`release-1.0` flake references dropped commit

The release-1.0 branch's flake.nix contains the following fetchGit.

naersk = builtins.fetchGit {
url = "https://github.com/yusdacra/naersk.git";
ref = "feat/cargolock-git-deps";
rev = "f411315a2954bd60bdcba2bc0cff7f4b0012a12a";
};

Looking at yusdacra/naersk@f411315, it looks like that commit does not belong to the ref mentioned in the above fetchGit.

My local hydra instance seems to have a problem with that:

in job ‘x86_64-linux.mensa-tests’:
error: Cannot find Git revision 'f411315a2954bd60bdcba2bc0cff7f4b0012a12a' in ref 'feat/cargolock-git-deps' of repository 'https://github.com/yusdacra/naersk.git'! Please make sure that the rev exists on the ref you've specified or add allRefs = true; to fetchGit.

I'm not actually sure how to reproduce this, nix building my package shows no problems, even if run with --option restrict-eval true. This commit seems to fix it: MalteT@e17b083

Build does not work on the latest stable version of NixOS

Hello,

First of all, thanks for this great tool, which makes it easy to package a Rust project with Nix 🙂

The current version of Nix in the latest stable release of NixOS is 2.3

nix-build --version
nix-build (Nix) 2.3.16

Using this version of Nix, the build fails

nix-build --show-trace
warning: unknown setting 'experimental-features'
error: while evaluating the attribute 'cargoArtifacts' of the derivation 'hello-0.0.0' at /nix/store/ny7x54058ki7k1d3ny0jx5h6kw926mxv-source/pkgs/stdenv/generic/make-derivation.nix:278:7:
while evaluating the attribute 'src' of the derivation 'hello-deps-0.0.0' at /nix/store/ny7x54058ki7k1d3ny0jx5h6kw926mxv-source/pkgs/stdenv/generic/make-derivation.nix:278:7:
while evaluating the attribute 'buildCommand' of the derivation 'dummy-src' at /nix/store/ny7x54058ki7k1d3ny0jx5h6kw926mxv-source/pkgs/stdenv/generic/make-derivation.nix:278:7:
while evaluating anonymous function at /nix/store/yi2qhdxw7hrj73l5aj5xdyhsvp576ws6-source/lib/findCargoFiles.nix:4:1, called from /nix/store/yi2qhdxw7hrj73l5aj5xdyhsvp576ws6-source/lib/mkDummySrc.nix:36:12:
attribute 'groupBy' missing, at /nix/store/yi2qhdxw7hrj73l5aj5xdyhsvp576ws6-source/lib/findCargoFiles.nix:32:13

I setup a test project to play with it, you can try in your browser with the button below

Open in Gitpod

I would like to have backward compatibility support

Without updating Nix from 2.3 to the latest version, how can I fix this error?

Better tests

We should test the output of devshell tests by comparing the resulting config attribute set and more generally test the output of common.nix for tests.

Can't eval aarch64-linux package on x86_64-linux

Since adding helix's flake to my nixcfg, I'm no longer able to evaluate my aarch64 systems on my x86_64 boxes. This is pretty painful since I rely on evaluating on my main CI machine and then remote building the derivations and copying outputs back.

I'm not sure though, if this is because of a specific Rust dep that is triggering this, or if its an overall symptom of helix's use of nix-cargo-integration.

Any tips?

❯ nix eval --raw --derivation 'github:helix-editor/helix/e267dc#packages.aarch64-linux.helix'
error: a 'aarch64-linux' with features {} is required to build '/nix/store/l4r33m9ys148295f3djjys1hf1vxpvap-crates-io-aho-corasick-0.7.18.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, recursive-nix}
(use '--show-trace' to show detailed location information)

fix: hrpc-rs 0.26.0 breaking build

Probably happens for other crates too (which ones?).

Error output:

error: opening file '/nix/store/gzf8jc8jyhf65kzppljkgfxbvc2akhm9-source/crates/*/Cargo.toml': No such file or directory

TODO: also add a test for this in fix PR

attribute packages is missing

Idk why but it says packages is missing? idk

Trace
error: attribute 'packages' missing

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/build/default.nix:209:22:

          208|   _outputs = l.dbgX "outputs" (utils.mkCrateOutputs baseConfig);
          209|   unwrappedPackage = _outputs.packages.${cargoPkg.name};
             |                      ^
          210|   shell = _outputs.devShells.${cargoPkg.name};

       … while evaluating anonymous lambda

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/build/default.nix:215:8:

          214|     wrapped = l.pipe unwrappedPackage [
          215|       (old:
             |        ^
          216|         old

       … from call site

       at /nix/store/lwnrrndriqm2d588lgd6184bcawj3b0z-source/lib/trivial.nix:62:30:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                              ^
           63|     in builtins.foldl' reverseApply val functions;

       … while evaluating 'reverseApply'

       at /nix/store/lwnrrndriqm2d588lgd6184bcawj3b0z-source/lib/trivial.nix:62:27:

           61|   pipe = val: functions:
           62|     let reverseApply = x: f: f x;
             |                           ^
           63|     in builtins.foldl' reverseApply val functions;

       … from call site

       at /nix/store/lwnrrndriqm2d588lgd6184bcawj3b0z-source/lib/trivial.nix:63:8:

           62|     let reverseApply = x: f: f x;
           63|     in builtins.foldl' reverseApply val functions;
             |        ^
           64|

       … while evaluating 'pipe'

       at /nix/store/lwnrrndriqm2d588lgd6184bcawj3b0z-source/lib/trivial.nix:61:15:

           60|   */
           61|   pipe = val: functions:
             |               ^
           62|     let reverseApply = x: f: f x;

       … from call site

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/build/default.nix:214:15:

          213|   package = let
          214|     wrapped = l.pipe unwrappedPackage [
             |               ^
          215|       (old:

       … while evaluating the attribute 'package'

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/build/default.nix:213:3:

          212|   config = baseConfig // {inherit profile features doCheck;};
          213|   package = let
             |   ^
          214|     wrapped = l.pipe unwrappedPackage [

       … while evaluating anonymous lambda

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/makeOutput.nix:119:30:

          118|   # Packages set to be put in the outputs.
          119|   _packages = l.mapAttrs (_: v: v.package) packagesRaw;
             |                              ^
          120|   packages = {

       … from call site

       … while evaluating anonymous lambda

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/shell.nix:1:1:

            1| {
             | ^
            2|   common,

       … from call site

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/makeOutput.nix:154:25:

          153|   devShells = {
          154|     ${system}.${name} = mkShell {
             |                         ^
          155|       inherit common;

       … while evaluating 'mergeShells'

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/makeOutputs.nix:144:17:

          143|
          144|   mergeShells = shellAttrs: let
             |                 ^
          145|     shells = l.attrValues shellAttrs;

       … from call site

       at /nix/store/xla5whhibb8b3gnbfidic1kcj9yy5lbg-source/src/makeOutputs.nix:187:32:

          186|         l.mapAttrs
          187|         (_: s: s // {default = mergeShells s;})
             |                                ^
          188|         combinedOutputs.devShells;

And the code is:

{
  description = "dev shell";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
		rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nci.url = "github:yusdacra/nix-cargo-integration";
    nci.inputs.nixpkgs.follows = "nixpkgs";
		nci.inputs.rust-overlay.follows = "rust-overlay";
  };

  outputs = { nci, ...}: 
    nci.lib.makeOutputs {
      root = ./.;
      config = common: {
        shell = {
          packages = with common.pkgs; [ rust-analyzer wasm-pack ];
        };
      };
    };
}
[package]
name = "cf-analytics"
version = "0.1.0"
authors = ["yavko <[email protected]>"]
edition = "2021"

[package.metadata.nix]
build = true
#systems = ["wasm32-unknown-unknown"]

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.63"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.6", optional = true }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
wee_alloc = { version = "0.4.5", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.13"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

Release a stable 1.0 API

A stable API should be provided sooner or later. While much of the public API hasn't seen a change anyways, after adding some more useful features (#20) a 1.0 release should be made.

`nix run .` fails to work when `app = true` in Cargo.toml

Little minimal toy application over at https://github.com/Grumbel/rustywatch

If I set:

[package.metadata.nix]
app = true

nix-cargo-integration will generate app entries in the flake outputs:

├───apps
│   ├───aarch64-darwin
│   │   ├───rustywatch: app
│   │   └───rustywatch-debug: app
│   ├───aarch64-linux
│   │   ├───rustywatch: app
│   │   └───rustywatch-debug: app
│   ├───i686-linux
│   │   ├───rustywatch: app
│   │   └───rustywatch-debug: app
│   ├───x86_64-darwin
│   │   ├───rustywatch: app
│   │   └───rustywatch-debug: app
│   └───x86_64-linux
│       ├───rustywatch: app
│       └───rustywatch-debug: app
...
───defaultApp
│   ├───aarch64-darwin: app
│   ├───aarch64-linux: app
│   ├───i686-linux: app
│   ├───x86_64-darwin: app
│   └───x86_64-linux: app

However if I try to run it I get this:

$ nix run github:Grumbel/rustywatch?ref=b08922c
error: attribute 'defaultApp.x86_64-linux' should have type 'derivation'

Trying to run the app objects directly however works:

nix run github:Grumbel/rustywatch?ref=b08922c#rustywatch
nix run github:Grumbel/rustywatch?ref=b08922c#apps.x86_64-linux.rustywatch

It seems like defaultApp requires a derivation, not an "app" to run. For using an app directly, apps."<system>".default seems to be required instead of defaultApp.

Setting app = false in Cargo.toml to prevent the generation of apps in the flake output also gives a working nix run ..

nix (Nix) 2.9.0pre20220422_7f814d6
nci is at c9e1ecf

Optional dependencies cause build failures when incompatible

Any project with the reqwest crate as a dependency fails to build on linux because it optionally depends on MacOS_SDK-10.12

❯ nix build
error: Package ‘MacOS_SDK-10.12’ in /nix/store/hsff9pi1qinxljahr833z0xivr1apx27-source/pkgs/os-specific/darwin/apple-sdk/default.nix:50 is not supported on ‘x86_64-linux’, refusing to evaluate.

       a) To temporarily allow packages that are unsupported for this system, you can use an environmentvariable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1

        Note: For `nix shell`, `nix build`, `nix develop` or any other Nix 2.4+
        (Flake) command, `--impure` must be passed in order to read this
        environment variable.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnsupportedSystem = true; }
       in configuration.nix to override this.

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnsupportedSystem = true; }
       to ~/.config/nixpkgs/config.nix.
(use '--show-trace' to show detailed location information)

Minimal reproducible example

Debug output package depends on compiler toolchain

Unknown why (or if there is a way to turn it off), but it seems the debug builds bring in a dependency on the rust compiler toolchain.

Split builds for each variant of build would allow smaller closures when only a production build is needed.

how to override specific crate

This is how I try to override the preConfigure phase for a crate in my workspace but the phase is never run.

 cargo-outputs = (nix-cargo-integration.lib.makeOutputs {
  root = ./src/rust;
  overrides = {
    common = prev: {
      buildInputs = prev.buildInputs ++ deps;
      env = {
        LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
      };
    };
    crateOverrides = common: prev: {
      my_crate = oldAttrs: {
        preConfigure = with pkgs; '' ...

Does someone know how to achieve this ?

How to use `installShellFiles` with the new API ?

Hello,

I tried to upgrade Rust from 1.64 to 1.65 but it fails https://gitlab.com/pinage404/git-gamble/-/jobs/3342573954 ; i think it's because i use an old version of nix-cargo-integration

I'm trying to upgrade from https://github.com/yusdacra/nix-cargo-integration/tree/3df28172b283d56c5b4f08d0291087a12da7c6f1 (previous main branch) to https://github.com/yusdacra/nix-cargo-integration/tree/5cc9744efb05e9bd4f0760e487f177eb47b74dac (current main branch)

I don't understand how to upgrade

Example in https://yusdacra.github.io/nix-cargo-integration/pkg-config-options.html#overrides seems to not match the templates https://github.com/yusdacra/nix-cargo-integration/blob/master/templates/full/flake.nix (overrideAttrs vs override)

Tries :
https://gitlab.com/pinage404/git-gamble/-/jobs/3350297601
https://gitlab.com/pinage404/git-gamble/-/jobs/3351015661

Related to #53

How to use installShellFiles with the new API ?

Mutiple runtime libs result in none of them being in LD_LIBRARY_PATH

{
  inputs = {
    nixCargoIntegration.url = "github:yusdacra/nix-cargo-integration";
  };

  outputs = inputs: inputs.nixCargoIntegration.lib.makeOutputs {
    root = ./.;
    config = common: {
      shell = {
        packages = [common.pkgs.pkg-config common.pkgs.alsa-lib];
      };
      runtimeLibs = [
        common.pkgs.xorg.libX11
      ];
    };
    pkgConfig = common: {
      "creepers" = {
        depsOverrides = {
          sys-deps = {
            buildInputs = [common.pkgs.pkg-config common.pkgs.alsa-lib common.pkgs.udev];
          };
        };
      };
    };
  };
}

Shows that $LD_LIBRARY_PATH is /nix/store/8bf8li7ajgb15ivpy2gsbaf7111jpb21-libX11-1.7.2/lib:/nix/store/1166267pz76awyfswidh3rz995xq8kyh-devshell-dir/lib:/nix/store/am86zfqj5pmfbf9mm822hzfd4d6372aw-sane-config/lib/sane:/nix/store/7li4k00ri8siawwi8vdibbdmsaiwd18i-pipewire-0.3.56-jack/lib

However if I change it to:

      runtimeLibs = [
        common.pkgs.xorg.libX11
        common.pkgs.xorg.libXcursor
      ];

I got an error /nix/store/n95s7s6ilkjc7xwqml93acxzj6k0hsfn-coreutils-9.1/bin/realpath: '/nix/store/8bf8li7ajgb15ivpy2gsbaf7111jpb21-libX11-1.7.2/lib:/nix/store/9w8qaifxnwg8mdxmcbwd79gjw3p27acs-libXcursor-1.2.0/lib': No such file or directory and X11 and Xcursor are not in path.

Support `*` in workspace members

[workspace]
members = [
  "crates/*",
]

A Cargo.toml like this is very common and much nicer to use than to list every crate, however, nix-cargo-integration currently fails with

'/nix/store/v7nikwxvxcs9brviravwal66r2b2ivwg-source/crates/*': No such file or directory

if you try to use *.

It would be nice to have support for glob paths.

Include `shell.nix`, a-la flake-utils `simpleFlake`

flake-utils has a simpleFlake output that allows the following flake format:

{
  description = "Flake utils demo";

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

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.simpleFlake {
      inherit self nixpkgs;
      name = "simple-flake";

      # NOTABLY:
      shell = ./shell.nix;
    };
}

I have a shell.nix that includes things that nix-cargo-integration's overrides system does not allow, e.g. mkShell.override { ... }:

{pkgs ? import <nixpkgs> {}}:
with pkgs;
  (mkShell.override {stdenv = llvmPackages_11.stdenv;}) {
    buildInputs = [
      ...
    ];
  }

I would like to be able to use this shell.nix file - including, and especially, the call to mkShell.override - from nix-cargo-integration. Is this possible?

error: A definition for option `features' is not of type `attribute set of list of string'

Just started happening, idk why

Details ``` error: A definition for option `features' is not of type `attribute set of list of string'. Definition values: - In `/nix/store/gphwcj87jh3b64a8iha6hyj109n84rq7-source/src/lib/namespacedConfigModule.nix': [ ]
   … while evaluating the attribute 'mergedValue'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:758:5:

      757|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
      758|     mergedValue =
         |     ^
      759|       if isDefined then

   … while evaluating the option `features':

   … while evaluating the attribute 'value'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:723:9:

      722|     in warnDeprecation opt //
      723|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
         |         ^
      724|         inherit (res.defsFinal') highestPrio;

   … while evaluating anonymous lambda

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:265:72:

      264|           # For definitions that have an associated option
      265|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
         |                                                                        ^
      266|

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:532:20:

      531|               then recurse (path ++ [name]) value
      532|               else f (path ++ [name]) value;
         |                    ^
      533|         in mapAttrs g;

   … while evaluating 'g'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:529:19:

      528|           g =
      529|             name: value:
         |                   ^
      530|             if isAttrs value && cond value

   … from call site

   … while evaluating 'optional'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/lists.nix:255:20:

      254|   */
      255|   optional = cond: elem: if cond then [elem] else [];
         |                    ^
      256|

   … from call site

   at /nix/store/gphwcj87jh3b64a8iha6hyj109n84rq7-source/src/build/default.nix:65:19:

       64|   # Specify --features if we have enabled features other than the default ones
       65|   featuresFlags = l.optional ((l.length features) > 0) "--no-default-features --features ${(l.concatStringsSep "," features)}";
         |                   ^
       66|   # Specify the --profile flag to set the profile we will use for compiling

   … while evaluating 'applySingleAttributeOverride'

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/modules/utils.override/implementation.nix:103:44:

      102|     # apply single attribute override
      103|     applySingleAttributeOverride = oldVal: functionOrValue:
         |                                            ^
      104|       if b.isFunction functionOrValue

   … from call site

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/modules/utils.override/implementation.nix:182:13:

      181|           (attrName: functionOrValue:
      182|             applySingleAttributeOverride old."${attrName}" functionOrValue)
         |             ^
      183|           updateAttrsFuncs))

   … while evaluating anonymous lambda

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/modules/utils.override/implementation.nix:181:22:

      180|           l.mapAttrs
      181|           (attrName: functionOrValue:
         |                      ^
      182|             applySingleAttributeOverride old."${attrName}" functionOrValue)

   … from call site

   … while evaluating anonymous lambda

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/subsystems/rust/builders/devshell.nix:106:18:

      105|             (
      106|               n: v:
         |                  ^
      107|                 if ! (l.isAttrs v || l.isFunction v)

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:478:16:

      477|     attrs:
      478|     map (name: f name attrs.${name}) (attrNames attrs);
         |                ^
      479|

   … while evaluating anonymous lambda

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:478:10:

      477|     attrs:
      478|     map (name: f name attrs.${name}) (attrNames attrs);
         |          ^
      479|

   … from call site

   … while evaluating anonymous lambda

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/subsystems/rust/builders/devshell.nix:102:12:

      101|           l.filter
      102|           (env: (env != null) && (! isIllegalEnv env.name))
         |            ^
      103|           (

   … from call site

   … while evaluating the attribute 'env'

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/subsystems/rust/builders/devshell.nix:99:9:

       98|         ];
       99|         env =
         |         ^
      100|           # filter out attrsets, functions and illegal environment vars

   … while evaluating the attribute 'env'

   at /nix/store/h1afjh95v8q5h6vxz3xxgxj5zs7iddyl-source/src/subsystems/rust/builders/devshell.nix:28:9:

       27|         commands = l.unique ((c.commands or []) ++ (oc.commands or []));
       28|         env = l.unique ((c.env or []) ++ (oc.env or []));
         |         ^
       29|         devshell =

   … while evaluating the attribute 'value'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:563:44:

      562|       defnsByName' = byName "config" (module: value:
      563|           [{ inherit (module) file; inherit value; }]
         |                                            ^
      564|         ) configs;

   … while evaluating 'dischargeProperties'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:810:25:

      809|   */
      810|   dischargeProperties = def:
         |                         ^
      811|     if def._type or "" == "merge" then

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:739:137:

      738|         defs' = concatMap (m:
      739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
         |                                                                                                                                         ^
      740|         ) defs;

   … while evaluating definitions from `<unknown-file>':

   … while evaluating anonymous lambda

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:738:28:

      737|         # Process mkMerge and mkIf properties.
      738|         defs' = concatMap (m:
         |                            ^
      739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:738:17:

      737|         # Process mkMerge and mkIf properties.
      738|         defs' = concatMap (m:
         |                 ^
      739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

   … while evaluating the attribute 'values'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:851:7:

      850|     in {
      851|       values = concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
         |       ^
      852|       inherit highestPrio;

   … while evaluating the attribute 'values'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:752:9:

      751|       in {
      752|         values = defs''';
         |         ^
      753|         inherit (defs'') highestPrio;

   … while evaluating the attribute 'mergedValue'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:758:5:

      757|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
      758|     mergedValue =
         |     ^
      759|       if isDefined then

   … while evaluating the option `env':

   … while evaluating the attribute 'value'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:723:9:

      722|     in warnDeprecation opt //
      723|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
         |         ^
      724|         inherit (res.defsFinal') highestPrio;

   … while evaluating anonymous lambda

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:265:72:

      264|           # For definitions that have an associated option
      265|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
         |                                                                        ^
      266|

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:532:20:

      531|               then recurse (path ++ [name]) value
      532|               else f (path ++ [name]) value;
         |                    ^
      533|         in mapAttrs g;

   … while evaluating 'g'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:529:19:

      528|           g =
      529|             name: value:
         |                   ^
      530|             if isAttrs value && cond value

   … from call site

   … while evaluating the attribute 'value'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:563:44:

      562|       defnsByName' = byName "config" (module: value:
      563|           [{ inherit (module) file; inherit value; }]
         |                                            ^
      564|         ) configs;

   … while evaluating 'dischargeProperties'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:810:25:

      809|   */
      810|   dischargeProperties = def:
         |                         ^
      811|     if def._type or "" == "merge" then

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:739:137:

      738|         defs' = concatMap (m:
      739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
         |                                                                                                                                         ^
      740|         ) defs;

   … while evaluating definitions from `/nix/store/4cnrzgx9w9cdvwic4iyg0k128b30i44s-source/modules/env.nix':

   … while evaluating anonymous lambda

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:738:28:

      737|         # Process mkMerge and mkIf properties.
      738|         defs' = concatMap (m:
         |                            ^
      739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:738:17:

      737|         # Process mkMerge and mkIf properties.
      738|         defs' = concatMap (m:
         |                 ^
      739|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

   … while evaluating the attribute 'values'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:851:7:

      850|     in {
      851|       values = concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
         |       ^
      852|       inherit highestPrio;

   … while evaluating the attribute 'values'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:752:9:

      751|       in {
      752|         values = defs''';
         |         ^
      753|         inherit (defs'') highestPrio;

   … while evaluating the attribute 'mergedValue'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:758:5:

      757|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
      758|     mergedValue =
         |     ^
      759|       if isDefined then

   … while evaluating the option `devshell.startup_env':

   … while evaluating the attribute 'value'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:723:9:

      722|     in warnDeprecation opt //
      723|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
         |         ^
      724|         inherit (res.defsFinal') highestPrio;

   … while evaluating anonymous lambda

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/modules.nix:265:72:

      264|           # For definitions that have an associated option
      265|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
         |                                                                        ^
      266|

   … from call site

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:532:20:

      531|               then recurse (path ++ [name]) value
      532|               else f (path ++ [name]) value;
         |                    ^
      533|         in mapAttrs g;

   … while evaluating 'g'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/lib/attrsets.nix:529:19:

      528|           g =
      529|             name: value:
         |                   ^
      530|             if isAttrs value && cond value

   … from call site

   … while evaluating the attribute 'text' of the derivation 'devshell-env.bash'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/pkgs/stdenv/generic/make-derivation.nix:270:7:

      269|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
      270|       name =
         |       ^
      271|         let

   … while evaluating the attribute 'postBuild' of the derivation 'devshell-dir'

   at /nix/store/2n3ykdi3lamr8gn2if8wkf0px0kg1bnp-source/pkgs/stdenv/generic/make-derivation.nix:270:7:

      269|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
      270|       name =
         |       ^
      271|         let

   … while evaluating the attribute 'args' of the derivation 'devshell'

   at /nix/store/4cnrzgx9w9cdvwic4iyg0k128b30i44s-source/nix/mkNakedShell.nix:30:10:

       29| (derivation {
       30|   inherit name system;
         |          ^
       31|
</details>

How to use `installShellFiles` ?

Hello,

How to put shell completions files in derivation using installShellFiles ?

Usually it is something like that

{
  # ...
  nativeBuildInputs = [ pkgs.installShellFiles ];
  postInstall = ''
    installShellCompletion $releaseDir/build/lsd-*/out/{_lsd,lsd.{bash,fish}}
  '';
  # ...
}

Importing a `devshell.toml` fails when running `nix develop`

I have a basic flake:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixCargoIntegration = {
      url = "github:yusdacra/nix-cargo-integration";
      #url = "gitlab:Austreelis/nix-cargo-integration";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = inputs: inputs.nixCargoIntegration.lib.makeOutputs {
    root = ./.;
    buildPlatform = "crate2nix";
    defaultOutputs = {
      package = "utf8-bufread";
    };
  };
}

And a basic devshell.toml in my repo's root directory:

[[commands]]
package = "hello"

running nix develop fails with the following error:

> nix develop
error: value is a function while a set was expected

       at /nix/store/ig5xhkhfhdsa249bs65j7g42h45hm8s4-source/devShell.nix:116:17:

          115|           then { config = combineWithBase devshellConfig; imports = [ ]; }
          116|           else {
             |                 ^
          117|             config = combineWithBase importedDevshell.config;
(use '--show-trace' to show detailed location information)

After some digging, it turns out the value returned by devshell's importTOML is a function (that is: importedDevshell is a function, one taking lib as argument).

When applying the following patch:

diff --git a/devShell.nix b/devShell.nix
index 86c78e9..550c100 100644
--- a/devShell.nix
+++ b/devShell.nix
@@ -13,7 +13,9 @@ let
   devshellFilePath = common.prevRoot + "/devshell.toml";
 
   # Import the devshell specified in devshell.toml if it exists
-  importedDevshell = if (builtins.pathExists devshellFilePath) then (pkgs.devshell.importTOML devshellFilePath) else null;
+  importedDevshell = if (builtins.pathExists devshellFilePath)
+    then (pkgs.devshell.importTOML devshellFilePath { inherit lib; })
+    else null;
 
   # Create a base devshell config
   baseConfig = {

The shell launches successfully.

I don't know if this is intended or not, but if it's an actual issue, I have a PR ready here 🙂
I quickly looked into the tests but I don't think there is one for projects with a devshell.toml ? That's also something I could add if that's welcome.

Building library needs staged Cargo.lock

When using this project in a Rust library with flakes, the following error occurs:

error: A Cargo.lock file must be present, please make sure it's at least staged in git.
(use '--show-trace' to show detailed location information)

This is probably not a problem with nix-cargo-integration, but with the way purity is handled. Is there any workaround other than just staging Cargo.lock (and unstaging for every commit)?

Thanks for the awesome work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.