-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
self-hosted-runner: | ||
labels: | ||
- deedee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# yamllint disable rule:comments | ||
--- | ||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | ||
name: nix cache | ||
'on': | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
lint-build-and-push: | ||
runs-on: deedee | ||
steps: | ||
- name: Generate Token | ||
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1 | ||
id: app-token | ||
with: | ||
app-id: "${{ secrets.BOT_APP_ID }}" | ||
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}" | ||
|
||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
token: "${{ steps.app-token.outputs.token }}" | ||
persist-credentials: false | ||
|
||
- name: Flake Check | ||
run: nix flake check | ||
|
||
- name: Build and push to cache | ||
run: | | ||
for sub in $(nix eval --json '.#nixlab.nixConfig.substituters' | jq -r '.[]' | grep '^s3:'); do | ||
for machine in $(nix flake show --json 2> /dev/null | jq -r '.nixosConfigurations | keys | .[]'); do | ||
nix copy --to "$sub" ".#nixosConfigurations.$machine.config.system.build.toplevel" | ||
done | ||
nix copy --to "$sub" .#devShells.x86_64-linux.default | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,8 @@ rec { | |
pruneAll = true; | ||
}; | ||
|
||
github-runners.enable = true; | ||
|
||
incus = { | ||
enable = true; | ||
enableUI = true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ _: { | |
./adguardhome | ||
./ddclient | ||
./docker | ||
./github-runners | ||
./incus | ||
./letsencrypt | ||
./mosquitto | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = config.mySystemApps.github-runners; | ||
in | ||
{ | ||
options.mySystemApps.github-runners = { | ||
enable = lib.mkEnableOption "github runners"; | ||
runners = lib.mkOption { | ||
type = lib.types.int; | ||
description = "Number of runners"; | ||
default = 4; | ||
}; | ||
githubTokenSopsSecret = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Sops secret name containing cloudflare token."; | ||
default = "system/apps/github-runners/github_token"; | ||
}; | ||
}; | ||
|
||
config = | ||
let | ||
paddedNum = n: if n < 10 then "0${builtins.toString n}" else builtins.toString n; | ||
|
||
name = "deedee-ops"; | ||
host = config.networking.hostName; | ||
user = "github-runner"; | ||
group = "github-runner"; | ||
in | ||
lib.mkIf cfg.enable { | ||
sops.secrets."${cfg.githubTokenSopsSecret}" = { | ||
restartUnits = builtins.map (i: "github-runner-${host}-${name}-${paddedNum i}.service") ( | ||
lib.lists.range 1 cfg.runners | ||
); | ||
}; | ||
|
||
users = { | ||
users."${user}" = { | ||
inherit group; | ||
isSystemUser = true; | ||
}; | ||
groups."${group}" = { }; | ||
}; | ||
nix.settings.trusted-users = [ user ]; | ||
|
||
services.github-runners = builtins.listToAttrs ( | ||
builtins.map (i: { | ||
name = "${host}-${name}-${paddedNum i}"; | ||
value = { | ||
inherit user group; | ||
|
||
enable = true; | ||
ephemeral = true; | ||
extraLabels = [ host ]; | ||
extraPackages = [ | ||
pkgs.nix | ||
pkgs.coreutils | ||
pkgs.gnutar | ||
pkgs.jq | ||
pkgs.which | ||
]; | ||
noDefaultLabels = true; | ||
replace = true; | ||
tokenFile = config.sops.secrets."${cfg.githubTokenSopsSecret}".path; | ||
url = "https://github.com/${name}"; | ||
}; | ||
}) (lib.lists.range 1 cfg.runners) | ||
); | ||
}; | ||
} |