null-dev / firefox-profile-switcher-connector

Native connector software for the 'Profile Switcher for Firefox' extension.
GNU General Public License v3.0
121 stars 25 forks source link

Problem compiling for NixOS #10

Open quigonjeff opened 2 years ago

quigonjeff commented 2 years ago

Hi. I am having problems compiling for NixOS. I am getting the following error messages:

error: failed to run custom build command for `nng-sys v1.4.0-rc.0`

Caused by:
  process didn't exit successfully: `/home/jefferson/workspace/firefox-profile-switcher-connector/target/release/build/nng-sys-cc321bf4e0b088b8/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=try_from
  CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
  CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
  CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
  CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-unknown-linux-gnu = None
  CMAKE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE = None
  CMAKE = None
  running: "cmake" "/home/jefferson/.cargo/registry/src/github.com-1ecc6299db9ec823/nng-sys-1.4.0-rc.0/nng" "-DNNG_TESTS=OFF" "-DNNG_TOOLS=OFF" "-DNNG_ENABLE_STATS=OFF" "-DNNG_ENABLE_TLS=OFF" "-DCMAKE_INSTALL_PREFIX=/home/jefferson/workspace/firefox-profile-switcher-connector/target/release/build/nng-sys-d6d52e806f81ce06/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/run/current-system/sw/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/run/current-system/sw/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/run/current-system/sw/bin/cc" "-DCMAKE_BUILD_TYPE=Release"
  -- Configuring for NNG version 1.4.0
  -- Building static libs.
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /home/jefferson/workspace/firefox-profile-switcher-connector/target/release/build/nng-sys-d6d52e806f81ce06/out/build
  running: "cmake" "--build" "." "--target" "install" "--config" "Release" "--parallel" "12"
  Consolidate compiler generated dependencies of target nng
  [  0%] Linking C static library libnng.a

  --- stderr
  make: warning: -j12 forced in submake: resetting jobserver mode.
  Error running link command: No such file or directory
  make[2]: *** [CMakeFiles/nng.dir/build.make:1426: libnng.a] Error 2
  make[1]: *** [CMakeFiles/Makefile2:723: CMakeFiles/nng.dir/all] Error 2
  make: *** [Makefile:156: all] Error 2
  thread 'main' panicked at '
  command did not execute successfully, got: exit status: 2

  build script failed, must exit now', /home/jefferson/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

Any advise on how to fix the problem?

Also, is there any chance you could provide an AppImage version of the connector?

Thanks a lot.

epetousis commented 2 years ago

How are you writing the derivation? I managed to get the extension compiling using the following:

{ lib, fetchFromGitHub, rustPlatform, cmake }:

rustPlatform.buildRustPackage rec {
  pname = "firefox-profile-switcher-connector";
  version = "0.1.1";

  src = fetchFromGitHub {
    owner = "null-dev";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-mnPpIJ+EQAjfjhrSSNTrvCqGbW0VMy8GHbLj39rR8r4=";
  };

  nativeBuildInputs = [ cmake ];

  cargoSha256 = "sha256-EQIBeZwF9peiwpgZNfMmjvLv8NyhvVGUjVXgkf12Wig=";

  postInstall = ''
  mkdir -p $out/lib/mozilla/native-messaging-hosts
  sed -i s#/usr/bin/ff-pswitch-connector#$out/bin/firefox_profile_switcher_connector# manifest/manifest-linux.json
  cp manifest/manifest-linux.json $out/lib/mozilla/native-messaging-hosts/ax.nd.profile_switcher_ff.json
  '';

  meta = with lib; {
    description = "Native connector software for the 'Profile Switcher for Firefox' extension.";
    homepage = "https://github.com/null-dev/firefox-profile-switcher-connector";
    license = licenses.gpl3;
  };
}

You can then add the extension as a messaging host to Firefox with something like:

{
  firefox = prev.firefox.override { extraNativeMessagingHosts = [ firefox-profile-switcher-connector ]; };
}

or:

{
  packages = with pkgs; [
    (firefox.override { extraNativeMessagingHosts = [ firefox-profile-switcher-connector ]; })
  ];
}

This seemed to compile for me just fine against nixpkgs-unstable. The only issue is I can't actually get the extension to switch profiles now...

addy419 commented 1 year ago

@epetousis were you able to get it working?

Edit: Nevermind, got it working with https://github.com/null-dev/firefox-profile-switcher-connector/issues/14#issuecomment-1366879583

genebean commented 11 months ago

Have any of you gotten this working in a way I could consume instead of writing my own thing? Relatedly, anyone submitted it to be in the default set of packages?

addy419 commented 11 months ago

@genebean Yes, I got it working with @epetousis method and the link posted in my comment.

genebean commented 11 months ago

@addy419 is your package / code published somewhere that I can pull from or do I need to replicate what you have done? I am still fairly new to Nix so sorry if this sounds like a no duh question.

addy419 commented 11 months ago

Hi @genebean you can check my config here https://github.com/addy419/configurations/blob/master/modules/desktop/firefox/firefox-profile-switcher-connector.nix and https://github.com/addy419/configurations/blob/master/modules/desktop/firefox/default.nix

Be sure to add the config file pointed in my comment once you are able to do this.

Edit: You can use the config on line 53 in my default.nix and set it automatically.

genebean commented 11 months ago

Many thanks @addy419

genebean commented 1 month ago

I created a packaging request for Nix at https://github.com/NixOS/nixpkgs/issues/332470 - it would be great if you all would +1 it if interested. Also, @epetousis if you are game to submit the package I'd be happy to try and help maintain it. I don't know enough about rust or nix packaging to be the sole maintainer, but am happy to help.

epetousis commented 1 month ago

Is that config hack still necessary to get the extension working? If it isn't I'll happily submit a PR, although it's been a while since I last used this.

genebean commented 1 month ago

Is that config hack still necessary to get the extension working? If it isn't I'll happily submit a PR, although it's been a while since I last used this.

As far as I know, yes. It doesn't seem to be packaged in Nix anywhere.