See changes between two generations

#1

If I use system.autoUpgrade.enable = true, how can I see which upgrades were installed between two generations?

0 Likes

#2

NixOS doesn’t do upgrades in the traditional sense.
Nix builds a new system, that may share some data with the old system if it happens to use the same derivations.
There are basically two ways to go about this:

  1. Compare the input (typically nixpkgs and your configuration)
    For your own configuration, you should use a version control system to get the differences.
    For nixpkgs, you can look up the system path that contains the nixpkgs git revision that was used to build it (/nix/store/x04dfrwv3qariypy4m7lw4ldz98rmm4s-nixos-system-yuna-18.09.2347.fdb5b68d155 -> nixpkgs git revision fdb5b68d155) and read the Commit messages between these two commits.

  2. Ask nix about each system generation for the full set of derivations that each generation uses and then compare them for their differences.
    First thing is to get the links to the generations you want to compare:

$ ls -ld /nix/var/nix/profiles/system* /run/current-system /run/booted-system
lrwxrwxrwx 1 root root 15 20. Mär 01:25 /nix/var/nix/profiles/system -> system-185-link
lrwxrwxrwx 1 root root 79  8. Feb 16:23 /nix/var/nix/profiles/system-165-link -> /nix/store/77jx66dn1f0r8da2i1xm28m8hwcyfgzv-nixos-system-yuna-18.09.git.b1f4d5d
lrwxrwxrwx 1 root root 84 28. Feb 05:55 /nix/var/nix/profiles/system-166-link -> /nix/store/l0kgd1w5ja6m7s7vhz3sy1rhzblqjmis-nixos-system-yuna-18.09.2273.1374ba6080b
lrwxrwxrwx 1 root root 79 28. Feb 10:27 /nix/var/nix/profiles/system-167-link -> /nix/store/3116yzipa3dhcfjlgzl7ymycnpqm8icw-nixos-system-yuna-18.09.git.49043ea
lrwxrwxrwx 1 root root 79  2. Mär 01:21 /nix/var/nix/profiles/system-168-link -> /nix/store/0xan64rv784fg2s47ic79h52403qi5h5-nixos-system-yuna-18.09.git.49043ea
lrwxrwxrwx 1 root root 79  2. Mär 01:23 /nix/var/nix/profiles/system-169-link -> /nix/store/0d53g9j6snh2wp2wz8mf2zx61lvlgxyk-nixos-system-yuna-18.09.git.49043ea
lrwxrwxrwx 1 root root 79  4. Mär 03:48 /nix/var/nix/profiles/system-170-link -> /nix/store/45bnngnm7a38f67akkadnh07mb4w1f27-nixos-system-yuna-18.09.git.c4e8634
lrwxrwxrwx 1 root root 84  4. Mär 04:41 /nix/var/nix/profiles/system-171-link -> /nix/store/spbrvhdkl32qki22l4yz0c224z94bgjy-nixos-system-yuna-18.09.2300.770d3ca4910
lrwxrwxrwx 1 root root 84  5. Mär 00:16 /nix/var/nix/profiles/system-172-link -> /nix/store/gyv6mfs79w6hyjcsfy8x0pmlbr03balz-nixos-system-yuna-18.09.2300.770d3ca4910
lrwxrwxrwx 1 root root 79  5. Mär 22:26 /nix/var/nix/profiles/system-173-link -> /nix/store/6479wbbcvmczz89nliapf8ww35x28s3y-nixos-system-yuna-18.09.git.1fc3a8b
lrwxrwxrwx 1 root root 79  7. Mär 22:50 /nix/var/nix/profiles/system-174-link -> /nix/store/fybwb0pkv8zg8fzzw6yjnkvnyjg72laz-nixos-system-yuna-18.09.git.1fc3a8b
lrwxrwxrwx 1 root root 79  7. Mär 23:31 /nix/var/nix/profiles/system-175-link -> /nix/store/csp3fdd3gi7jq8wbk95wq6qrxzzd6ssk-nixos-system-yuna-18.09.git.1fc3a8b
lrwxrwxrwx 1 root root 79  7. Mär 23:40 /nix/var/nix/profiles/system-176-link -> /nix/store/42a5zcz6gdyzlbqy4sd8fn3nf4brzfxh-nixos-system-yuna-18.09.git.1fc3a8b
lrwxrwxrwx 1 root root 79 13. Mär 00:02 /nix/var/nix/profiles/system-177-link -> /nix/store/8pi6rfgccl9x2r1n3xgncljfhl8ywnvj-nixos-system-yuna-18.09.git.1fc3a8b
lrwxrwxrwx 1 root root 79 15. Mär 03:13 /nix/var/nix/profiles/system-178-link -> /nix/store/rxlgci5raax4dmjfqrszad8ysxdsblmh-nixos-system-yuna-18.09.git.b5bfc29
lrwxrwxrwx 1 root root 79 16. Mär 02:33 /nix/var/nix/profiles/system-179-link -> /nix/store/d1dnblsf2f5xj8cw3qr96qv342wp6pjn-nixos-system-yuna-18.09.git.b5bfc29
lrwxrwxrwx 1 root root 79 16. Mär 03:11 /nix/var/nix/profiles/system-180-link -> /nix/store/awcj0m4jnq5wbdij4dajryq4607i0mdl-nixos-system-yuna-18.09.git.b5bfc29
lrwxrwxrwx 1 root root 84 16. Mär 05:33 /nix/var/nix/profiles/system-181-link -> /nix/store/x04dfrwv3qariypy4m7lw4ldz98rmm4s-nixos-system-yuna-18.09.2347.fdb5b68d155
lrwxrwxrwx 1 root root 79 16. Mär 21:15 /nix/var/nix/profiles/system-182-link -> /nix/store/7qsjmalyvli3c1lihzn3kamsd7g82dqy-nixos-system-yuna-18.09.git.bf51577
lrwxrwxrwx 1 root root 79 19. Mär 23:35 /nix/var/nix/profiles/system-183-link -> /nix/store/aiw9dxq1m0r52vxc8kra943jj1r4mabs-nixos-system-yuna-18.09.git.bf51577
lrwxrwxrwx 1 root root 79 20. Mär 00:25 /nix/var/nix/profiles/system-184-link -> /nix/store/n43vmgkxag08sqa235b0k1j1209disn5-nixos-system-yuna-18.09.git.d670e90
lrwxrwxrwx 1 root root 79 20. Mär 01:15 /nix/var/nix/profiles/system-185-link -> /nix/store/h1w0zf0i8zg1160m19bw6ihnsmmpgq15-nixos-system-yuna-18.09.git.d670e90
lrwxrwxrwx 1 root root 79 20. Mär 21:28 /run/booted-system -> /nix/store/h1w0zf0i8zg1160m19bw6ihnsmmpgq15-nixos-system-yuna-18.09.git.d670e90
lrwxrwxrwx 1 root root 79 20. Mär 21:28 /run/current-system -> /nix/store/h1w0zf0i8zg1160m19bw6ihnsmmpgq15-nixos-system-yuna-18.09.git.d670e90

Then get the list of derivations used by each generation:

$ nix-store -qR /nix/var/nix/profiles/system-184-link
/nix/store/7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27
/nix/store/3s920c43pgzi6vdabjs90in308jnbckv-zlib-1.2.11
[...]

To compare them you can use something like the following command, here I’m comparing the generations 184 and 185, which only differ through configuration changes, not any updates to nixpkgs.

$ diff -Naur <( nix-store -qR /nix/var/nix/profiles/system-184-link ) <( nix-store -qR /nix/var/nix/profiles/system-185-link ) | egrep ^[+-]/
-/nix/store/hbzc2rk2mqp4f7z7ylv9wcz4gm42fjgs-font-adobe-75dpi-1.0.3
-/nix/store/szqi2l00ijd5zix6i4p6ljh4y7h9n4ad-kyocera-ppds-1.4
-/nix/store/maf70vcsgp04k32b5iy21rnrilaq6izx-cups-progs
-/nix/store/wcq7xs1kgl3vf989zxxfl4sx5mcgmrq0-cups-files.conf
-/nix/store/z6gd2prsy32g8qi4ka5hc19fzknw15pb-snmp.conf
-/nix/store/m8j9i7aq180xb7l6mcp1kz5fj2ay4v35-cups-progs
-/nix/store/hdhvj8l5vlyjnvyhvva3ilhykmzhfn7g-unit-script-cups-pre-start
-/nix/store/i8ld0glqrb2mgrjzb6pxx0sxdh1vcdr1-unit-zfs-share.service
-/nix/store/icq4p3mkc8c1flmbysidsyxfv2dgbpdl-libva-vdpau-driver-0.7.4
-/nix/store/iqz3rqdc92d2x11k0v7w7jiva19vx7xg-unit-script-nix-gc-start
-/nix/store/iwk62wwyb5hhqlr32wibxxkhh832764h-unit-upower.service
-/nix/store/j4l88fq04w5j4fp5pjn22mdl65hnvbjr-unit-zfs-import.target
-/nix/store/j6l5mcbkjwdyv2d10zk1piw7m1n0n3nd-desktops
-/nix/store/jmcj5yryd3f4cqmqxx1nbvh58j78fwgh-unit-burpClient.service
-/nix/store/y9mlxa5frlff3s6idhsrzssp7yq2fvll-Xresources-Xft
-/nix/store/k19fa5a2cgsc09nr8nzq56j3p05bjfvi-xsession-wrapper
-/nix/store/y2ndj4bwdlgmlijv679fvai9aklifzyk-unit-script-prepare-kexec-start
-/nix/store/k5rzi579hyz240srqqsx2viab2rf7jss-unit-prepare-kexec.service
-/nix/store/kd28l168krl6kxxlyj61qdxvnni3vbzv-unit-network-interfaces.target
-/nix/store/kd49ram95ri5bqz69q3293nk3qkzrckl-mesa-drivers+txc-18.1.7
-/nix/store/kdwsfn6c6jiyj1hcvd011rwl8lj24rbw-unit-network-online.target
+/nix/store/hbzc2rk2mqp4f7z7ylv9wcz4gm42fjgs-font-adobe-75dpi-1.0.3
+/nix/store/i8ld0glqrb2mgrjzb6pxx0sxdh1vcdr1-unit-zfs-share.service
+/nix/store/iwk62wwyb5hhqlr32wibxxkhh832764h-unit-upower.service
+/nix/store/j4l88fq04w5j4fp5pjn22mdl65hnvbjr-unit-zfs-import.target
+/nix/store/jmcj5yryd3f4cqmqxx1nbvh58j78fwgh-unit-burpClient.service
+/nix/store/y2ndj4bwdlgmlijv679fvai9aklifzyk-unit-script-prepare-kexec-start
+/nix/store/k5rzi579hyz240srqqsx2viab2rf7jss-unit-prepare-kexec.service
+/nix/store/kd28l168krl6kxxlyj61qdxvnni3vbzv-unit-network-interfaces.target
+/nix/store/kdwsfn6c6jiyj1hcvd011rwl8lj24rbw-unit-network-online.target
+/nix/store/szqi2l00ijd5zix6i4p6ljh4y7h9n4ad-kyocera-ppds-1.4
+/nix/store/maf70vcsgp04k32b5iy21rnrilaq6izx-cups-progs
+/nix/store/wcq7xs1kgl3vf989zxxfl4sx5mcgmrq0-cups-files.conf
+/nix/store/z6gd2prsy32g8qi4ka5hc19fzknw15pb-snmp.conf
+/nix/store/m8j9i7aq180xb7l6mcp1kz5fj2ay4v35-cups-progs
+/nix/store/hdhvj8l5vlyjnvyhvva3ilhykmzhfn7g-unit-script-cups-pre-start
+/nix/store/iqz3rqdc92d2x11k0v7w7jiva19vx7xg-unit-script-nix-gc-start
+/nix/store/j6l5mcbkjwdyv2d10zk1piw7m1n0n3nd-desktops
+/nix/store/y9mlxa5frlff3s6idhsrzssp7yq2fvll-Xresources-Xft
+/nix/store/k19fa5a2cgsc09nr8nzq56j3p05bjfvi-xsession-wrapper
+/nix/store/icq4p3mkc8c1flmbysidsyxfv2dgbpdl-libva-vdpau-driver-0.7.4
+/nix/store/kd49ram95ri5bqz69q3293nk3qkzrckl-mesa-drivers+txc-18.1.7
-/nix/store/n43vmgkxag08sqa235b0k1j1209disn5-nixos-system-yuna-18.09.git.d670e90
+/nix/store/h1w0zf0i8zg1160m19bw6ihnsmmpgq15-nixos-system-yuna-18.09.git.d670e90
1 Like

#3

I’ve found the nox-update command in https://github.com/madjar/nox to be really useful for this. It produces a lot of output when comparing two entire systems, so I usually run it like this to get a higher-level summary:

nox-update --quiet /run/current-system result | \
grep -v '\.drv : $' | \
sed 's|^ */nix/store/[a-z0-9]*-||' | \
sort -u
0 Likes

#4

You can use nix-diff to see the difference between two generations.

nix run nixpkgs.nix-diff
cd /nix/var/nix/profiles
nix-diff $(nix-store -qd system-1139-link system-1140-link)

Unfortunately you have to provide the deriver files instead of the output paths, hence the nix-store -qd.

2 Likes

#5

It looks like this works for NixOS but doesn’t provide anything useful on a single-user Nix install on macOS:

bash-3.2$ nix-diff $(nix-store -qd profile-49-link profile-50-link)
- /nix/store/98m72sh8yj6qrk421sf1yab81ysbyb8r-user-environment.drv:{out}
+ /nix/store/nashi0qvbgrybxwfs24864kahslxzz95-user-environment.drv:{out}
• The set of input sources do not match:
    - /nix/store/q62ifwlk3pa5ab634bcsvg6qqjam84fn-env-manifest.nix
    + /nix/store/jylxqib8rima6yp92kvf1zic0gp9kzdk-env-manifest.nix
0 Likes

#6

That just tells you that you need to diff those two files

diff /nix/store/q62ifwlk3pa5ab634bcsvg6qqjam84fn-env-manifest.nix /nix/store/jylxqib8rima6yp92kvf1zic0gp9kzdk-env-manifest.nix
0 Likes

#7

Ah. Unfortunately, those files are single-line JSON blobs so diffing isn’t very effective >_< I suppose I could write tooling around this.

Alternatively, I may just explore trying to script diffing the output of nix-env -q between generations, using NIX_PROFILE to specify the generation to look at. That will probably give me the closest output to what I want (which is primarily to see which explicitly requested packages were installed/uninstalled/updated in each generation). I’m kind of surprised there’s no built-in way to diff generations like this.

0 Likes

#8

You should have a look at nix-script diff-generations ... from https://github.com/matthiasbeyer/nixos-scripts. It is the best option that I am aware of.

1 Like

#9

Thanks! Kind of surprised there’s no derivation to install that.

0 Likes