A tool for looking if installed packages are up to date?

hello

Is there an equivalent in nix to guix refresh ? see guix documentation

When running this command, it looks for installed package, search if upstream (not nixpkgs, but the software upstream) has a newer version and report it. That’s handy to find updates for software we are using.

3 Likes

If upstream is nixpkgs, I use nvd (Nvd: Simple Nix/NixOS version diff tool):


which is part of a nixos-rebuild build --upgrade | nix-output-monitor ; nvd $currentsystem $builtsystem with a prompt asking me if I want to upgrade.
If I don’t, channel is rollbacked.

I guess that reusing the appstream metadata stuff for Software Center, it should be possible to build a true command that will ask upstream in reasonable scenarios, e.g. proper upstream metadata.

3 Likes

That’s cool!

However I’m looking for a program to tell me which package I use in nixpkgs should be updated in nixpkgs :slight_smile:

I think the closest equivalent is the nixpkgs-update tool that automatically updates packages in nixpkgs. See a recent example PR cinnamon.warpinator: 1.2.14 -> 21 by r-ryantm · Pull Request #190934 · NixOS/nixpkgs · GitHub

That tool essentially replaces the need to run guix refresh locally, since it monitors when any package in Nixpkgs can be updated. Assuming of course it knows how to update it.

Thank you, I’ll give it a try. However I need to find a way to feed it with packages installed on my computer. I prefer to focus on those :slight_smile:

I personally instantiate the system locally and diff against repology’s database. I’m using very hacky bash and jq. Would be nice to have a better maintained tool :slight_smile: Example session (it compares against staging local branch):

$ ./fetch_outadted_packages.bash
...
$ ./print_local_outdated.bash
# installed(staging): unstable(master) -> latest(others)
afdko-3.9.0:   "afdko": "python3.10-afdko: 3.9.0 -> 3.9.1",
alsa-ucm-conf-1.2.7.1:   "alsa-ucm-conf": "alsa-ucm-conf: 1.2.7.1 -> 1.2.7.2",
attica-5.97.0:   "attica": "attica: 5.97.0 -> 5.98.0",
audit-2.8.5:   "audit": "audit: 2.8.5 -> 3.0.9",
autoconf-archive-2022.02.11:   "autoconf-archive": "autoconf-archive: 2022.02.11 -> 2022.09.03",
autogen-5.18.16:   "autogen": "autogen: 5.18.16 -> 5.19.96",
aws-c-common-0.7.4:   "aws-c-common": "aws-c-common: 0.7.4 -> 0.8.1",
aws-c-io-0.13.3:   "aws-c-io": "aws-c-io: 0.13.3 -> 0.13.4",
aws-crt-cpp-0.17.32:   "aws-crt-cpp": "aws-crt-cpp: 0.17.32 -> 0.18.5",
aws-c-s3-0.1.46:   "aws-c-s3": "aws-c-s3: 0.1.46 -> 0.1.47",
aws-sdk-cpp-1.9.294:   "aws-sdk-cpp": "aws-sdk-cpp: 1.9.294 -> 1.9.340",
bcache-tools-1.0.7:   "bcache-tools": "bcache-tools: 1.0.7 -> 1.1",
blas-3:   "blas": "blas: 3 -> 3.10.1",
boost-1.79.0:   "boost": "boost: 1.59.0 -> 1.80.0",
...

Gory details (complete implementation):

#! /usr/bin/env bash
# cat installed.bash

nix show-derivation --derivation -r $(nix-instantiate ~/n/nixos -A system) |
    jq -r '.[] | "\(.env.pname) \(.env.version)"' | fgrep -v "null" | sort -u
#!/usr/bin/env bash
# cat fetch_outadted_packages.bash

rm -rfv d
mkdir -p d

suffix=
while :; do
    #break
    echo "Fetching '$suffix'"
    curl --compressed -s "https://repology.org/api/v1/projects/${suffix:+${suffix}/}?inrepo=nix_unstable&outdated=1" > "d/l_${suffix}"
    next=$(jq --sort-keys --raw-output 'keys|last' < "d/l_${suffix}")
    [[ $suffix == $next ]] && break
    suffix=$next
done

# TODO print:
# - nixpkgs version
# - newest version
# - nixpkgs name
for f in d/l_*; do
jq --sort-keys '

map_values({
  "newest": map(
    select(.status|in({"newest":1}))
  )|first(.[].version),
  "nix_unstable_version": map(
    select(.repo|in({"nix_unstable":1}))
  )|first(.[].version),
  "nix_name": map(
    select(.repo|in({"nix_unstable":1}))
  )|first(.[].name),
})' <"${f}" |
# pretty print"
jq --sort-keys '
  map_values(
    "\(.nix_name): \(.nix_unstable_version) -> \(.newest)"
  )
'

done > d/l
#! /usr/bin/env bash
# cat print_local_outdated.bash

echo "# installed(staging): unstable(master) -> latest(others)"
./installed.bash |
while read l; do
    set -- $l
    p=$1
    v=$2
    #echo "$p - $v"
    if [[ $(fgrep '"'"$p"'"' d/l | fgrep -v -- '-> '"$v"'"' | wc -l) -gt 0 ]]; then
        echo -n "$p-$v: "
        fgrep '"'"$p"'"' d/l | fgrep -v -- '-> '"$v"'"'
    fi
done
7 Likes

This is working fine! :star_struck:

That’s a really cool idea. Makes it easy to see where upstream might need some help with things I actually use.

2 Likes

I ended up writing a tool for that as I kept bumping into smaller corner cases that were not handled by simple grep: GitHub - trofi/nix-olde: Show details about outdated packages in your NixOS system.. Now the output looks like that (~/n is nixpkgs/staging):

$ ./mkrun.bash -n ~/n
Fetching 'installed' ...
Fetching 'available' ...
Fetching 'repology' ...
... 'available' done.
... 'installed' done.
... 'repology' done.
repology a52dec "0.8.0" | nixpkgs {"0.7.4"} {"a52dec"}
repology alsa-lib "1.2.8" | nixpkgs {"1.2.7.2"} {"alsa-lib"}
repology alsa-ucm-conf "1.2.8" | nixpkgs {"1.2.7.1"} {"alsa-ucm-conf"}
repology appstream "0.15.6" | nixpkgs {"0.15.5"} {"appstream"}
...
repology xprop "1.2.6" | nixpkgs {"1.2.5"} {"xorg.xprop"}
repology xrandr "1.5.2" | nixpkgs {"1.5.1"} {"xorg.xrandr"}
repology xset "1.2.5" | nixpkgs {"1.2.4"} {"xorg.xset"}
repology xsetroot "1.1.3" | nixpkgs {"1.1.2"} {"xorg.xsetroot"}
repology xterm "378" | nixpkgs {"377"} {"xterm"}
repology zxing-cpp-nu-book "2.0.0" | nixpkgs {"1.4.0"} {"zxing-cpp"}
6 Likes

@trofi I have my flake saved in ~/.dotfiles so when I run: nix run github:trofi/nix-olde
I get:

Fetching 'installed'
Fetching 'repology'
Fetching 'available'
INFO: Failed running ["nix", "--extra-experimental-features", "nix-command", "--extra-experimental-features", "flakes", "flake", "archive", "/etc/nixos", "--json"]: ExitStatus(unix_wait_status(256))

Do I need to compile and run this locally to get it to work with flakes? And any plans on adding this to the nix package repo?

Do I need to compile and run this locally to get it to work with flakes?

It should work as is. I’m a bit surprised you don’t see out / err output on command failures. Can you post the full logs including the command you run?

You can also add -v to see the failure details. My session looks like:

$ nix run github:trofi/nix-olde -- -v
Fetching 'installed'
Fetching 'repology'
Fetching 'available'
...
333 of 1941 (17.16%) installed packages are outdated according to https://repology.org.
...

And any plans on adding this to the nix package repo?

I have no concrete plans but I don’t mind if anyone packages it.

Here you go:

❯ nix run github:trofi/nix-olde -- -v
Fetching 'installed'
Fetching 'repology'
DEBUG: Fetching from repology: ""
Fetching 'available'
INFO: Failed running ["nix", "--extra-experimental-features", "nix-command", "--extra-experimental-features", "flakes", "flake", "archive", "/etc/nixos", "--json"]: ExitStatus(unix_wait_status(256))
INFO: Failed running ["nix", "--extra-experimental-features", "nix-command", "--extra-experimental-features", "flakes", "eval", "--impure", "--raw", "/etc/nixos#nixosConfigurations.nixos.config.system.build.toplevel.drvPath"]: ExitStatus(unix_wait_status(256))
INFO: err> path '/etc/nixos' does not contain a 'flake.nix', searching up
INFO: err> error: could not find a flake.nix file
INFO: err> path '/etc/nixos' does not contain a 'flake.nix', searching up
INFO: err> error: could not find a flake.nix file
DEBUG: Failed to fetch flake archive. Not a flake based system?
INFO: Failed running ["nix-instantiate", "<nixpkgs/nixos>", "-A", "system"]: ExitStatus(unix_wait_status(256))
INFO: err> error:
INFO: err>        … while evaluating the attribute 'config.system.build.toplevel'
INFO: err>          at /nix/store/f3rv70nrmkfya581f1j2z9a6yx0b83np-source/lib/modules.nix:322:9:
INFO: err>           321|         options = checked options;
INFO: err>           322|         config = checked (removeAttrs config [ "_module" ]);
INFO: err>              |         ^
INFO: err>           323|         _module = checked (config._module);
INFO: err>        … while calling the 'seq' builtin
INFO: err>          at /nix/store/f3rv70nrmkfya581f1j2z9a6yx0b83np-source/lib/modules.nix:322:18:
INFO: err>           321|         options = checked options;
INFO: err>           322|         config = checked (removeAttrs config [ "_module" ]);
INFO: err>              |                  ^
INFO: err>           323|         _module = checked (config._module);
INFO: err>        (stack trace truncated; use '--show-trace' to show the full trace)
INFO: err>        error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)
INFO: err>        at «none»:0: (source not available)
'installed' failed, took 1.12 s.
DEBUG: Running ["curl", "--user-agent", "nix-olde/0.2.0 (+https://github.com/trofi/nix-olde)", "--compressed", "https://repology.org/api/v1/projects/?inrepo=nix_unstable&outdated=1"]: ExitStatus(unix_wait_status(0))
'repology' failed, took 5.33 s.

nix-olde was not able to instantiate your system derivation: neither via /etc/nixos/flake.nix (not a flake-based system?) nor via nix-instantiate '<nixpkgs/nixos>' -A system (missing nixos-config). Do you know where any of those comes from on your system?

I may be misunderstanding, but my flake is saved in ~/.dotfiles/flake.nix and my configuration.nix file is in ~/.dotfiles/nixos and my home-manager config is in ~/.dotfiles/home/home.nix.

I tried creating a symlink to it in /etc/nixos, but that gives me the following errors:

INFO: err> error: 'flake.nix' file of flake 'path:/etc/nixos?lastModified=1717976976&narHash=sha256-Uuuq80LpGYXBikTvEoMuGo2b/l8f11dJhvahM9j2Stg%3D' escapes from '/nix/store/i6agp0a5zqm402xr2jl2h7xaci34pybz-source'
INFO: Failed running ["nix", "--extra-experimental-features", "nix-command", "--extra-experimental-features", "flakes", "flake", "archive", "/etc/nixos", "--json"]: ExitStatus(unix_wait_status(256))
INFO: err> error: 'flake.nix' file of flake 'path:/etc/nixos?lastModified=1717976976&narHash=sha256-Uuuq80LpGYXBikTvEoMuGo2b/l8f11dJhvahM9j2Stg%3D' escapes from '/nix/store/i6agp0a5zqm402xr2jl2h7xaci34pybz-source'

My setup may not be vanilla enough, but I just wanted to pass the feedback on. Looks like a cool program. I’m honestly surprised that it isn’t baked into NixOS.

Aha, can yo file a bug in Issues · trofi/nix-olde · GitHub? We’ll try to get it to work for you there.

1 Like

Ok, posted. Thank you for the help.

1 Like