mirror of https://gitlab.crans.org/nounous/nixos
Merge branch 'autoflakeupdate' into 'main'
Draft: Ajouter un script d'auto-update nix See merge request nounous/nixos!110merge-requests/110/merge
commit
5df6b8306c
|
|
@ -9,3 +9,14 @@ nix-flake-check:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- nix flake check --no-build
|
- nix flake check --no-build
|
||||||
|
|
||||||
|
# Adapted from https://cobalt.rocks/posts/nix-update/ AGPLv3+
|
||||||
|
|
||||||
|
nix-flake-update:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- nix run .#update-flake
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "schedule"
|
||||||
|
variables:
|
||||||
|
GIT_STRATEGY: clone
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
{
|
{
|
||||||
type = "app";
|
type = "app";
|
||||||
}
|
}
|
||||||
// import (./scripts + "/${name}") { inherit pkgs lib; }
|
// import (./scripts + "/${name}") { inherit inputs pkgs lib; }
|
||||||
)
|
)
|
||||||
) (attrNames (readDir ./scripts))
|
) (attrNames (readDir ./scripts))
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
# Adapted from https://cobalt.rocks/posts/nix-update/ AGPLv3+
|
||||||
|
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
{
|
||||||
|
meta.description = "Script utilisé pour mettre à jour la flake";
|
||||||
|
|
||||||
|
program = pkgs.writeShellApplication {
|
||||||
|
name = "update-flake";
|
||||||
|
runtimeInputs = with pkgs; [
|
||||||
|
jq
|
||||||
|
coreutils
|
||||||
|
gitMinimal
|
||||||
|
glab
|
||||||
|
gnugrep
|
||||||
|
nix
|
||||||
|
coreutils
|
||||||
|
# niks3
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
# sometimes nix does not play well with ssl certs from the CI runner
|
||||||
|
# explicitly providing one should make it less flaky
|
||||||
|
export NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
|
||||||
|
|
||||||
|
git switch "$CI_DEFAULT_BRANCH"
|
||||||
|
|
||||||
|
${lib.toShellVar "inputs" inputs}
|
||||||
|
${lib.toShellVar "updated_inputs" [ ]}
|
||||||
|
|
||||||
|
for input in "''${inputs[@]}"; do
|
||||||
|
if nix flake update "$input" |& tee /dev/stderr | grep -i updated; then
|
||||||
|
updated_inputs+=("$input")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ''${#updated_inputs[@]} -eq 0 ]; then
|
||||||
|
echo "No updates for inputs found"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if [ -n "''${NIKS3_AUTH_TOKEN_FILE:-}" ]; then
|
||||||
|
# if ! nix flake archive --json \
|
||||||
|
# | jq -r '.inputs | .. | objects | .path? // empty' \
|
||||||
|
# | xargs -r niks3 push --auth-token-path "$NIKS3_AUTH_TOKEN_FILE" --max-concurrent-uploads 8; then
|
||||||
|
# echo "warning: failed to upload the updated flake inputs to the Nix cache" >&2
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
|
||||||
|
if [ "''${CI:-}" = "true" ]; then
|
||||||
|
git config --global user.name "$GITLAB_USER_LOGIN"
|
||||||
|
git config --global user.email "$GITLAB_USER_EMAIL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# run formatter
|
||||||
|
nix fmt
|
||||||
|
|
||||||
|
# build commit title/message, this should contain the updated inputs and revs
|
||||||
|
commit_title="''${updated_inputs[*]}"
|
||||||
|
commit_title="''${commit_title// /, }"
|
||||||
|
# commit_title="[ci] Flake update $commit_title"
|
||||||
|
commit_title="[ci] Flake update $(date '+%d/%m/%Y')"
|
||||||
|
|
||||||
|
commit_message=""
|
||||||
|
|
||||||
|
for input in "''${updated_inputs[@]}"; do
|
||||||
|
commit_message="$commit_message$input: $(jq -r .nodes.\""$input"\".locked.rev flake.lock)"$'\n'
|
||||||
|
done
|
||||||
|
commit_message=''${commit_message%$'\n'} # remove trailing newline from last item
|
||||||
|
|
||||||
|
git commit -a -m "$commit_title" -m "$commit_message"
|
||||||
|
git push
|
||||||
|
|
||||||
|
# # a commit from a scheduled job (or a CI job in general), will not trigger a pipeline
|
||||||
|
# # we manually use the gitlab cli to start a pipeline
|
||||||
|
# # auth snippet from https://gitlab.com/gitlab-org/cli#ci-job-token
|
||||||
|
# glab auth login --job-token "$CI_JOB_TOKEN" --hostname "$CI_SERVER_HOST" --api-protocol "$CI_SERVER_PROTOCOL"
|
||||||
|
# GITLAB_HOST="$CI_SERVER_URL" glab ci run-trig -R "$CI_PROJECT_PATH" -b "$CI_DEFAULT_BRANCH"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue