Compare commits

...

5 commits

Author SHA1 Message Date
Bruno BELANYI 464ed92b00 pkgs: diff-flake: re-order functions
All checks were successful
continuous-integration/drone/push Build is passing
This makes it more consistent across the entire file, and follows
alphabetical order (home -> host -> shell).
2023-03-16 11:49:26 +00:00
Bruno BELANYI 08740e846f pkgs: diff-flake: quote attribute names
Since we don't know if they contain `.` or other characters that might
need quoting.
2023-03-16 11:49:26 +00:00
Bruno BELANYI 66fc43f7ca pkgs: diff-flake: 0.3.1 -> 0.4.0
Add home-manager configurations.
2023-03-16 11:49:26 +00:00
Bruno BELANYI a5da0abbc2 pkgs: diff-flake: 0.3.0 -> 0.3.1
Add all dev shells when run without any arguments.
2023-03-16 11:49:26 +00:00
Bruno BELANYI b56674728f pkgs: diff-flake: 0.2.0 -> 0.3.0
Change how `devShells` is handled: always build for the current system
and instead query for the name of the shell that should be built.
2023-03-16 11:49:26 +00:00
2 changed files with 48 additions and 17 deletions

View file

@ -1,7 +1,7 @@
{ lib, coreutils, git, gnused, makeWrapper, stdenvNoCC }: { lib, coreutils, git, gnused, makeWrapper, stdenvNoCC }:
stdenvNoCC.mkDerivation rec { stdenvNoCC.mkDerivation rec {
pname = "diff-flake"; pname = "diff-flake";
version = "0.2.0"; version = "0.4.0";
src = ./diff-flake; src = ./diff-flake;

View file

@ -20,19 +20,21 @@ sanitize_output() {
fi fi
} }
add_shell() { current_system() {
local SYSTEM nix eval --raw --impure --expr 'builtins.currentSystem'
if [ $# -gt 0 ] && [ -n "$1" ]; then }
SYSTEM="$1"
else add_home() {
SYSTEM="$(nix eval --raw --impure --expr 'builtins.currentSystem')" FLAKE_OUTPUTS+=("homeConfigurations.\"$1\".activationPackage")
fi
# Use 'inputDerivation' attribute to make sure that it is build-able
FLAKE_OUTPUTS+=("devShells.$SYSTEM.default.inputDerivation")
} }
add_host() { add_host() {
FLAKE_OUTPUTS+=("nixosConfigurations.$1.config.system.build.toplevel") FLAKE_OUTPUTS+=("nixosConfigurations.\"$1\".config.system.build.toplevel")
}
add_shell() {
# Use 'inputDerivation' attribute to make sure that it is build-able
FLAKE_OUTPUTS+=("devShells.\"$(current_system)\".\"$1\".inputDerivation")
} }
usage() { usage() {
@ -52,17 +54,21 @@ usage() {
print_err " -p, --previous-rev" print_err " -p, --previous-rev"
print_err " which git revision should be considered the 'previous' state," print_err " which git revision should be considered the 'previous' state,"
print_err " defaults to HEAD~" print_err " defaults to HEAD~"
print_err " --home [name]"
print_err " specify the name of a home-manager output configuration whose"
print_err " closure should be diffed, can be used multiple times"
print_err " if no configuration name is given, defaults to current username"
print_err " --host [name]" print_err " --host [name]"
print_err " specify the name of a NixOS output configuration whose" print_err " specify the name of a NixOS output configuration whose"
print_err " closure should be diffed, can be used multiple times" print_err " closure should be diffed, can be used multiple times"
print_err " if no host name is given, defaults to current hostname" print_err " if no host name is given, defaults to current hostname"
print_err " --shell [system]" print_err " --shell [name]"
print_err " specify a specific system's devShell output whose closure" print_err " specify a specific devShell configuration name whose closure"
print_err " should be diffed, can be used multiple times" print_err " should be diffed, can be used multiple times"
print_err " if no system is given, defaults to current system" print_err " if no name is given, defaults to 'default'"
print_err "" print_err ""
print_err "when no flake outputs are specified, automatically queries for" print_err "when no flake outputs are specified, automatically queries for"
print_err "all NixOS configurations, and devShell for current system" print_err "all NixOS configurations, and devShells for current system"
} }
is_option() { is_option() {
@ -95,6 +101,14 @@ parse_args() {
PREVIOUS_REV="$(git rev-parse "$1")" PREVIOUS_REV="$(git rev-parse "$1")"
shift shift
;; ;;
--home)
if [ $# -gt 0 ] && ! is_option "$1"; then
add_home "$1"
shift
else
add_home "$USER"
fi
;;
--host) --host)
if [ $# -gt 0 ] && ! is_option "$1"; then if [ $# -gt 0 ] && ! is_option "$1"; then
add_host "$1" add_host "$1"
@ -108,7 +122,7 @@ parse_args() {
add_shell "$1" add_shell "$1"
shift shift
else else
add_shell add_shell "default"
fi fi
;; ;;
--) --)
@ -124,12 +138,24 @@ parse_args() {
done done
} }
list_home_configurations() {
nix eval '.#homeConfigurations' \
--apply 'attrs: with builtins; concatStringsSep "\n" (attrNames attrs)' \
--raw
}
list_nixos_configurations() { list_nixos_configurations() {
nix eval '.#nixosConfigurations' \ nix eval '.#nixosConfigurations' \
--apply 'attrs: with builtins; concatStringsSep "\n" (attrNames attrs)' \ --apply 'attrs: with builtins; concatStringsSep "\n" (attrNames attrs)' \
--raw --raw
} }
list_dev_shells() {
nix eval ".#devShells.\"$(current_system)\"" \
--apply 'attrs: with builtins; concatStringsSep "\n" (attrNames attrs)' \
--raw
}
diff_output() { diff_output() {
local PREV NEW; local PREV NEW;
PREV="$(mktemp --dry-run)" PREV="$(mktemp --dry-run)"
@ -149,10 +175,15 @@ diff_output() {
parse_args "$@" parse_args "$@"
if [ "${#FLAKE_OUTPUTS[@]}" -eq 0 ]; then if [ "${#FLAKE_OUTPUTS[@]}" -eq 0 ]; then
for home in $(list_home_configurations); do
add_home "$home"
done
for host in $(list_nixos_configurations); do for host in $(list_nixos_configurations); do
add_host "$host" add_host "$host"
done done
add_shell for shell in $(list_dev_shells); do
add_shell "$shell"
done
fi fi
for out in "${FLAKE_OUTPUTS[@]}"; do for out in "${FLAKE_OUTPUTS[@]}"; do