Skip to content

Generate a pretty list of packages to be installed from Nix flake configurations

Notifications You must be signed in to change notification settings

admiralakber/nix-extract-flake-programs

Repository files navigation

List programs/packages to be installed given a NixOS flake configuration

nix-extract-flake-programs is a tool to document and compare packages in Nix flakes. Simplify and organise your Nix configurations with ease!

nix-extract-flake-programs 💅✨💻

nix-extract-flake-programs makes it simple to generate a list of installed packages—complete with versions—from your Nix flake configurations. Whether you’re documenting your current setup, comparing multiple configurations, or preparing for a migration, this script quickly produces clean, shareable output.

Say goodbye to manual comparisons and hello to structured, reproducible package documentation.

Try it out now:

nix run github:admiralakber/nix-extract-flake-programs -- -r https://github.com/admiralakber/nix-config -h discipline --stdout

tl;dr 🌸

  • Extracts package lists from nixosConfigurations and Home Manager.
  • Works with any flake configuration, not just the installed one.
  • Outputs a sorted Org-mode table for documentation or comparison.
  • Now runnable directly with Nix flakes!
  • Can even take a git repository as an input!

Features 💕

  • System Packages: Extracts from nixosConfigurations.environment.systemPackages.
  • Home Manager Packages: Includes home.packages if configured.
  • Multi-config Support: Query and compare any flake, not just your installed system.
  • Org-mode Ready: Produces structured tables for seamless documentation.
  • Flake-ready: Use directly from the repository with nix run.
  • Customisable: Specify flake paths and hostnames for flexible use.

Dependencies 📦

This script requires the Nix package manager or NixOS to run. You can install Nix on most Linux distributions and macOS by following the instructions at nixos.org/download.

Required tools:

  • nix (the Nix package manager)
  • jq (JSON parsing utility)
  • emacs (Used for Org-mode table formatting)
  • git (Direct pulling of remote repositories)

Dependency Management:

The script uses a nix-shell shebang, ensuring all dependencies are installed in an isolated environment. No manual installation is required; the shebang fetches:

  • nix
  • jq
  • emacs
  • git

This makes the script self-contained and easy to run on any system with Nix installed.

Installation 💻

The script can now be used directly with Nix flakes. To build locally:

nix-build -o result default.nix

The script will be available at result/bin/nix-extract-flake-programs.

Usage 🎀

Run the script directly using flakes or from a local build. Here’s how:

With Flakes

Run directly from the repository:

nix run github:admiralakber/nix-extract-flake-programs -- --help

Local Build

Run from a locally built binary:

./result/bin/nix-extract-flake-programs --help

Examples

Print the package table to stdout:

nix run github:admiralakber/nix-extract-flake-programs -- --stdout

Save the table to a file for documentation or sharing:

nix run github:admiralakber/nix-extract-flake-programs -- --output packages.org

Query a specific flake and hostname to compare configurations:

nix run github:admiralakber/nix-extract-flake-programs -- --flake /path/to/flake --hostname my-hostname

Specify a git repository directly and print to stdout:

nix run github:admiralakber/nix-extract-flake-programs -- -r https://github.com/admiralakber/nix-config -h discipline --stdout

Specify a branch from a different repo:

nix run github:admiralakber/nix-extract-flake-programs -- -r https://github.com/ryan4yin/nix-config -b i3-kickstarter -h nixos-test --stdout

Example Output 💖

Here’s what you get—useful, structured, and ready to document:

| Package Name             | Version    |
|--------------------------|------------|
| git                      | 2.44.1     |
| vim                      | 9.1.0707   |
| emacs                    | 29.4       |
| curl                     | 8.7.1-bin  |
| sway                     | 1.9        |

FAQ 🌷

Why use this?

I created this script to make it easy to see what’s in my system and quickly produce clean documentation for my Nix configurations. It’s great for auditing, comparing, or just keeping track of your setup. Curious about my setup? Check out my config here: admiralakber/nix-config.

Does it work outside of NixOS?

No, this is a NixOS-specific tool, and there’s no intention of expanding beyond that. If you’re not using NixOS, I highly recommend giving it a try. After 20+ years as a Linux daily driver, I can confidently say NixOS is what I’ve always wanted for my system. If you’re new, my config and ryan4yin’s config & documentation on flakes are great starting points.

What’s Org-mode?

It’s a plain-text markup format for organising and documenting information, commonly used in Emacs. Even if you don’t use Emacs, the tables work perfectly as structured plain text.

Future Plans 🌟

  1. Add better handling for multi-host configurations to streamline fleet management.
  2. Improve error handling for more robust output.
  3. Keep it lightweight and focused—no unnecessary features or bloat.

Suggestions 🪩

Have feedback, ideas, or just want to collaborate? Open an issue or send a pull request. Contributions are always welcome.

Closing Thoughts ✨

This script isn’t fancy—it’s practical and gets the job done. If it helps you document and compare your Nix setups, then it’s doing its job.

Licence

Copyright 2024 Aqeel Akber <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Generate a pretty list of packages to be installed from Nix flake configurations

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages