diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-23 18:38:26 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-23 18:38:26 +0100 |
commit | f92b8b3c229582f3f7095a68df554f9a535ca702 (patch) | |
tree | 1cf5519f73abae8ad627b49856ca010c82d3068c | |
parent | feat(pkgs/back): Init (diff) | |
download | nixos-server-f92b8b3c229582f3f7095a68df554f9a535ca702.tar.gz nixos-server-f92b8b3c229582f3f7095a68df554f9a535ca702.zip |
feat(pkgs): Hook up to the flake and add needed infrastructure
-rw-r--r-- | flake.nix | 3 | ||||
-rwxr-xr-x | pkgs/by-name/ba/back/update.sh | 2 | ||||
-rw-r--r-- | pkgs/default.nix | 22 | ||||
-rwxr-xr-x | pkgs/update_pkgs.sh | 44 | ||||
-rwxr-xr-x | update.sh | 14 |
5 files changed, 83 insertions, 2 deletions
diff --git a/flake.nix b/flake.nix index ff3014f..dc63ea9 100644 --- a/flake.nix +++ b/flake.nix @@ -104,6 +104,7 @@ ]; tests = import ./tests {inherit pkgs specialArgs nixLib;}; + vhackPackages = import ./pkgs {inherit pkgs nixLib;}; inherit (library) nixLib; in { @@ -120,6 +121,8 @@ checks."${system}" = tests; + packages."${system}" = vhackPackages; + devShells."${system}" = { default = pkgs.mkShell { packages = with pkgs; [ diff --git a/pkgs/by-name/ba/back/update.sh b/pkgs/by-name/ba/back/update.sh index 3247c21..c715a63 100755 --- a/pkgs/by-name/ba/back/update.sh +++ b/pkgs/by-name/ba/back/update.sh @@ -11,7 +11,5 @@ # You should have received a copy of the License along with this program. # If not, see <https://www.gnu.org/licenses/agpl.txt>. -nix flake update - [ "$1" = "upgrade" ] && cargo upgrade cargo update diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..e665eb2 --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,22 @@ +{ + pkgs, + nixLib, +}: let + inherit (pkgs) lib; + + warnMergeMessage = "the ./pkgs/by-name set"; + wMM = warnMergeMessage; + callPackage = + lib.callPackageWith + (nixLib.warnMerge + pkgs + vhackPkgs + wMM); + + vhackPkgs = nixLib.mkByName { + baseDirectory = ./by-name; + fileName = "package.nix"; + finalizeFunction = name: value: callPackage value {}; + }; +in + vhackPkgs diff --git a/pkgs/update_pkgs.sh b/pkgs/update_pkgs.sh new file mode 100755 index 0000000..3e33b72 --- /dev/null +++ b/pkgs/update_pkgs.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +die() { + printf "\033[31;1mError: \033[0m%s\n" "$1" + exit 1 +} + +cd "$(dirname "$0")" || die "Bug: run with the wrong first arg: '$0'!" +cd ./by-name || die "(BUG): The directory './by-name' does not exist?" + +# First check if all the update scripts conform to the standard +files_with_update="$(mktemp)" +trap 'rm "$files_with_update"' EXIT + +fd '^update.sh$' . --type file --extension sh --max-depth 3 | while read -r file; do + grep -q "nix flake update" "$file" && echo "$file" >>"$files_with_update" +done + +if [ "$(wc -l <"$files_with_update")" != 0 ]; then + die "Some packages seem to try to update their flake with 'nix flake update'. This is redundant. These Packages are: $(echo && cat "$files_with_update")" +fi + +# Than actually perform the update +fd . --type directory --max-depth 1 | while read -r shard; do + cd "$shard" || die "(BUG): Shard '$shard' does not exist?" + + fd . --type directory --max-depth 1 | while read -r package; do + cd "$package" || die "(BUG): Package '$package' does not exist?" + + if [ -x update.sh ]; then + printf " \033[34;1m> \033[0m\033[34;1m%s\033[0m\n" "Running '${shard}${package}update.sh' .." + + [ -f flake.nix ] && nix flake update + + direnv allow + eval "$(direnv export bash 2>/dev/null)" + ./update.sh "$@" + fi + cd - >/dev/null || die "Bug: Last dir does not exist" + done + cd - >/dev/null || die "Bug: Last dir does not exist" +done + +# vim: ft=sh diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..c43b80b --- /dev/null +++ b/update.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +__update_sh_run() { + __update_sh_command="$1" + shift 1 + + printf "\033[35;1m> \033[0m\033[35;1m%s\033[0m\n" "Running '$(basename "$__update_sh_command")' .." + + "$__update_sh_command" "$@" + + unset __update_sh_command +} + +__update_sh_run ./pkgs/update_pkgs.sh "$@" +# vim: ft=sh |