nix-helpers: d76d6e8a6c5ded37a6e2bde1fd8e587cada27704
1: # Evaluate and/or build all derivations in a release.nix file
2: { attrsToDirs', bash, fail, git, lib, gnutar, wrap }:
3:
4: with rec {
5: inherit (lib) cleanSource concatStringsSep escapeShellArg;
6:
7: # TODO: It might be better to check if the import is callable, rather than
8: # not-an-attrset. In particular, it would be nice to support {__functor = ...}
9: nix_release_eval = wrap {
10: name = "nix_release_eval";
11: paths = [ bash fail ];
12: script = ''
13: #!${bash}/bin/bash
14: set -e
15:
16: if [[ "x$1" = "x-h" ]] || [[ "x$1" = "x--help" ]] || [[ "x$1" = "x-?" ]]
17: then
18: {
19: echo "nix_release_eval: Find all Nix derivations defined in a file"
20: echo
21: echo "Set the F env var to the path you'd like to import. If F is not"
22: echo "set, we default to looking for a ./release.nix file, then"
23: echo "./nix/release.nix, then ./default.nix and finally"
24: echo "./nix/default.nix; the first one found will be used, or we abort"
25: echo "if none is found."
26: echo
27: echo "We import this path in a Nix derivation, and check if it's an"
28: echo "attrset; if so, we look through it recursively for derivations."
29: echo "If it's not an attrset, we try calling it with argument '{}'"
30: echo "and search for derivations in the result. This behaviour works"
31: echo "well for functions with default arguments, since it avoids the"
32: echo "need for a separate .nix file just to perform that call."
33: } 1>&2
34: exit 0
35: fi
36:
37: [[ -n "$1" ]] && F="$1"
38: [[ -z "$F" ]] && [[ -e release.nix ]] && F='release.nix'
39: [[ -z "$F" ]] && [[ -e nix/release.nix ]] && F='nix/release.nix'
40: [[ -z "$F" ]] && [[ -e default.nix ]] && F='default.nix'
41: [[ -z "$F" ]] && [[ -e nix/default.nix ]] && F='nix/default.nix'
42: [[ -z "$F" ]] &&
43: fail "Error: No file given and didn't find release.nix or default.nix"
44:
45: echo "Finding derivations from '$F'" 1>&2
46: F="$F" nix eval --show-trace --raw ${
47: escapeShellArg ("(" + concatStringsSep " " [
48: ''with { raw = import (./. + ("/" + (builtins.getEnv "F"))); };''
49: "with { val = if builtins.isAttrs raw then raw else raw {}; };"
50: ''(import "${cleanSource ../..}").drvPathsIn val''
51: ] + ")")
52: }
53: '';
54: };
55:
56: nix_release = wrap {
57: name = "nix_release";
58: file = ./nix_release.sh;
59: paths = [ bash fail git gnutar ];
60: vars = { inherit nix_release_eval; };
61: };
62: };
63: attrsToDirs' "nix_release" { bin = { inherit nix_release nix_release_eval; }; }
Generated by git2html.