docs: package list

This commit is contained in:
Daniel Langbein 2025-01-22 17:40:49 +01:00
parent 911ec74db2
commit d7172d6452
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
3 changed files with 72 additions and 6 deletions

View File

@ -24,7 +24,8 @@ This document contains general notes about NixOS that are independent of my NixO
* [List system profiles](#list-system-profiles)
* [Deleting generations - Keep most recent X system profiles](#deleting-generations---keep-most-recent-x-system-profiles)
* [Garbage collection - Delete unreachable store objects](#garbage-collection---delete-unreachable-store-objects)
* [why-depends: Why is a package/dependency installed](#why-depends-why-is-a-packagedependency-installed)
* [List installed packages](#list-installed-packages)
* [why-depends: Why is a package installed](#why-depends-why-is-a-package-installed)
* [Compare two system profiles](#compare-two-system-profiles)
* [NixOS configuration debugging](#nixos-configuration-debugging)
* [Show Nix configuration](#show-nix-configuration)
@ -524,7 +525,45 @@ Then remove leftover EFI entries of deleted generations:
sudo /run/current-system/bin/switch-to-configuration boot
```
### why-depends: Why is a package/dependency installed
### List installed packages
https://nix.dev/manual/nix/2.23/command-ref/nix-store
Command explanation:
- `--query`: Display information about store paths.
- `--requisites`: Prints out the closure of the store path paths.
- Closure:
- The closure of a store path is the set of store paths that are directly or indirectly “reachable” from that store path; that is, its the closure of the path under the references relation. For a package, the closure of its derivation is equivalent to the build-time dependencies, while the closure of its output path is equivalent to its runtime dependencies. For correct deployment it is necessary to deploy whole closures, since otherwise at runtime files could be missing. The command nix-store --query --requisites prints out closures of store paths.
- As an example, if the store object at path P contains a reference to a store object at path Q, then Q is in the closure of P. Further, if Q references R then R is also in the closure of P.
```shell
nix-store --query --requisites /run/current-system | grep cpupower
#=> /nix/store/2mnk7jknv47a5ja17i7gwfgmyqng0jbn-cpupower-6.12.10
```
Not sure if this differs from (https://www.reddit.com/r/NixOS/comments/fsummx/comment/fm3xken/):
```shell
nix-store --query --requisites /run/current-system/sw | grep cpupower
#=> /nix/store/2mnk7jknv47a5ja17i7gwfgmyqng0jbn-cpupower-6.12.10
```
Alternative:
- Include [package-list.nix](modules/package-list.nix) in your NixOS config, then a file with this content will be created:
```console
/nix/store/xqvjf11c3kkg6i2zmcv9hdxl6547p1zn-nixpkgs-src/nixos/modules/config/fonts/fontdir.nix
/nix/store/2afpklvkf7xcw2f9kghpza4vfdgiphjj-X11-fonts
/nix/store/xqvjf11c3kkg6i2zmcv9hdxl6547p1zn-nixpkgs-src/nixos/modules/config/fonts/fontconfig.nix
/nix/store/c1alidglhx0as1n7mqf1a0cp4w9pdpy1-fontconfig-2.15.0-bin
/nix/store/xqvjf11c3kkg6i2zmcv9hdxl6547p1zn-nixpkgs-src/nixos/modules/config/console.nix
/nix/store/a0fbsn0xx6c1zviv2y24s2ryy2jdj6k0-kbd-2.6.4
```
### why-depends: Why is a package installed
Usage of `why-depends`: https://github.com/tldr-pages/tldr/blob/f952fc71c2587fa13207aee278eb8795af913438/pages/common/nix3-why-depends.md
@ -533,12 +572,12 @@ Show why the currently running NixOS system requires a certain store path.
- Example: Why is one store path required.
```shell
nix --extra-experimental-features flakes --extra-experimental-features nix-command why-depends /run/current-system /nix/store/mzx8sgjkw7x2p9alq6cgz0vcdzaqz188-openssh-9.6p1
nix --extra-experimental-features flakes --extra-experimental-features nix-command why-depends /run/current-system /nix/store/2mnk7jknv47a5ja17i7gwfgmyqng0jbn-cpupower-6.12.10
```
```console
/nix/store/k7c7576sz868gzjci1z6l6nzmdnpd6xr-nixos-system-yodaTux-23.11pre-git
└───/nix/store/b9mbk3jvazblxfma5p2yvc9xlmvrqxx7-etc
└───/nix/store/mzx8sgjkw7x2p9alq6cgz0vcdzaqz188-openssh-9.6p1
/nix/store/qskanrhcqj6nirzv7v04j0im727yjxh3-nixos-system-yodaTab-24.11pre-git
└───/nix/store/r3qqxybh1g6kg653n04a51m26qw84hxv-system-path
└───/nix/store/2mnk7jknv47a5ja17i7gwfgmyqng0jbn-cpupower-6.12.10
```
- Example: Why are any of the `ffmpeg-headless` store paths currently required?

View File

@ -24,6 +24,7 @@
../../modules/ssh-client.nix
../../modules/ssh-server.nix
../../modules/lid-switch-handling.nix
#../../modules/package-list.nix
../../modules/btrfs-scrub.nix
../../modules/btrfs-mount-options.nix

26
modules/package-list.nix Normal file
View File

@ -0,0 +1,26 @@
# Sources:
# https://www.reddit.com/r/NixOS/comments/fsummx/comment/fm45htj/
# https://www.reddit.com/r/NixOS/comments/fsummx/comment/kt9fb74/
# https://discourse.nixos.org/t/better-why-depends-fill-in-the-gaps/31246/10
# This creates /etc/current-system-packages with list of all packages and their versions.
{ lib, config, options, pkgs, ... }:
{
environment.etc."system-packages-with-source-v1".text =
builtins.concatStringsSep "\n\n" (
map
(x: x.file + "\n" +
builtins.concatStringsSep "\n" (map (s: " " + s) x.value)
)
options.environment.systemPackages.definitionsWithLocations
);
environment.etc."current-system-packages-v2".text =
let
packages = builtins.map (p: "${p.name}") config.environment.systemPackages;
sortedUnique = builtins.sort builtins.lessThan (pkgs.lib.lists.unique packages);
formatted = builtins.concatStringsSep "\n" sortedUnique;
in
formatted;
}