Configuring withHoogle in default.nix: - haskell

I'm trying to setup withHoogle in my default.nix, but I'm getting this error:
developPackage, error: attempt to call something which is not a function but a set(at line 26).
Here is my default.nix code:
let
pkgs = import <nixpkgs> {};
compilerVersion = "ghc865";
compiler = pkgs.haskell.packages."${compilerVersion}";
in
compiler.developPackage
{
# returnShellEnv = false;
root = ./.;
# source-overrides = {};
modifier = drv:
let pkg = pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
[
cabal-install
cabal2nix
ghcid
control
text
brick
]);
in pkg // {
env = (pkg.env { withHoogle = true; }).overrideAttrs (old: {
shellHook =
''
export PS1='\n\[\033[1;32m\][\[\e]0;nix-shell: \W\a\]nix-shell:/\W]\$ \[\033[0m\]'
'';
});
};
}

I had a similar error message when trying to nix-build a seemingly correct derivation (default.nix).
Eventually I found out using the --show-trace parameter to nix-build, that the error lie in an overlay I had in my user's ~/.config/nixpkgs/overlays directory lying around.
HTH

Related

How do I override the libc in a Nix package to be musl?

I'm using Nix as a dependency manager for a Rust program. I have the following default.nix (simplified, but working):
rec {
pkgs = import <nixpkgs> {};
hello = pkgs.stdenv.mkDerivation rec {
name = "rust-hello";
buildInputs = [
pkgs.rustc
];
src = ./source;
buildPhase = "rustc main.rs -o rust-hello";
installPhase = ''
mkdir -p $out/bin
install -s rust-hello $out/bin
'';
};
}
I'm trying to override the libc for all dependencies (including the Rust compiler) to be pkg.musl, but I fail to do so. How can this be achieved?
Try the pkgsMusl convenience attribute (source)
rec {
pkgs = (import <nixpkgs> {}).pkgsMusl;
# ...
}

overridePackages of local nixpkgs' config to add new packages

i'm looking for enlightenment on how to do the best way on my situation as follows:
I have a nixpkgs folder on my project, which I download from other repo. It located on my theproject/front-plat/default.nix then the code is look like this.
{ nixpkgsFunc ? import ./nixpkgs }: let nixpkgs = nixpkgsFunc ({ config = { ... }; lib = {...}; etc.
In my theproject/release.nix I want to add a new packages which will be used for my built using the nixpkgs' front-plat. So the code looks like this.
{ front-plat ? import ./deps/front-plat {}}:
let
nixpkgs = front-platform.nixpkgs;
packageCompiler = front-plat.compiler;
config = rec { ...
packageOverrides = pkgs: rec {
packageCompiler = pkgs.packageCompiler.override {
overrides = self: super: rec {
fronFrint = self.callPackage (import ./frontFrint { inherit front-plat; });
};
};
};
3 Which I assume, now i'm using the nixpkgs from the front-plat but i'm still not sure does my nixpkgs' packageCompiler already contains fronFrint package or not.
The question is, how can I add my new packages called "frontFrint" to the nixpkgs's packageCompiler. so that the packageCompiler can built fronFrint. for example in the end, the code will be
in { front = pkgs.packageCompiler.frontFrint; }

Get cordova package name from javascript hook

I am writing a cordova plugin with a node hook to run after_prepare .
This is for Android only.
From within this hook I need to get the cordova package name, so I can copy a file to the src/com/example/myproject folder (if the package is com.example.myproject).
If I know the package name I can make this path. I have it working hardcoded now but I need this to work with two different package names.
Is there a way to get the package name from within this code in the plugin hook?
module.exports = function(ctx){
var fs = ctx.requireCordovaModule('fs');
var path = ctx.requireCordovaModule('path');
var deferral = ctx.requireCordovaModule('q').defer();
//get package name here
//do other stuff
}
I have done a lot of research but have not been able to find this.
Thanks.
It doesn't look like it is available off of the context object, but you could try to parse the config.xml.
module.exports = function(context) {
var fs = require('fs');
var path = require('path');
var config_xml = path.join(context.opts.projectRoot, 'config.xml');
var et = context.requireCordovaModule('elementtree');
var data = fs.readFileSync(config_xml).toString();
var etree = et.parse(data);
console.log(etree.getroot().attrib.id);
};
The local-webserver plugin uses a similar strategy for reading config properties.
Here my compilation from different answers that works in 2021.
I use it to update some parameters in Xcode project for plugins compilation.
You can see that I am getting here app id and name from config.xml
And you can add it to after_prepare hook:
<hook src="scripts/addBuildSettingsToXcode.js" type="after_prepare" />
#!/usr/bin/env node
let fs = require('fs');
let xcode = require('xcode');
let path = require('path');
let et = require('elementtree');
module.exports = function (context) {
//console.log(context);
function addBuildPropertyToDebugAndRelease(prop, value) {
console.log('Xcode Adding ' + prop + '=' + value);
myProj.addBuildProperty(prop, value, 'Debug');
myProj.addBuildProperty(prop, value, 'Release');
}
function updateBuildPropertyToDebugAndRelease(prop, value) {
console.log('Xcode Updating ' + prop + '=' + value );
myProj.updateBuildProperty(prop, value, 'Debug');
myProj.updateBuildProperty(prop, value, 'Release');
}
// Getting app id and name from config.xml
let config_xml = path.join(context.opts.projectRoot, 'config.xml');
let data = fs.readFileSync(config_xml).toString();
let etree = et.parse(data);
let appId = etree.getroot().attrib.id ;
let appName = etree.getroot().find('name')['text'];
// Building project path
let projectPath = 'platforms/ios/' + appName + '.xcodeproj/project.pbxproj';
// Opening Xcode project and parsing it
myProj = xcode.project(projectPath);
myProj = myProj.parseSync();
// Common properties
addBuildPropertyToDebugAndRelease('DEVELOPMENT_TEAM', 'CGXXXXXXX');
addBuildPropertyToDebugAndRelease('CODE_SIGN_IDENTITY', '"Apple Development"');
// Compilation properties
addBuildPropertyToDebugAndRelease('ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES', 'YES');
// Save project file
fs.writeFileSync(projectPath, myProj.writeSync());
};

How to reliably locate/import a dependency of a dependency?

I want to import a dependency of a dependency. For example, I want to import jade-load directly into my app:
my-app
┗━jade
┗━jade-load
I could do require('jade/node_modules/jade-load'), but this won't work if the node_modules tree has been flattened or deduped.
I thought of using require.resolve() to find out where jade-load really is, but there doesn't seem to be a way to tell it the starting point for the resolution. I need to be able to say "require jade-load from wherever jade is".
NB. I do not want to install jade-load as a direct dependency of my app; the point is to import the same instance that jade uses, so I can monkeypatch it.
I guess you may want to use proxyquire for managing dependencies of required modules. You can set proxyquire to globally override methods of the submodule when it will be loaded.
main.js
var proxyquire = require('proxyquire');
// use default childModule properties and methods unless they are redefined here
var childModuleStub = {
/* redefine here some necessary methods */
'#global': true
};
// parent module itself does't require childModule
var parentModuleStubs = {
'./childModule': childModuleStub
};
var parentModule = proxyquire('./parentModule', parentModuleStubs);
var result;
result = parentModule.exec();
console.log(result);
childModuleStub.data.sentence = "Overridden property.";
result = parentModule.exec();
console.log(result);
childModuleStub._exec = function () {
return "Overridden function.";
};
result = parentModule.exec();
console.log(result);
parentModule.js
var intermediateLibrary = require('./intermediateLibrary');
module.exports = {
exec: function() {
return intermediateLibrary.exec();
}
};
intermediateLibrary.js
var childModule = require('./childModule');
module.exports = {
exec: function() {
return childModule._exec();
}
};
childModule.js
var lib = {};
lib.data = {};
lib.data.sentence = "Hello, World!";
lib._exec = function () {
return lib.data.sentence;
};
module.exports = lib;
Results:
Hello, World!
Overridden property.
Overridden function.

NodeJS - How to resolve “Cannot find module 'ar-drone' ” error

I installed the following package over the command prompt:
npm install -g ar-drone
and then hit via Node.js
var arDrone = require('ar-drone');
and it gives me cannot find module 'ar-drone'
I thought when I install something with -g it will be installed globally?
What did I do wrong?
Check whether the module is downloaded in /usr/local/lib/node_modules if you use ubuntu. Thats the global location for node_modules.
Also you can try to install in your local directory.
Yes I had to transfer all code from index.js to repl.js. My repl.js looks like so and works.
let arDrone = exports;
exports.Client = require('./lib/Client');
exports.UdpControl = require('./lib/control/UdpControl');
exports.PngStream = require('./lib/video/PngStream');
exports.UdpNavdataStream = require('./lib/navdata/UdpNavdataStream');
exports.createClient = function(options) {
let client = new arDrone.Client(options);
client.resume();
return client;
};
exports.createUdpControl = function(options) {
return new arDrone.UdpControl(options);
};
exports.createPngStream = function(options) {
let stream = new arDrone.PngStream(options);
stream.resume();
return stream;
};
exports.createUdpNavdataStream = function(options) {
let stream = new arDrone.UdpNavdataStream(options);
stream.resume();
return stream;
};
let client = arDrone.createClient();
client.createRepl();

Resources