mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 14:31:55 +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)
|
- Nixpkgs Compatibility (not enforcing IFD)
|
||||||
- Code de-duplication across 2nix tools
|
- Code de-duplication across 2nix tools
|
||||||
- Code de-duplication in nixpkgs
|
- 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
|
- Common UI across 2nix tools
|
||||||
- Reduce effort to develop new 2nix solutions
|
- Reduce effort to develop new 2nix solutions
|
||||||
- Exploration and adoption of new nix features
|
- Exploration and adoption of new nix features
|
||||||
|
- Simplified updating of packages
|
||||||
|
|
||||||
### Motivation
|
### 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.
|
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);
|
defaultApp = forAllSystems (system: self.apps."${system}".cli);
|
||||||
|
|
||||||
apps = forAllSystems (system: {
|
apps = forAllSystems (system:
|
||||||
cli = {
|
lib.mapAttrs (appName: app:
|
||||||
"type" = "app";
|
{
|
||||||
"program" = builtins.toString (dream2nixFor."${system}".apps.cli);
|
type = "app";
|
||||||
};
|
program = builtins.toString app;
|
||||||
install = {
|
}
|
||||||
"type" = "app";
|
) dream2nixFor."${system}".apps
|
||||||
"program" = builtins.toString (dream2nixFor."${system}".apps.install);
|
);
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
devShell = forAllSystems (system: nixpkgsFor."${system}".mkShell {
|
devShell = forAllSystems (system: nixpkgsFor."${system}".mkShell {
|
||||||
buildInputs = with nixpkgsFor."${system}"; [
|
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,
|
pkgs,
|
||||||
|
|
||||||
|
callPackage,
|
||||||
externalSources,
|
externalSources,
|
||||||
location,
|
location,
|
||||||
translators,
|
translators,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
callPackage = pkgs.callPackage;
|
|
||||||
|
|
||||||
cliPython = pkgs.python3.withPackages (ps: [ ps.networkx ]);
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
|
|
||||||
# the unified translator cli
|
# the unified translator cli
|
||||||
cli = callPackage ({ writeScript, ... }:
|
cli = callPackage (import ./cli) {};
|
||||||
writeScript "cli" ''
|
|
||||||
export d2nExternalSources=${externalSources}
|
|
||||||
|
|
||||||
translatorsJsonFile=${translators.translatorsJsonFile} \
|
# the contribute cli
|
||||||
dream2nixSrc=${../.} \
|
contribute = callPackage (import ./contribute) {};
|
||||||
${cliPython}/bin/python ${./cli.py} "$@"
|
|
||||||
''
|
|
||||||
) {};
|
|
||||||
|
|
||||||
# install the framework to a specified location by copying the code
|
# install the framework to a specified location by copying the code
|
||||||
install = callPackage ({ writeScript, }:
|
install = callPackage ({ writeScript, }:
|
||||||
|
@ -18,6 +18,8 @@ let
|
|||||||
inherit callPackage;
|
inherit callPackage;
|
||||||
inherit externals;
|
inherit externals;
|
||||||
inherit externalSources;
|
inherit externalSources;
|
||||||
|
inherit location;
|
||||||
|
inherit translators;
|
||||||
inherit utils;
|
inherit utils;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,12 +30,8 @@ let
|
|||||||
|
|
||||||
config = builtins.fromJSON (builtins.readFile ./config.json);
|
config = builtins.fromJSON (builtins.readFile ./config.json);
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
rec {
|
|
||||||
|
|
||||||
# apps for CLI and installation
|
# apps for CLI and installation
|
||||||
apps = callPackage ./apps { inherit location translators; };
|
apps = callPackage ./apps {};
|
||||||
|
|
||||||
# builder implementaitons for all subsystems
|
# builder implementaitons for all subsystems
|
||||||
builders = callPackage ./builders {};
|
builders = callPackage ./builders {};
|
||||||
@ -44,12 +42,17 @@ rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
# the translator modules and utils for all subsystems
|
# 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.)
|
# the location of the dream2nix framework for self references (update scripts, etc.)
|
||||||
location = ./.;
|
location = ./.;
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
rec {
|
||||||
|
|
||||||
|
inherit apps builders fetchers location translators;
|
||||||
|
|
||||||
# automatically find a suitable builder for a given generic lock
|
# automatically find a suitable builder for a given generic lock
|
||||||
findBuilder = dreamLock:
|
findBuilder = dreamLock:
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
externals,
|
externals,
|
||||||
location,
|
location,
|
||||||
utils,
|
utils,
|
||||||
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user