This commit is contained in:
stubbfelnewpc
2020-06-20 20:31:24 +02:00
commit 28f9a40d68
6 changed files with 420 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
# Created by https://www.toptal.com/developers/gitignore/api/rust
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
### Rust ###
# Generated by Cargo
# will have compiled files and executables
target/
.theia
# These are backup files generated by rustfmt
**/*.rs.bk
# End of https://www.toptal.com/developers/gitignore/api/rust

184
.nixide/start-ide.nix Normal file
View File

@@ -0,0 +1,184 @@
{
pkgs ? import <nixpkgs> {},
listenAddress ? "0.0.0.0",
listenPort ? 3000,
theiaideAppFolder ? "_theiaideApp",
projectFolder ? "$PWD",
workingFolder ? "$PWD"
}:
let
theiaideBuildDependencies = [
pkgs.nano
pkgs.curl
pkgs.yarn
pkgs.nodejs-10_x
pkgs.python27Full
pkgs.git
pkgs.wget
pkgs.lzma
pkgs.gcc
pkgs.gnumake
pkgs.gccStdenv
pkgs.binutils
pkgs.gnupg
];
projectDependencies = [
pkgs.rustc
pkgs.rls
pkgs.cargo
pkgs.rustracer
pkgs.clippy
pkgs.rustfmt
pkgs.rustup
];
theiaidePackageConfig = {
private= true;
theia.frontend.config.applicationName = "DevelNixos";
dependencies = {
"@theia/callhierarchy" = "latest";
"@theia/console" = "latest";
"@theia/core" = "latest";
"@theia/editor" = "latest";
"@theia/editor-preview" = "latest";
"@theia/file-search" = "latest";
"@theia/filesystem" = "latest";
"@theia/git" = "latest";
"@theia/json" = "latest";
"@theia/keymaps" = "latest";
"@theia/languages" = "latest";
"@theia/markers" = "latest";
"@theia/messages" = "latest";
"@theia/metrics" = "latest";
"@theia/mini-browser" = "latest";
"@theia/monaco" = "latest";
"@theia/navigator" = "latest";
"@theia/outline-view" = "latest";
"@theia/output" = "latest";
"@theia/plugin" = "latest";
"@theia/plugin-ext" = "latest";
"@theia/plugin-ext-vscode" = "latest";
"@theia/preferences" = "latest";
"@theia/preview" = "latest";
"@theia/process" = "latest";
"@theia/rust" = "latest";
"@theia/scm" = "latest";
"@theia/search-in-workspace" = "latest";
"@theia/task" = "latest";
"@theia/terminal" = "latest";
"@theia/userstorage" = "latest";
"@theia/variable-resolver" = "latest";
"@theia/vsx-registry" = "latest";
"@theia/workspace" = "latest";
};
theiaPlugins = {
vscode-builtin-json = "https://open-vsx.org/api/vscode/json/1.46.1/file/vscode.json-1.46.1.vsix";
vscode-json-language-features = "https://open-vsx.org/api/vscode/json-language-features/1.46.1/file/vscode.json-language-features-1.46.1.vsix";
vscode-builtin-markdown = "https://open-vsx.org/api/vscode/markdown/1.46.1/file/vscode.markdown-1.46.1.vsix";
vscode-builtin-markdown-language-features = "https://open-vsx.org/api/vscode/markdown-language-features/1.46.1/file/vscode.markdown-language-features-1.46.1.vsix";
vscode-builtin-merge-conflicts = "https://open-vsx.org/api/vscode/merge-conflict/1.46.1/file/vscode.merge-conflict-1.46.1.vsix";
vscode-builtin-shellscript = "https://open-vsx.org/api/vscode/shellscript/1.46.1/file/vscode.shellscript-1.46.1.vsix";
vscode-builtin-xml = "https://open-vsx.org/api/vscode/xml/1.46.1/file/vscode.xml-1.46.1.vsix";
vscode-builtin-yaml = "https://open-vsx.org/api/vscode/yaml/1.46.1/file/vscode.yaml-1.46.1.vsix";
vscode-editorconfig = "https://open-vsx.org/api/EditorConfig/EditorConfig/0.15.1/file/EditorConfig.EditorConfig-0.15.1.vsix";
vscode-githistory = "https://open-vsx.org/api/donjayamanne/githistory/0.6.6/file/donjayamanne.githistory-0.6.6.vsix";
vscode-gitlens = "https://open-vsx.org/api/eamodio/gitlens/10.2.1/file/eamodio.gitlens-10.2.1.vsix";
vscode-shellcheck= "https://open-vsx.org/api/timonwong/shellcheck/0.9.0/file/timonwong.shellcheck-0.9.0.vsix";
vscode-rust = "https://open-vsx.org/api/vscode/rust/1.46.1/file/vscode.rust-1.46.1.vsix";
formulahendry-code-runner = "https://open-vsx.org/api/formulahendry/code-runner/0.10.0/file/formulahendry.code-runner-0.10.0.vsix";
rust-lang-rust = "https://open-vsx.org/api/rust-lang/rust/0.7.8/file/rust-lang.rust-0.7.8.vsix";
# swellaby-vscode-rust-test-adapter = "https://open-vsx.org/api/Swellaby/vscode-rust-test-adapter/0.11.0/file/Swellaby.vscode-rust-test-adapter-0.11.0.vsix";
serayuzgur-crates = "https://open-vsx.org/api/serayuzgur/crates/0.5.0/file/serayuzgur.crates-0.5.0.vsix";
belfz-search-crates-io = "https://open-vsx.org/api/belfz/search-crates-io/1.2.1/file/belfz.search-crates-io-1.2.1.vsix";
};
devDependencies = {
"@theia/cli" = "latest";
};
resolutions ={};
theiaPluginsDir = "plugins";
scripts = {
prepare = "yarn run clean && yarn build && yarn run download:plugin";
clean= "theia clean";
build= "theia build";
start= "theia start --plugins=local-dir:plugins";
"download:plugin" = "theia download:plugins";
};
};
theiaidePackageFile = pkgs.writeText "package.json" (builtins.toJSON theiaidePackageConfig);
run_ide_script = pkgs.writeShellScriptBin "run_ide.sh" ''
mkdir -p $THEIA_IDE_APP_FOLDER && \
rm -f $THEIA_IDE_APP_FOLDER/package.json && \
ln -s ${theiaidePackageFile} $THEIA_IDE_APP_FOLDER/package.json && \
cd $THEIA_IDE_APP_FOLDER && \
yarn && \
yarn start $PROJECT_FOLDER --hostname ${listenAddress} --port ${toString listenPort}
'';
clean_run_ide_script = pkgs.writeShellScriptBin "clean_run_ide.sh" ''
rm -rf $THEIA_IDE_APP_FOLDER && \
${run_ide_script}/bin/run_ide.sh
'';
base_service_file = pkgs.writeText "nixide.service" ''
[Unit]
Description=nixide service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
Environment=THEIA_IDE_APP_FOLDER=THEIA_IDE_APP_FOLDER_PLACE_HOLDER
Environment=PROJECT_FOLDER=PROJECT_FOLDER_PLACE_HOLDER
WorkingDirectory=WORKING_DIRECTORY_PLACE_HOLDER
ExecStart=/usr/bin/nix-shell --expr 'with import <nixpkgs> {}; callPackage PWD_PLACE_HOLDER/start-ide.nix {listenAddress = "${listenAddress}"; listenPort = ${toString listenPort}; theiaideAppFolder = "${theiaideAppFolder}"; projectFolder = "${projectFolder}";}' --pure --run ${run_ide_script}/bin/run_ide.sh
[Install]
WantedBy=multi-user.target
'';
base_clean_file = pkgs.writeText "clean-nixide.service" ''
[Unit]
Description= nixide clean service
[Service]
Type=Oneshot
Restart=always
RestartSec=1
Environment=THEIA_IDE_APP_FOLDER=THEIA_IDE_APP_FOLDER_PLACE_HOLDER
WorkingDirectory=WORKING_DIRECTORY_PLACE_HOLDER
ExecStart=rm -rf $THEIA_IDE_APP_FOLDER
[Install]
WantedBy=multi-user.target
'';
create_service_file = pkgs.writeShellScriptBin "create_service_file.sh" ''
export NIXIDE_SERVICE_NAME=''${1:-nixide}
cp -f ${base_service_file} $NIXIDE_SERVICE_NAME.service
sed -i "s|THEIA_IDE_APP_FOLDER_PLACE_HOLDER|$THEIA_IDE_APP_FOLDER|g" $NIXIDE_SERVICE_NAME.service
sed -i "s|PROJECT_FOLDER_PLACE_HOLDER|$PROJECT_FOLDER|g" $NIXIDE_SERVICE_NAME.service
sed -i "s|WORKING_DIRECTORY_PLACE_HOLDER|$WORKING_FOLDER|g" $NIXIDE_SERVICE_NAME.service
sed -i "s|PWD_PLACE_HOLDER|$PWD|g" $NIXIDE_SERVICE_NAME.service
cp -f ${base_clean_file} clean-$NIXIDE_SERVICE_NAME.service
sed -i "s|THEIA_IDE_APP_FOLDER_PLACE_HOLDER|$THEIA_IDE_APP_FOLDER|g" clean-$NIXIDE_SERVICE_NAME.service
sed -i "s|WORKING_DIRECTORY_PLACE_HOLDER|$WORKING_FOLDER|g" clean-$NIXIDE_SERVICE_NAME.service
'';
in
pkgs.mkShell {
name = "dev-shell";
buildInputs = theiaideBuildDependencies ++ projectDependencies ++ [run_ide_script clean_run_ide_script create_service_file] ;
shellHook =
''
export THEIA_IDE_APP_FOLDER=$(realpath ${theiaideAppFolder})
export PROJECT_FOLDER=$(realpath ${projectFolder})
export WORKING_FOLDER=$(realpath ${workingFolder})
'';
}

113
Cargo.lock generated Normal file
View File

@@ -0,0 +1,113 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "clap"
version = "2.33.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "hermit-abi"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
[[package]]
name = "nixidectl_cli"
version = "0.1.0"
dependencies = [
"clap",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "unicode-width"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "winapi"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

2
Cargo.toml Normal file
View File

@@ -0,0 +1,2 @@
[workspace]
members = ["control/cli"]

10
control/cli/Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
name = "nixidectl_cli"
version = "0.1.0"
authors = ["stubbfelnewpc <stubbfelnewpc@stubbe.rocks>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "2.33.1"

97
control/cli/src/main.rs Normal file
View File

@@ -0,0 +1,97 @@
extern crate clap;
use clap::{Arg, App, SubCommand};
use std::process::{Command, Stdio};
use std::io::{BufRead, BufReader, Error, ErrorKind};
const START_SUBCOMMAND_NAME: &str = "start";
const STOP_SUBCOMMAND_NAME: &str = "stop";
const START_FILE_ARGUMENT_NAME: &str = "start-ide-file";
const START_ARGS_ARGUMENT_NAME: &str = "start-ide-arguments";
const CLEAN_RUN_ARGUMENT_NAME: &str = "clean-run";
const VERBOSE_ARGUMENT_NAME: &str = "verbose";
const IDE_ID_ARGUMENT_NAME: &str = "ide-id";
fn main() {
let matches =
App::new("nixidectl")
.version("0.1.0")
.author("stubbfel")
.about("control nixide process")
.subcommand(SubCommand::with_name(START_SUBCOMMAND_NAME)
.arg(Arg::with_name(START_FILE_ARGUMENT_NAME)
.short("f")
.long("start-ide-file")
.value_name("START_IDE_FILE")
.help("path to start-ide.nix")
.required(true)
.takes_value(true))
.arg(Arg::with_name(START_ARGS_ARGUMENT_NAME)
.short("a")
.long("start-ide-arguments")
.value_name("START_IDE_ARGUMENTS")
.help("the start arguments of the start-ide.nix")
.default_value("{}")
.takes_value(true))
.arg(Arg::with_name(CLEAN_RUN_ARGUMENT_NAME)
.short("c")
.long("clean-run")
.help("clean app folder, before start runnnig"))
.arg(Arg::with_name(VERBOSE_ARGUMENT_NAME)
.short("v")
.long("verbose")
.help("verbose")))
.subcommand(SubCommand::with_name("stop")
.arg(Arg::with_name(IDE_ID_ARGUMENT_NAME)
.short("i")
.long("ide-id")
.value_name("IDE_ID")
.help("the ide id is the process group id")
.required(true)
.takes_value(true)))
.get_matches();
match matches.subcommand() {
(START_SUBCOMMAND_NAME, Some(start_cmd)) => {
println!("{}", std::process::id());
let file = start_cmd.value_of(START_FILE_ARGUMENT_NAME).unwrap();
let args = start_cmd.value_of(START_ARGS_ARGUMENT_NAME).unwrap();
let run_script = match start_cmd.is_present(CLEAN_RUN_ARGUMENT_NAME) {
true => "clean_run_ide.sh",
_ => "run_ide.sh"
};
let nix_expression = format!("with import <nixpkgs> {{}}; callPackage {} {}", file, args);
let cmd = Command::new("nix-shell")
.stderr(Stdio::null())
//.stdout(Stdio::null())
.stdout(Stdio::piped())
.arg("--expr")
.arg(nix_expression)
.arg("--pure")
.arg("--run")
.arg(run_script)
.spawn()
.expect("start ide command failed");
let out = cmd.stdout.ok_or_else(|| Error::new(ErrorKind::Other,"Could not capture standard output.")).unwrap();
let reader = BufReader::new(out);
let start_up_log = reader.lines()
.filter_map(|line| line.ok())
.take_while(|line| !line.find("theia start").is_some());
match start_cmd.is_present(VERBOSE_ARGUMENT_NAME) {
true => start_up_log.for_each(|line| println!("{}", line)),
_ => start_up_log.for_each(|_| {})
};
},
(STOP_SUBCOMMAND_NAME, Some(stop_cmd)) => {
let ide_id = stop_cmd.value_of(IDE_ID_ARGUMENT_NAME).unwrap();
Command::new("pkill")
.arg("-TERM")
.arg("-g")
.arg(ide_id)
.output().unwrap();
}
_ => println!("-1")
};
}