Commit c662fba
2026-04-29 07:34:34
Changed files (14)
.github
workflows
lib
nixos-modules
overlays
pkgs
example-package
.github/workflows/build.yml
@@ -0,0 +1,76 @@
+name: "Build and populate cache"
+on:
+ pull_request:
+ push:
+ branches:
+ - main
+ - master
+ schedule:
+ # rebuild everyday at 2:51
+ # TIP: Choose a random time here so not all repositories are build at once:
+ # https://www.random.org/clock-times/?num=1&earliest=01%3A00&latest=08%3A00&interval=5&format=html&rnd=new
+ - cron: '51 2 * * *'
+ workflow_dispatch:
+jobs:
+ tests:
+ strategy:
+ matrix:
+ # Set this to notify the global nur package registry that changes are
+ # available.
+ #
+ # The repo name as used in
+ # https://github.com/nix-community/NUR/blob/master/repos.json
+ nurRepo:
+ - <YOUR_REPO_NAME>
+ # Set this to cache your build results in cachix for faster builds
+ # in CI and for everyone who uses your cache.
+ #
+ # Format: Your cachix cache host name without the ".cachix.org" suffix.
+ # Example: mycache (for mycache.cachix.org)
+ #
+ # For this to work, you also need to set the CACHIX_SIGNING_KEY or
+ # CACHIX_AUTH_TOKEN secret in your repository secrets settings in
+ # Github found at
+ # https://github.com/<your_githubname>/nur-packages/settings/secrets
+ cachixName:
+ - <YOUR_CACHIX_NAME>
+ nixPath:
+ - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixpkgs-unstable.tar.gz
+ - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz
+ - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-25.11.tar.gz
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v5
+ - name: Install nix
+ uses: cachix/install-nix-action@v31
+ with:
+ nix_path: "${{ matrix.nixPath }}"
+ extra_nix_config: |
+ experimental-features = nix-command flakes
+ access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
+ - name: Show nixpkgs version
+ run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
+ - name: Setup cachix
+ uses: cachix/cachix-action@v16
+ # Don't replace <YOUR_CACHIX_NAME> here!
+ if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
+ with:
+ name: ${{ matrix.cachixName }}
+ signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
+ authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
+ - name: Check evaluation
+ run: |
+ nix-env -f . -qa \* --meta --xml \
+ --allowed-uris https://static.rust-lang.org \
+ --option restrict-eval true \
+ --option allow-import-from-derivation true \
+ --drv-path --show-trace \
+ -I nixpkgs=$(nix-instantiate --find-file nixpkgs) \
+ -I $PWD
+ - name: Build nix packages
+ run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs
+ - name: Trigger NUR update
+ # Don't replace <YOUR_REPO_NAME> here!
+ if: ${{ matrix.nurRepo != '<YOUR_REPO_NAME>' }}
+ run: curl -XPOST "https://nur-update.nix-community.org/update?repo=${{ matrix.nurRepo }}"
.github/dependabot.yml
@@ -0,0 +1,10 @@
+version: 2
+updates:
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ - package-ecosystem: "nix"
+ directory: "/"
+ schedule:
+ interval: "weekly"
lib/default.nix
@@ -0,0 +1,7 @@
+{ pkgs }:
+
+with pkgs.lib; {
+ # Add your library functions here
+ #
+ # hexint = x: hexvals.${toLower x};
+}
nixos-modules/default.nix
@@ -0,0 +1,5 @@
+{
+ # Add your NixOS modules here
+ #
+ # my-module = ./my-module;
+}
overlays/default.nix
@@ -0,0 +1,5 @@
+{
+ # Add your overlays here
+ #
+ # my-overlay = import ./my-overlay;
+}
pkgs/example-package/default.nix
@@ -0,0 +1,9 @@
+{ stdenv }:
+
+stdenv.mkDerivation rec {
+ name = "example-package-${version}";
+ version = "1.0";
+ src = ./.;
+ buildPhase = "echo echo Hello World > example";
+ installPhase = "install -Dm755 example $out";
+}
.gitignore
@@ -0,0 +1,3 @@
+result
+result-*
+
ci.nix
@@ -0,0 +1,56 @@
+# This file provides all the buildable and cacheable packages and
+# package outputs in your package set. These are what gets built by CI,
+# so if you correctly mark packages as
+#
+# - broken (using `meta.broken`),
+# - unfree (using `meta.license.free`), and
+# - locally built (using `preferLocalBuild`)
+#
+# then your CI will be able to build and cache only those packages for
+# which this is possible.
+
+{ pkgs ? import <nixpkgs> { } }:
+
+with builtins;
+let
+ isReserved = n: n == "lib" || n == "overlays" || n == "nixosModules" || n == "homeModules" || n == "darwinModules" || n == "flakeModules";
+ isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
+ isBuildable = p: let
+ licenseFromMeta = p.meta.license or [];
+ licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [licenseFromMeta];
+ in !(p.meta.broken or false) && builtins.all (license: license.free or true) licenseList;
+ isCacheable = p: !(p.preferLocalBuild or false);
+ shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false;
+
+ nameValuePair = n: v: { name = n; value = v; };
+
+ concatMap = builtins.concatMap or (f: xs: concatLists (map f xs));
+
+ flattenPkgs = s:
+ let
+ f = p:
+ if shouldRecurseForDerivations p then flattenPkgs p
+ else if isDerivation p then [ p ]
+ else [ ];
+ in
+ concatMap f (attrValues s);
+
+ outputsOf = p: map (o: p.${o}) p.outputs;
+
+ nurAttrs = import ./default.nix { inherit pkgs; };
+
+ nurPkgs =
+ flattenPkgs
+ (listToAttrs
+ (map (n: nameValuePair n nurAttrs.${n})
+ (filter (n: !isReserved n)
+ (attrNames nurAttrs))));
+
+in
+rec {
+ buildPkgs = filter isBuildable nurPkgs;
+ cachePkgs = filter isCacheable buildPkgs;
+
+ buildOutputs = concatMap outputsOf buildPkgs;
+ cacheOutputs = concatMap outputsOf cachePkgs;
+}
default.nix
@@ -0,0 +1,25 @@
+# This file describes your repository contents.
+# It should return a set of nix derivations
+# and optionally the special attributes `lib`, `overlays`,
+# `nixosModules`, `homeModules`, `darwinModules` and `flakeModules`.
+# It should NOT import <nixpkgs>. Instead, you should take pkgs as an argument.
+# Having pkgs default to <nixpkgs> is fine though, and it lets you use short
+# commands such as:
+# nix-build -A mypackage
+
+{ pkgs ? import <nixpkgs> { } }:
+
+{
+ # The `lib`, `overlays`, `nixosModules`, `homeModules`,
+ # `darwinModules` and `flakeModules` names are special
+ lib = import ./lib { inherit pkgs; }; # functions
+ nixosModules = import ./nixos-modules; # NixOS modules
+ # homeModules = { }; # Home Manager modules
+ # darwinModules = { }; # nix-darwin modules
+ # flakeModules = { }; # flake-parts modules
+ overlays = import ./overlays; # nixpkgs overlays
+
+ example-package = pkgs.callPackage ./pkgs/example-package { };
+ # some-qt5-package = pkgs.libsForQt5.callPackage ./pkgs/some-qt5-package { };
+ # ...
+}
flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1776949667,
+ "narHash": "sha256-GMSVw35Q+294GlrTUKlx087E31z7KurReQ1YHSKp5iw=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "01fbdeef22b76df85ea168fbfe1bfd9e63681b30",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
flake.nix
@@ -0,0 +1,18 @@
+{
+ description = "My personal NUR repository";
+ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+ outputs = { self, nixpkgs }:
+ let
+ forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
+ in
+ {
+ legacyPackages = forAllSystems (system: import ./default.nix {
+ pkgs = import nixpkgs { inherit system; };
+ });
+ packages = forAllSystems (system: nixpkgs.lib.filterAttrs (_: v: nixpkgs.lib.isDerivation v) self.legacyPackages.${system});
+ nixosModules = import ./nixos-modules;
+ # homeModules = import ./home-modules;
+ # darwinModules = import ./darwin-modules;
+ # flakeModules = import ./flake-modules;
+ };
+}
LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2018 Francesco Gazzetta
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
overlay.nix
@@ -0,0 +1,15 @@
+# You can use this file as a nixpkgs overlay. This is useful in the
+# case where you don't want to add the whole NUR namespace to your
+# configuration.
+
+self: super:
+let
+ isReserved = n: n == "lib" || n == "overlays" || n == "nixosModules" || n == "homeModules" || n == "darwinModules" || n == "flakeModules";
+ nameValuePair = n: v: { name = n; value = v; };
+ nurAttrs = import ./default.nix { pkgs = super; };
+
+in
+builtins.listToAttrs
+ (map (n: nameValuePair n nurAttrs.${n})
+ (builtins.filter (n: !isReserved n)
+ (builtins.attrNames nurAttrs)))
README.md
@@ -0,0 +1,37 @@
+# nur-packages-template
+
+**A template for [NUR](https://github.com/nix-community/NUR) repositories**
+
+## Setup
+
+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.)
+2. Add your packages to the [pkgs](./pkgs) directory and to
+ [default.nix](./default.nix)
+ * Remember to mark the broken packages as `broken = true;` in the `meta`
+ attribute, or travis (and consequently caching) will fail!
+ * Library functions, modules and overlays go in the respective directories
+3. Choose your CI: Depending on your preference you can use github actions (recommended) or [Travis ci](https://travis-ci.com).
+ - 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
+ to a random value as described in the file
+ - Travis ci: Change your NUR repo name and optionally your cachix repo name in
+ [.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
+5. Change your travis and cachix names on the README template section and delete
+ the rest
+6. [Add yourself to NUR](https://github.com/nix-community/NUR#how-to-add-your-own-repository)
+
+## README template
+
+# nur-packages
+
+**My personal [NUR](https://github.com/nix-community/NUR) repository**
+
+<!-- Remove this if you don't use github actions -->
+
+
+<!--
+Uncomment this if you use travis:
+
+[](https://travis-ci.com/<YOUR_TRAVIS_USERNAME>/nur-packages)
+-->
+[](https://<YOUR_CACHIX_CACHE_NAME>.cachix.org)
+