feat: Add Nix backend support#220
Conversation
ripytide
left a comment
There was a problem hiding this comment.
Pretty good PR, thanks for adding a changelog too.
| } | ||
| } | ||
|
|
||
| fn append_profile_arg(args: &mut Vec<String>, config: &NixConfig) { |
There was a problem hiding this comment.
Don't bother trying to make the code overly DRY, I'd again just inline this logic when it is needed, see other backends for examples.
There was a problem hiding this comment.
This is still relevant I believe
| config: &Self::Config, | ||
| ) -> Result<()> { | ||
| for (name, options) in packages { | ||
| let mut args = vec!["nix".to_string(), "profile".to_string(), "add".to_string()]; |
There was a problem hiding this comment.
Inlining the profile logic may also mean you no longer need all these .to_string() calls, or at least if you do you can that after in a .map(|x| x.to_string()`
dbfaadd to
d2c376b
Compare
|
Thanks for the feedback. I've updated the PR according to suggested changes. |
| if !packages.is_empty() { | ||
| let mut args = vec!["nix", "profile", "remove"] | ||
| .into_iter() | ||
| .map(String::from) | ||
| .collect::<Vec<_>>(); | ||
| if let Some(profile) = &config.profile { | ||
| args.extend(["--profile".to_string(), profile.clone()]); | ||
| } | ||
| args.extend(packages.iter().cloned()); | ||
| run_command(args, Perms::Same)?; |
There was a problem hiding this comment.
Please try to follow the patterns from other backends, mainly using iterator methods for building the arguments rather than a mutable vec. Here is an example from dnf.rs:
fn install_packages(
packages: &BTreeMap<String, Self::PackageOptions>,
no_confirm: bool,
_: &Self::Config,
) -> Result<()> {
if !packages.is_empty() {
run_command(
["dnf", "install"]
.into_iter()
.chain(Some("--assumeyes").filter(|_| no_confirm))
.chain(packages.keys().map(String::as_str)),
Perms::Sudo,
)?;
}
Ok(())
}|
Here is an example of how I would rewrite your fn update_packages(packages: &BTreeSet<String>, _: bool, config: &Self::Config) -> Result<()> {
if !packages.is_empty() {
run_command(
["nix", "profile", "upgrade"]
.into_iter()
.chain(Some("--profile").filter(|_| config.profile.is_some()))
.chain(config.profile.as_deref())
.chain(Some("--impure").filter(|_| config.impure))
.chain(Some("--accept-flake-config").filter(|_| config.accept_flake_config))
.chain(packages.iter().map(String::as_str)),
Perms::Same,
)?;
}
Ok(())
} |
|
I refactored the command building parts of concerned functions. |
Related to #219
I took a first pass at Nix support in Metapac, using
nix profileas the backend.What’s in:
clean-cachefor nix runsnix store gcWhat’s not in (yet):
Why these choices:
Validation:
Happy to incorporate any feedback !