Need help on failing build - packaging onedriver for nixos

Good Evening, I’m working on packaging onedriver for nixOS.

My derivation is currently as follows:

{stdenv, buildGoModule, fetchFromGitHub, lib, makeWrapper, pkgs, ...}:

{onedriver = buildGoModule rec {
  pname = "onedriver";
  version = "0.14.0";

  src = fetchFromGitHub {
    owner = "jstaf";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-Jo+J719mtsDxqwETT80Q0k6t3bhApBEd4v9dR2w81Y0=";
  };

  nativeBuildInputs = [
    stdenv
    makeWrapper
    pkgs.gcc
    pkgs.libwebkit2gtk-4.0.dev
    pkgs.json-glib.dev
  ];

  buildPhase = ''
    make
  '';

  installPhase = ''
    # Custom installation commands, if needed
    mkdir -p $out/bin
    cp onedriver $out/bin/
  '';

  meta = with lib; {
    description = "onedriver is a native Linux filesystem for Microsoft OneDrive.";
    homepage = "https://github.com/jstaf/onedriver";
    license = licenses.gpl3;
  };

};
}

However, when I use the command nix build --dry-run --file Onedriver.nix onedriver to test this derivation, I get the following error message:

error:
… from call site

     at «none»:0: (source not available)

   error: function 'anonymous lambda' called without required argument 'stdenv'

   at /path/to/file/Onedriver.nix:1:1:

        1| {stdenv, buildGoModule, fetchFromGitHub, lib, makeWrapper, pkgs, ...}:
         | ^
        2|

Could someone help me to find the error in my derivation?

Your file defines a function expecting the following args:

{stdenv, buildGoModule, fetchFromGitHub, lib, makeWrapper, pkgs, ...}:

it means you have to set all those args in the command:

nix build --dry-run \
  --arg stdenv '(import <nixpkgs> {}).stdenv'   \
  --arg fetchFromGitHub '(import <nixpkgs> {}).fetchFromGitHub' \
  --file Onedriver.nix onedriver

Or use callPackage:

nix build --dry-run \
  --expr '((import <nixpkgs> {}).callPackage ./Onedriver.nix {}).onedriver'

Furthermore, I have a local version here that works (yes, it should have been upstreamed):

{ lib
, buildGoModule
, fetchFromGitHub
, installShellFiles
, pkg-config
, glib-networking
, json-glib
, withGUI ? true
, webkitgtk
, wrapGAppsHook
}:

let
  bins = if withGUI then "onedriver onedriver-launcher" else "onedriver-headless";

in
buildGoModule rec {
  pname = "onedriver";
  version = "0.12.0";

  src = fetchFromGitHub {
    owner = "jstaf";
    repo = "onedriver";
    rev = "v${version}";
    hash = "sha256-KuFJKB2SjCl8UL1GMuLpWMkNmHntMzAl5rHoOeY2fYw=";
  };

  vendorSha256 = "sha256-vHmSmluiJdfIvVyAc7Um9v+1I50AGGIYw6la9w8rNso=";

  postPatch = ''
    substituteInPlace resources/onedriver.desktop \
      --replace /usr $out

    substituteInPlace resources/onedriver@.service \
      --replace /usr/bin/fusermount /run/wrappers/bin/fusermount \
      --replace /usr/bin            $out/bin
  '';

  buildInputs = [ glib-networking json-glib ]
    ++ lib.optional withGUI webkitgtk;

  nativeBuildInputs = [ installShellFiles pkg-config ]
    ++ lib.optional withGUI wrapGAppsHook;

  # I couldn't find a way to pass the correct parameter to have it build the
  # headless version when using our Go infrastructure, so just use upstream's
  # Makefile
  buildPhase = ''
    runHook preBuild

    make ${bins}

    runHook postBuild
  '';

  # the Makefile assumes FHS, so we would have to create a bunch of directories
  # for it to work.
  installPhase = ''
    runHook preInstall

    install -Dm555 -t $out/bin                   ${bins}
    install -Dm444 -t $out/share/icons/onedriver resources/*.{png,svg}
    install -Dm444 -t $out/share/applications    resources/*.desktop
    install -Dm444 -t $out/lib/systemd/user      resources/*.service
    install -Dm444 -t $out/share/doc/onedriver   LICENSE *.md
    installManPage resources/*.?

    runHook postInstall
  '';

  doCheck = false;

  meta = with lib; {
    description = "OneDrive file system";
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ peterhoeg ];
  };
}

1 Like