Facing a strange error when building a C program from Github

So I was trying to build the keydogger, a C-language program from github (I am using flake) but I was getting a very strange error even though everything is seemingly fine?

Command ran:

nix build .#keydogger

Error:

error: flake 'git+file:///home/abdulla/.dotfiles?dir=myApplications' does not provide attribute 'packages.x86_64-linux.keydogger', 'legacyPackages.x86_64-linux.keydogger' or 'keydogger'

I tried to look it up online and even asked Chatgpt but chatgpt keeps telling me to repeat the correction I already made again and again. I have been kind of breaking my head at this simple problem for the last 2 hours but can’t seem to get it to work. Can anyone help me out here?

Here’s my file structure:

.
├── flake.lock
├── flake.nix
└── keydogger.nix

Here’s the content of my flake.nix:

# flake.nix

{
  description = "Testing";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs, ... }:
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; config = {}; overlays = []; };
    lib = pkgs.lib;
  in {
    packages = {
      keydogger = pkgs.callPackage ./keydogger.nix { };
    };

    defaultPackage.x86_64-linux = self.packages.x86_64-linux.keydogger; # chatgpt answer had this line, so I put this here, though removing or adding this line did nothing.
    };
}

Here’s the content of my keydogger.nix:

# keydogger.nix

{ stdenv, fetchFromGitHub, gcc, make, wl-clipboard }:

stdenv.mkDerivation rec {
  pname = "keydogger";
  version = "1.0";

  src = fetchFromGitHub {
    owner = "jarusll";
    repo = "keydogger";
    rev = "main";  # Use a specific commit hash for reproducibility
    sha256 = "";  # Placeholder
  };

  buildInputs = [
    wl-clipboard
    gcc
    make
  ];

  buildPhase = ''
    echo "Building keydogger..."
    make
  '';

  installPhase = ''
    echo "Installing keydogger..."
    mkdir -p $out/bin
    cp -r * $out/bin
  '';

}

I would really appreciate any guidance you can give me here~ Thank you~

It’s as the error says, you have packages.kdogger, you need packages.x86_64-linux.kdogger

Also, your derivation has some issues, I recommend reading the nixpkgs manual to see what’s already provided in stdenv and reading nix.dev for best practices in packages.
(And don’t rely on chatgpt for nix, it’s usually atrocious.)

2 Likes

Thank you for the correction and suggestion, I will look into the nixpkgs manual to write better derivation~

These are the changes I made to the flake.nix (I used ${}) :

...
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; config = {}; overlays = []; };
    lib = pkgs.lib;
  in {
    packages = {
      ${system} = {
        keydogger = pkgs.callPackage ./keydogger.nix { };
      };
    };
...

Even though the build runs a bit longer but I get a new error now:

error:
       … while evaluating a branch condition

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/customisation.nix:263:8:

          262|
          263|     in if missingArgs == {}
             |        ^
          264|        then makeOverridable f allArgs

       … while calling the 'listToAttrs' builtin

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/attrsets.nix:647:5:

          646|     set:
          647|     listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));
             |     ^
          648|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/lrk2jcm53w7brh9k72a4l49gf3v63rxn-source/myApplications/keydogger.nix': No such file or directory

What could be causing this?~

I ran nix build again after changing ${system} to x86_64-linux just to check but the error remains. :\

You forgot to git-add, probably.

Apologies for my late reply, I didn’t get notification for some reason~

I tried to build after git-add but no success :disappointed:

This is the error I get, I added --show-trace option to the nix build:

$ nix build .#keydogger --show-trace
error:
       … from call site

         at /nix/store/3xvw9g3bpj3yb86j0d6szap7r55vfn3y-source/myApplications/flake.nix:18:21:

           17|       x86_64-linux = {
           18|         keydogger = pkgs.callPackage ./home/abdulla/.dotfiles/myApplications/keydogger.nix { };
             |                     ^
           19|         busybox = pkgs.callPackage ./busybox.nix { };

       … while calling 'callPackageWith'

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/customisation.nix:212:35:

          211|   */
          212|   callPackageWith = autoArgs: fn: args:
             |                                   ^
          213|     let

       … from call site

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/customisation.nix:225:10:

          224|         # Filter out arguments that have a default value
          225|         (filterAttrs (name: value: ! value)
             |          ^
          226|         # Filter out arguments that would be passed

       … while calling 'filterAttrs'

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/attrsets.nix:646:5:

          645|     pred:
          646|     set:
             |     ^
          647|     listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));

       … from call site

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/customisation.nix:215:15:

          214|       f = if isFunction fn then fn else import fn;
          215|       fargs = functionArgs f;
             |               ^
          216|

       … while calling 'functionArgs'

         at /nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source/lib/trivial.nix:975:18:

          974|   */
          975|   functionArgs = f:
             |                  ^
          976|     if f ? __functor

       error: getting status of '/nix/store/3xvw9g3bpj3yb86j0d6szap7r55vfn3y-source/myApplications/home': No such file or directory