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

nix run .# in workspace doesn't work unless version = is set #224

Open
dpc opened this issue Jan 12, 2022 · 5 comments
Open

nix run .# in workspace doesn't work unless version = is set #224

dpc opened this issue Jan 12, 2022 · 5 comments

Comments

@dpc
Copy link
Contributor

dpc commented Jan 12, 2022

Without version = the binary will be /nix/store/0xdfyy5fsl4pisiqki0slc2ajr62jdfg-<name>-unknown/bin/<name> but nix run will try to execute /nix/store/0xdfyy5fsl4pisiqki0slc2ajr62jdfg-<name>-unknown/bin/<name>-unknown

@dpc
Copy link
Contributor Author

dpc commented Jan 12, 2022

Code examples (the fix: crev-dev/cargo-crev@3d24846)

@blitz
Copy link
Member

blitz commented Jan 12, 2022

This is interesting. It seems Nix automatically strips version numbers, but fails (understandably) for the "unknown" suffix. We can either:

  • drop "-unknown" in the derivation names,
  • set meta.programName to ${pname}.

@Sean1708
Copy link

Hmmm.... I'm running into a similar problem where instead of trying to run <name>-unknown it's trying to execute <name>-<version> but the binary is just called <name>. Setting version doesn't fix it, instead I have to strip the version manually in the exePath argument to mkApp.

@Sean1708
Copy link

In case a little more info is useful, my working flake.nix is

{

  inputs = {
    naersk.url = "github:nmattia/naersk/master";
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils, naersk }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
        naersk-lib = pkgs.callPackage naersk { };
        nativeBuildInputs = with pkgs; [ gtk4 pkg-config ];
      in {
        defaultPackage = naersk-lib.buildPackage {
          root = ./.;

          inherit nativeBuildInputs;
        };

        defaultApp = let
          drv = self.defaultPackage."${system}";
          name = pkgs.lib.strings.removeSuffix ("-" + drv.version) drv.name;
        in utils.lib.mkApp {
          inherit drv;
          # TODO: https://github.com/nix-community/naersk/issues/224
          exePath = "/bin/${name}";
        };

        devShell = with pkgs;
          mkShell {
            buildInputs =
              [ cargo rust-analyzer rustc rustfmt rustPackages.clippy ];

            RUST_SRC_PATH = rustPlatform.rustLibSrc;

            inherit nativeBuildInputs;
          };
      });
}

@noebm
Copy link

noebm commented Apr 10, 2024

I just stumbled upon this issue myself.
AFAICT modifying build.nix to use pname instead of specifying name manually should be enough and works for me with flake-utils.lib.mkApp.
This seems to be the preferred method anyway.

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

4 participants