Skip to content

Commit

Permalink
nixos/services/flatpak: use nix-flatpak module
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Dec 22, 2024
1 parent 20f03c2 commit e72e1a4
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions modules/nixos/services/flatpak/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
config,
lib,
namespace,
pkgs,
...
}:
let
Expand All @@ -15,15 +14,18 @@ in
options.${namespace}.services.flatpak = {
enable = mkBoolOpt false "Whether or not to enable flatpak support.";
extraRepos = lib.mkOption {
default = {
flathub = "https://flathub.org/repo/flathub.flatpakrepo";
};
type = lib.types.attrsOf lib.types.str;
default = [
{
name = "flathub-beta";
location = "https://flathub.org/beta-repo/flathub-beta.flatpakrepo";
}
];
type = lib.types.listOf (lib.types.attrsOf lib.types.str);
description = "Extra flatpak repositories to add.";
};
extraRefs = lib.mkOption {
extraPackages = lib.mkOption {
default = [ ];
type = lib.types.listOf lib.types.str;
type = lib.types.listOf (lib.types.either lib.types.str (lib.types.attrsOf lib.types.anything));
description = "Flatpaks to install.";
example = [
"https://sober.vinegarhq.org/sober.flatpakref"
Expand All @@ -32,39 +34,11 @@ in
};

config = mkIf cfg.enable {
services.flatpak.enable = true;
systemd.services = {
flatpak-repos = lib.mkIf (cfg.extraRepos != { }) {
services.flatpak = {
enable = true;

wantedBy = [ "multi-user.target" ];
path = [ pkgs.flatpak ];
script =
let
generateRepoScript =
repos:
lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: url: ''
flatpak remote-add --if-not-exists ${name} ${url}
'') repos
);
in
generateRepoScript cfg.extraRepos;
};
flatpak-refs = lib.mkIf (cfg.extraRefs != [ ]) {
wantedBy = [ "multi-user.target" ];
path = [ pkgs.flatpak ];
script =
let
generateRepoScript =
repos:
lib.concatStringsSep "\n" (
lib.map (url: ''
flatpak install --system ${url}
'') repos
);
in
generateRepoScript cfg.extraRefs;
};
remotes = cfg.extraRepos;
packages = cfg.extraPackages;
};
};
}

0 comments on commit e72e1a4

Please sign in to comment.