···11+MIT License
22+33+Copyright (c) 2018 Francesco Gazzetta
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
2222+
+37
README.md
···11+# nur-packages-template
22+33+**A template for [NUR](https://github.com/nix-community/NUR) repositories**
44+55+## Setup
66+77+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.)
88+2. Add your packages to the [pkgs](./pkgs) directory and to
99+ [default.nix](./default.nix)
1010+ * Remember to mark the broken packages as `broken = true;` in the `meta`
1111+ attribute, or travis (and consequently caching) will fail!
1212+ * Library functions, modules and overlays go in the respective directories
1313+3. Choose your CI: Depending on your preference you can use github actions (recommended) or [Travis ci](https://travis-ci.com).
1414+ - 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
1515+ to a random value as described in the file
1616+ - Travis ci: Change your NUR repo name and optionally your cachix repo name in
1717+ [.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
1818+5. Change your travis and cachix names on the README template section and delete
1919+ the rest
2020+6. [Add yourself to NUR](https://github.com/nix-community/NUR#how-to-add-your-own-repository)
2121+2222+## README template
2323+2424+# nur-packages
2525+2626+**My personal [NUR](https://github.com/nix-community/NUR) repository**
2727+2828+<!-- Remove this if you don't use github actions -->
2929+
3030+3131+<!--
3232+Uncomment this if you use travis:
3333+3434+[](https://travis-ci.com/<YOUR_TRAVIS_USERNAME>/nur-packages)
3535+-->
3636+[](https://<YOUR_CACHIX_CACHE_NAME>.cachix.org)
3737+
+56
ci.nix
···11+# This file provides all the buildable and cacheable packages and
22+# package outputs in your package set. These are what gets built by CI,
33+# so if you correctly mark packages as
44+#
55+# - broken (using `meta.broken`),
66+# - unfree (using `meta.license.free`), and
77+# - locally built (using `preferLocalBuild`)
88+#
99+# then your CI will be able to build and cache only those packages for
1010+# which this is possible.
1111+1212+{ pkgs ? import <nixpkgs> { } }:
1313+1414+with builtins;
1515+let
1616+ isReserved = n: n == "lib" || n == "overlays" || n == "modules";
1717+ isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
1818+ isBuildable = p: let
1919+ licenseFromMeta = p.meta.license or [];
2020+ licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [licenseFromMeta];
2121+ in !(p.meta.broken or false) && builtins.all (license: license.free or true) licenseList;
2222+ isCacheable = p: !(p.preferLocalBuild or false);
2323+ shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false;
2424+2525+ nameValuePair = n: v: { name = n; value = v; };
2626+2727+ concatMap = builtins.concatMap or (f: xs: concatLists (map f xs));
2828+2929+ flattenPkgs = s:
3030+ let
3131+ f = p:
3232+ if shouldRecurseForDerivations p then flattenPkgs p
3333+ else if isDerivation p then [ p ]
3434+ else [ ];
3535+ in
3636+ concatMap f (attrValues s);
3737+3838+ outputsOf = p: map (o: p.${o}) p.outputs;
3939+4040+ nurAttrs = import ./default.nix { inherit pkgs; };
4141+4242+ nurPkgs =
4343+ flattenPkgs
4444+ (listToAttrs
4545+ (map (n: nameValuePair n nurAttrs.${n})
4646+ (filter (n: !isReserved n)
4747+ (attrNames nurAttrs))));
4848+4949+in
5050+rec {
5151+ buildPkgs = filter isBuildable nurPkgs;
5252+ cachePkgs = filter isCacheable buildPkgs;
5353+5454+ buildOutputs = concatMap outputsOf buildPkgs;
5555+ cacheOutputs = concatMap outputsOf cachePkgs;
5656+}
+20
default.nix
···11+# This file describes your repository contents.
22+# It should return a set of nix derivations
33+# and optionally the special attributes `lib`, `modules` and `overlays`.
44+# It should NOT import <nixpkgs>. Instead, you should take pkgs as an argument.
55+# Having pkgs default to <nixpkgs> is fine though, and it lets you use short
66+# commands such as:
77+# nix-build -A mypackage
88+99+{ pkgs ? import <nixpkgs> { } }:
1010+1111+{
1212+ # The `lib`, `modules`, and `overlays` names are special
1313+ lib = import ./lib { inherit pkgs; }; # functions
1414+ modules = import ./modules; # NixOS modules
1515+ overlays = import ./overlays; # nixpkgs overlays
1616+1717+ example-package = pkgs.callPackage ./pkgs/example-package { };
1818+ # some-qt5-package = pkgs.libsForQt5.callPackage ./pkgs/some-qt5-package { };
1919+ # ...
2020+}
···11+{
22+ # Add your NixOS modules here
33+ #
44+ # my-module = ./my-module;
55+}
+15
overlay.nix
···11+# You can use this file as a nixpkgs overlay. This is useful in the
22+# case where you don't want to add the whole NUR namespace to your
33+# configuration.
44+55+self: super:
66+let
77+ isReserved = n: n == "lib" || n == "overlays" || n == "modules";
88+ nameValuePair = n: v: { name = n; value = v; };
99+ nurAttrs = import ./default.nix { pkgs = super; };
1010+1111+in
1212+builtins.listToAttrs
1313+ (map (n: nameValuePair n nurAttrs.${n})
1414+ (builtins.filter (n: !isReserved n)
1515+ (builtins.attrNames nurAttrs)))
+5
overlays/default.nix
···11+{
22+ # Add your overlays here
33+ #
44+ # my-overlay = import ./my-overlay;
55+}
+9
pkgs/example-package/default.nix
···11+{ stdenv }:
22+33+stdenv.mkDerivation rec {
44+ name = "example-package-${version}";
55+ version = "1.0";
66+ src = ./.;
77+ buildPhase = "echo echo Hello World > example";
88+ installPhase = "install -Dm755 example $out";
99+}