I'm trying to build for a nix-shell that aren't in the current nixpkgs repository.
Specifically: raylua
I've managed to get Raylib itself built as part of a nix-shell using Nim.
I'm trying to now modify this to use Lua Raylib and the Lua libraries and am unsure how to procede.
I see people use nix-shell ... commands to bypass a lot of this pain, but I want something I can commit to a repo.
Files I have are:
shell.nix
{ pkgs ? import <nixpkgs> {} }:
let
unstable = import <unstable> {};
raylib = pkgs.callPackage ./nix/raylib/default.nix { };
# toLuaModule
#raylib-lua = pkgs.callPackage ./nix/raylib-lua/default.nix { raylib };
in
pkgs.mkShell {
buildInputs = [
pkgs.bashInteractive
pkgs.glfw
pkgs.luajit
raylib
#raylua
];
}
nix/raylib/default.nix
Same as in https://github.com/adamlwgriffiths/nix-nim/
nix/raylua/default.nix
{ stdenv, lib, fetchFromGitHub, make, luaPackages }: #, raylib }:
with luaPackages;
let
libs = [];
in
stdenv.mkDerivation rec {
pname = "raylua";
version = "3.5.0";
src = fetchFromGitHub {
owner = "Rabios";
repo = pname;
rev = version;
sha256 = "0syvd5js1lbx3g4cddwwncqg95l6hb3fdz5nsh5pqy7fr6v84kwj";
};
lualibs = [ luaPackages.lua ];
buildInputs = [ make ] ++ lualibs;
LUA_PATH = stdenv.lib.concatStringsSep ";" (map luaPackages.getLuaPath lualibs);
LUA_CPATH = stdenv.lib.concatStringsSep ";" (map luaPackages.getLuaCPath lualibs);
configureFlags = ''
LUA_PATH="${LUA_PATH}"
LUA_CPATH="${LUA_CPATH}"
INST_LIBDIR="$out/lib/lua/${luaPackages.lua.luaversion}"
INST_LUADIR="$out/share/lua/${luaPackages.lua.luaversion}"
LUA_BINDIR="${luaPackages.lua}/bin"
LUA_INCDIR="-I${luaPackages.lua}/include"
LUA_LIBDIR="-L${luaPackages.lua}/lib"
'';
meta = with stdenv.lib; {
description = "Lua bindings for raylib, a simple and easy-to-use library to enjoy videogames programming";
homepage = "https://github.com/Rabios/raylua";
license = licenses.isc;
maintainers = with maintainers; [ adamlwgriffiths ];
platforms = platforms.linux;
};
}
Related
I'm trying to use nix flakes for android development.
This is my flake.nix:
{
description = "test";
outputs = { self, nixpkgs }: {
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
devShell.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.mkShell {
buildInputs = [
nixpkgs.legacyPackages.x86_64-linux.androidenv.androidPkgs_9_0.androidsdk
];
};
};
}
Running nix develop gives me this message:
You must accept the following licenses:
- android-sdk-license
by setting nixpkgs config option 'android_sdk.accept_license = true;'.
How can I pass this option to nixpkgs when using flakes?
legacyPackages does not let you pass config. You have to call Nixpkgs yourself:
outputs = { self, nixpkgs, ... }:
let pkgs = import nixpkgs {
system = "x86_64-linux";
config = {
android_sdk.accept_license = true;
};
};
in { /* ... */ pkgs.androidenv.androidPkgs_9_0.androidsdk
# ...
I want to use hubstaff package from local nixpkgs repository,
let
# pass config so that packages use correct allowUnfree for example
nixpkgs-local = import /home/bjorn/projects/nixpkgs { inherit config; };
in
rec {
config.allowUnfree = true;
config.packageOverrides = old: {
# packages from local nixpkgs
inherit (nixpkgs-local) safeeyes hubstaff;
....
but its unfree package, so throws unfree package error
$ sudo nixos-rebuild dry-build
building the system configuration...
error: Package ‘hubstaff-1.3.1-ff75f26’ in /home/bjorn/projects/nixpkgs/pkgs/applications/misc/hubstaff/default.nix:60 has an unfree license (‘unfree’), refusing to evaluate.
As I understand I need to pass nixpkgs.config.allowUnfree = true, but import /home/bjorn/projects/nixpkgs { inherit config; }; above is not working
P.S.
other issue I have is that I have tried to peek what value I am passing in config.nixpkgs.allowUnfree here
{ config, pkgs, lib, ... }:
let r = {
imports = [
./hardware-configuration.nix
./hardware-configuration-override.nix
./hardware-programs.nix
/home/bjorn/projects/nixpkgs/nixos/modules/services/misc/safeeyes.nix
];
....
};
in
builtins.seq (lib.debug.showVal config.nixpkgs.allowUnfree) r
but I get infinite recursion error, maybe someone knows the way to do this?
To answer your second "P.S." question, here's the reason why and suggestions what to do instead.
The infinite recursion occurs because the module system needs to evaluate the 'root' of every module and some attributes like imports in order to build the term that represents the root of config.
With your call to seq you're evaluating an attribute of config at a point where config itself is still being evaluated.
Technically, you can solve this by adding your seq call to an attribute instead of around the entire module. This way, config can be evaluated without evaluating your seq call.
Probably an easier way to have a look at your configuration is to import it in nix repl
nix-repl> c = import <nixpkgs/nixos> { configuration = ./nixos/root/default.nix; /* or the file usually called configuration.nix */ }
nix-repl> c.config.nixpkgs.config.allowUnfree
true
You can use the :r command to reload all files when iterating. Nix likes to cache them because the implementation is geared toward batch execution.
Tnx to tilpner
I was passing wrong config
Namely,
this is config that import /home/bjorn/projects/nixpkgs was expecting
nix-repl> c = import <nixpkgs/nixos> {}
nix-repl> c.config.nixpkgs
{ config = { ... }; overlays = [ ... ]; pkgs = { ... }; system = "x86_64-linux"; }
This is what I was passing
nix-repl> c.config
{ _module = { ... }; assertions = [ ... ]; boot = { ... }; config = { ... }; containers = { ... }; dysnomia = { ... }; ec2 = { ... }; environment = { ... }; fileSystems = { ... }; fonts = { ... }; gnu = false; hardware = { ... }; i18n = { ... }; ids = { ... }; jobs = «error: The option `jobs' is used but not defined.»; kde = { ... }; krb5 = { ... }; lib = { ... }; meta = { ... }; nesting = { ... }; networking = { ... }; nix = { ... }; nixpkgs = { ... }; passthru = «error: The option `passthru' is used but not defined.»; power = { ... }; powerManagement = { ... }; programs = { ... }; security = { ... }; services = { ... }; sound = { ... }; swapDevices = [ ... ]; system = {
Its the one that passed to /etc/nixos/configuration.nix
Fix:
{ config, pkgs }:
let
# pass config so that packages use correct allowUnfree for example
unfreeConfig = config.nixpkgs.config // {
allowUnfree = true;
};
nixpkgs-local = import /home/bjorn/projects/nixpkgs { config = unfreeConfig; };
in
I'm trying to use nix-generate-from-cspan to install sqitch
From nix-generate-from-cpan App::Sqitch DBD::Pg, I made this file:
{buildPerlModule, fetchurl}:
buildPerlModule rec {
name = "App-Sqitch-0.9995";
src = fetchurl {
url = "mirror://cpan/authors/id/D/DW/DWHEELER/${name}.tar.gz";
sha256 = "c29b4610ce43bd43ecfa39188f4cbb00b38c390136fcdd9984142efd99eba292";
};
buildInputs = [ CaptureTiny ModuleBuild TestDeep TestDir TestException TestFile TestFileContents TestMockModule TestNoWarnings ];
propagatedBuildInputs = [ Clone ConfigGitLike DBI DateTime DateTimeTimeZone DevelStackTrace EncodeLocale FileHomeDir HashMerge IOPager IPCRun3 IPCSystemSimple ListMoreUtils Moo PathClass PerlIOutf8_strict StringFormatter StringShellQuote SubExporter TemplateTiny Throwable TryTiny TypeTiny URI URIdb libintlperl namespaceautoclean self."if" ];
meta = {
homepage = http://sqitch.org/;
description = "Sane database change management";
license = stdenv.lib.licenses.mit;
};
}
but running nix-build -E 'with import <nixpkgs> { }; callPackage ./sqitch.nix' gives this error:
expression does not evaluate to a derivation (or a set or list of those)
To debug, I tried nix-instantiate --eval --expr 'with import <nixpkgs> { }; callPackage ./sqitch.nix' which gives:
<LAMBDA>
So I tried nix-build -E 'with import <nixpkgs> { }; callPackage callPackage ./sqitch.nix' but it still gives the same error, and nix-instantiate --eval --expr 'with import <nixpkgs> { }; callPackage callPackage ./sqitch.nix' gives:
{ __functor = <CODE>; override = <CODE>; overrideDerivation = <CODE>; }
which does not help me much.
Short answer
the result of buildPerlModule is meant to be used as src in mkDerivation params.
Long answer
It turns out sqitch is already part of nixpkgs, and it is defined like this:
https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/pkgs/development/tools/misc/sqitch/default.nix
{ name, stdenv, perl, makeWrapper, sqitchModule, databaseModule }:
stdenv.mkDerivation {
name = "${name}-${sqitchModule.version}";
buildInputs = [ perl makeWrapper sqitchModule databaseModule ];
src = sqitchModule;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin
for d in bin/sqitch etc lib share ; do
ln -s ${sqitchModule}/$d $out/$d
done
'';
dontStrip = true;
postFixup = "wrapProgram $out/bin/sqitch --prefix PERL5LIB : $PERL5LIB";
meta = {
platforms = stdenv.lib.platforms.unix;
};
}
https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/pkgs/top-level/all-packages.nix#L10116-L10120
sqitchPg = callPackage ../development/tools/misc/sqitch {
name = "sqitch-pg";
databaseModule = perlPackages.DBDPg;
sqitchModule = perlPackages.AppSqitch;
};
https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/pkgs/top-level/perl-packages.nix#L281-L305 (which is the output of nix-generate-from-cpan App::Sqitch)
AppSqitch = buildPerlModule rec {
version = "0.9994";
name = "App-Sqitch-${version}";
src = fetchurl {
url = "mirror://cpan/authors/id/D/DW/DWHEELER/${name}.tar.gz";
sha256 = "0in602z40s50fdlmws4g0a1pb8p7yn0wx8jgsacz26a4i1q7gpi4";
};
buildInputs = [
CaptureTiny PathClass TestDeep TestDir TestException
TestFile TestFileContents TestMockModule TestNoWarnings
];
propagatedBuildInputs = [
Clone ConfigGitLike DBI DateTime
DevelStackTrace EncodeLocale FileHomeDir HashMerge IOPager IPCRun3
IPCSystemSimple ListMoreUtils Moo PathClass PerlIOutf8_strict StringFormatter
StringShellQuote SubExporter TemplateTiny Throwable TryTiny TypeTiny URI
URIdb libintlperl namespaceautoclean
];
doCheck = false; # Can't find home directory.
meta = {
homepage = http://sqitch.org/;
description = "Sane database change management";
license = stdenv.lib.licenses.mit;
};
};
https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/pkgs/top-level/perl-packages.nix#L3555-L3558
DBDPg = import ../development/perl-modules/DBD-Pg {
inherit stdenv fetchurl buildPerlPackage DBI;
inherit (pkgs) postgresql;
};
https://github.com/NixOS/nixpkgs/blob/56904d7c423f2b13b37fbd29f39bbb4b52bc7824/pkgs/development/perl-modules/DBD-Pg/default.nix (which looks like the output of nix-generate-from-cpan DBD::Pg, but not exactly)
{ stdenv, fetchurl, buildPerlPackage, DBI, postgresql }:
buildPerlPackage rec {
name = "DBD-Pg-3.5.3";
src = fetchurl {
url = "mirror://cpan/authors/id/T/TU/TURNSTEP/${name}.tar.gz";
sha256 = "03m9w1cd0yyrbqwkwcl92j1cpmasmm69f3hwvcrlfsi5fnwsk63y";
};
buildInputs = [ postgresql ];
propagatedBuildInputs = [ DBI ];
makeMakerFlags = "POSTGRES_HOME=${postgresql}";
meta = {
homepage = http://search.cpan.org/dist/DBD-Pg/;
description = "DBI PostgreSQL interface";
license = with stdenv.lib.licenses; [ artistic1 gpl1Plus ];
platforms = stdenv.lib.platforms.unix;
};
}
So that's how it is meant to be used.
NB : as I just noted in the comments of my question, I also forgot to add {} after my callPackages, which explains the weird types I was getting.
(I failed at getting this working in dart2js so I'm trying in dart dev compiler; but I'd happily take an answer for dart2j!).
If I have test.dart:
void activate() {
print("activating...");
}
and run dartdevc --modules node -o test.js test.dart the output is:
(function() {
'use strict';
const dart_sdk = require('dart_sdk');
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const __test = Object.create(null);
let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [])))();
__test.activate = function() {
core.print("activating...");
};
dart.fn(__test.activate, VoidTovoid());
// Exports:
exports.__test = __test;
})();
This means my function is exported as __test.activate but what I need is for it just to be activate.
How can I control this? The JS I'm aiming for the equivilent of this:
exports.activate = function() { core.print("activating"); }
This isn't currently possible but I worked around it with a wrapper:
var extension = require('./dartvsjs/extension.js');
exports.activate = extension.__lib__extension.activate;
exports.deactivate = extension.__lib__extension.deactivate;
I have some package to override in my configuration.nix. So I write the code as follows:
nixpkgs.config = {
allowUnfree = true;
packageOverrides = {
pkgs: rec {
#mumble + pulse audio
mumble = pkgs.mumble.override {
pulseSupport = true;
};
#kernel for intel ethernet and Testing e1000e package override
linuxPackages.e1000e = pkgs.linuxPackages.e1000e.overrideDerivation (attrs: {
name = "e1000e-3.3.3-${config.boot.kernelPackages.kernel.version}";
src = fetchurl {
url = "https://www.dropbox.com/s/pxx883hx9763ygn/e1000e-3.3.3.tar.gz?dl=0";
sha256 = "1s2w54927fsxg0f037h31g3qkajgn5jd0x3yi1chxsyckrcr0x80";
};
});
};
};
};
but when I do nixos-rebuild switch, I got the following error:
syntax error, unexpected ':', expecting '.' or '=', at 37,11
which is at pkgs: rec {...
What did I do wrong? At first I write it by separating the pkgs like this:
packageOverrides = {
pkgs: with pkgs: {......}; #this is for mumble
pkgs: rec {...}; #this is for kernel
};
and still got the same error.
The proper solution is:
nixpkgs.config = {
allowUnfree = true;
packageOverrides = super: let self = super.pkgs; in {
mumble = super.mumble.override { pulseSupport = true; };
linuxPackages = super.linuxPackages // {
e1000e = super.linuxPackages.e1000e.overrideDerivation (old: {
name = "e1000e-3.3.3-${config.boot.kernelPackages.kernel.version}";
src = fetchurl {
url = "https://www.dropbox.com/s/pxx883hx9763ygn/e1000e-3.3.3.tar.gz?dl=0";
sha256 = "1s2w54927fsxg0f037h31g3qkajgn5jd0x3yi1chxsyckrcr0x80";
};
});
};
};
}
The variable super refers to the Nixpkgs set before the overrides are applied and self refers to it after the overrides are applied. It's important to distinguish these two explicitly to avoid infinite recursions, etc.
Also, note that your override
linuxPackages.e1000e = pkgs.linuxPackages.e1000e.overrideDerivation ...
replaces the linuxPackages attribute set with one that contains nothing but the (overriden) e1000e derivation. That's probably not what you want.