Skip to content

Commit

Permalink
Merge pull request #394 from imincik/geonix-update
Browse files Browse the repository at this point in the history
pkgs(geonixcli): add update command
  • Loading branch information
imincik authored Dec 23, 2023
2 parents 238fdb5 + b1023d6 commit 5ff3c94
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test-geonixcli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
nix run ${GITHUB_WORKSPACE}#geonixcli -- search gdal | grep 'geopkgs.gdal'
working-directory: ${{ env.TEMPLATE_PROJECT_DIR }}

- name: Test geonix update
run: |
nix run ${GITHUB_WORKSPACE}#geonixcli -- update
working-directory: ${{ env.TEMPLATE_PROJECT_DIR }}

# NOTE: `geonix override` is tested in test-custom-packages workflow

# TODO: test `geonix up`
72 changes: 48 additions & 24 deletions pkgs/geonixcli/geonix.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ search PACKAGE Search for packages available in Geospatial NIX or Nixpkgs
To search for multiple package names separate them with
pipe ("PACKAGE-X|PACKAGE-Y").
override Create overrides.nix template file in current
directory for building customized Geospatial NIX packages.
update Update Geospatial NIX packages and environment
(will update flake.lock file).
container NAME Build and import container image to Docker local registry.
See: https://devenv.sh/containers
override Create overrides.nix template file in current
directory for building customized Geospatial NIX packages.
EOF
exit
}
Expand Down Expand Up @@ -87,11 +91,15 @@ function parse_params {
return 0
}

parse_params "$@"
setup_colors
NIX_FLAGS=( --accept-flake-config --no-warn-dirty --extra-experimental-features nix-command --extra-experimental-features flakes )

function nix_version {
nix --version | grep --only-matching --extended-regexp '[0-9]+.[0-9]+.[0-9]+'
}

NIX_FLAGS=( --accept-flake-config --no-warn-dirty --extra-experimental-features nix-command --extra-experimental-features flakes )
function versionge {
[ "$1" == "$(echo -e "$1\n$2" | sort --version-sort | tail -n1)" ]
}

function get_nixpkgs_metadata {
nixpkgs_exists=$( \
Expand Down Expand Up @@ -174,6 +182,9 @@ function get_geonix_metadata {
}


parse_params "$@"
setup_colors

# INIT
if [ "${args[0]}" == "init" ]; then

Expand Down Expand Up @@ -269,27 +280,16 @@ elif [ "${args[0]}" == "search" ]; then
fi


# OVERRIDE
elif [ "${args[0]}" == "override" ]; then
# UPDATE
elif [ "${args[0]}" == "update" ]; then

if [ -f "$(pwd)/overrides.nix" ]; then
die "Override template file already exists in $(pwd) directory."
# `nix flake lock --update-input` was removed in nix 2.19
if versionge "$(nix_version)" "2.19.0"; then
# new syntax
nix "${NIX_FLAGS[@]}" flake update geonix
else
cp "$GEONIX_TEMPLATES_DIR"/override/overrides.nix "$(pwd)"/overrides.nix
chmod u+w "$(pwd)"/overrides.nix

echo "Override template file created in $(pwd)/overrides.nix ."
echo
echo "Use overrides.nix file with customizePackages function."
echo
echo "Example usage in geonix.nix file:"
echo "geopkgs = inputs.geonix.lib.customizePackages { "
echo " nixpkgs = pkgs; "
echo " geopkgs = inputs.geonix.packages.\${pkgs.system}; "
echo " overridesFile = ./overrides.nix; "
echo "}; "
echo
echo "And don't forget to add all files to git."
# old syntax
nix "${NIX_FLAGS[@]}" flake lock --update-input geonix
fi


Expand All @@ -313,6 +313,30 @@ elif [ "${args[0]}" == "container" ]; then
echo " docker run --rm -p <PORT>:<PORT> $image_name:latest"


# OVERRIDE
elif [ "${args[0]}" == "override" ]; then

if [ -f "$(pwd)/overrides.nix" ]; then
die "Override template file already exists in $(pwd) directory."
else
cp "$GEONIX_TEMPLATES_DIR"/override/overrides.nix "$(pwd)"/overrides.nix
chmod u+w "$(pwd)"/overrides.nix

echo "Override template file created in $(pwd)/overrides.nix ."
echo
echo "Use overrides.nix file with customizePackages function."
echo
echo "Example usage in geonix.nix file:"
echo "geopkgs = inputs.geonix.lib.customizePackages { "
echo " nixpkgs = pkgs; "
echo " geopkgs = inputs.geonix.packages.\${pkgs.system}; "
echo " overridesFile = ./overrides.nix; "
echo "}; "
echo
echo "And don't forget to add all files to git."
fi


# HELP
elif [ "${args[0]}" == "help" ]; then
usage
Expand Down

0 comments on commit 5ff3c94

Please sign in to comment.