mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 14:36:16 +02:00
Add "nix flake init" command for creating a flake
This commit is contained in:
parent
ee1254d4f5
commit
47727252ff
1 changed files with 48 additions and 1 deletions
|
@ -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
|
struct CmdFlake : virtual MultiCommand, virtual Command
|
||||||
{
|
{
|
||||||
CmdFlake()
|
CmdFlake()
|
||||||
|
@ -190,7 +235,9 @@ struct CmdFlake : virtual MultiCommand, virtual Command
|
||||||
, make_ref<CmdFlakeInfo>()
|
, make_ref<CmdFlakeInfo>()
|
||||||
, make_ref<CmdFlakeAdd>()
|
, make_ref<CmdFlakeAdd>()
|
||||||
, make_ref<CmdFlakeRemove>()
|
, make_ref<CmdFlakeRemove>()
|
||||||
, make_ref<CmdFlakePin>()})
|
, make_ref<CmdFlakePin>()
|
||||||
|
, make_ref<CmdFlakeInit>()
|
||||||
|
})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue