mirror of https://github.com/rapenne-s/bento
bento: add command diff
This commit is contained in:
parent
b98bd0f845
commit
f14121f9bb
43
bento
43
bento
|
@ -5,7 +5,7 @@ TIMEOUT=20
|
|||
# FUNCTION LIBRARIES
|
||||
usage() {
|
||||
cat <<EOF
|
||||
usage: bento init | deploy | build [dry-run|test|switch] | status [delay] | flake-update [input]
|
||||
usage: bento init | deploy | diff | build [dry-run|test|switch] | status [delay] | flake-update [input]
|
||||
|
||||
bento init
|
||||
: create the layout for bento in the current directory
|
||||
|
@ -13,6 +13,9 @@ bento init
|
|||
bento deploy
|
||||
: build configurations and deploy configuration files, require to be root
|
||||
|
||||
bento diff
|
||||
: display the closures difference between the current and new system versions
|
||||
|
||||
bento build [dry-run|test|switch]
|
||||
: build configurations, can activate (test or switch) a build locally
|
||||
|
||||
|
@ -42,6 +45,35 @@ check_bento() {
|
|||
fi
|
||||
}
|
||||
|
||||
version_diff() {
|
||||
cd "${CHROOT_DIR}" || exit 5
|
||||
|
||||
for i in $1
|
||||
do
|
||||
test -d "${i}" || continue
|
||||
|
||||
# date calculation
|
||||
LASTLOG=$(find "${i}/logs/" -type f | sort -n | tail -n 1)
|
||||
LASTLOGVERSION="$(basename "$LASTLOG" | awk -F '_' '{ print $2 }' )"
|
||||
EXPECTED_CONFIG="$(awk -F '=' -v host="${i}" 'host == $1 { print $2 }' states.txt)"
|
||||
|
||||
# we can't do anything for non-flakes systems
|
||||
if [ -z "${EXPECTED_CONFIG}" ]; then continue ; fi
|
||||
|
||||
if [ -n "${LASTLOG}" ]
|
||||
then
|
||||
if [ ! "${LASTLOGVERSION}" = "${EXPECTED_CONFIG}" ]
|
||||
then
|
||||
echo "Changes in $i between ${LASTLOGVERSION} and ${EXPECTED_CONFIG}"
|
||||
nix store diff-closures "/nix/store/${LASTLOGVERSION}" "/nix/store/${EXPECTED_CONFIG}"
|
||||
else
|
||||
echo "$i is running the latest version"
|
||||
fi
|
||||
echo "-------------"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
display_status() {
|
||||
cd "${CHROOT_DIR}" || exit 5
|
||||
PRETTY_OUT_COLUMN=$(ls -1 | awk '{ if(length($1) > max) { max = length($1) }} END { print max }')
|
||||
|
@ -731,4 +763,13 @@ then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# show a diff of closures
|
||||
if [ "$1" = "diff" ]
|
||||
then
|
||||
. ./config.sh
|
||||
version_diff "$NAME"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
usage
|
||||
|
|
|
@ -87,3 +87,31 @@ Using `bento status` you can track the current state of each hosts (time since l
|
|||
With `bento flake-update` you can easily update your flakes recursively to the latest version.
|
||||
|
||||
A parameter can be added to only update a given source with, i.e to update all nixpkgs in the flakes `bento flake-update nixpkgs`.
|
||||
|
||||
# Show differences between a running system version and its new version
|
||||
|
||||
With `env NAME=my-laptop bento diff` you can display the differences of packages between what `my-laptop` is running and its new version.
|
||||
|
||||
The output should look like this:
|
||||
|
||||
```
|
||||
Changes in x1 between p50qql7f42rl0fccdwxw45k21pnqb9ii-nixos-system-x1-22.11.20220921.d6490a0 and 7zfxxddmg8l6qc6bksar5gm62ylwsdv5-nixos-system-x1-22.11.20220927.7e52b35
|
||||
bind: 9.18.6 → 9.18.7
|
||||
cpupower: 5.19.9, 5.19.9_fish → 5.19.11, 5.19.11_fish
|
||||
gh: 2.15.0, 2.15.0_fish → 2.16.1, 2.16.1_fish
|
||||
imagemagick: 7.1.0-48 → 7.1.0-49, +18.0 KiB
|
||||
initrd-linux: 5.19.9 → 5.19.11
|
||||
libblockdev: 2.26 → 2.28
|
||||
libbytesize: 2.6 → 2.7
|
||||
libdmtx: 0.7.5 → 0.7.7
|
||||
linux: 5.19.9, 5.19.9-modules → 5.19.11, 5.19.11-modules, +126.6 KiB
|
||||
man: -11.8 KiB
|
||||
nixos: +12.5 KiB
|
||||
nixos-system-x1: 22.11.20220921.d6490a0 → 22.11.20220927.7e52b35
|
||||
opencv: 4.5.4 → 4.6.0, +1901.6 KiB
|
||||
plasma-workspace: +62.4 KiB
|
||||
root-authorized_keys: ∅ → ε
|
||||
source: +701.9 KiB
|
||||
systemsettings: +62.6 KiB
|
||||
-------------
|
||||
```
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
- create the layout for bento in the current directory (only work from flakes)
|
||||
|
||||
- `bento deploy`
|
||||
- build configurations and deploy configuration files, requires to be root
|
||||
- build configurations and deploy configuration files, requires to be root.
|
||||
|
||||
- `bento diff`
|
||||
- display the difference between each remote system version and their new version. Supports `NAME` environment variable.
|
||||
|
||||
- `bento build [dry-run|build|test|switch]`
|
||||
- dry-build or build configurations. Using `test` or `switch`, can be used to apply a configuration locally. Default is `build`.
|
||||
|
@ -31,7 +34,7 @@ A local file `config.sh` is required for Bento, it contains variable used to gen
|
|||
|
||||
`bento` is using the following environment variables as configuration:
|
||||
- `BENTO_DIR`: contains the path of a bento directory, so you can run `bento` commands from anywhere
|
||||
- `NAME`: contains machine names (flake config or directory in `hosts/`) to restrict commands `deploy` and `build` to this machine only
|
||||
- `NAME`: contains machine names (flake config or directory in `hosts/`) to restrict commands `deploy`, `diff` and `build` to this machine only
|
||||
- `VERBOSE`: if defined to anything, display `nixos-rebuild` output for local builds done with `bento build` or `bento deploy`
|
||||
|
||||
# Self update mode
|
||||
|
|
Loading…
Reference in New Issue