aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-04-08 23:36:12 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-04-08 23:36:12 +0200
commit47727252ff4e536dd47b73949033d3349923fbbb (patch)
treee9a15d4c3436181c1f48999c98eeecdd314432db /src
parentee1254d4f50f5908fa4913253a643d14cb263c45 (diff)
Add "nix flake init" command for creating a flake
Diffstat (limited to 'src')
-rw-r--r--src/nix/flake.cc49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 470dfdc08..01385ff8d 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -182,6 +182,51 @@ struct CmdFlakePin : virtual Args, StoreCommand, MixEvalArgs
}
};
+struct CmdFlakeInit : virtual Args, Command
+{
+ std::string name() override
+ {
+ return "init";
+ }
+
+ std::string description() override
+ {
+ return "create a skeleton 'flake.nix' file in the current directory";
+ }
+
+ void run() override
+ {
+ Path flakeDir = absPath(".");
+
+ if (!pathExists(flakeDir + "/.git"))
+ throw Error("the directory '%s' is not a Git repository", flakeDir);
+
+ Path flakePath = flakeDir + "/flake.nix";
+
+ if (pathExists(flakePath))
+ throw Error("file '%s' already exists", flakePath);
+
+ writeFile(flakePath,
+R"str(
+{
+ name = "hello";
+
+ description = "A flake for building Hello World";
+
+ epoch = 2019;
+
+ requires = [ "nixpkgs" ];
+
+ provides = deps: rec {
+
+ packages.hello = deps.nixpkgs.provides.packages.hello;
+
+ };
+}
+)str");
+ }
+};
+
struct CmdFlake : virtual MultiCommand, virtual Command
{
CmdFlake()
@@ -190,7 +235,9 @@ struct CmdFlake : virtual MultiCommand, virtual Command
, make_ref<CmdFlakeInfo>()
, make_ref<CmdFlakeAdd>()
, make_ref<CmdFlakeRemove>()
- , make_ref<CmdFlakePin>()})
+ , make_ref<CmdFlakePin>()
+ , make_ref<CmdFlakeInit>()
+ })
{
}