Merge pull request #6 from rycee/refactor-support-code
Refactor support code
This commit is contained in:
commit
6a90fd0664
4 changed files with 71 additions and 48 deletions
|
@ -22,13 +22,13 @@ install:
|
||||||
- travis_retry nix-channel --update
|
- travis_retry nix-channel --update
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- outs=$(nix-build buildable.nix) && echo Produced $outs
|
- nix-build ci.nix -A buildOutputs
|
||||||
- nix eval -f default.nix 'lib'
|
- nix eval -f default.nix 'lib'
|
||||||
- nix eval -f default.nix 'modules'
|
- nix eval -f default.nix 'modules'
|
||||||
- nix eval -f default.nix 'overlays'
|
- nix eval -f default.nix 'overlays'
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- if [ -n "${CACHIX_CACHE}" ]; then cachix push "${CACHIX_CACHE}" $outs; fi
|
- if [ -n "${CACHIX_CACHE}" ]; then nix-build ci.nix -A cacheOutputs | cachix push "${CACHIX_CACHE}"; fi
|
||||||
- if [ "false" = "${TRAVIS_PULL_REQUEST}" -a "master" = "${TRAVIS_BRANCH}" ]; then
|
- if [ "false" = "${TRAVIS_PULL_REQUEST}" -a "master" = "${TRAVIS_BRANCH}" ]; then
|
||||||
curl -XPOST "https://nur-update.herokuapp.com/update?repo=${NUR_REPO}"; fi
|
curl -XPOST "https://nur-update.herokuapp.com/update?repo=${NUR_REPO}"; fi
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
# This file filters out all the unbuildable packages from your package set.
|
|
||||||
# It's what gets built by CI, so if you correctly mark broken/unfree packages
|
|
||||||
# as such your CI will not try to build them and the buildable packages will
|
|
||||||
# be added to the cache.
|
|
||||||
{ pkgs ? import <nixpkgs> {} }:
|
|
||||||
|
|
||||||
let
|
|
||||||
filterSet =
|
|
||||||
(f: g: s: builtins.listToAttrs
|
|
||||||
(map
|
|
||||||
(n: { name = n; value = builtins.getAttr n s; })
|
|
||||||
(builtins.filter
|
|
||||||
(n: f n && g (builtins.getAttr n s))
|
|
||||||
(builtins.attrNames s)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
isReserved = n: builtins.elem n ["lib" "overlays" "modules"];
|
|
||||||
isBroken = p: p.meta.broken or false;
|
|
||||||
isFree = p: p.meta.license.free or true;
|
|
||||||
in filterSet
|
|
||||||
(n: !(isReserved n)) # filter out non-packages
|
|
||||||
(p: (builtins.isAttrs p)
|
|
||||||
&& !(isBroken p)
|
|
||||||
&& isFree p
|
|
||||||
)
|
|
||||||
(import ./default.nix { inherit pkgs; })
|
|
||||||
|
|
56
ci.nix
Normal file
56
ci.nix
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# This file provides all the buildable and cacheable packages and
|
||||||
|
# package outputs in you 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 == "modules";
|
||||||
|
isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
|
||||||
|
isBuildable = p: !(p.meta.broken or false) && p.meta.license.free or false;
|
||||||
|
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;
|
||||||
|
}
|
31
overlay.nix
31
overlay.nix
|
@ -1,23 +1,18 @@
|
||||||
# You can use this file as a nixpkgs overlay.
|
# You can use this file as a nixpkgs overlay. This is useful in the
|
||||||
# It's useful in the case where you don't want to add the whole NUR namespace
|
# case where you don't want to add the whole NUR namespace to your
|
||||||
# to your configuration.
|
# configuration.
|
||||||
|
|
||||||
self: super:
|
self: super:
|
||||||
|
|
||||||
let
|
let
|
||||||
filterSet =
|
|
||||||
(f: g: s: builtins.listToAttrs
|
|
||||||
(map
|
|
||||||
(n: { name = n; value = builtins.getAttr n s; })
|
|
||||||
(builtins.filter
|
|
||||||
(n: f n && g (builtins.getAttr n s))
|
|
||||||
(builtins.attrNames s)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
isReserved = n: builtins.elem n ["lib" "overlays" "modules"];
|
|
||||||
in filterSet
|
|
||||||
(n: !(isReserved n)) # filter out non-packages
|
|
||||||
(p: true) # all packages are ok
|
|
||||||
(import ./default.nix { pkgs = super; })
|
|
||||||
|
|
||||||
|
isReserved = n: n == "lib" || n == "overlays" || n == "modules";
|
||||||
|
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)))
|
||||||
|
|
Loading…
Reference in a new issue