Skip to content

Commit 4f50f8a

Browse files
authored
Initial commit
0 parents  commit 4f50f8a

File tree

14 files changed

+306
-0
lines changed

14 files changed

+306
-0
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/build.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: "Build and populate cache"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
schedule:
9+
# rebuild everyday at 2:51
10+
# TIP: Choose a random time here so not all repositories are build at once:
11+
# https://www.random.org/clock-times/?num=1&earliest=01%3A00&latest=08%3A00&interval=5&format=html&rnd=new
12+
- cron: '51 2 * * *'
13+
jobs:
14+
tests:
15+
strategy:
16+
matrix:
17+
# Set this to notify the global nur package registry that changes are
18+
# available.
19+
#
20+
# The repo name as used in
21+
# https://github.com/nix-community/NUR/blob/master/repos.json
22+
nurRepo:
23+
- <YOUR_REPO_NAME>
24+
# Set this to cache your build results in cachix for faster builds
25+
# in CI and for everyone who uses your cache.
26+
#
27+
# Format: Your cachix cache host name without the ".cachix.org" suffix.
28+
# Example: mycache (for mycache.cachix.org)
29+
#
30+
# For this to work, you also need to set the CACHIX_SIGNING_KEY or
31+
# CACHIX_AUTH_TOKEN secret in your repository secrets settings in
32+
# Github found at
33+
# https://github.com/<your_githubname>/nur-packages/settings/secrets
34+
cachixName:
35+
- <YOUR_CACHIX_NAME>
36+
nixPath:
37+
- nixpkgs=channel:nixos-unstable
38+
- nixpkgs=channel:nixpkgs-unstable
39+
- nixpkgs=channel:nixos-23.11
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
- name: Install nix
45+
uses: cachix/install-nix-action@v26
46+
with:
47+
nix_path: "${{ matrix.nixPath }}"
48+
extra_nix_config: |
49+
experimental-features = nix-command flakes
50+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
51+
- name: Show nixpkgs version
52+
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
53+
- name: Setup cachix
54+
uses: cachix/cachix-action@v14
55+
# Don't replace <YOUR_CACHIX_NAME> here!
56+
if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
57+
with:
58+
name: ${{ matrix.cachixName }}
59+
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
60+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
61+
- name: Check evaluation
62+
run: |
63+
nix-env -f . -qa \* --meta --xml \
64+
--allowed-uris https://static.rust-lang.org \
65+
--option restrict-eval true \
66+
--option allow-import-from-derivation true \
67+
--drv-path --show-trace \
68+
-I nixpkgs=$(nix-instantiate --find-file nixpkgs) \
69+
-I $PWD
70+
- name: Build nix packages
71+
run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs
72+
- name: Trigger NUR update
73+
# Don't replace <YOUR_REPO_NAME> here!
74+
if: ${{ matrix.nurRepo != '<YOUR_REPO_NAME>' }}
75+
run: curl -XPOST "https://nur-update.nix-community.org/update?repo=${{ matrix.nurRepo }}"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
result
2+
result-*
3+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Francesco Gazzetta
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# nur-packages-template
2+
3+
**A 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) to start a repo based on this template. (Do _not_ fork it.)
8+
2. Add your packages to the [pkgs](./pkgs) directory and to
9+
[default.nix](./default.nix)
10+
* Remember to mark the broken packages as `broken = true;` in the `meta`
11+
attribute, or travis (and consequently caching) will fail!
12+
* Library functions, modules and overlays go in the respective directories
13+
3. Choose your CI: Depending on your preference you can use github actions (recommended) or [Travis ci](https://travis-ci.com).
14+
- Github actions: Change your NUR repo name and optionally add a cachix name in [.github/workflows/build.yml](./.github/workflows/build.yml) and change the cron timer
15+
to a random value as described in the file
16+
- Travis ci: Change your NUR repo name and optionally your cachix repo name in
17+
[.travis.yml](./.travis.yml). Than enable travis in your repo. You can add a cron job in the repository settings on travis to keep your cachix cache fresh
18+
5. Change your travis and cachix names on the README template section and delete
19+
the rest
20+
6. [Add yourself to NUR](https://github.com/nix-community/NUR#how-to-add-your-own-repository)
21+
22+
## README template
23+
24+
# nur-packages
25+
26+
**My personal [NUR](https://github.com/nix-community/NUR) repository**
27+
28+
<!-- Remove this if you don't use github actions -->
29+
![Build and populate cache](https://github.com/<YOUR-GITHUB-USER>/nur-packages/workflows/Build%20and%20populate%20cache/badge.svg)
30+
31+
<!--
32+
Uncomment this if you use travis:
33+
34+
[![Build Status](https://travis-ci.com/<YOUR_TRAVIS_USERNAME>/nur-packages.svg?branch=master)](https://travis-ci.com/<YOUR_TRAVIS_USERNAME>/nur-packages)
35+
-->
36+
[![Cachix Cache](https://img.shields.io/badge/cachix-<YOUR_CACHIX_CACHE_NAME>-blue.svg)](https://<YOUR_CACHIX_CACHE_NAME>.cachix.org)
37+

ci.nix

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This file provides all the buildable and cacheable packages and
2+
# package outputs in your package set. These are what gets built by CI,
3+
# so if you correctly mark packages as
4+
#
5+
# - broken (using `meta.broken`),
6+
# - unfree (using `meta.license.free`), and
7+
# - locally built (using `preferLocalBuild`)
8+
#
9+
# then your CI will be able to build and cache only those packages for
10+
# which this is possible.
11+
12+
{ pkgs ? import <nixpkgs> { } }:
13+
14+
with builtins;
15+
let
16+
isReserved = n: n == "lib" || n == "overlays" || n == "modules";
17+
isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
18+
isBuildable = p: !(p.meta.broken or false) && p.meta.license.free or true;
19+
isCacheable = p: !(p.preferLocalBuild or false);
20+
shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false;
21+
22+
nameValuePair = n: v: { name = n; value = v; };
23+
24+
concatMap = builtins.concatMap or (f: xs: concatLists (map f xs));
25+
26+
flattenPkgs = s:
27+
let
28+
f = p:
29+
if shouldRecurseForDerivations p then flattenPkgs p
30+
else if isDerivation p then [ p ]
31+
else [ ];
32+
in
33+
concatMap f (attrValues s);
34+
35+
outputsOf = p: map (o: p.${o}) p.outputs;
36+
37+
nurAttrs = import ./default.nix { inherit pkgs; };
38+
39+
nurPkgs =
40+
flattenPkgs
41+
(listToAttrs
42+
(map (n: nameValuePair n nurAttrs.${n})
43+
(filter (n: !isReserved n)
44+
(attrNames nurAttrs))));
45+
46+
in
47+
rec {
48+
buildPkgs = filter isBuildable nurPkgs;
49+
cachePkgs = filter isCacheable buildPkgs;
50+
51+
buildOutputs = concatMap outputsOf buildPkgs;
52+
cacheOutputs = concatMap outputsOf cachePkgs;
53+
}

default.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file describes your repository contents.
2+
# It should return a set of nix derivations
3+
# and optionally the special attributes `lib`, `modules` and `overlays`.
4+
# It should NOT import <nixpkgs>. Instead, you should take pkgs as an argument.
5+
# Having pkgs default to <nixpkgs> is fine though, and it lets you use short
6+
# commands such as:
7+
# nix-build -A mypackage
8+
9+
{ pkgs ? import <nixpkgs> { } }:
10+
11+
{
12+
# The `lib`, `modules`, and `overlays` names are special
13+
lib = import ./lib { inherit pkgs; }; # functions
14+
modules = import ./modules; # NixOS modules
15+
overlays = import ./overlays; # nixpkgs overlays
16+
17+
example-package = pkgs.callPackage ./pkgs/example-package { };
18+
# some-qt5-package = pkgs.libsForQt5.callPackage ./pkgs/some-qt5-package { };
19+
# ...
20+
}

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
description = "My personal NUR repository";
3+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
4+
outputs = { self, nixpkgs }:
5+
let
6+
systems = [
7+
"x86_64-linux"
8+
"i686-linux"
9+
"x86_64-darwin"
10+
"aarch64-linux"
11+
"armv6l-linux"
12+
"armv7l-linux"
13+
];
14+
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
15+
in
16+
{
17+
legacyPackages = forAllSystems (system: import ./default.nix {
18+
pkgs = import nixpkgs { inherit system; };
19+
});
20+
packages = forAllSystems (system: nixpkgs.lib.filterAttrs (_: v: nixpkgs.lib.isDerivation v) self.legacyPackages.${system});
21+
};
22+
}

lib/default.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{ pkgs }:
2+
3+
with pkgs.lib; {
4+
# Add your library functions here
5+
#
6+
# hexint = x: hexvals.${toLower x};
7+
}

modules/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
# Add your NixOS modules here
3+
#
4+
# my-module = ./my-module;
5+
}

overlay.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# You can use this file as a nixpkgs overlay. This is useful in the
2+
# case where you don't want to add the whole NUR namespace to your
3+
# configuration.
4+
5+
self: super:
6+
let
7+
isReserved = n: n == "lib" || n == "overlays" || n == "modules";
8+
nameValuePair = n: v: { name = n; value = v; };
9+
nurAttrs = import ./default.nix { pkgs = super; };
10+
11+
in
12+
builtins.listToAttrs
13+
(map (n: nameValuePair n nurAttrs.${n})
14+
(builtins.filter (n: !isReserved n)
15+
(builtins.attrNames nurAttrs)))

overlays/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
# Add your overlays here
3+
#
4+
# my-overlay = import ./my-overlay;
5+
}

pkgs/example-package/default.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ stdenv }:
2+
3+
stdenv.mkDerivation rec {
4+
name = "example-package-${version}";
5+
version = "1.0";
6+
src = ./.;
7+
buildPhase = "echo echo Hello World > example";
8+
installPhase = "install -Dm755 example $out";
9+
}

0 commit comments

Comments
 (0)