Using wine? (Installing Foobar2000)

I wanted to install Foobar2000 on NixOS. However, it will require Wine. But I couldn’t find how to use Wine on NixOS.

Is there a way to package windows applications as if they were native using Wine and Nix?

Some people do this, here’s a discourse thread discussing some options that I keep meaning to read again: What is your approach to packaging Wine applications with Nix derivations?

One day I’ll package all my GoG games :wink:

It’s definitely not necessary, though, you can just use wine with a normal prefix.

1 Like

Here’s an example package using mkWindowsApp, which you can get from my erosanix flake:

The app crashes with an NTLM error, so additional work would be needed, but this gives you the idea.

{ stdenv
, lib
, mkWindowsApp
, wine
, fetchurl
, makeDesktopItem
, makeDesktopIcon
, copyDesktopItems
, copyDesktopIcons
}:
mkWindowsApp rec {
  inherit wine;

  pname = "foobar2000";
  version = "1.6.10";
  wineArch = "win64";

  src = fetchurl {
    url = "https://www.foobar2000.org/files/foobar2000_v${version}.exe";
    sha256 = "02yk82gzddl8rcmr4i5p3nvdcz08c6qkdmk8a1fl4j4yd4piriyk";
  };

  dontUnpack = true;
  nativeBuildInputs = [ copyDesktopItems copyDesktopIcons ];

  winAppInstall = ''
    wine start /unix ${src} /S
  '';

  winAppRun = ''
    wine start /unix "$WINEPREFIX/drive_c/Program Files (x86)/foobar2000/foobar2000.exe"
  '';

  installPhase = ''
    runHook preInstall

    ln -s $out/bin/.launcher $out/bin/${pname}

    runHook postInstall
  '';

  desktopItems = [
    (makeDesktopItem {
      name = pname;
      exec = pname;
      icon = pname;
      desktopName = "Foobar2000";
      categories = ["Audio" "Player"];
    })
  ];

  desktopIcon = makeDesktopIcon {
    name = "foobar2000";

    src = fetchurl {
      url = "https://www.foobar2000.org/favicon.ico";
      sha256 = "1lk997iqaf7ma7jrfld6wc6spcgmz198nhrqclxn7bjvdws4csr6";
    };
  };

  meta = with lib; {
    description = "An advanced freeware audio player for the Windows platform.";
    homepage = "https://www.foobar2000.org";
    license = licenses.unfree;
    platforms = [ "x86_64-linux" ];
   };
}
5 Likes

I got it working :slight_smile:

The package is here.

You can demo it with nix run github:emmanuelrosa/erosanix#foobar2000

5 Likes

Amazing! Thank you so much for sharing this! :smiley:

I hope it’s still current. Do you have an example which demonstrates your issue?

if I try to add the code to my flake.nix file, I get an error about ‘anonymous lambda’

{
  description = "A simple NixOS flake";

  inputs = {
    # NixOS official package source, using the nixos-23.11 branch here
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
        erosanix.url = "github:emmanuelrosa/erosanix";
        home-manager = {
                url = "github:nix-community/home-manager/release-24.05";
                inputs.nixpkgs.follows = "nixpkgs";
        };

        firefox-addons = {
                url = "gitlab:rycee/nur-expressions?dir=pkgs/firefox-addons";
                inputs.nixpkgs.follows = "nixpkgs";
        };
  };

  outputs = { self, home-manager, nixpkgs, erosanix, ... }@inputs:
    # Please replace my-nixos with your hostname
    let
        system = "x86_64-linux";
        pkgs = nixpkgs.legacyPackages.${system};
    in
        {
        nixosConfigurations.default = nixpkgs.lib.nixosSystem {
        specialArgs = {inherit inputs;};
        modules = [
        # Import the previous configuration.nix we used,
        # so the old configuration file still takes effect
        ./configuration.nix
        inputs.home-manager.nixosModules.default
        ];
        environment.systemPackages = with pkgs; [
        erosanix.packages.x86_64-linux.foobar2000
        ];
    };
  };
}
sudo nixos-rebuild switch --flake ".#default"
error:
       … from call site

         at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/flake.nix:24:11:

           23|         nixosSystem = args:
           24|           import ./nixos/lib/eval-config.nix (
             |           ^
           25|             {

       error: function 'anonymous lambda' called with unexpected argument 'environment'

       at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/nixos/lib/eval-config.nix:11:1:

           10| # types.submodule instead of using eval-config.nix
           11| evalConfigArgs@
             | ^
           12| { # !!! system can be set modularly, would be nice to remove,

I think the issue is that you’re adding environment.systemPackages to your flake.nix instead of your configuration.nix.

Take a look at your configuration.nix and see if you already have environment.systemPackages in there.

If that solves your issue, then that would mean my README is incorrect.

Sadly, it doesn’t. When I add it to configuration.nix, I get a different error:

error:
       … while calling the 'head' builtin

         at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/lib/modules.nix:821:9:

          820|     in warnDeprecation opt //
          821|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          822|         inherit (res.defsFinal') highestPrio;

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

       error: undefined variable 'erosanix'

       at /nix/store/5wza875h9dz3mmv17pm61crhksqg8k3l-source/configuration.nix:153:2:

          152|  autojump
          153|  erosanix.packages.x86_64-linux.foobar2000

(And the NUR method doesn’t work for me either.)

edit to add (since I’m a new user, limited responses allowed). adding erosanix at the top yields this:

error:
       … while calling the 'head' builtin

         at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/lib/modules.nix:821:9:

          820|     in warnDeprecation opt //
          821|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          822|         inherit (res.defsFinal') highestPrio;

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

       error: attribute 'erosanix' missing

       at /nix/store/ia1zpg1s63v6b3vin3n7bxxjgcs51s2r-source/lib/modules.nix:520:28:

          519|         addErrorContext (context name)
          520|           (args.${name} or config._module.args.${name})
             |                            ^
          521|       ) (functionArgs f);

@emmanuelrosa I edited this reply since I’m not allowed to post >3 replies to a thread yet.

Check the top of configuration.nix. You probably have lib, pkgs, etc. Add erosanix to it.

Thanks. (Sorry, I had to wait a while before gaining the ability to reply beyond reply 3.)
I’m afraid I already had that added to the list, it doesn’t solve the issue.

Oh this is really impressive, any plans on upstreaming this?

No, because upstream does not accept Windows applications.

Well, it has winbox, which is a windows app: nixpkgs/pkgs/tools/admin/winbox/default.nix at 71e91c409d1e654808b2621f28a327acfdad8dc2 · NixOS/nixpkgs · GitHub

Which upstream are you referring to here?

Also you can just install playonlinux or bottles, if you want an easier configuration

okay, I figured out the issue. to use the flake config, you need to add ‘inputs.’, so ‘inputs.erosanix.packages.x86_64-linux.appname’

Now working fine, except I ran into an issue with .wma playback, it doesn’t work/isn’t supported and crashes foobar. (You see an error about wine.gstreamer in terminal.)

That said, would you mind adding a separate ~build target for 32-bit foobar2000? I’m still using the old facets plugin as I vastly prefer it over the new reFacets one, but it’s 32-bit only.

The 32-bit version is erosanix.packages.i686-linux.foobar2000

I changed the Wine package to the “full” version so that gstreamer is included.

1 Like