2016-02-09 22:28:29 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-14 15:40:16 +03:00
|
|
|
#include "installables.hh"
|
2016-02-09 22:28:29 +02:00
|
|
|
#include "args.hh"
|
2017-10-24 13:45:11 +03:00
|
|
|
#include "common-eval-args.hh"
|
2019-10-14 15:40:16 +03:00
|
|
|
|
2019-03-21 10:30:16 +02:00
|
|
|
#include <optional>
|
2016-02-09 22:28:29 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2018-01-31 17:14:47 +02:00
|
|
|
extern std::string programPath;
|
|
|
|
|
2017-04-25 13:06:32 +03:00
|
|
|
class EvalState;
|
2016-02-09 22:28:29 +02:00
|
|
|
class Store;
|
2019-05-29 16:31:07 +03:00
|
|
|
|
|
|
|
namespace flake {
|
2019-05-22 14:46:07 +03:00
|
|
|
enum HandleLockFile : unsigned int;
|
2019-05-29 16:31:07 +03:00
|
|
|
}
|
2016-02-09 22:28:29 +02:00
|
|
|
|
2019-10-27 19:45:02 +02:00
|
|
|
/* A command that requires a Nix store. */
|
2016-02-09 22:28:29 +02:00
|
|
|
struct StoreCommand : virtual Command
|
|
|
|
{
|
2016-03-21 19:03:36 +02:00
|
|
|
StoreCommand();
|
2016-02-09 22:28:29 +02:00
|
|
|
void run() override;
|
2017-04-25 12:20:37 +03:00
|
|
|
ref<Store> getStore();
|
2017-03-16 15:25:54 +02:00
|
|
|
virtual ref<Store> createStore();
|
2016-02-09 22:28:29 +02:00
|
|
|
virtual void run(ref<Store>) = 0;
|
2017-04-25 12:20:37 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<Store> _store;
|
2016-02-09 22:28:29 +02:00
|
|
|
};
|
|
|
|
|
2019-05-16 23:48:16 +03:00
|
|
|
struct EvalCommand : virtual StoreCommand, MixEvalArgs
|
|
|
|
{
|
|
|
|
ref<EvalState> getEvalState();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::shared_ptr<EvalState> evalState;
|
|
|
|
};
|
|
|
|
|
2019-05-22 14:46:07 +03:00
|
|
|
struct MixFlakeOptions : virtual Args
|
2017-04-25 13:06:32 +03:00
|
|
|
{
|
2019-05-01 12:38:48 +03:00
|
|
|
bool recreateLockFile = false;
|
|
|
|
|
2019-05-14 12:34:45 +03:00
|
|
|
bool saveLockFile = true;
|
|
|
|
|
2019-05-22 14:46:07 +03:00
|
|
|
bool useRegistries = true;
|
|
|
|
|
|
|
|
MixFlakeOptions();
|
|
|
|
|
2019-05-29 16:31:07 +03:00
|
|
|
flake::HandleLockFile getLockFileMode();
|
2019-05-22 14:46:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
|
|
|
|
{
|
|
|
|
std::optional<Path> file;
|
|
|
|
|
|
|
|
SourceExprCommand();
|
2019-05-14 12:34:45 +03:00
|
|
|
|
2019-04-08 17:11:17 +03:00
|
|
|
std::vector<std::shared_ptr<Installable>> parseInstallables(
|
|
|
|
ref<Store> store, std::vector<std::string> ss);
|
|
|
|
|
|
|
|
std::shared_ptr<Installable> parseInstallable(
|
|
|
|
ref<Store> store, const std::string & installable);
|
|
|
|
|
Support non-x86_64-linux system types in flakes
A command like
$ nix run nixpkgs#hello
will now build the attribute 'packages.${system}.hello' rather than
'packages.hello'. Note that this does mean that the flake needs to
export an attribute for every system type it supports, and you can't
build on unsupported systems. So 'packages' typically looks like this:
packages = nixpkgs.lib.genAttrs ["x86_64-linux" "i686-linux"] (system: {
hello = ...;
});
The 'checks', 'defaultPackage', 'devShell', 'apps' and 'defaultApp'
outputs similarly are now attrsets that map system types to
derivations/apps. 'nix flake check' checks that the derivations for
all platforms evaluate correctly, but only builds the derivations in
'checks.${system}'.
Fixes #2861. (That issue also talks about access to ~/.config/nixpkgs
and --arg, but I think it's reasonable to say that flakes shouldn't
support those.)
The alternative to attribute selection is to pass the system type as
an argument to the flake's 'outputs' function, e.g. 'outputs = { self,
nixpkgs, system }: ...'. However, that approach would be at odds with
hermetic evaluation and make it impossible to enumerate the packages
provided by a flake.
2019-10-15 18:52:10 +03:00
|
|
|
virtual Strings getDefaultFlakeAttrPaths();
|
2019-06-17 17:58:59 +03:00
|
|
|
|
Support non-x86_64-linux system types in flakes
A command like
$ nix run nixpkgs#hello
will now build the attribute 'packages.${system}.hello' rather than
'packages.hello'. Note that this does mean that the flake needs to
export an attribute for every system type it supports, and you can't
build on unsupported systems. So 'packages' typically looks like this:
packages = nixpkgs.lib.genAttrs ["x86_64-linux" "i686-linux"] (system: {
hello = ...;
});
The 'checks', 'defaultPackage', 'devShell', 'apps' and 'defaultApp'
outputs similarly are now attrsets that map system types to
derivations/apps. 'nix flake check' checks that the derivations for
all platforms evaluate correctly, but only builds the derivations in
'checks.${system}'.
Fixes #2861. (That issue also talks about access to ~/.config/nixpkgs
and --arg, but I think it's reasonable to say that flakes shouldn't
support those.)
The alternative to attribute selection is to pass the system type as
an argument to the flake's 'outputs' function, e.g. 'outputs = { self,
nixpkgs, system }: ...'. However, that approach would be at odds with
hermetic evaluation and make it impossible to enumerate the packages
provided by a flake.
2019-10-15 18:52:10 +03:00
|
|
|
virtual Strings getDefaultFlakeAttrPathPrefixes();
|
2017-07-17 20:02:56 +03:00
|
|
|
};
|
|
|
|
|
2017-09-10 16:58:30 +03:00
|
|
|
enum RealiseMode { Build, NoBuild, DryRun };
|
|
|
|
|
2017-07-17 20:02:56 +03:00
|
|
|
/* A command that operates on a list of "installables", which can be
|
|
|
|
store paths, attribute paths, Nix expressions, etc. */
|
|
|
|
struct InstallablesCommand : virtual Args, SourceExprCommand
|
|
|
|
{
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables;
|
|
|
|
|
|
|
|
InstallablesCommand()
|
|
|
|
{
|
|
|
|
expectArgs("installables", &_installables);
|
|
|
|
}
|
|
|
|
|
2017-04-25 13:06:32 +03:00
|
|
|
void prepare() override;
|
|
|
|
|
2019-04-19 17:07:37 +03:00
|
|
|
virtual bool useDefaultInstallables() { return true; }
|
|
|
|
|
2017-04-25 13:06:32 +03:00
|
|
|
private:
|
|
|
|
|
2017-10-24 13:45:11 +03:00
|
|
|
std::vector<std::string> _installables;
|
2017-04-25 13:06:32 +03:00
|
|
|
};
|
|
|
|
|
2019-10-27 19:45:02 +02:00
|
|
|
/* A command that operates on exactly one "installable" */
|
2017-08-29 17:18:00 +03:00
|
|
|
struct InstallableCommand : virtual Args, SourceExprCommand
|
|
|
|
{
|
|
|
|
std::shared_ptr<Installable> installable;
|
|
|
|
|
|
|
|
InstallableCommand()
|
|
|
|
{
|
2019-04-19 17:07:37 +03:00
|
|
|
expectArg("installable", &_installable, true);
|
2017-08-29 17:18:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-04-19 17:07:37 +03:00
|
|
|
std::string _installable{"."};
|
2017-08-29 17:18:00 +03:00
|
|
|
};
|
|
|
|
|
2017-04-25 14:20:26 +03:00
|
|
|
/* A command that operates on zero or more store paths. */
|
|
|
|
struct StorePathsCommand : public InstallablesCommand
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool recursive = false;
|
|
|
|
bool all = false;
|
|
|
|
|
2018-03-30 01:56:13 +03:00
|
|
|
protected:
|
|
|
|
|
|
|
|
RealiseMode realiseMode = NoBuild;
|
|
|
|
|
2017-04-25 14:20:26 +03:00
|
|
|
public:
|
|
|
|
|
2017-09-27 19:28:54 +03:00
|
|
|
StorePathsCommand(bool recursive = false);
|
2017-04-25 14:20:26 +03:00
|
|
|
|
|
|
|
using StoreCommand::run;
|
|
|
|
|
|
|
|
virtual void run(ref<Store> store, Paths storePaths) = 0;
|
|
|
|
|
|
|
|
void run(ref<Store> store) override;
|
2019-04-19 17:07:37 +03:00
|
|
|
|
|
|
|
bool useDefaultInstallables() override { return !all; }
|
2017-04-25 14:20:26 +03:00
|
|
|
};
|
|
|
|
|
2017-05-04 15:16:26 +03:00
|
|
|
/* A command that operates on exactly one store path. */
|
|
|
|
struct StorePathCommand : public InstallablesCommand
|
|
|
|
{
|
|
|
|
using StoreCommand::run;
|
|
|
|
|
|
|
|
virtual void run(ref<Store> store, const Path & storePath) = 0;
|
|
|
|
|
|
|
|
void run(ref<Store> store) override;
|
|
|
|
};
|
|
|
|
|
2016-02-09 22:28:29 +02:00
|
|
|
/* A helper class for registering commands globally. */
|
|
|
|
struct RegisterCommand
|
|
|
|
{
|
2019-06-18 17:01:35 +03:00
|
|
|
static Commands * commands;
|
2016-02-09 22:28:29 +02:00
|
|
|
|
2019-06-18 17:01:35 +03:00
|
|
|
RegisterCommand(const std::string & name,
|
|
|
|
std::function<ref<Command>()> command)
|
2016-02-09 22:28:29 +02:00
|
|
|
{
|
2019-06-18 17:01:35 +03:00
|
|
|
if (!commands) commands = new Commands;
|
|
|
|
commands->emplace(name, command);
|
2016-02-09 22:28:29 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-18 17:01:35 +03:00
|
|
|
template<class T>
|
|
|
|
static RegisterCommand registerCommand(const std::string & name)
|
|
|
|
{
|
|
|
|
return RegisterCommand(name, [](){ return make_ref<T>(); });
|
|
|
|
}
|
|
|
|
|
2018-02-09 17:42:32 +02:00
|
|
|
Buildables build(ref<Store> store, RealiseMode mode,
|
2017-09-10 16:58:30 +03:00
|
|
|
std::vector<std::shared_ptr<Installable>> installables);
|
|
|
|
|
|
|
|
PathSet toStorePaths(ref<Store> store, RealiseMode mode,
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables);
|
|
|
|
|
|
|
|
Path toStorePath(ref<Store> store, RealiseMode mode,
|
|
|
|
std::shared_ptr<Installable> installable);
|
|
|
|
|
Add "nix show-derivation"
This debug command prints a store derivation in JSON format. For
example:
$ nix show-derivation nixpkgs.hello
{
"/nix/store/ayjwpwwiyy04nh9z71rsdgd3q7bra7ch-hello-2.10.drv": {
"outputs": {
"out": {
"path": "/nix/store/w5w4v29ql0qwqhczkdxs94ix2lh7ibgs-hello-2.10"
}
},
"inputSrcs": [
"/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
],
"inputDrvs": {
"/nix/store/13839aqdf6x4k3b785rw5f2l7857l6y3-bash-4.4-p12.drv": [
"out"
],
"/nix/store/vgdx7fdc7d4iirmnwj2py1nrvr5qwzj7-hello-2.10.tar.gz.drv": [
"out"
],
"/nix/store/x3kkd0vsqfflbvwf1055l9mr39bg0ms0-stdenv.drv": [
"out"
]
},
"platform": "x86_64-linux",
"builder": "/nix/store/qp5fw57d38bd1n07ss4zxh88zg67c3vg-bash-4.4-p12/bin/bash",
"args": [
"-e",
"/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
],
"env": {
"buildInputs": "",
"builder": "/nix/store/qp5fw57d38bd1n07ss4zxh88zg67c3vg-bash-4.4-p12/bin/bash",
"configureFlags": "",
"doCheck": "1",
"name": "hello-2.10",
"nativeBuildInputs": "",
"out": "/nix/store/w5w4v29ql0qwqhczkdxs94ix2lh7ibgs-hello-2.10",
"propagatedBuildInputs": "",
"propagatedNativeBuildInputs": "",
"src": "/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz",
"stdenv": "/nix/store/6zngq1rdh0ans9qyckqimqibgnlvlfrm-stdenv",
"system": "x86_64-linux"
}
}
}
This removes the need for pp-aterm.
2017-09-25 14:43:35 +03:00
|
|
|
PathSet toDerivations(ref<Store> store,
|
|
|
|
std::vector<std::shared_ptr<Installable>> installables,
|
|
|
|
bool useDeriver = false);
|
|
|
|
|
2019-07-12 16:32:17 +03:00
|
|
|
struct MixProfile : virtual Args, virtual StoreCommand
|
|
|
|
{
|
|
|
|
std::optional<Path> profile;
|
|
|
|
|
|
|
|
MixProfile();
|
|
|
|
|
|
|
|
/* If 'profile' is set, make it point at 'storePath'. */
|
|
|
|
void updateProfile(const Path & storePath);
|
|
|
|
|
|
|
|
/* If 'profile' is set, make it point at the store path produced
|
|
|
|
by 'buildables'. */
|
|
|
|
void updateProfile(const Buildables & buildables);
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:21:58 +03:00
|
|
|
struct MixDefaultProfile : MixProfile
|
|
|
|
{
|
|
|
|
MixDefaultProfile();
|
|
|
|
};
|
|
|
|
|
2016-02-09 22:28:29 +02:00
|
|
|
}
|