gmodena / nix-flatpak

Install flatpaks declaratively
Apache License 2.0
276 stars 10 forks source link

`overrides` are not applied #54

Closed yellowhat closed 5 months ago

yellowhat commented 6 months ago

Hi, I would like to apply an override to installed flatpak:

    nix-flatpak.url = "github:gmodena/nix-flatpak?ref=v0.3.0";
...
  services = {
    flatpak = {
      enable = true;
      update.onActivation = true;  # Trigger update on system activation
      uninstallUnmanagedPackages = true;
      remotes = [
        {
          name = "flathub";
          location = "https://flathub.org/repo/flathub.flatpakrepo";
        }
      ];
      packages = [
        { appId = "io.freetubeapp.FreeTube"; origin = "flathub"; }
      ];
      overrides = {
        # global = {
          Context.sockets = ["wayland"];
        };
      };
    };
  };

But the overrides are not applied:

$ sudo flatpak override --show io.freetubeapp.Freetube

$ sudo flatpak override --show 

$ flatpak run io.freetubeapp.Freetube --ozone-platform=wayland
<error>

$ flatpak run --socker=wayland io.freetubeapp.Freetube --ozone-platform=wayland
<works>

Thanks Same result with

...
        "io.freetubeapp.FreeTube" = {
          Context.sockets = ["wayland"];
        };
...
gmodena commented 5 months ago

hey @yellowhat could you share some details on how you installed and configured nix-flatpak?

I applied the config you provided to a nixos created using the testing-base/ sample configs and flakes. nix-flatpak is installed as a nixos module.

This is the content of flatpak.nix:

{ lib, ... }: {
    services = {
    flatpak = {
      enable = true;
      update.onActivation = true;  # Trigger update on system activation
      uninstallUnmanaged = true; # I am tracking master, where this config has been introduced.
      packages = [
        { appId = "io.freetubeapp.FreeTube"; origin = "flathub"; }
        { appId = "com.brave.Browser"; origin = "flathub"; }
        "com.obsproject.Studio"
        "im.riot.Riot"
      ];
      overrides = {
        global = {
          Context.sockets = ["wayland"];
        };
      };
    };
  };
}

I built a vm with:

nix build .#nixosConfigurations.test-hm-module.config.system.build.vm

After activation (on boot):

[antani@nixos:~]$ /nix/store/wwkvnj972s80c835ssnci4f2sgzggrjc-flatpak-1.14.4/bin/flatpak override --show 
[Context]
sockets=wayland
yellowhat commented 5 months ago

Sure.

{
  description = "HTPC on NixOS";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nix-flatpak.url = "github:gmodena/nix-flatpak?ref=v0.3.0";
    home-manager = {
      url = "github:nix-community/home-manager/master";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    disko = {
      url = "github:nix-community/disko";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, nix-flatpak, home-manager, ... }@attrs:
    let system = "x86_64-linux";
    in {
      nixosConfigurations = {
        # Build qcow2 images and run in VM
        qcow2 = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [
            nix-flatpak.nixosModules.nix-flatpak
            (import "${home-manager}/nixos")
            ./os/common.nix
            ./os/qcow2.nix
          ];
        };
        # htpc host
        htpc = nixpkgs.lib.nixosSystem {
          inherit system;
          specialArgs = attrs;
          modules = [
            nix-flatpak.nixosModules.nix-flatpak
            (import "${home-manager}/nixos")
            ./os/common.nix
            ./os/htpc.nix
          ];
        };
      };
    };
}
{ pkgs, home-manager, ... }: {
...
  services = {
    fstrim.enable = true;
    openssh.enable = true;
    flatpak = {
      enable = true;
      update.onActivation = true; # Trigger update on system activation
      uninstallUnmanagedPackages = true;
      remotes = [{
        name = "flathub";
        location = "https://flathub.org/repo/flathub.flatpakrepo";
      }];
      packages = [
        {
          appId = "io.freetubeapp.FreeTube";
          origin = "flathub";
        }
        {
          appId = "org.mozilla.firefox";
          origin = "flathub";
        }
      ];
      overrides = {
        global = {
          # Force Wayland by default
          Context.sockets = ["wayland" "!x11" "!fallback-x11"];
        };
      };
    };
    pipewire = {
      enable = true;
      alsa.enable = true;
      pulse.enable = true;
    };
  };
}

I have just retried, and I am not sure what changed but the "overrides" shows now:

$ flatpak override --show
[Context]
sockets=!fallback-x11;!x11;wayland

But seems not applied for the application:

$ flatpak run io.freetubeapp.FreeTube --ozone-platform=wayland
<error>
$ flatpak --socket=wayland run io.freetubeapp.FreeTube --ozone-platform=wayland
<works as expected>

Update

...
      overrides = {
        "io.freetubeapp.FreeTube" = {
          Context.sockets = ["wayland"];
        };
      };

seems to work.

yellowhat commented 5 months ago

Sorry for wasting your time, seems a problem with FreeTube and running in a VM. On bare-metal everything works as expected.

Thanks for this amazing project.