home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 291b6d1cb6503a0fd245d22fc5dbd25de8c7f16c
parent 86851d20e5abbc72e23b6701b2673c517220e5e8
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Wed,  6 May 2020 08:40:39 +0200

builds/nixos: add ci.nix and use only on nixos build

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
D.builds/nixos.19.09.yml | 9---------
D.builds/nixos.20.03.yml | 9---------
A.builds/nixos.yml | 9+++++++++
Aci.nix | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpkgs/default.nix | 6++----
5 files changed, 69 insertions(+), 22 deletions(-)

diff --git a/.builds/nixos.19.09.yml b/.builds/nixos.19.09.yml @@ -1,9 +0,0 @@ -image: nixos/19.09 -sources: - - https://gitlab.com/vdemeester/home.git -secrets: - - 0818d60d-b587-4d4e-81d8-dc15072ccb97 -tasks: -- pkgs: | - export CACHIX_SIGNING_KEY=$(cat ~/.cachix.key) - nix-build home/pkgs | cachix push shortbrain diff --git a/.builds/nixos.20.03.yml b/.builds/nixos.20.03.yml @@ -1,9 +0,0 @@ -image: nixos/20.03 -sources: - - https://gitlab.com/vdemeester/home.git -secrets: - - 0818d60d-b587-4d4e-81d8-dc15072ccb97 -tasks: -- pkgs: | - export CACHIX_SIGNING_KEY=$(cat ~/.cachix.key) - nix-build home/pkgs | cachix push shortbrain diff --git a/.builds/nixos.yml b/.builds/nixos.yml @@ -0,0 +1,9 @@ +image: nixos/20.03 +sources: + - https://gitlab.com/vdemeester/home.git +secrets: + - 0818d60d-b587-4d4e-81d8-dc15072ccb97 +tasks: +- pkgs: | + export CACHIX_SIGNING_KEY=$(cat ~/.cachix.key) + nix-build ci.nix -A cacheOutputs | cachix push shortbrain diff --git a/ci.nix b/ci.nix @@ -0,0 +1,58 @@ +# 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 true; + 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 ./pkgs/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; +} diff --git a/pkgs/default.nix b/pkgs/default.nix @@ -1,7 +1,5 @@ -{ system ? builtins.currentSystem }: -let - pkgs = import <nixpkgs> { inherit system; }; -in +{ pkgs ? import <nixpkgs> {} }: + rec { # pre nur-packages import scripts = pkgs.callPackage ./scripts {};