Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use flake to push to ghcr.io with multiplatform images #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use nix

source_env_if_exists .local.envrc
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}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Nix
result
result-*

.direnv
.local.envrc
163 changes: 163 additions & 0 deletions flake.lock

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

75 changes: 75 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
inputs = {
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";
flake = false;
};
devshell.url = "github:numtide/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 =
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./overlay.nix)
(final: prev: {
flakeParameters = {
nixpkgsChannel = "nixos-unstable";
};
})
];
};
pkgs-23-05 = import nixpkgs-23-05 {
inherit system;
overlays = [
(import ./overlay.nix)
(final: prev: {
flakeParameters = {
nixpkgsChannel = "nixos-23.05";
};
})
];
};
pkgs-22-11 = import nixpkgs-22-11 {
inherit system;
overlays = [
(import ./overlay.nix)
(final: prev: {
flakeParameters = {
nixpkgsChannel = "nixos-22.11";
};
})
];
};
in
{
"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 {
inherit system;
overlays = [
devshell.overlays.default
(import ./overlay.nix)
];
};
in
pkgs.devshell.mkShell {
name = "docker-nixpkgs";
commands = [ ];
packages = [ ];
env = [ ];
};
});
}
Loading