Skip to content

Commit

Permalink
add: github workflows from flake
Browse files Browse the repository at this point in the history
  • Loading branch information
lucernae committed Aug 26, 2023
1 parent 22fa20c commit fe76433
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 14 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/nix-build-flake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Nix Build
on:
push:
branches:
- master
# for testing at the moment
- flake
pull_request:
workflow_dispatch:
schedule:
# Run once per day
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
nix_system:
- "x86_64-linux"
- "aarch64-linux"
nix_channel:
- "nixos-unstable"
- "nixos-22.11"
- "nixos-23.05"
target_image:
- bash
# - busybox
# - cachix
# - cachix-flakes
# - caddy
# - curl
# - devcontainer
# - docker-compose
# - hugo
# - kubectl
# - kubernetes-helm
# - nginx
# - nix
# - nix-flakes
# - nix-unstable
# - nix-unstable-static
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:${{matrix.nix_channel}}
extra_nix_config: |
filter-syscalls = false
experimental-features = nix-command flakes
extra-platforms = aarch64-linux
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Nix Build Base Images
run: |
nix build '.#docker-nixpkgs.${{matrix.nix_system}}."${{matrix.nix_channel}}".${{matrix.target_image}}'
- name: Login to Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Load to local registry and retag
run: |
export derivation_name=$(nix derivation show '.#docker-nixpkgs.${{matrix.nix_system}}."${{matrix.nix_channel}}".${{matrix.target_image}}' | jq '.[].outputs.out.path' -r)
export tag=$(cat $derivation_name | docker load | awk '{print $3}')
export image_prefix=ghcr.io/${{github.actor}}/${{secrets.CI_PROJECT_PATH}}/${{matrix.target_image}}
docker tag $tag $image_prefix:${{matrix.nix_channel}}--${{matrix.nix_system}}
docker push $image_prefix:${{matrix.nix_channel}}--${{matrix.nix_system}}
manifests-create:
runs-on: ubuntu-latest
strategy:
matrix:
nix_channel:
- "nixos-unstable"
- "nixos-22.11"
- "nixos-23.05"
target_image:
- bash
# - busybox
# - cachix
# - cachix-flakes
# - caddy
# - curl
# - devcontainer
# - docker-compose
# - hugo
# - kubectl
# - kubernetes-helm
# - nginx
# - nix
# - nix-flakes
# - nix-unstable
# - nix-unstable-static
needs:
- build
steps:
- uses: actions/checkout@v3
- name: Login to Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifests
run: |
export image_prefix=ghcr.io/${{github.actor}}/${{secrets.CI_PROJECT_PATH}}/${{matrix.target_image}}
docker manifest create $image_prefix:${{matrix.nix_channel}} \
--amend $image_prefix:${{matrix.nix_channel}}--x86_64-linux \
--amend $image_prefix:${{matrix.nix_channel}}--aarch64-linux
docker manifest push $image_prefix:${{matrix.nix_channel}}
56 changes: 45 additions & 11 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-23-05.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs-22-11.url = "github:NixOS/nixpkgs/nixos-22.11";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
Expand All @@ -9,7 +11,7 @@
devshell.url = "github:numtide/devshell";
};

outputs = { self, nixpkgs, flake-utils, devshell, ... }:
outputs = { self, nixpkgs, nixpkgs-23-05, nixpkgs-22-11, flake-utils, devshell, ... }:
flake-utils.lib.eachDefaultSystem (system: {
formatter = nixpkgs.legacyPackages.${system}.nixpkgs-fmt;
docker-nixpkgs =
Expand All @@ -20,8 +22,24 @@
(import ./overlay.nix)
];
};
pkgs-23-05 = import nixpkgs-23-05 {
inherit system;
overlays = [
(import ./overlay.nix)
];
};
pkgs-22-11 = import nixpkgs-22-11 {
inherit system;
overlays = [
(import ./overlay.nix)
];
};
in
pkgs.docker-nixpkgs;
{
"nixos-unstable" = pkgs.docker-nixpkgs;
"nixos-23.05" = pkgs-23-05.docker-nixpkgs;
"nixos-22.11" = pkgs-22-11.docker-nixpkgs;
};
devShell =
let
pkgs = import nixpkgs {
Expand Down

0 comments on commit fe76433

Please sign in to comment.