Skip to content

Commit

Permalink
Merge pull request #1 from Ericson2314/fix-build-in-nix-shell
Browse files Browse the repository at this point in the history
Fix build in nix shell
  • Loading branch information
polar authored Nov 4, 2019
2 parents 507d28f + b380f75 commit 21185d9
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 47 deletions.
5 changes: 5 additions & 0 deletions doc/manual/expressions/builtins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ builtins.genList (x: x * x) 5
separate file, and use it from Nix expressions in other
files.</para>

<note><para>Unlike some languages, <function>import</function> is a regular
function in Nix. Paths using the angle bracket syntax (e.g., <function>
import</function> <replaceable>&lt;foo&gt;</replaceable>) are normal path
values (see <xref linkend='ssec-values' />).</para></note>

<para>A Nix expression loaded by <function>import</function> must
not contain any <emphasis>free variables</emphasis> (identifiers
that are not defined in the Nix expression itself and are not
Expand Down
1 change: 0 additions & 1 deletion doc/manual/packages/s3-substituter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ the S3 URL:</para>
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts",
"s3:ListObjects",
"s3:PutObject"
],
"Resource": [
Expand Down
64 changes: 41 additions & 23 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ config_h = configuration_data()

config_h.set(
'HAVE_CXX17', 1,
description : 'define if the compiler supports basic C++17 syntax')
description : 'Define if the compiler supports basic C++17 syntax')

package_name = meson.project_name()
config_h.set_quoted(
Expand Down Expand Up @@ -163,7 +163,8 @@ if (cpp.has_header('sys/ndir.h'))
description : 'Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR`')
endif

if (cpp.has_header('dirent.h'))
has_dirent_h = cpp.has_header('dirent.h')
if (has_dirent_h)
config_h.set(
'HAVE_DIRENT_H', 1,
description : 'Define to 1 if you have the <dirent.h> header file, and it defines `DIR`')
Expand Down Expand Up @@ -309,6 +310,21 @@ if meson.get_compiler('cpp').compiles(
description : 'Define to 1 if you have the `pubsetbuf` function.')
endif



# checking data types
#============================================================================


dirent_h_prefix = '''
#include <sys/types.h>
#include <dirent.h>
'''

if has_dirent_h and meson.get_compiler('cpp').has_member('struct dirent', 'd_type', prefix: dirent_h_prefix)
config_h.set('HAVE_STRUCT_DIRENT_D_TYPE', 1)
endif

# required dependancies
#============================================================================

Expand All @@ -330,8 +346,8 @@ tar = find_program('tar', required : true)
bzip2 = find_program('bzip2', required : true)
gzip = find_program('gzip', required : true)
xz = find_program('xz', required : true)
dot = find_program('dot', required : true)
lsof = find_program('lsof', required : true)
dot = find_program('dot', required : false)
lsof = find_program('lsof', required : false)
tr = find_program('tr', required : true)
coreutils = run_command('dirname', cat.path()).stdout().strip()

Expand Down Expand Up @@ -361,13 +377,13 @@ description : 'Whether link() works on symlinks')
#--------------------------------------------------
boost_dep = declare_dependency(
dependencies : [
cpp.find_library('libboost_system', dirs : libdir),
cpp.find_library('libboost_context', dirs : libdir),
cpp.find_library('libboost_thread', dirs : libdir)],
cpp.find_library('boost_system'),
cpp.find_library('boost_context'),
cpp.find_library('boost_thread')],
link_args : get_option('boost_link_args'))

if (boost_dep.found())
config_h.set('HAVE_BOOST', 1, description : 'define if the Boost library is available.')
config_h.set('HAVE_BOOST', 1, description : 'Define if the Boost library is available.')
endif


Expand All @@ -390,7 +406,7 @@ libbrotli_dep = declare_dependency(
# Look for OpenSSL, a required dependency.
#--------------------------------------------------
openssl_dep = declare_dependency(
dependencies: cpp.find_library('libssl', dirs : libdir),
dependencies: cpp.find_library('ssl'),
link_args : get_option('openssl_link_args'))


Expand Down Expand Up @@ -418,14 +434,14 @@ pthread_dep = declare_dependency(
# Look for libdl, a required dependency.
#--------------------------------------------------
libdl_dep = declare_dependency(
dependencies : cpp.find_library('dl', dirs : libdir),
dependencies : cpp.find_library('dl'),
link_args : get_option('dl_link_args'))


# Look for libbz2, a required dependency.
#--------------------------------------------------
libbz2_dep = declare_dependency(
dependencies : cpp.find_library('bz2', dirs : libdir),
dependencies : cpp.find_library('bz2'),
link_args : get_option('bz2_link_args'))


Expand All @@ -437,7 +453,7 @@ libbz2_dep = declare_dependency(
# editline.h when the pkg-config approach fails.

editline_dep = declare_dependency(
dependencies : cpp.find_library('libeditline'),
dependencies : cpp.find_library('editline'),
link_args : get_option('editline_link_args'))

if not (
Expand All @@ -458,13 +474,14 @@ endif

# Look for libsodium, an optional dependency.
#--------------------------------------------------
if (get_option('with_libsodium'))
libsodium_lib = cpp.find_library('sodium', required: get_option('with_libsodium'))
if (libsodium_lib.found())
libsodium_dep = declare_dependency(
dependencies : cpp.find_library('libsodium', dirs : libdir),
dependencies : libsodium_lib,
link_args : get_option('sodium_link_args'))
config_h.set('HAVE_SODIUM', 1, description : 'Whether to use libsodium for cryptography.')
else
libsodium_dep = declare_dependency()
libsodium_dep = dependency('', required: false)
endif


Expand All @@ -478,7 +495,7 @@ if (get_option('with_gc'))
'HAVE_BOEHMGC', 1,
description : 'Whether to use the Boehm garbage collector.')
else
gc_dep = declare_dependency()
gc_dep = dependency('', required: false)
endif


Expand All @@ -503,15 +520,16 @@ endif
# OS Specific checks
#============================================================================
# Look for libsecppomp, required for Linux sandboxing.
libseccomp_dep = ''
if sys_name.contains('linux')
libseccomp_dep = dependency('libseccomp', version : '>= 2.3.1', required: false)
if not (libseccomp_dep.found())
error('Nix requires libseccomp on a linux host system')
endif
libseccomp_dep = dependency(
'libseccomp',
version : '>= 2.3.1',
not_found_message : 'Nix requires libseccomp on a linux host system')
config_h.set(
'HAVE_SECCOMP', 1,
description : 'Whether seccomp is available and should be used for sandboxing.')
description : 'Whether seccomp is available and should be used for sandboxing.')
else
libseccomp_dep = dependency('', required: false)
endif

if (sys_name.contains('freebsd'))
Expand Down Expand Up @@ -552,4 +570,4 @@ project_dirs = [

foreach dir : project_dirs
subdir(dir)
endforeach
endforeach
12 changes: 6 additions & 6 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,19 @@ option(
'with_gc',
type : 'boolean',
value : 'false',
description : 'build nix with Boehm garbage collector')
description : 'Build nix with Boehm garbage collector')

option(
'with_libsodium',
type : 'boolean',
value : 'true',
description : 'build nix with shared libs')
type : 'feature',
value : 'auto',
description : 'Build nix with libsodium')

option(
'with_s3',
type : 'boolean',
value : 'false',
description : 'build nix with s3')
description : 'Build nix with s3')

option(
'with_coreutils_bin',
Expand All @@ -182,7 +182,7 @@ option(
'build_shared_libs',
type : 'boolean',
value : 'false',
description : 'build nix with shared libs')
description : 'Build nix with shared libs')

option(
'sandbox_shell',
Expand Down
39 changes: 31 additions & 8 deletions release-common.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{ pkgs }:

with pkgs;
let
inherit (pkgs) stdenv lib curl;
# TODO upstream
mesonFlag = key: value: "-D${key}=${value}";
mesonBool = feature: cond: mesonFlag feature (if cond then "true" else "false");
mesonFeature = feature: cond: mesonFlag feature (if cond then "enabled" else "disabled");
in

rec {
# Use "busybox-sandbox-shell" if present,
# if not (legacy) fallback and hope it's sufficient.
sh = pkgs.busybox-sandbox-shell or (busybox.override {
sh = pkgs.busybox-sandbox-shell or (pkgs.busybox.override {
useMusl = true;
enableStatic = true;
enableMinimal = true;
Expand All @@ -29,14 +35,19 @@ rec {
'';
});

mesonFlags = [
(mesonBool "with_gc" true)
(mesonFeature "with_libsodium" stdenv.hostPlatform.isLinux)
];

configureFlags =
[
"--enable-gc"
] ++ lib.optionals stdenv.isLinux [
"--with-sandbox-shell=${sh}/bin/busybox"
];

tarballDeps =
tarballDeps = with pkgs.buildPackages;
[ bison
flex
libxml2
Expand All @@ -47,10 +58,22 @@ rec {
autoreconfHook
];

buildDeps =
[ curl
bzip2 xz brotli editline
openssl pkgconfig sqlite boehmgc
nativeBuildDeps = with pkgs.buildPackages; [
pkgconfig
meson
ninja
];

buildDeps = with pkgs;
[
curl
bzip2
xz
brotli
editline
openssl
sqlite
boehmgc
boost

# Tests
Expand All @@ -72,7 +95,7 @@ rec {
*/
}));

perlDeps =
perlDeps = with pkgs;
[ perl
perlPackages.DBDSQLite
];
Expand Down
9 changes: 7 additions & 2 deletions release.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ nix ? builtins.fetchGit ./.
, nixpkgs ? builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz
, nixpkgs ? builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.09.tar.gz
, officialRelease ? false
, systems ? [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" ]
}:
Expand All @@ -23,7 +23,8 @@ let
src = nix;
inherit officialRelease;

buildInputs = tarballDeps ++ buildDeps;
nativeBuildInputs = tarballDeps ++ nativeBuildDeps;
buildInputs = buildDeps;

configureFlags = "--enable-gc";

Expand Down Expand Up @@ -65,6 +66,7 @@ let
name = "nix";
src = tarball;

nativeBuildInputs = nativeBuildDeps;
buildInputs = buildDeps;

preConfigure =
Expand All @@ -80,6 +82,8 @@ let
''}
'';

inherit mesonFlags;

configureFlags = configureFlags ++
[ "--sysconfdir=/etc" ];

Expand Down Expand Up @@ -196,6 +200,7 @@ let
name = "nix-build";
src = tarball;

nativeBuildInputs = nativeBuildDeps;
buildInputs = buildDeps;

dontInstall = false;
Expand Down
3 changes: 0 additions & 3 deletions scripts/install-multi-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ readonly BLUE_UL='\033[38;4;34m'
readonly GREEN='\033[38;32m'
readonly GREEN_UL='\033[38;4;32m'
readonly RED='\033[38;31m'
readonly RED_UL='\033[38;4;31m'
readonly YELLOW='\033[38;33m'
readonly YELLOW_UL='\033[38;4;33m'

readonly NIX_USER_COUNT="32"
readonly NIX_BUILD_GROUP_ID="30000"
Expand Down
14 changes: 10 additions & 4 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{ useClang ? false }:
{ useClang ? false, crossSystem ? null }:

with import (builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz) {};
let
pkgsSrc = builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.09.tar.gz;
in

with import pkgsSrc { inherit crossSystem; };

with import ./release-common.nix { inherit pkgs; };

(if useClang then clangStdenv else stdenv).mkDerivation {
name = "nix";

buildInputs = buildDeps ++ tarballDeps ++ perlDeps;
nativeBuildInputs = nativeBuildDeps ++ tarballDeps;

buildInputs = buildDeps ++ perlDeps;

inherit configureFlags;
inherit mesonFlags configureFlags;

enableParallelBuilding = true;

Expand Down

0 comments on commit 21185d9

Please sign in to comment.