Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openssl missing when using crate2nix with fenix #383

Open
bbigras opened this issue Feb 5, 2025 · 0 comments
Open

openssl missing when using crate2nix with fenix #383

bbigras opened this issue Feb 5, 2025 · 0 comments

Comments

@bbigras
Copy link
Contributor

bbigras commented Feb 5, 2025

❯ nix build && ./result/bin/test-rustls
./result/bin/test-rustls: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
❯ nix build && ldd ./result/bin/test-rustls
        linux-vdso.so.1 (0x00007f31329e3000)
        libssl.so.3 => not found
        libcrypto.so.3 => not found
        libgcc_s.so.1 => /nix/store/2d5spnl8j5r4n1s4bj1zmra7mwx0f1n8-xgcc-13.3.0-libgcc/lib/libgcc_s.so.1 (0x00007f31329b8000)
        libc.so.6 => /nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib/libc.so.6 (0x00007f3132407000)
        /nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib/ld-linux-x86-64.so.2 => /nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib64/ld-linux-x86-64.so.2 (0x00007f31329e5000)

It works if I remove inherit rustc; from app.nix.

It's possible I'm not using crate2nix right. Maybe I need to pass more than rustc to it.

flake.nix

{
  description = "test-rustls";

  inputs = {
    devenv-root = {
      url = "file+file:///dev/null";
      flake = false;
    };
    flake-parts.url = "github:hercules-ci/flake-parts";
    nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
    devenv.url = "github:cachix/devenv";
    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
    fenix.url = "github:nix-community/fenix";
    fenix.inputs = {nixpkgs.follows = "nixpkgs";};
    crate2nix = {
      url = "github:nix-community/crate2nix";
      inputs = {
        flake-parts.follows = "flake-parts";
        nixpkgs.follows = "nixpkgs";
      };
    };
  };

  nixConfig = {
    extra-substituters = [
      "https://devenv.cachix.org"
      "https://nix-community.cachix.org"
    ];
    extra-trusted-public-keys = [
      "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
      "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
    ];
  };

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

      perSystem = {
        config,
        self',
        inputs',
        pkgs,
        system,
        ...
      }: let
        inherit (fenix.packages.${system}.minimal) rustc;
        my-crate = import ./app.nix {inherit pkgs rustc;};
      in {
        # Per-system attributes can be defined here. The self' and inputs'
        # module parameters provide easy access to attributes of the same
        # system.

        packages.default = my-crate;

        devenv.shells.default = let
          crate2nix_pkgs = crate2nix.packages.${system}.default;
        in {
          devenv.root = let
            devenvRootFileContent = builtins.readFile devenv-root.outPath;
          in
            pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;

          name = "my-project";

          imports = [
            # This is just like the imports in devenv.nix.
            # See https://devenv.sh/guides/using-with-flake-parts/#import-a-devenv-module
            # ./devenv-foo.nix
          ];

          # https://devenv.sh/reference/options/
          packages = with pkgs; [
            crate2nix_pkgs
            openssl
          ];

          languages = {
            c.enable = false;
            nix.enable = true;
            nix.lsp.package = pkgs.nixd;
            rust.enable = true;
          };
        };
      };
      flake = {
        # The usual flake attributes can be defined here, including system-
        # agnostic ones like nixosModule and system-enumerating ones, although
        # those are more easily expressed in perSystem.
      };
    };
}

app.nix

{
  pkgs,
  generatedBuild ? ./Cargo.nix,
  rustc,
}: let
  customBuildRustCrateForPkgs = pkgs:
    pkgs.buildRustCrate.override {
      inherit rustc;
      defaultCrateOverrides =
        pkgs.defaultCrateOverrides
        // {
        };
    };
  basePackage = pkgs.callPackage generatedBuild {
    inherit pkgs;
    buildRustCrateForPkgs = customBuildRustCrateForPkgs;
  };
  submodulePackage = basePackage.rootCrate.build.override {
    # runTests = true;
    # testInputs = [ ];
  };
in
  submodulePackage

Here's a full repo https://github.com/bbigras/test-rustls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant