Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6636808e9000
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 65e88694c27a
Choose a head ref
  • 11 commits
  • 8 files changed
  • 1 contributor

Commits on May 29, 2019

  1. Copy the full SHA
    c356d03 View commit details
  2. Copy the full SHA
    6e4a8c4 View commit details
  3. Remove makeFlakeValue()

    edolstra committed May 29, 2019
    Copy the full SHA
    6ae4437 View commit details
  4. Doh

    edolstra committed May 29, 2019
    Copy the full SHA
    de00ed1 View commit details
  5. Add 'nix flake check' command

    This evaluates all the 'provides' of a flake and builds the 'check'
    attributes.
    edolstra committed May 29, 2019
    Copy the full SHA
    e0aaf05 View commit details
  6. Copy the full SHA
    0e32b32 View commit details
  7. Copy the full SHA
    a9d3524 View commit details
  8. flake.nix: Add more checks

    edolstra committed May 29, 2019
    Copy the full SHA
    b70fc8f View commit details
  9. Hack: Use legacyPackages from Nixpkgs

    Nixpkgs doesn't provide a clean "packages" set yet, so until that's
    the case, look for packages in "legacyPackages" as well.
    edolstra committed May 29, 2019
    Copy the full SHA
    3488fa7 View commit details
  10. nix flake info --json: List the "provides"

    It also lists the contents of "checks" and "packages".
    
    For example:
    
      $ nix flake info --json | jq
      {
        "branch": "HEAD",
        "description": "The purely functional package manager",
        "epoch": 2019,
        "id": "nix",
        "lastModified": 1559161142,
        "path": "/nix/store/2w2qla8735dbxah8gai8r1nsbf5x4f5d-source",
        "provides": {
          "checks": {
            "binaryTarball": {},
            "nix-copy-closure": {},
            "perlBindings": {},
            "remoteBuilds": {},
            "setuid": {}
          },
          "defaultPackage": {},
          "devShell": {},
          "hydraJobs": {},
          "packages": {
            "nix": {},
            "nix-perl-bindings": {}
          }
        },
        "revCount": 6955,
        "revision": "8cb24e04e8b6cc60e2504733afe78e0eadafcd98",
        "uri": "/home/eelco/Dev/nix"
      }
    
    Fixes #2820.
    edolstra committed May 29, 2019
    Copy the full SHA
    49436bd View commit details

Commits on May 31, 2019

  1. Merge pull request #2903 from NixOS/check-flake

    Add "nix flake check"
    edolstra authored May 31, 2019
    Copy the full SHA
    65e8869 View commit details
Showing with 248 additions and 67 deletions.
  1. +11 −2 flake.nix
  2. +1 −1 shell.nix
  3. +6 −3 src/libexpr/eval.hh
  4. +60 −42 src/libexpr/primops/flake.cc
  5. +7 −5 src/libexpr/primops/flake.hh
  6. +4 −1 src/nix/command.hh
  7. +139 −7 src/nix/flake.cc
  8. +20 −6 src/nix/installables.cc
13 changes: 11 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -14,13 +14,22 @@
nixpkgs = deps.nixpkgs;
};

packages.nix = hydraJobs.build.x86_64-linux;
checks = {
binaryTarball = hydraJobs.binaryTarball.x86_64-linux;
perlBindings = hydraJobs.perlBindings.x86_64-linux;
inherit (hydraJobs.tests) remoteBuilds nix-copy-closure;
setuid = hydraJobs.tests.setuid.x86_64-linux;
};

packages = {
nix = hydraJobs.build.x86_64-linux;
nix-perl-bindings = hydraJobs.perlBindings.x86_64-linux;
};

defaultPackage = packages.nix;

devShell = import ./shell.nix {
nixpkgs = deps.nixpkgs;
};

};
}
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
, nixpkgs ? builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz
}:

with import (builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz) { system = builtins.currentSystem or "x86_64-linux"; };
with import nixpkgs { system = builtins.currentSystem or "x86_64-linux"; };

with import ./release-common.nix { inherit pkgs; };

9 changes: 6 additions & 3 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
@@ -17,7 +17,10 @@ namespace nix {
class Store;
class EvalState;
enum RepairFlag : bool;

namespace flake {
struct FlakeRegistry;
}


typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args, Value & v);
@@ -323,12 +326,12 @@ private:

public:

const std::vector<std::shared_ptr<FlakeRegistry>> getFlakeRegistries();
const std::vector<std::shared_ptr<flake::FlakeRegistry>> getFlakeRegistries();

std::shared_ptr<FlakeRegistry> getGlobalFlakeRegistry();
std::shared_ptr<flake::FlakeRegistry> getGlobalFlakeRegistry();

private:
std::shared_ptr<FlakeRegistry> _globalFlakeRegistry;
std::shared_ptr<flake::FlakeRegistry> _globalFlakeRegistry;
std::once_flag _globalFlakeRegistryInit;
};

102 changes: 60 additions & 42 deletions src/libexpr/primops/flake.cc
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@

namespace nix {

using namespace flake;

namespace flake {

/* Read a registry. */
std::shared_ptr<FlakeRegistry> readRegistry(const Path & path)
{
@@ -133,24 +137,6 @@ void writeLockFile(const LockFile & lockFile, const Path & path)
writeFile(path, json.dump(4) + "\n"); // '4' = indentation in json file
}

std::shared_ptr<FlakeRegistry> EvalState::getGlobalFlakeRegistry()
{
std::call_once(_globalFlakeRegistryInit, [&]() {
auto path = evalSettings.flakeRegistry;

if (!hasPrefix(path, "/")) {
CachedDownloadRequest request(evalSettings.flakeRegistry);
request.name = "flake-registry.json";
request.gcRoot = true;
path = getDownloader()->downloadCached(store, request).path;
}

_globalFlakeRegistry = readRegistry(path);
});

return _globalFlakeRegistry;
}

Path getUserRegistryPath()
{
return getHome() + "/.config/nix/registry.json";
@@ -170,17 +156,6 @@ std::shared_ptr<FlakeRegistry> getFlagRegistry(RegistryOverrides registryOverrid
return flagRegistry;
}

// This always returns a vector with flakeReg, userReg, globalReg.
// If one of them doesn't exist, the registry is left empty but does exist.
const Registries EvalState::getFlakeRegistries()
{
Registries registries;
registries.push_back(getFlagRegistry(registryOverrides));
registries.push_back(getUserRegistry());
registries.push_back(getGlobalFlakeRegistry());
return registries;
}

static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries,
std::vector<FlakeRef> pastSearches = {});

@@ -327,7 +302,9 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe

state.forceAttrs(vInfo);

if (auto epoch = vInfo.attrs->get(state.symbols.create("epoch"))) {
auto sEpoch = state.symbols.create("epoch");

if (auto epoch = vInfo.attrs->get(sEpoch)) {
flake.epoch = state.forceInt(*(**epoch).value, *(**epoch).pos);
if (flake.epoch > 2019)
throw Error("flake '%s' requires unsupported epoch %d; please upgrade Nix", flakeRef, flake.epoch);
@@ -342,14 +319,18 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
if (auto description = vInfo.attrs->get(state.sDescription))
flake.description = state.forceStringNoCtx(*(**description).value, *(**description).pos);

if (auto requires = vInfo.attrs->get(state.symbols.create("requires"))) {
auto sRequires = state.symbols.create("requires");

if (auto requires = vInfo.attrs->get(sRequires)) {
state.forceList(*(**requires).value, *(**requires).pos);
for (unsigned int n = 0; n < (**requires).value->listSize(); ++n)
flake.requires.push_back(FlakeRef(state.forceStringNoCtx(
*(**requires).value->listElems()[n], *(**requires).pos)));
}

if (std::optional<Attr *> nonFlakeRequires = vInfo.attrs->get(state.symbols.create("nonFlakeRequires"))) {
auto sNonFlakeRequires = state.symbols.create("nonFlakeRequires");

if (std::optional<Attr *> nonFlakeRequires = vInfo.attrs->get(sNonFlakeRequires)) {
state.forceAttrs(*(**nonFlakeRequires).value, *(**nonFlakeRequires).pos);
for (Attr attr : *(*(**nonFlakeRequires).value).attrs) {
std::string myNonFlakeUri = state.forceStringNoCtx(*attr.value, *attr.pos);
@@ -358,12 +339,25 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
}
}

if (auto provides = vInfo.attrs->get(state.symbols.create("provides"))) {
auto sProvides = state.symbols.create("provides");

if (auto provides = vInfo.attrs->get(sProvides)) {
state.forceFunction(*(**provides).value, *(**provides).pos);
flake.vProvides = (**provides).value;
} else
throw Error("flake '%s' lacks attribute 'provides'", flakeRef);

for (auto & attr : *vInfo.attrs) {
if (attr.name != sEpoch &&
attr.name != state.sName &&
attr.name != state.sDescription &&
attr.name != sRequires &&
attr.name != sNonFlakeRequires &&
attr.name != sProvides)
throw Error("flake '%s' has an unsupported attribute '%s', at %s",
flakeRef, attr.name, *attr.pos);
}

return flake;
}

@@ -572,18 +566,11 @@ void callFlake(EvalState & state, const ResolvedFlake & resFlake, Value & v)
v.attrs->sort();
}

// Return the `provides` of the top flake, while assigning to `v` the provides
// of the dependencies as well.
void makeFlakeValue(EvalState & state, const FlakeRef & flakeRef, HandleLockFile handle, Value & v)
{
callFlake(state, resolveFlake(state, flakeRef, handle), v);
}

// This function is exposed to be used in nix files.
static void prim_getFlake(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
makeFlakeValue(state, state.forceStringNoCtx(*args[0], pos),
evalSettings.pureEval ? AllPure : UseUpdatedLockFile, v);
callFlake(state, resolveFlake(state, state.forceStringNoCtx(*args[0], pos),
evalSettings.pureEval ? AllPure : UseUpdatedLockFile), v);
}

static RegisterPrimOp r2("getFlake", 1, prim_getFlake);
@@ -618,3 +605,34 @@ void gitCloneFlake(FlakeRef flakeRef, EvalState & state, Registries registries,
}

}

std::shared_ptr<flake::FlakeRegistry> EvalState::getGlobalFlakeRegistry()
{
std::call_once(_globalFlakeRegistryInit, [&]() {
auto path = evalSettings.flakeRegistry;

if (!hasPrefix(path, "/")) {
CachedDownloadRequest request(evalSettings.flakeRegistry);
request.name = "flake-registry.json";
request.gcRoot = true;
path = getDownloader()->downloadCached(store, request).path;
}

_globalFlakeRegistry = readRegistry(path);
});

return _globalFlakeRegistry;
}

// This always returns a vector with flakeReg, userReg, globalReg.
// If one of them doesn't exist, the registry is left empty but does exist.
const Registries EvalState::getFlakeRegistries()
{
Registries registries;
registries.push_back(getFlagRegistry(registryOverrides));
registries.push_back(getUserRegistry());
registries.push_back(getGlobalFlakeRegistry());
return registries;
}

}
12 changes: 7 additions & 5 deletions src/libexpr/primops/flake.hh
Original file line number Diff line number Diff line change
@@ -5,13 +5,15 @@

namespace nix {

struct Value;
class EvalState;

namespace flake {

static const size_t FLAG_REGISTRY = 0;
static const size_t USER_REGISTRY = 1;
static const size_t GLOBAL_REGISTRY = 2;

struct Value;
class EvalState;

struct FlakeRegistry
{
std::map<FlakeRef, FlakeRef> entries;
@@ -73,8 +75,6 @@ enum HandleLockFile : unsigned int
, UseNewLockFile // `RecreateLockFile` without writing to file
};

void makeFlakeValue(EvalState &, const FlakeRef &, HandleLockFile, Value &);

std::shared_ptr<FlakeRegistry> readRegistry(const Path &);

void writeRegistry(const FlakeRegistry &, const Path &);
@@ -143,3 +143,5 @@ void updateLockFile(EvalState &, const FlakeRef & flakeRef, bool recreateLockFil
void gitCloneFlake(FlakeRef flakeRef, EvalState &, Registries, const Path & destDir);

}

}
5 changes: 4 additions & 1 deletion src/nix/command.hh
Original file line number Diff line number Diff line change
@@ -12,7 +12,10 @@ struct Value;
class Bindings;
class EvalState;
class Store;

namespace flake {
enum HandleLockFile : unsigned int;
}

/* A command that require a Nix store. */
struct StoreCommand : virtual Command
@@ -71,7 +74,7 @@ struct MixFlakeOptions : virtual Args

MixFlakeOptions();

HandleLockFile getLockFileMode();
flake::HandleLockFile getLockFileMode();
};

struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
Loading