nixos/.gitlab-ci.yml

68 lines
2.2 KiB
YAML
Raw Normal View History

2023-06-18 20:22:44 +00:00
# borrowed from https://gitlab.com/nix17/nixos-config/-/blob/main/.gitlab-ci.yml
stages:
- flake
- test
2023-07-26 22:23:55 +00:00
- deploy
2023-06-18 20:22:44 +00:00
2023-07-26 22:32:20 +00:00
# Update the flake for any changes upstream
2023-06-18 20:22:44 +00:00
# Passed in from upstream
# $PACKAGE_NAME = name of the flake that needs to be updated
# $UPDATE_FLAKE = flag to update the flake
update:
stage: flake
# from https://forum.gitlab.com/t/git-push-from-inside-a-gitlab-runner/30554/5
before_script:
2023-07-26 22:32:20 +00:00
# set teh ssh key for the commit
2023-07-26 22:35:58 +00:00
- eval $(ssh-agent -s)
2023-06-18 20:22:44 +00:00
- echo "${CI_KEY}" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$CI_KEY" >> ~/.ssh/id_rsa.pub
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- git config --global user.email "${CI_EMAIL}"
- git config --global user.name "${CI_USERNAME}"
# the part that updates the flake
- nix --experimental-features 'nix-command flakes' flake lock --update-input $PACKAGE_NAME
- git add flake.lock
- git commit -m "[skip ci] Updated flake for $PACKAGE_NAME" || echo "No changes, nothing to commit"
# we have a custom domain
2023-06-18 22:05:25 +00:00
- git remote rm origin && git remote add origin ssh://git@gitlab.skynet.ie:2222/compsoc/skynet/nixos.git
2023-06-18 20:22:44 +00:00
- git push origin HEAD:$CI_COMMIT_REF_NAME
only:
refs:
- main
variables:
- $UPDATE_FLAKE == "yes"
build:
stage: test
before_script:
- . "$HOME/.nix-profile/etc/profile.d/nix.sh"
2023-07-27 20:19:33 +00:00
# use the new flake
2023-07-27 21:11:28 +00:00
- git pull
script:
- nix --experimental-features 'nix-command flakes' run nixpkgs#colmena -- build
2023-07-26 22:32:20 +00:00
# every commit on main will build and deploy
2023-07-26 22:23:55 +00:00
deploy:
stage: deploy
before_script:
2023-07-26 22:32:20 +00:00
# setup ssh key
2023-07-26 22:35:58 +00:00
- eval $(ssh-agent -s)
2023-07-26 22:23:55 +00:00
- echo "$DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
2023-07-26 22:32:20 +00:00
# load nix environment
2023-07-26 22:23:55 +00:00
- . "$HOME/.nix-profile/etc/profile.d/nix.sh"
2023-07-27 21:11:28 +00:00
- git pull
2023-07-26 22:23:55 +00:00
script:
2023-07-26 22:32:20 +00:00
# dns is always deployed first
2023-07-26 22:23:55 +00:00
- nix --experimental-features 'nix-command flakes' run nixpkgs#colmena -- apply --on @active-dns
2023-07-26 22:53:26 +00:00
- nix --experimental-features 'nix-command flakes' run nixpkgs#colmena -- apply --on @active-core
2023-07-26 22:32:20 +00:00
- nix --experimental-features 'nix-command flakes' run nixpkgs#colmena -- apply --on @active
only:
refs:
- main