mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-08-17 02:10:31 +03:00
Merge pull request #8 from DavHau/dev
add app 'contribute' to initialize templates
This commit is contained in:
commit
9692a6dde1
@ -7,10 +7,11 @@ It focuses on the following aspects:
|
||||
- Nixpkgs Compatibility (not enforcing IFD)
|
||||
- Code de-duplication across 2nix tools
|
||||
- Code de-duplication in nixpkgs
|
||||
- Risk free opt-in FOD fetching
|
||||
- Risk free opt-in FOD fetching (no reproducibility issues)
|
||||
- Common UI across 2nix tools
|
||||
- Reduce effort to develop new 2nix solutions
|
||||
- Exploration and adoption of new nix features
|
||||
- Simplified updating of packages
|
||||
|
||||
### Motivation
|
||||
2nix tools, or in other words, tools converting instructions of other build systems to nix build instructions, are an important part of the nix/nixos ecosystem. These tools make packaging workflows easier and often allow to manage complexity that would be hard or impossible to manage without.
|
||||
|
18
flake.nix
18
flake.nix
@ -41,16 +41,14 @@
|
||||
|
||||
defaultApp = forAllSystems (system: self.apps."${system}".cli);
|
||||
|
||||
apps = forAllSystems (system: {
|
||||
cli = {
|
||||
"type" = "app";
|
||||
"program" = builtins.toString (dream2nixFor."${system}".apps.cli);
|
||||
};
|
||||
install = {
|
||||
"type" = "app";
|
||||
"program" = builtins.toString (dream2nixFor."${system}".apps.install);
|
||||
};
|
||||
});
|
||||
apps = forAllSystems (system:
|
||||
lib.mapAttrs (appName: app:
|
||||
{
|
||||
type = "app";
|
||||
program = builtins.toString app;
|
||||
}
|
||||
) dream2nixFor."${system}".apps
|
||||
);
|
||||
|
||||
devShell = forAllSystems (system: nixpkgsFor."${system}".mkShell {
|
||||
buildInputs = with nixpkgsFor."${system}"; [
|
||||
|
22
src/apps/cli/default.nix
Normal file
22
src/apps/cli/default.nix
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
# from dream2nix
|
||||
externalSources,
|
||||
translators,
|
||||
|
||||
# from nixpkgs
|
||||
python3,
|
||||
writeScript,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cliPython = python3.withPackages (ps: [ ps.networkx ]);
|
||||
in
|
||||
|
||||
writeScript "cli" ''
|
||||
export d2nExternalSources=${externalSources}
|
||||
|
||||
translatorsJsonFile=${translators.translatorsJsonFile} \
|
||||
dream2nixSrc=${../../.} \
|
||||
${cliPython}/bin/python ${./cli.py} "$@"
|
||||
''
|
107
src/apps/contribute/contribute.py
Normal file
107
src/apps/contribute/contribute.py
Normal file
@ -0,0 +1,107 @@
|
||||
import os
|
||||
import subprocess as sp
|
||||
from cleo import Application, Command
|
||||
from cleo.helpers import option
|
||||
|
||||
|
||||
dream2nix_src = "./src"
|
||||
|
||||
|
||||
class ContributeCommand(Command):
|
||||
|
||||
description = (
|
||||
"Creates a basic <comment>pyproject.toml</> file in the current directory."
|
||||
)
|
||||
|
||||
name = "contribute"
|
||||
|
||||
options = [
|
||||
option("module", None, "Which kind of module to contribute", flag=False),
|
||||
option("buildsystem", None, "which kind of buildsystem", flag=False),
|
||||
option("type", None, "pure or impure translator", flag=False),
|
||||
option("name", None, "name of the new module", flag=False),
|
||||
option(
|
||||
"dependency",
|
||||
None,
|
||||
"Package to require, with an optional version constraint, "
|
||||
"e.g. requests:^2.10.0 or requests=2.11.1.",
|
||||
flag=False,
|
||||
multiple=True,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def handle(self):
|
||||
module = self.option('module')
|
||||
print(f"module: {module}")
|
||||
|
||||
if self.io.is_interactive():
|
||||
self.line("")
|
||||
self.line(
|
||||
"This command will initialize a template for adding a new module to dream2nix"
|
||||
)
|
||||
self.line("")
|
||||
|
||||
module = self.option("module")
|
||||
if not module:
|
||||
module = self.choice(
|
||||
'Select module type',
|
||||
['translator'],
|
||||
0
|
||||
)
|
||||
module = f"{module}s"
|
||||
module_dir = dream2nix_src + f"/{module}/"
|
||||
|
||||
buildsystem = self.option('buildsystem')
|
||||
known_buildsystems = list(dir for dir in os.listdir(module_dir) if os.path.isdir(module_dir + dir))
|
||||
if not buildsystem:
|
||||
buildsystem = self.choice(
|
||||
'Select buildsystem',
|
||||
known_buildsystems
|
||||
+
|
||||
[
|
||||
" -> add new"
|
||||
],
|
||||
0
|
||||
)
|
||||
if buildsystem == " -> add new":
|
||||
buildsystem = self.ask('Please enter the name of a new buildsystem:')
|
||||
if buildsystem in known_buildsystems:
|
||||
raise Exception(f"buildsystem {buildsystem} already exists")
|
||||
|
||||
|
||||
if module == 'translators':
|
||||
type = self.option("type")
|
||||
if not type:
|
||||
type = self.choice(
|
||||
f'Select {module} type',
|
||||
['impure', 'pure'],
|
||||
0
|
||||
)
|
||||
|
||||
name = self.option("name")
|
||||
if not name:
|
||||
name = self.ask('Specify name of new module:')
|
||||
|
||||
for path in (
|
||||
module_dir + f"{buildsystem}",
|
||||
module_dir + f"{buildsystem}/{type}",
|
||||
module_dir + f"{buildsystem}/{type}/{name}"):
|
||||
if not os.path.isdir(path):
|
||||
os.mkdir(path)
|
||||
target_file = module_dir + f"{buildsystem}/{type}/{name}/default.nix"
|
||||
with open(dream2nix_src + f"/templates/{module}/{type}.nix") as template:
|
||||
with open(target_file, 'w') as new_file:
|
||||
new_file.write(template.read())
|
||||
|
||||
self.line(f"The template has been initialized in {target_file}")
|
||||
if self.confirm('Would you like to open it in your default editor now?', True, '(?i)^(y|j)'):
|
||||
sp.run(f"{os.environ.get('EDITOR')} {target_file}", shell=True)
|
||||
|
||||
|
||||
|
||||
application = Application("contribute")
|
||||
application.add(ContributeCommand())
|
||||
|
||||
if __name__ == '__main__':
|
||||
application.run()
|
15
src/apps/contribute/default.nix
Normal file
15
src/apps/contribute/default.nix
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
# from nixpkgs
|
||||
python3,
|
||||
writeScript,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cliPython = python3.withPackages (ps: [ ps.cleo ]);
|
||||
in
|
||||
|
||||
writeScript "cli" ''
|
||||
dream2nixSrc=${../../.} \
|
||||
${cliPython}/bin/python ${./contribute.py} contribute "$@"
|
||||
''
|
@ -1,28 +1,19 @@
|
||||
{
|
||||
pkgs,
|
||||
|
||||
callPackage,
|
||||
externalSources,
|
||||
location,
|
||||
translators,
|
||||
...
|
||||
}:
|
||||
let
|
||||
callPackage = pkgs.callPackage;
|
||||
|
||||
cliPython = pkgs.python3.withPackages (ps: [ ps.networkx ]);
|
||||
in
|
||||
{
|
||||
|
||||
# the unified translator cli
|
||||
cli = callPackage ({ writeScript, ... }:
|
||||
writeScript "cli" ''
|
||||
export d2nExternalSources=${externalSources}
|
||||
cli = callPackage (import ./cli) {};
|
||||
|
||||
translatorsJsonFile=${translators.translatorsJsonFile} \
|
||||
dream2nixSrc=${../.} \
|
||||
${cliPython}/bin/python ${./cli.py} "$@"
|
||||
''
|
||||
) {};
|
||||
# the contribute cli
|
||||
contribute = callPackage (import ./contribute) {};
|
||||
|
||||
# install the framework to a specified location by copying the code
|
||||
install = callPackage ({ writeScript, }:
|
||||
|
@ -18,6 +18,8 @@ let
|
||||
inherit callPackage;
|
||||
inherit externals;
|
||||
inherit externalSources;
|
||||
inherit location;
|
||||
inherit translators;
|
||||
inherit utils;
|
||||
});
|
||||
|
||||
@ -28,12 +30,8 @@ let
|
||||
|
||||
config = builtins.fromJSON (builtins.readFile ./config.json);
|
||||
|
||||
in
|
||||
|
||||
rec {
|
||||
|
||||
# apps for CLI and installation
|
||||
apps = callPackage ./apps { inherit location translators; };
|
||||
apps = callPackage ./apps {};
|
||||
|
||||
# builder implementaitons for all subsystems
|
||||
builders = callPackage ./builders {};
|
||||
@ -44,12 +42,17 @@ rec {
|
||||
};
|
||||
|
||||
# the translator modules and utils for all subsystems
|
||||
translators = callPackage ./translators { inherit location; };
|
||||
translators = callPackage ./translators {};
|
||||
|
||||
|
||||
# the location of the dream2nix framework for self references (update scripts, etc.)
|
||||
location = ./.;
|
||||
|
||||
in
|
||||
|
||||
rec {
|
||||
|
||||
inherit apps builders fetchers location translators;
|
||||
|
||||
# automatically find a suitable builder for a given generic lock
|
||||
findBuilder = dreamLock:
|
||||
|
@ -7,6 +7,7 @@
|
||||
externals,
|
||||
location,
|
||||
utils,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user