Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,14 @@ locked = false
binstall = false

[flatpak]
# If this is `true` then flatpak packages default to using the `--system`
# option.
# If this is `false` then flatpak packages default to using the `--user`
# option.
# Default: true
systemwide = true
# The default installation to use for flatpak packages. If equal to "user"
# then the --user option is passed when installing packages, if it is equal
# to "system" then the "--system" option is passed, and if it is equal to
# anything else then "--installation={installation}" is passed. If this is
# not set then nothing is passed. This config can be overridden on a
# per-package basis.
# Default: None
installation = "system"

[vscode]
# Since VSCode and VSCodium both operate on the same package database
Expand Down Expand Up @@ -492,7 +494,15 @@ flatpak = {
"package1",
{
name = "package2",
options = { remote = "flathub", systemwide = false }
options = { remote = "flathub", installation = "user" },
},
{
name = "package3",
options = { remote = "flathub", installation = "system" },
},
{
name = "package4",
options = { remote = "flathub", installation = "my_custom_installation" },
},
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/backends/brew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Brew;
#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BrewConfig {
#[serde_inline_default(FlatpakConfig::default().systemwide)]
#[serde_inline_default(BrewConfig::default().quarantine)]
quarantine: bool,
}
impl Default for BrewConfig {
Expand Down
82 changes: 33 additions & 49 deletions src/backends/flatpak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ use serde_inline_default::serde_inline_default;
pub struct Flatpak;

#[serde_inline_default]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct FlatpakConfig {
#[serde_inline_default(FlatpakConfig::default().systemwide)]
pub systemwide: bool,
}
impl Default for FlatpakConfig {
fn default() -> Self {
Self { systemwide: true }
}
installation: Option<String>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FlatpakPackageOptions {
pub systemwide: Option<bool>,
pub installation: Option<String>,
pub remote: Option<String>,
}

Expand Down Expand Up @@ -58,71 +52,61 @@ impl Backend for Flatpak {
return Ok(BTreeMap::new());
}

let system_apps = run_command_for_stdout(
let apps = run_command_for_stdout(
[
"flatpak",
"list",
"--system",
"--app",
"--columns=application",
"--columns=application,installation",
],
Perms::Same,
false,
)?;
let system_apps = system_apps.lines().map(|x| {
(
x.trim().to_owned(),
Self::PackageOptions {
systemwide: Some(true),
remote: None,
},
)
});

let user_apps = run_command_for_stdout(
[
"flatpak",
"list",
"--user",
"--app",
"--columns=application",
],
Perms::Same,
false,
)?;
let user_apps = user_apps.lines().map(|x| {
let apps = apps.lines().map(|line| {
let parts = line.split_whitespace().collect::<Vec<_>>();

(
x.trim().to_owned(),
parts[0].to_string(),
Self::PackageOptions {
systemwide: Some(false),
installation: Some(parts[1].to_string()),
remote: None,
},
)
});

Ok(system_apps.chain(user_apps).collect())
Ok(apps.collect())
}

fn install_packages(
packages: &BTreeMap<String, Self::PackageOptions>,
no_confirm: bool,
config: &Self::Config,
) -> Result<()> {
let mut groups = BTreeMap::new();
for (package, options) in packages {
let installation = options.installation.clone().or(config.installation.clone());
let remote = options.remote.clone();
groups
.entry((installation, remote))
.or_insert_with(Vec::new)
.push(package.clone());
}

for ((installation, remote), packages) in groups {
run_command(
[
"flatpak",
"install",
if options.systemwide.unwrap_or(config.systemwide) {
"--system"
} else {
"--user"
},
]
.into_iter()
.chain(Some("--assumeyes").filter(|_| no_confirm))
.chain(options.remote.as_deref())
.chain([package.as_str()]),
["flatpak", "install"]
.into_iter()
.chain(Some("--assumeyes").filter(|_| no_confirm))
.map(|x| x.to_string())
.chain(match installation.as_deref() {
Some("user") => Some("--user".to_string()),
Some("system") => Some("--system".to_string()),
Some(x) => Some(format!("--installation={x}")),
None => None,
})
.chain(remote)
.chain(packages),
Perms::Same,
)?;
}
Expand Down