Nix config outside of NixOS - zsh

So I’m trying to make a development environment that’s easily reproducible (staying away from home-manager currently to understand Nix better). After enough searching around I figured out how to make a few custom derivations, use buildEnv for package sets, and use ~/.config/nixpkgs/config.nix to do overrides. I’m working now to setup zsh and oh-my-zsh which have a ton of configuration options, but the only documentation I can find seems to suggest adding them to configuration.nix, which is a NixOS option I can’t use.
Currently my config.nix code looks something like this:
let
pkgs = import <nixpkgs> {};
in {
allowUnfree = true;
programs = {
zsh = {
enable = true;
promptInit = "source ${pkgs.zsh-powerlevel9k}/share/zsh-powerlevel9k/powerlevel9k.zsh-theme";
ohMyZsh = {
enable = true;
plugins = ["autojump"];
theme = "powerlevel9k/powerlevel9k";
};
};
};
packageOverrides = pkgs: with pkgs; rec {
all = buildEnv {
name = "all";
paths = with pkgs; [
tmuxinator
zsh
oh-my-zsh
autojump
...
];
};
};
}
My understanding so far is that within ~/.config/nixpkgs/config.nix, there should be a single config set which contains things like the overrides function and corresponds to documentation examples of config.programs.zsh.enable, etc. However, nothing I write in that programs section affects or causes a different ouput of any of my programs.
What am I missing? How can I affect the configuration options listed here (https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/zsh/zsh.nix)?

You seem to be trying to use home-manager's config without using home-manager itself. As you can see in the NixOS module you linked, this actually sets up /etc/zshrc etc, so it's not intended for use in a user-local config and won't do anything there. If you look at the corresponding home-manager module, you'll see that it basically reimplements the whole module for user-local purposes. So you won't get far with this approach without relying on home-manager.

Related

How customize machine dependency in Frama-C?

I have got a 16-bit MPU which is different from x86_16 in size of size_t, ptrdiff_t etc. Can anybody give me details and clear instructions about how to customize machine dependency in Frama-C for my MPU?
There is currently no way to do that directly from the command line: you have to write a small OCaml script that will essentially define a new Cil_types.mach (a record containing the necessary information about your architecture) and register it through File.new_machdep. Assuming you have a file my_machdep.ml looking like that:
let my_machdep = {
Cil_types.sizeof_short = 2;
sizeof_int = 2;
sizeof_long = 4;
(* ... See `cil_types.mli` for the complete list of fields to define *)
}
let () = File.new_machdep "my_machdep" my_machdep
You will then be able to launch Frama-C that way to use the new machdep:
frama-c -load-script my_machdep.ml -machdep my_machdep [normal options]
If you want to have the new machdep permanently available, you can make it a Frama-C plugin. For that, you need a Makefile of the following form:
FRAMAC_SHARE:=$(shell frama-c -print-share-path)
PLUGIN_NAME=Custom_machdep
PLUGIN_CMO=my_machdep
include $(FRAMAC_SHARE)/Makefile.dynamic
my_machdep must be the name of your .ml file. Be sure to choose a different name for PLUGIN_NAME. Then, create an empty Custom_machdep.mli file (touch Custom_machdep.mli should do the trick). Afterwards, make && make install should compile and install the plug-in so that it will be automatically loaded by Frama-C. You can verify this by launching frama-c -machdep help that should output my_machdep among the list of known machdeps.
UPDATE
If you are using some headers from Frama-C's standard library, you will also have to update $(frama-c -print-share-path)/libc/__fc_machdep.h in order to define appropriate macros (related to limits.h and stdint.h mostly).

gulp-autoprefixer simply doesn't work

Wasted over 3 days of troubleshooting; have gotten nowhere further. Appreciate any assistance at this point. Here's my code:
var gulp = require('gulp'),
path = require('path');
gulp.task('prefix', function() {
var prefixer = require('gulp-autoprefixer');
gulp.src(path.join(__dirname, 'app/styles/assets/**/*.css'))
.pipe(prefixer({ browsers: [ '> 1%' ] }))
.pipe(gulp.dest('./');
});
I placed a single .css file in the specified source directory and added properties/values that would require prefixing, like: transform, column-count and the 'flex' value of the display property.
When run, gulp gives no errors, no file is modified, pretty much nothing happens. I've tried specifying a path to an output file, removing the options from the prefixer() call, hard-coding values into the .src() and .dest() methods, running the whole command in a singular file, inside a sequence runner, reinstalled the module, updated packages and more.
I've read the docs inside and out, am following them to a 'T', and even contacted the module author to look at my code, and he stated it looked fine to him. I simply cannot see what I'm doing wrong.

Can I use sbt's `apiMappings` setting for managed dependencies?

I'd like the ScalaDoc I generate with sbt to link to external libraries, and in sbt 0.13 we have autoAPIMappings which is supposed to add these links for libraries that declare their apiURL. In practice though, none of the libraries I use provide this in their pom/ivy metadata, and I suspect some of these libraries will never do so.
The apiMappings setting is supposed to help with just that, but it is typed as Map[File, URL] and hence geared towards setting doc urls for unmanaged dependencies. Managed dependencies are declared as instances of sbt.ModuleID and cannot be inserted directly in that map.
Can I somehow populate the apiMappings setting with something that will associate an URL with a managed dependency ?
A related question is: does sbt provide an idiomatic way of getting a File from a ModuleID? I guess I could try to evaluate some classpaths and get back Files to try and map them to ModuleIDs but I hope there is something simpler.
Note: this is related to https://stackoverflow.com/questions/18747265/sbt-scaladoc-configuration-for-the-standard-library/18747266, but that question differs by linking to the scaladoc for the standard library, for which there is a well known File scalaInstance.value.libraryJar, which is not the case in this instance.
I managed to get this working for referencing scalaz and play by doing the following:
apiMappings ++= {
val cp: Seq[Attributed[File]] = (fullClasspath in Compile).value
def findManagedDependency(organization: String, name: String): File = {
( for {
entry <- cp
module <- entry.get(moduleID.key)
if module.organization == organization
if module.name.startsWith(name)
jarFile = entry.data
} yield jarFile
).head
}
Map(
findManagedDependency("org.scalaz", "scalaz-core") -> url("https://scalazproject.ci.cloudbees.com/job/nightly_2.10/ws/target/scala-2.10/unidoc/")
, findManagedDependency("com.typesafe.play", "play-json") -> url("http://www.playframework.com/documentation/2.2.1/api/scala/")
)
}
YMMV of course.
The accepted answer is good, but it'll fail when assumptions about exact project dependencies don't hold. Here's a variation that might prove useful:
apiMappings ++= {
def mappingsFor(organization: String, names: List[String], location: String, revision: (String) => String = identity): Seq[(File, URL)] =
for {
entry: Attributed[File] <- (fullClasspath in Compile).value
module: ModuleID <- entry.get(moduleID.key)
if module.organization == organization
if names.exists(module.name.startsWith)
} yield entry.data -> url(location.format(revision(module.revision)))
val mappings: Seq[(File, URL)] =
mappingsFor("org.scala-lang", List("scala-library"), "http://scala-lang.org/api/%s/") ++
mappingsFor("com.typesafe.akka", List("akka-actor"), "http://doc.akka.io/api/akka/%s/") ++
mappingsFor("com.typesafe.play", List("play-iteratees", "play-json"), "http://playframework.com/documentation/%s/api/scala/index.html", _.replaceAll("[\\d]$", "x"))
mappings.toMap
}
(Including scala-library here is redundant, but useful for illustration purposes.)
If you perform mappings foreach println, you'll get output like (note that I don't have Akka in my dependencies):
(/Users/michaelahlers/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar,http://scala-lang.org/api/2.11.7/)
(/Users/michaelahlers/.ivy2/cache/com.typesafe.play/play-iteratees_2.11/jars/play-iteratees_2.11-2.4.6.jar,http://playframework.com/documentation/2.4.x/api/scala/)
(/Users/michaelahlers/.ivy2/cache/com.typesafe.play/play-json_2.11/jars/play-json_2.11-2.4.6.jar,http://playframework.com/documentation/2.4.x/api/scala/)
This approach:
Allows for none or many matches to the module identifier.
Concisely supports multiple modules to link the same documentation.
Or, with Nil provided to names, all modules for an organization.
Defers to the module as the version authority.
But lets you map over versions as needed.
As in the case with Play's libraries, where x is used for the patch number.
Those improvements allow you to create a separate SBT file (call it scaladocMappings.sbt) that can be maintained in a single location and easily copy and pasted into any project.
Alternatively to my last suggestion, the sbt-api-mappings plugin by ThoughtWorks shows a lot of promise. Long term, that's a far more sustainable route than each project maintaining its own set of mappings.

How do I change the autoindent to 2 space in IPython notebook

I find that developing functions in IPython notebook allows me to work quickly. When I'm happy with the results I copy-paste to a file. The autoindent is 4 spaces, but the coding style for indentation at my company is 2 spaces. How do I change the autoindent to 2 spaces?
The official documentation has an example answering this specific question. This worked for me with IPython 4.
Summary: Paste the following into your browser's javascript console
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
The setting is persisted. You can roll back by exchanging : 2 for : null.
From the official documentation for CodeMirror Code Cells:
Open an Ipython Notebook
Create a Code Cell e.g. by pressing b
Open your browser’s JavaScript console and run the following
snippet:
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
Reload the notebook page in the browser e.g. by pressing F5
This will fix it permanently. I assume this works only on recent versions, not sure though!
AdamAL's answer is correct. It worked for me.
However it only changes the indentation in the Jupyter Notebook and leaves the indentation in the Jupyter Editor unaffected.
A more direct way to change the indentation is to directly edit the Jupyter config files in the .jupyter/nbconfig directory. This directory contains 2 files:
edit.json
notebook.json
The option you must set in either one is indentUnit. Here is the content of my Jupyter config files:
edit.json:
{
"Editor": {
"codemirror_options": {
"indentUnit": 2,
"vimMode": false,
"keyMap": "default"
}
}
}
notebook.json:
{
"CodeCell": {
"cm_config": {
"indentUnit": 2
}
}
}
With this approach I've set the default indentation to 2 in both the Jupyter Notebook and the Jupyter Editor.
Based on this question and the options found here:
In your custom.js file (location depends on your OS) put
IPython.Cell.options_default.cm_config.indentUnit = 2;
On my machine the file is located in ~/.ipython/profile_default/static/custom
Update:
In IPython 3 the plain call does not work any more, thus it is required to place the setting within an appropriate event handler. A possible solution could look like
define([
'base/js/namespace',
'base/js/events'
],
function(IPython, events) {
events.on("app_initialized.NotebookApp",
function () {
IPython.Cell.options_default.cm_config.indentUnit = 2;
}
);
}
);
If you use jupyterlab, there seems to be an easier way:
1) Click jupyterlab menu Settings > Advanced Setting Editor
2) Click "Notebook" on the left hand pane, make sure you are on "Raw View"
3) On the right pane, under "User Overrides", enter this:
{
"codeCellConfig": {
"tabSize": 2
}
}
If you look at the System Defaults, that will give you hint on whats overridable and you can repeat this for other settings.
I tried this on Google Platform AI Notebook which uses Jupyterlab.
I believe this is now best wrapped in a event handler to load once per notebook load:
$([IPython.events]).on('app_initialized.NotebookApp', function(){
IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
});
In addition to adding
IPython.Cell.options_default.cm_config.indentUnit = 2;
to your custom.js file as suggested by Jakob, be sure to clear your browser cache as well before restarting ipython notebook!
Also, you may have to first create the ~/.config/ipython/profile_default/static/custom/ directory (use echo $(ipython locate default) to find your default directory) before adding the custom.js file.

Switching to dynamic linking

I'm building some packages with autoconf and automake, and would like to make sure libraries are dynamically linked (i.e. no static links).
How should one set up the autotools to force dynamic library linking?
Something like this comes to mind:
# Makefile.am
lib_LTLIBRARIES = libpart.la
libpart_la_SOURCES = lgpl_chunk.c
bin_PROGRAMS = prop
prop_SOURCES = prop.c
prop_LDADD = libpart.la
And make sure that you always build a shared library. Best by disabling static builds by default,
#configure.ac
AC_DISABLE_STATIC
if test "$enable_static" != "no"; then
echo "Sorry Dave, I can't let you do that";
exit 1;
fi;
You don't necessarily have to rely on autotools for this. You could use dlopen or some other facility to load the dynamic lib.

Resources