Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Displaying package parameters #78

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NIXOS_VERSION = 16.03
NIXPKGS = https://nixos.org/channels/nixos-$(NIXOS_VERSION)/nixexprs.tar.xz
NIXPKGS_UNSTABLE = https://nixos.org/channels/nixos-16.03-beta/nixexprs.tar.xz

rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))

Expand All @@ -15,7 +16,11 @@ HTML = index.html news.html \
disnix/index.html disnix/download.html disnix/docs.html \
disnix/extensions.html disnix/examples.html disnix/support.html \
docs/papers.html \
nixops/index.html
nixops/index.html \
nixpkgs/packages.json.gz \
nixpkgs/packages-unstable.json.gz \
nixos/options.json.gz \
nix/install


### Prettify the NixOS manual.
Expand Down Expand Up @@ -160,13 +165,11 @@ ifeq ($(UPDATE), 1)
endif

nixpkgs/packages.json.gz:
nixpkgs=$$(nix-instantiate --find-file nixpkgs -I nixpkgs=$(NIXPKGS)); \
(echo -n '{ "commit": "' && cat $$nixpkgs/.git-revision && echo -n '","packages":' \
&& nix-env -f '<nixpkgs>' -I nixpkgs=$(NIXPKGS) -qa --json --arg config '{}' \
&& echo -n '}') \
| sed "s|$$nixpkgs/||g" | gzip -9 > [email protected]
gunzip < [email protected] | python -mjson.tool > /dev/null
mv [email protected] $@
nixpkgs/packages.json-generation/generate-packages.json.gzip $@ $(NIXPKGS)

nixpkgs/packages-unstable.json.gz:
nixpkgs/packages.json-generation/generate-packages.json.gzip $@ $(NIXPKGS_UNSTABLE)


nixos/options.json.gz:
gzip -9 < $$(nix-build --no-out-link '<nixpkgs/nixos/release.nix>' -I nixpkgs=$(NIXPKGS) -A options)/share/doc/nixos/options.json > [email protected]
Expand Down
84 changes: 77 additions & 7 deletions nixos/packages.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
<input name='query' type='text' class='search-query span3'
placeholder='Search by name or description'
id='search' value='' autofocus='autofocus'/>

<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="releases" id="release-stable" checked="checked" /> 15.09
</label>
<label class="btn btn-primary">
<input type="radio" name="releases" id="release-unstable" /> 16.03 (beta)
</label>
<label><input type="checkbox" id="search-in-parameters" />Search in parameters</label>
<label><input type="checkbox" id="show-failing-packages" />Show failing packages</label>
</div>
</p>

<hr />
Expand Down Expand Up @@ -60,6 +71,10 @@
<th style='width: 10em'>Long description:</th>
<td class='long-description'><em>Not specified</em></td>
</tr>
<tr>
<th>Parameters</th>
<td class='parameters'><em>Not specified</em></td>
</tr>
</table>
</div>

Expand Down Expand Up @@ -121,6 +136,13 @@ function refilter() {
var attrs = Object.keys(packageData);

var words = $('#search').val().toLowerCase().split(/ +/).filter(Boolean);
var searchParameters = $('#search-in-parameters').prop('checked');
var showFailing = $('#show-failing-packages').prop('checked');
if (!showFailing) {
attrs = attrs.filter(function(attr) {
return !('error' in packageData[attr]);
});
}

if (words.length > 0) {
attrs = attrs.filter(function (attr) {
Expand All @@ -132,7 +154,10 @@ function refilter() {
return (attr.toLowerCase().indexOf(word) != -1
|| info['name'].toLowerCase().indexOf(word) != -1
|| description.toLowerCase().indexOf(word) != -1
|| longDescription.toLowerCase().indexOf(word) != -1);
|| longDescription.toLowerCase().indexOf(word) != -1
|| (searchParameters && Object.keys(info['parameters']).some(function(val) {
return val.toLowerCase().indexOf(word) != -1;
})));
};

return words.every(match);
Expand Down Expand Up @@ -206,30 +231,75 @@ function showPackage() {
if (typeof longDescription == 'string')
$('.long-description', details).empty().addClass("pre").text(longDescription);

var parameters = info['parameters'];
if (typeof parameters == 'object') {
var detailsP = [];

for (var param in parameters) {
if (parameters.hasOwnProperty(param)) {
detailsP.push($('<tr/>').append($('<td/>').text(param)).append($('<td/>').text(parameters[param])));
}
}

$('.parameters', details).empty().append($('<table/>', {colspan: 2}).addClass('table').append($('<tr/>').append($('<th/>').text('Name')).append($('<th/>').text('Value'))).append(detailsP));



}

$(this).after($('<tr/>')
.addClass('details')
.append($('<td/>', { colspan: 3 })
.append(details))
).attr('expanded', 1);
};

$.ajax({
url: '[%root%]nixpkgs/packages.json.gz',
function initializeEvents() {
$("#release-stable").change(function() {
download("packages");
});
$("#release-unstable").change(function() {
download("packages-unstable");
});

$("#search-in-parameters").change(function() {
refilter();
});
$("#show-failing-packages").change(function() {
refilter();
});
$('#search').on('input', function() {
refilter();
});
};

function download(name) {
if (request) request.abort();
$(function() {
$("#how-many").text("Loading...");
});
request = $.ajax({
url: '[%root%]nixpkgs/' + name + '.json.gz',
type: 'GET',
dataType: 'json',
error: function(a, status, error) { alert('Failed to get package data [' + status + ']: ' + error); },
success: function(data) {
$(function() {
var firstTime = packageData === null;
nixpkgsCommit = data.commit;
packageData = data.packages;

refilter();

$('#search').on('input', function() {
refilter();
if (firstTime) {
initializeEvents();
}
});
}
});
}

request = null;
packageData = null;
download("packages");
//]]>
</script>

Expand Down
33 changes: 33 additions & 0 deletions nixpkgs/packages.json-generation/addAttrs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let config = {
config = {
allowBroken = true;
allowUnfree = true;
};
}; in
{ nixpkgs ? import ./nixpkgs config }:

let inherit (nixpkgs) lib;
forceCatch = error-handler: x:
let result = builtins.catch "EvalError" (builtins.deepSeq x x); in
if lib.isAttrs result && result ? type && result.type == "error" then error-handler result else result;
get-attribute = package: import ./get-attributes.nix { inherit package forceCatch lib; };
info = x: {
name = x.name;
system = x.system;
meta = x.meta;
parameters = forceCatch (x: x) (get-attribute x);
};
mapRecursively = n: x:
forceCatch (error: [ ({ ${n + "(error)"} = { name = n; inherit error; meta = { longDescription = error.message; }; }; }) ])
(if lib.isDerivation x then
[(lib.setAttrByPath [n] (info x))]
else if lib.isAttrs x then
if x ? "recurseForDerivations" && x.recurseForDerivations then
lib.concatMap (name: mapRecursively "${n}.${name}" x.${name}) (lib.attrNames x)
else
[]
else if lib.isList x then
[] # map (mapRecursively "${n}.list") x
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should raise an error, or actually recurse over it.

else []); in
lib.zipAttrsWith (name: values: lib.head values)
(mapRecursively "__elim__" (nixpkgs // { recurseForDerivations = true; }))
22 changes: 22 additions & 0 deletions nixpkgs/packages.json-generation/generate-packages.json.gzip
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
set -e
set -o pipefail
# hack to build nix
unset IN_NIX_SHELL
# download nixpkgs and patch
nixpkgs=$(nix-instantiate --find-file nixpkgs -I nixpkgs=$2); \
pushd nixpkgs/packages.json-generation; \
rm -rf nixpkgs nix
cp -R $nixpkgs nixpkgs
chmod u+w -R nixpkgs
patch -p1 -d nixpkgs < nixpkgs.patch
# download and build patched nix version
nix-build -A nixUnstable ./nixpkgs --arg config 'import ./nixUnstable.nix'
(echo -n '{ "commit": "' && cat nixpkgs/.git-revision && echo -n '","packages":' \
&& ./result/bin/nix-instantiate --eval --expr 'import ./addAttrs.nix {}' --strict --json --show-trace \
&& echo -n '}') \
| sed "s|$(pwd)/nixpkgs/||g" | sed "s|__elim__.||g" | gzip -9 > ../../$1.tmp
popd
echo "Written $1.tmp"
# gunzip < $1.stmp | python -mjson.tool
mv $1.tmp $1
21 changes: 21 additions & 0 deletions nixpkgs/packages.json-generation/get-attributes.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ lib, forceCatch
, package }:

let
isSimple = x: builtins.isString x || builtins.isBool x || builtins.isInt x || builtins.isNull x;
protect = x: if isDerivation x then { type = "derivation"; } else if isSimple x then x else "(protected)";
arguments =
if !(package ? _functionArgs) then { error = "This derivation seems not to use lib.makeOverridable, so parameters couldn't be determined"; } else
let f = name: isOptional:
forceCatch (x: x // { type = "derivation"; })
(if builtins.hasAttr name package.origArgs
then protect package.origArgs.${name}
else if isOptional then "(optional)" else { type = "derivation"; }); in
lib.mapAttrs f package._functionArgs;
isDerivation = x:
lib.isDerivation x || lib.isFunction x ||
(if lib.isList x then lib.any isDerivation x
else if lib.isAttrs x then lib.any isDerivation (lib.attrValues x)
else false);
result = lib.filterAttrs (x: y: !isDerivation y) arguments;
in result
9 changes: 9 additions & 0 deletions nixpkgs/packages.json-generation/nixUnstable.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let path-to-nix = builtins.fetchTarball https://github.com/fkz/nix/archive/generate-nixos-packages.tar.gz; in {
packageOverrides = pkgs: {
nixUnstable = pkgs.lib.overrideDerivation pkgs.nixUnstable (old: rec {
name = "nix-${version}";
version = builtins.readFile (path-to-nix + "/version");
src = (import "${path-to-nix}/release.nix" {}).tarball + "/tarballs/${name}pre1234_abcdef.tar.xz";
});
};
}
27 changes: 27 additions & 0 deletions nixpkgs/packages.json-generation/nixpkgs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/lib/customisation.nix b/lib/customisation.nix
index 5854954..57995a4 100644
--- a/lib/customisation.nix
+++ b/lib/customisation.nix
@@ -60,9 +60,13 @@ rec {
{ override = newArgs: makeOverridable f (overrideWith newArgs);
overrideDerivation = fdrv:
makeOverridable (args: overrideDerivation (f args) fdrv) origArgs;
+ inherit origArgs;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we shouldn't inherit, it's a bit dangerous. _origArgs = origArgs?

+ _functionArgs = builtins.functionArgs f;
})
else if builtins.isFunction ff then
{ override = newArgs: makeOverridable f (overrideWith newArgs);
+ inherit origArgs;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

+ _functionArgs = builtins.functionArgs f;
+ __functor = self: args: let result = makeOverridable ff args; in result // { origArgs = origArgs // result.origArgs; _functionArgs = builtins.functionArgs f // result._functionArgs; };
- __functor = self: ff;
overrideDerivation = throw "overrideDerivation not yet supported for functors";
}
@@ -112,5 +119,7 @@
pkgs = f finalArgs;
mkAttrOverridable = name: pkg: pkg // {
override = newArgs: mkAttrOverridable name (f (finalArgs // newArgs)).${name};
+ _functionArgs = builtins.functionArgs f;
+ origArgs = finalArgs;
};
in lib.mapAttrs mkAttrOverridable pkgs;