cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

Can not specify nativeBuildInputs = [ pkgs.autoPatchelfHook ]; in devenv mkShell #292

Closed sandangel closed 3 weeks ago

sandangel commented 1 year ago

Describe the bug I can not specify like I did with pkgs.mkShell. I use this package to avoid libstd.so.6 issue

nativeBuildInputs = [ pkgs.autoPatchelfHook ];

To Reproduce Please provide an sscce by creating a gist using devenv.nix, devenv.yaml and optionally devenv.lock.

Version

Paste here the output of $ devenv version. main

domenkozar commented 1 year ago

@sandangel can you please provide a full example how to reproduce the issue?

@thenonameguy do you have an idea what should we do to support such use cases?

We'd probably have to write our own autoPatchelfHook.

sandangel commented 1 year ago
{
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";

    devenv.url = "github:cachix/devenv";
    devenv.inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = { self, nixpkgs, flake-utils, devenv }@inputs:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
        deps = with pkgs; [
          (python3.withPackages (ps: with ps; [
            poetry
          ]))
          postgresql
          stdenv.cc.cc.lib
          autoPatchelfHook
        ];
        ciDeps = with pkgs; [
          awscli2
          curl
          git-lfs
          jq
        ];
        devDeps = with pkgs; [
          pre-commit
          redis
        ];
      in
      with pkgs;
      {
        packages.default = pkgs.buildEnv {
          name = "my-app";
          paths = deps;
        };
        devShells.ci = devenv.lib.mkShell {
          inherit inputs pkgs;
          modules = [
            {
              packages = deps ++ ciDeps;
            }
          ];
        };
        devShells.default = devenv.lib.mkShell {
          inherit inputs pkgs;
          # nativeBuildInputs = [ pkgs.autoPatchelfHook ]; does not work
          modules = [
            {
              packages = deps ++ ciDeps ++ devDeps;
            }
          ];
        };
      }
    );
}

this is my flake.nix file.

domenkozar commented 1 year ago

We'll need to write a version of autoPatchelf that doesn't use setup hooks.

sandangel commented 1 year ago

It would be great if devenv automatically add LD_LIBRARY_PATH and we don't even need autoPatchelf in nativeBuildInputs

domenkozar commented 1 year ago

That's not ideal to do by default but you can point to ${env.DEVENV_PROFILE}/lib yourself :)

domenkozar commented 1 month ago

Can you try with recently released 1.0?

sandangel commented 1 month ago

I have another issue though:

# devenv.nix

{ pkgs, ... }:

{
  dotenv.disableHint = true;

  packages =
    (with pkgs.darwin.apple_sdk.frameworks; [
      CoreFoundation
      Accelerate
      Security
      SystemConfiguration
      AppKit
      WebKit
    ])
    ++ (with pkgs; [
      pkg-config
      openssl
      libiconv
    ]);

  languages.rust.enable = true;
  languages.rust.channel = "stable";
}
# devenv.yaml
inputs:
  nixpkgs:
    url: github:NixOS/nixpkgs/nixpkgs-unstable
  fenix:
    url: github:nix-community/fenix
    inputs:
      nixpkgs:
        follows: nixpkgs
allowUnfree: true

Then run:

export PYAPP_PROJECT_NAME=cowsay
export PYAPP_PROJECT_VERSION=6.0

cargo install pyapp --root out

Error:

note: ld: library not found for -liconv
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `ring` (build script) due to 1 previous error
error: failed to compile `pyapp v0.16.0`, intermediate artifacts can be found at `/var/folders/rc/h9d5_1292lz6841wzkw14yrw0000gq/T/cargo-installv1Zwkl`.

Using nativeBuildInputs in the pkgs.mkShell does not have this issue.

domenkozar commented 1 month ago

Does it work if you set unsetEnvVars = lib.mkForce [];

sandangel commented 1 month ago

This flake.nix works for me:

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

  outputs =
    inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [ inputs.devenv.flakeModule ];
      systems = [
        "x86_64-linux"
        "x86_64-darwin"
        "aarch64-linux"
        "aarch64-darwin"
      ];

      perSystem =
        {
          config,
          self',
          inputs',
          pkgs,
          system,
          ...
        }:
        {
          devShells.default = pkgs.mkShell {
            buildInputs =
              (with pkgs; [
                gcc
                libiconv
              ])
              ++ (with pkgs.darwin.apple_sdk.frameworks; [ SystemConfiguration ]);
          };
        };
    };
}

When I set:

# devenv.nix

{ pkgs, lib, ... }:

{
  dotenv.disableHint = true;

  packages =
    (with pkgs; [
      gcc
      libiconv
    ])
    ++ (with pkgs.darwin.apple_sdk.frameworks; [ SystemConfiguration ]);

  languages.rust.enable = true;
  languages.rust.channel = "stable";
  unsetEnvVars = lib.mkForce [ ];
}

Then it works

domenkozar commented 1 month ago

Could you add this as a test to tests in a PR and we'll fix it?

domenkozar commented 1 month ago

For me removing unsetEnvVars = lib.mkForce [ ]; also works, can you confirm?

sandangel commented 1 month ago

Oh, after updating with devenv update. I was able to build without issue. Not sure what have been changed. THanks a lot.