How can I install extension of vscode? - nixos

This is a beginner question. So there is a package vscode-with-extensions.
The package says:
A set of vscode extensions to be installed alongside the editor. Here's a an example:
vscode-with-extensions.override {
# When the extension is already available in the default extensions set.
vscodeExtensions = with vscode-extensions; [
bbenoist.Nix
]
# Concise version from the vscode market place when not available in the default set.
++ vscode-utils.extensionsFromVscodeMarketplace [
{
name = "code-runner";
publisher = "formulahendry";
version = "0.6.33";
sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
}
];
}
Where in configuration.nix do I have to put this expression? I already have
environment.systemPackages = with pkgs; [
wget
vim
vscode-with-extensions
];
therein.

You’re supposed to use it as in the configuration.nix directly, like for instance
environment.systemPackages = with pkgs; [
wget
vim
(vscode-with-extensions.override {
# When the extension is already available in the default extensions set.
vscodeExtensions = with vscode-extensions; [
bbenoist.Nix
]
# Concise version from the vscode market place when not available in the default set.
++ vscode-utils.extensionsFromVscodeMarketplace [
{
name = "code-runner";
publisher = "formulahendry";
version = "0.6.33";
sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
}
];
})
];
Or, in a more readable version:
environment.systemPackages = with pkgs;
let
vcsodeWithExtension = vscode-with-extensions.override {
# When the extension is already available in the default extensions set.
vscodeExtensions = with vscode-extensions; [
bbenoist.Nix
]
# Concise version from the vscode market place when not available in the default set.
++ vscode-utils.extensionsFromVscodeMarketplace [
{
name = "code-runner";
publisher = "formulahendry";
version = "0.6.33";
sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
}
];
})
in
[
wget
vim
vcsodeWithExtension
];

So, apparently it can go directly into environment.systemPackages, but requires parentheses:
environment.systemPackages = with pkgs; [
wget
vim
(vscode-with-extensions.override {
vscodeExtensions = with vscode-extensions; [
bbenoist.Nix
];
})
];

Related

How to change `DIRS` path dynamically in Django?

I want to change DIRS dynamically.based on devices.
if request.user_agent.is_pc:
request.template_prefix = 'desktop'
else:
request.template_prefix = 'mobile'
Default (settings.py):
TEMPLATES = [
{
'DIRS': ['templates'],
},
]
I want to change my DIRS path like this (settings.py):
TEMPLATES = [
{
'DIRS': [f"templates/{request.template_prefix}"],
},
]
Also let me know if you need more codes.
Note: I can't use user_agent in settings.py Because it requires a request.
that's why I asked.
My django version is: 3.2.x
In simple words: How to change DIRS path in views.py.
Thanks!

refactor ensure_packages to switch version of installed packages

I am successfully installing several PHP modules by version with puppet on Debian linux like this:
$php_version = '7.3'
ensure_packages([
"php$php_version-xml",
"php$php_version-zip",
"php$php_version-curl",
"php$php_version-mbstring",
"libapache2-mod-php$php_version",
],
{
'ensure' => 'present',
}
)
now I want to prepare for an update from PHP 7.3 to 7.4. This basically works, but the 7.3 packages stay installed. I would like to adapt the code to remove the old packages. I am looking for a way to reuse the list of packages of modules for uninstalling.
I am thinking of a signature like this
class profile::software::apache (
$php_version = '7.4',
$php_remove = ['7.0‘, ‘7.3'],
#...
) {
$myPackages = [
"php$php_version-xml",
"php$php_version-zip",
"php$php_version-curl",
"php$php_version-mbstring",
"libapache2-mod-php$php_version",
]
ensure_packages($myPackages,
{
'ensure' => 'present',
}
)
$php_remove.each | String $php_version | {
ensure_packages($myPackages,
{
'ensure' => 'absent',
}
)
}
}
Is there a way to solve this?
thx
I was able to solve this by using iteration functions of puppet.
From the two parameters I build a hash with keys of versions to work on and values to either install or remove the given version.
Now I can iterate over this hash with each, reusing the structure:
class profile::software::apache (
$php_version = '7.4',
$php_remove = ['7.0‘, ‘7.3'],
#...
) {
# build a hash of PHP Versions with a value of either present or absent
# and iterate over it with each
$phpInstallHash = { $php_version => 'present' }
#notify { "Value of phpRemove: ${php_remove}": }
if $php_remove {
# We have the array, use the map function to build remove hash
$phpRemoveHash = $php_remove.map |$version| {
{ $version => 'absent' }
}
$phpFullHash = $phpInstallHash + $phpRemoveHash
} else {
$phpFullHash = $phpInstallHash
}
#notify { "phpHash to iterate over to install/uninstall: ${phpFullHash}": }
#iterate over the result installing/uninstalling
$phpFullHash.each | $php_version, $ensure_value | {
ensure_packages([
"php$php_version-xml",
"php$php_version-zip",
"php$php_version-curl",
"php$php_version-mbstring",
"libapache2-mod-php$php_version",
],
{
'ensure' => $ensure_value,
require => [Class['apt::update'],
Apt::Source['source_php_sury'],
],
notify => Class['apache::service'],
}
)
}
}
hth

Including runfiles in a filegroup

Im new to Bazel.
I thought id start by trying to build a simple nodejs project, it uses babel to do some transforming as part of the build process, the issue im having is I cant seem to find a way to get these transformed files into a filegroup.
Here's my BUILD file.
load("#build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
load("#bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
# Group all our initial code.
filegroup(
name = "src",
srcs = [
".babelrc",
"package.json",
"//config:src",
"//handlers:src",
"//migrations:src",
"//models:src",
"//services:src",
"//tasks:src",
"#dependencies//:node_modules",
],
)
# Group all our generated code.
filegroup(
name = "out",
srcs = [
"//:babel:runfiles" ### ???
],
)
nodejs_binary(
name = "babel",
entry_point = "babel-cli/bin/babel.js",
templated_args = [
".",
"--ignore node_modules,test/,migrations/,babel_bin_loader.js",
"-d out",
"--source-maps=both",
"--copy-files",
],
node_modules = "#nodejs_build_tools//:node_modules",
data = [
"//:src",
]
)
pkg_tar(
name = "build",
strip_prefix = "/",
package_dir = "/usr/src/app",
srcs = ["//:out"],
mode = "0755",
)
My issue is that im not sure how to reference the runfiles from my nodejs_binary rule.
https://github.com/bazelbuild/rules_nodejs/blob/master/internal/node/node.bzl#L130
Seems to indicate that there should be a :runfiles attribute or similar?
Thanks! :)
So turns out that the correct way to do this appears to be by using a genrule to actually call the configured nodejs binary. Eg.
## Artifact Construction ##
genrule(
name = "construct_artifact",
outs = ["artifact.tar"],
cmd = """./$(location babel) . --ignore bazel-
out,node_modules,text/,migrations/ -d out/ --source-maps=both --copy-files && tar cvf $# out/ """,
srcs = [
"//:src",
],
tools = [
"//:babel",
]
)

Xkb: Switch Overlay vs HotKeys

I'm trying to configure xkb to select each keyboard layouts with unique hotkey (en = Win+1, de = Win+2, jp = Win+3)
replace key <I156> { [NoSymbol], actions[Group1] = [ LockGroup(group=1) ] };
replace key <I157> { [NoSymbol], actions[Group1] = [ LockGroup(group=2) ] };
replace key <I210> { [NoSymbol], actions[Group1] = [ LockGroup(group=3) ] };
replace key <LWIN> {
symbols[Group1] = [ Super_L ],
actions[Group1] = [ SetControls(controls=overlay1) ]
};
key <AE01> { overlay1 = <I156> };
key <AE02> { overlay1 = <I157> };
key <AE03> { overlay1 = <I210> };
But it breaks hotkeys with Win key (e.g. Win + T). Is it possible to configure key to switch overlay that does not break hotkeys?
I tried something very similar but also with no luck. I ended up simply binding system-wide shortcuts to setxkbmap commands. In my case:
Super+F1 = setxkbmap de
Super+F2 = setxkbmap us -variant colemak
etc.
I'm on a Xfce desktop, which has a handy utility for keyboard shortcuts but there are other ways to do this on other desktops.
Cheers,
Os

Migrating from WAF to GYP - trouble including library

I'm migrating an out of date npm package from WAF to GYP, but having a few problems getting everything working. It runs a WSCRIPT which seems to include a 3rd party library:
import Options
from os import unlink, symlink, popen, sys
from os.path import exists
srcdir = '.'
blddir = 'build'
VERSION = '0.0.2'
def set_options(opt):
opt.tool_options('compiler_cxx')
def configure(conf):
conf.check_tool('compiler_cxx')
conf.check_tool('node_addon')
print(sys.platform)
if sys.platform == 'darwin':
conf.check_tool('osx')
tc_framework = 'TelldusCore'
conf.env.append_value("FRAMEWORK_TC", tc_framework)
tc_frameworkpath = '/Library/Frameworks/TelldusCore.framework/'
conf.env.append_value("FRAMEWORKPATH_TC", tc_frameworkpath)
tc_lib = tc_frameworkpath + 'Headers/'
conf.env.append_value("CPPPATH_TC", tc_lib)
elif sys.platform == 'linux2':
conf.env.LIB_TC = 'telldus-core'
#conf.env.LIBPATH_TC = ['/usr/lib']
#conf.env.CCFLAGS_TC = ['-O0']
conf.env.CCDEFINES_TC = ['TC']
#conf.env.LINKFLAGS_TC = ['-g']
else:
raise ValueError("Dose not support: %r" % sys.platform)
def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
obj.target = 'telldus'
obj.source = 'telldus.cc'
obj.uselib = "TC"
Now I've tried to convert it to a binding.gyp script, but not sure how to include the library:
{
"targets": [
{
"target_name": "tellduscorejs2",
"sources": [ "tellduscorejs2.cpp" ],
"conditions": [
['OS=="mac"', {
'defines': [
'FRAMEWORK_TC=TelldusCore',
'FRAMEWORKPATH_TC="/Library/Frameworks/TelldusCore.framework/"',
'CPPPATH_TC="/Library/Frameworks/TelldusCore.framework/Headers/"'
]
}],
['OS=="linux"', {
'defines': [
'LIB_TC=telldus-core',
'CCDEFINES_TC=TC'
]
}]
],
'link_settings': {
'libraries': [
???
],
},
}
]
}
If anyone could point out if I'm on the right lines or what I need to change to include the library it'd be appreciated!
I've actually done this for the telldus-core project. See https://github.com/marchaos/telldus-core-js/
i've also added events for devices and sensors.

Resources