Skip to content

Commit

Permalink
feat: Add configuration option for popularity data URL
Browse files Browse the repository at this point in the history
  • Loading branch information
tazjin authored and Vincent Ambo committed Sep 21, 2019
1 parent 30acc07 commit 6a4581c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ variables:
for building
* `NIX_TIMEOUT`: Number of seconds that any Nix builder is allowed to run
(defaults to 60
* `NIX_POPULARITY_URL`: URL to a file containing popularity data for the package set (see `popcount/`)
* `GCS_SIGNING_KEY`: A Google service account key (in PEM format) that can be
used to sign Cloud Storage URLs
* `GCS_SIGNING_ACCOUNT`: Google service account ID that the signing key belongs
Expand Down
8 changes: 4 additions & 4 deletions build-image/build-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
# layers. To allow for some extensibility (via additional layers),
# the default here is set to something a little less than that.
maxLayers ? 96,
# Popularity data for layer solving is fetched from the URL passed
# in here.
popularityUrl ? "https://storage.googleapis.com/nixery-layers/popularity/popularity-19.03.173490.5271f8dddc0.json",

...
}:
Expand Down Expand Up @@ -101,10 +104,7 @@ let
fetched = (map (deepFetch pkgs) (fromJSON packages));
in foldl' splitter init fetched;

popularity = builtins.fetchurl {
url = "https://storage.googleapis.com/nixery-layers/popularity/nixos-19.03-20190812.json";
sha256 = "16sxd49vqqg2nrhwynm36ba6bc2yff5cd5hf83wi0hanw5sx3svk";
};
popularity = builtins.fetchurl popularityUrl;

# Before actually creating any image layers, the store paths that need to be
# included in the image must be sorted into the layers that they should go
Expand Down
2 changes: 1 addition & 1 deletion build-image/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# all arguments of build-image.nix.
, srcType ? "nixpkgs"
, srcArgs ? "nixos-19.03"
, tag ? null, name ? null, packages ? null, maxLayers ? null
, tag ? null, name ? null, packages ? null, maxLayers ? null, popularityUrl ? null
}@args:

let pkgs = import ./load-pkgs.nix { inherit srcType srcArgs; };
Expand Down
4 changes: 4 additions & 0 deletions server/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func BuildImage(ctx *context.Context, cfg *config.Config, cache *LocalCache, ima
"--argstr", "srcArgs", srcArgs,
}

if cfg.PopUrl != "" {
args = append(args, "--argstr", "popularityUrl", cfg.PopUrl)
}

cmd := exec.Command("nixery-build-image", args...)

outpipe, err := cmd.StdoutPipe()
Expand Down
2 changes: 2 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Config struct {
Pkgs PkgSource // Source for Nix package set
Timeout string // Timeout for a single Nix builder (seconds)
WebDir string // Directory with static web assets
PopUrl string // URL to the Nix package popularity count
}

func FromEnv() (*Config, error) {
Expand All @@ -83,5 +84,6 @@ func FromEnv() (*Config, error) {
Signing: signingOptsFromEnv(),
Timeout: getConfig("NIX_TIMEOUT", "Nix builder timeout", "60"),
WebDir: getConfig("WEB_DIR", "Static web file dir", ""),
PopUrl: os.Getenv("NIX_POPULARITY_URL"),
}, nil
}

0 comments on commit 6a4581c

Please sign in to comment.