Skip to content

feat: Add Nix backend support - #220

Merged
ripytide merged 4 commits into
ripytide:mainfrom
maax3v3:feature/nix-backend
Jun 27, 2026
Merged

feat: Add Nix backend support#220
ripytide merged 4 commits into
ripytide:mainfrom
maax3v3:feature/nix-backend

Conversation

@maax3v3

@maax3v3 maax3v3 commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Related to #219

I took a first pass at Nix support in Metapac, using nix profile as the backend.

What’s in:

  • basic package lifecycle works: list, install (sync), remove (clean), update (update / update-all)
  • clean-cache for nix runs nix store gc
  • Nix packages in groups can use:
    • name (used as the stable package id in metapac)
    • optional options.installable (if missing, it falls back to nixpkgs#)
    • optional options.priority
  • backend config got a few practical knobs:
    • profile
    • impure
    • accept_flake_config

What’s not in (yet):

  • nix “repo-like” things (registries/channels/etc).

Why these choices:

  • nix profile is the modern CLI and works across distros, not just NixOS.
  • Using name as identity keeps metapac diffs predictable for sync/clean/unmanaged.
  • installable stays optional so common cases are still easy, but custom flakes/sources are supported.

Validation:

  • fmt/test/clippy all pass
  • I also ran manual end-to-end checks with cargo run -- ... + real nix commands:
    • install worked
    • upgrade worked
    • removal worked
    • unmanaged output looked correct

Happy to incorporate any feedback !

@ripytide ripytide left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good PR, thanks for adding a changelog too.

Comment thread src/backends/nix.rs Outdated
Comment thread src/backends/nix.rs Outdated
Comment thread src/backends/nix.rs Outdated
Comment thread src/backends/nix.rs Outdated
@maax3v3
maax3v3 force-pushed the feature/nix-backend branch from dbfaadd to d2c376b Compare April 6, 2026 20:56
@maax3v3

maax3v3 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I've updated the PR according to suggested changes.

@maax3v3
maax3v3 requested a review from ripytide April 6, 2026 21:30
Comment thread src/backends/nix.rs
@ripytide

Copy link
Copy Markdown
Owner

Here is an example of how I would rewrite your update_packages() method in case it helps:

    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(())
    }

@maax3v3

maax3v3 commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

I refactored the command building parts of concerned functions.

@ripytide

Copy link
Copy Markdown
Owner

Looks all good now, thanks for the PR and sorry for the slow review.

@ripytide
ripytide merged commit 71926f2 into ripytide:main Jun 27, 2026
5 checks passed
@ripytide ripytide mentioned this pull request Jun 27, 2026
@maax3v3

maax3v3 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants