Skip to content

Commit 0715588

Browse files
committed
Create config.yml as a central place to set the initial config
1 parent da93776 commit 0715588

7 files changed

Lines changed: 123 additions & 29 deletions

File tree

.github/workflows/build.yml

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,6 @@ jobs:
1515
tests:
1616
strategy:
1717
matrix:
18-
# Set this to notify the global nur package registry that changes are
19-
# available.
20-
#
21-
# The repo name as used in
22-
# https://github.com/nix-community/NUR/blob/master/repos.json
23-
nurRepo:
24-
- <YOUR_REPO_NAME>
25-
# Set this to cache your build results in cachix for faster builds
26-
# in CI and for everyone who uses your cache.
27-
#
28-
# Format: Your cachix cache host name without the ".cachix.org" suffix.
29-
# Example: mycache (for mycache.cachix.org)
30-
#
31-
# For this to work, you also need to set the CACHIX_SIGNING_KEY or
32-
# CACHIX_AUTH_TOKEN secret in your repository secrets settings in
33-
# Github found at
34-
# https://github.com/<your_githubname>/nur-packages/settings/secrets
35-
cachixName:
36-
- <YOUR_CACHIX_NAME>
3718
nixPath:
3819
- nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz
3920
- nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz
@@ -42,23 +23,39 @@ jobs:
4223
steps:
4324
- name: Checkout repository
4425
uses: actions/checkout@v4
26+
4527
- name: Install nix
4628
uses: cachix/install-nix-action@v31
4729
with:
4830
nix_path: "${{ matrix.nixPath }}"
4931
extra_nix_config: |
5032
experimental-features = nix-command flakes
5133
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Get config.yml
36+
id: config
37+
shell: python
38+
run: |
39+
import yaml, os
40+
41+
with open("config.yml") as f:
42+
data = yaml.safe_load(f)
43+
44+
with open(os.environ["GITHUB_OUTPUT"], "a") as out:
45+
out.write(f"cachixName={data.get('cachixName', '')}\n")
46+
out.write(f"nurRepo={data.get('nurRepo', '')}\n")
47+
5248
- name: Show nixpkgs version
5349
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
50+
5451
- name: Setup cachix
5552
uses: cachix/cachix-action@v16
56-
# Don't replace <YOUR_CACHIX_NAME> here!
57-
if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
53+
if: ${{ steps.config.outputs.cachixName != '<YOUR_CACHIX_NAME>' }}
5854
with:
59-
name: ${{ matrix.cachixName }}
55+
name: ${{ steps.config.outputs.cachixName }}
6056
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
6157
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
58+
6259
- name: Check evaluation
6360
run: |
6461
nix-env -f . -qa \* --meta --xml \
@@ -67,9 +64,10 @@ jobs:
6764
--drv-path --show-trace \
6865
-I nixpkgs=$(nix-instantiate --find-file nixpkgs) \
6966
-I $PWD
67+
7068
- name: Build nix packages
71-
run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs
69+
run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached maintainers/ci.nix -A cacheOutputs
70+
7271
- name: Trigger NUR update
73-
# Don't replace <YOUR_REPO_NAME> here!
74-
if: ${{ matrix.nurRepo != '<YOUR_REPO_NAME>' }}
72+
if: ${{ steps.config.outputs.nurRepo != '<YOUR_REPO_NAME>' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
7573
run: curl -XPOST "https://nur-update.nix-community.org/update?repo=${{ matrix.nurRepo }}"

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ An opinionated template for [NUR](https://github.com/nix-community/NUR) reposito
1212
attribute, or CI (and consequently caching) will fail!
1313
* Library functions, modules and overlays go in the respective directories
1414
3. Configure CI: Change your NUR repo name and optionally add a cachix name in
15-
[.github/workflows/build.yml](./.github/workflows/build.yml) and change the
16-
cron timer to a random value as described in the file.
15+
[CMakeLists.txt](./CMakeLists.txt).
1716
4. Change your cachix name on the README template section and delete the rest
1817
5. [Add yourself to NUR](https://github.com/nix-community/NUR#how-to-add-your-own-repository) <!-- markdownlint-disable-line MD013 -->
1918

@@ -24,4 +23,4 @@ My personal [NUR](https://github.com/nix-community/NUR) repository
2423

2524
![Build and populate cache](https://github.com/<YOUR-GITHUB-USER>/nur-packages/workflows/Build%20and%20populate%20cache/badge.svg)
2625

27-
[![Cachix Cache](https://img.shields.io/badge/cachix-<YOUR_CACHIX_CACHE_NAME>-blue.svg)](https://<YOUR_CACHIX_CACHE_NAME>.cachix.org)
26+
[![Cachix Cache](https://img.shields.io/badge/cachix-<YOUR_CACHIX_NAME>-blue.svg)](https://<YOUR_CACHIX_NAME>.cachix.org)

README.md.j2

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% if not setupComplete %}# nur-packages-template
2+
3+
An opinionated template for [NUR](https://github.com/nix-community/NUR) repositories
4+
5+
## Setup
6+
7+
1. Click on [Use this template](https://github.com/nix-community/nur-packages-template/generate) <!-- markdownlint-disable-line MD013 -->
8+
to start a repo based on this template. (Do _not_ fork it.)
9+
2. Add your packages to the [pkgs](./pkgs) directory and to
10+
[default.nix](./default.nix)
11+
* Remember to mark the broken packages as `broken = true;` in the `meta`
12+
attribute, or CI (and consequently caching) will fail!
13+
* Library functions, modules and overlays go in the respective directories
14+
3. Configure: Change your NUR repo name, fill in your GitHub username, and
15+
optionally add a cachix name in [CMakeLists.txt](./CMakeLists.txt).
16+
4. Run `nix run .#maintainers.render_templates` to regenerate the README
17+
5. [Add yourself to NUR](https://github.com/nix-community/NUR#how-to-add-your-own-repository) <!-- markdownlint-disable-line MD013 -->
18+
19+
<!-- markdownlint-disable-next-line MD025 -->{% endif %}
20+
# nur-packages
21+
22+
My personal [NUR](https://github.com/nix-community/NUR) repository
23+
24+
![Build and populate cache](https://github.com/{{ githubUser }}/nur-packages/workflows/Build%20and%20populate%20cache/badge.svg)
25+
26+
[![Cachix Cache](https://img.shields.io/badge/cachix-{{ cachixName }}-blue.svg)](https://{{ cachixName }}.cachix.org)
27+

config.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Set this to true to disable the setup instructions in the README
2+
setupComplete: false
3+
4+
# Set this to your github username
5+
githubUser: "<YOUR-GITHUB-USER>"
6+
7+
# Set this to notify the global nur package registry that changes are
8+
# available.
9+
#
10+
# The repo name as used in
11+
# https://github.com/nix-community/NUR/blob/master/repos.json
12+
nurRepo: "<YOUR_REPO_NAME>"
13+
14+
# Set this to cache your build results in cachix for faster builds
15+
# in CI and for everyone who uses your cache.
16+
#
17+
# Format: Your cachix cache host name without the ".cachix.org" suffix.
18+
# Example: mycache (for mycache.cachix.org)
19+
#
20+
# For this to work, you also need to set the CACHIX_SIGNING_KEY or
21+
# CACHIX_AUTH_TOKEN secret in your repository secrets settings in
22+
# Github found at
23+
# https://github.com/<your_githubname>/nur-packages/settings/secrets
24+
cachixName: "<YOUR_CACHIX_NAME>"

flake.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@
122122
{
123123
legacyPackages = (self.fromPkgs pkgs) // {
124124
inherit (self) lib overlays modules;
125+
126+
# Maintenance scripts
127+
# TODO: Move this out of the flake
128+
maintainers.render_templates = pkgs.stdenvNoCC.mkDerivation {
129+
name = "render_templates";
130+
131+
src = self;
132+
133+
nativeBuildInputs = [ pkgs.makeWrapper ];
134+
135+
installPhase = ''
136+
runHook preInstall
137+
138+
mkdir -p $out/bin
139+
makeWrapper ${pkgs.python3.interpreter} $out/bin/render_templates \
140+
--add-flags "${self}/maintainers/scripts/render_templates.py"
141+
142+
runHook postInstall
143+
'';
144+
};
125145
};
126146
packages = lib.filterAttrs (_: lib.isDerivation) self'.legacyPackages;
127147

ci.nix renamed to maintainers/ci.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let
5050

5151
outputsOf = p: map (o: p.${o}) p.outputs;
5252

53-
nurAttrs = import ./default.nix { inherit pkgs; };
53+
nurAttrs = import ../default.nix { inherit pkgs; };
5454

5555
nurPkgs = flattenPkgs (
5656
listToAttrs (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from jinja2 import Environment, FileSystemLoader
2+
import os, yaml
3+
4+
def load_config(config_path="config.yml"):
5+
with open(config_path, "r") as f:
6+
return yaml.safe_load(f)
7+
8+
def render_all_templates(src_dir=".", config_path="config.yml"):
9+
context = load_config(config_path)
10+
env = Environment(loader=FileSystemLoader(src_dir))
11+
12+
for root, dirs, files in os.walk(src_dir):
13+
for file in files:
14+
if file.endswith(".j2"):
15+
template_path = os.path.join(root, file)
16+
relative_template_path = os.path.relpath(template_path, src_dir)
17+
output_path = os.path.splitext(template_path)[0] # strip .j2
18+
19+
template = env.get_template(relative_template_path)
20+
rendered = template.render(context)
21+
22+
with open(output_path, "w") as f:
23+
f.write(rendered)
24+
25+
if __name__ == "__main__":
26+
render_all_templates()

0 commit comments

Comments
 (0)