From 3210dd3039798a10884925cae98ef3b2a4c10703 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 27 Jun 2018 15:35:07 -0400 Subject: [PATCH 1/6] generators: add PLIST handling /cc @LnL7 @3noch --- lib/generators.nix | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/generators.nix b/lib/generators.nix index c09384c00f5..aab4498f9c6 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -175,4 +175,52 @@ rec { else "<λ:{${showFnas}}>" else abort "toPretty: should never happen (v = ${v})"; + # PLIST handling + + toPLIST = x: '' + + + + '' + pprExpr "" x + + "\n"; + + pprExpr = ind: x: with builtins; + if isNull x then "" else + if isBool x then pprBool ind x else + if isInt x then pprInt ind x else + if isString x then pprStr ind x else + if isList x then pprList ind x else + if isAttrs x then pprAttrs ind x else + throw "invalid plist type"; + + pprLiteral = ind: x: ind + x; + + pprBool = ind: x: pprLiteral ind (if x then "" else ""); + pprInt = ind: x: pprLiteral ind "${toString x}"; + pprStr = ind: x: pprLiteral ind "${x}"; + pprKey = ind: x: pprLiteral ind "${x}"; + + pprIndent = ind: pprExpr "\t${ind}"; + + pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); + + pprList = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprItem ind x) + (pprLiteral ind "") + ]; + + pprAttrs = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprAttr ind x) + (pprLiteral ind "") + ]; + + attrFilter = name: value: name != "_module" && value != null; + + pprAttr = ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ + (pprKey "\t${ind}" name) + (pprExpr "\t${ind}" value) + ]) x)); + } From c672e37f4acf7e5bb8a794a0b342e1c693387f8a Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 27 Jun 2018 15:36:00 -0400 Subject: [PATCH 2/6] xcbuild: rework to use lib.PLIST This is a good way to test that plist works. Sorry for the large diff. There are a bunch of cleanups in here that needed to be done. Should make it possible to use in cross compilation. --- pkgs/development/tools/xcbuild/default.nix | 6 +- pkgs/development/tools/xcbuild/platform.nix | 34 ++--- pkgs/development/tools/xcbuild/sdk.nix | 22 ++- pkgs/development/tools/xcbuild/toolchain.nix | 144 ++++++------------- pkgs/development/tools/xcbuild/wrapper.nix | 31 ++-- pkgs/top-level/all-packages.nix | 3 +- 6 files changed, 83 insertions(+), 157 deletions(-) diff --git a/pkgs/development/tools/xcbuild/default.nix b/pkgs/development/tools/xcbuild/default.nix index b7b14128048..3f7b21be005 100644 --- a/pkgs/development/tools/xcbuild/default.nix +++ b/pkgs/development/tools/xcbuild/default.nix @@ -1,4 +1,5 @@ -{ stdenv, cmake, fetchFromGitHub, zlib, libxml2, libpng, CoreServices, CoreGraphics, ImageIO, ninja }: +{ stdenv, cmake, fetchFromGitHub, zlib, libxml2, libpng +, CoreServices, CoreGraphics, ImageIO, ninja }: let googletest = fetchFromGitHub { @@ -17,7 +18,8 @@ let in stdenv.mkDerivation rec { name = "xcbuild-${version}"; - # Once a version is released that includes https://github.com/facebook/xcbuild/commit/183c087a6484ceaae860c6f7300caf50aea0d710, + # Once a version is released that includes + # https://github.com/facebook/xcbuild/commit/183c087a6484ceaae860c6f7300caf50aea0d710, # we can stop doing this -pre thing. version = "0.1.2-pre"; diff --git a/pkgs/development/tools/xcbuild/platform.nix b/pkgs/development/tools/xcbuild/platform.nix index a36c4f4bf80..e3fb83edc67 100644 --- a/pkgs/development/tools/xcbuild/platform.nix +++ b/pkgs/development/tools/xcbuild/platform.nix @@ -1,7 +1,9 @@ -{ stdenv, sdk, writeText, platformName, xcbuild }: +{ runCommand, lib, sdk, platformName, writeText }: let + inherit (lib.generators) toPLIST; + Info = { CFBundleIdentifier = platformName; Type = "Platform"; @@ -283,24 +285,14 @@ let in -stdenv.mkDerivation { - name = "MacOSX.platform"; - buildInputs = [ xcbuild ]; - buildCommand = '' - mkdir -p $out/ - cd $out/ +runCommand "MacOSX.platform" {} '' + install -D ${writeText "Info.plist" (toPLIST Info)} $out/Info.plist + install -D ${writeText "version.plist" (toPLIST Version)} $out/version.plist + install -D ${writeText "Architectures.xcspec" (toPLIST Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec + install -D ${writeText "PackageTypes.xcspec" (toPLIST PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec + install -D ${writeText "ProductTypes.xcspec" (toPLIST ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec - plutil -convert xml1 -o Info.plist ${writeText "Info.plist" (builtins.toJSON Info)} - plutil -convert xml1 -o version.plist ${writeText "version.plist" (builtins.toJSON Version)} - - mkdir -p $out/Developer/Library/Xcode/Specifications/ - cd $out/Developer/Library/Xcode/Specifications/ - plutil -convert xml1 -o Architectures.xcspec ${writeText "Architectures.xcspec" (builtins.toJSON Architectures)} - plutil -convert xml1 -o PackageTypes.xcspec ${writeText "PackageTypes.xcspec" (builtins.toJSON PackageTypes)} - plutil -convert xml1 -o ProductTypes.xcspec ${writeText "ProductTypes.xcspec" (builtins.toJSON ProductTypes)} - - mkdir -p $out/Developer/SDKs/ - cd $out/Developer/SDKs/ - cp -r ${sdk} ${sdk.name} - ''; -} + mkdir -p $out/Developer/SDKs/ + cd $out/Developer/SDKs/ + cp -r ${sdk} ${sdk.name} +'' diff --git a/pkgs/development/tools/xcbuild/sdk.nix b/pkgs/development/tools/xcbuild/sdk.nix index 87bbedd5788..2d43347da03 100644 --- a/pkgs/development/tools/xcbuild/sdk.nix +++ b/pkgs/development/tools/xcbuild/sdk.nix @@ -1,6 +1,8 @@ -{ stdenv, writeText, toolchainName, sdkName, xcbuild }: +{ runCommand, lib, toolchainName, sdkName, writeText }: let + inherit (lib.generators) toPLIST; + # TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here. version = "10.10"; @@ -19,17 +21,9 @@ let }; in -stdenv.mkDerivation { - name = "MacOSX${version}.sdk"; +runCommand "MacOSX${version}.sdk" { inherit version; - - buildInputs = [ xcbuild ]; - - buildCommand = '' - mkdir -p $out/ - plutil -convert xml1 -o $out/SDKSettings.plist ${writeText "SDKSettings.json" (builtins.toJSON SDKSettings)} - - mkdir -p $out/System/Library/CoreServices/ - plutil -convert xml1 -o $out/System/Library/CoreServices/SystemVersion.plist ${writeText "SystemVersion.plist" (builtins.toJSON SystemVersion)} - ''; -} +} '' + install -D ${writeText "SDKSettings.plist" (toPLIST SDKSettings)} $out/SDKSettings.plist + install -D ${writeText "SystemVersion.plist" (toPLIST SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist +'' diff --git a/pkgs/development/tools/xcbuild/toolchain.nix b/pkgs/development/tools/xcbuild/toolchain.nix index 9e34360909f..d8c80b53831 100644 --- a/pkgs/development/tools/xcbuild/toolchain.nix +++ b/pkgs/development/tools/xcbuild/toolchain.nix @@ -1,16 +1,18 @@ -{stdenv, writeText, toolchainName, xcbuild, fetchurl -, llvm, cctools, gcc, bootstrap_cmds, binutils -, yacc, flex, m4, unifdef, gperf, indent, ctags, makeWrapper -, xib2nib}: +{ runCommand, toolchainName, fetchurl, makeWrapper, stdenv +, buildPackages, lib, writeText }: let + inherit (lib) getBin optionalString; + inherit (lib.generators) toPLIST; + ToolchainInfo = { Identifier = toolchainName; }; - # We could pull this out of developer_cmds but it adds an annoying loop if we want to bootstrap and - # this is just a tiny script so I'm not going to bother + # We could pull this out of developer_cmds but it adds an annoying + # loop if we want to bootstrap and this is just a tiny script so I'm + # not going to bother. mkdep-darwin-src = fetchurl { url = "https://opensource.apple.com/source/developer_cmds/developer_cmds-63/mkdep/mkdep.sh"; sha256 = "0n4wpqfslfjs5zbys5yri8pfi2awyhlmknsf6laa5jzqbzq9x541"; @@ -18,106 +20,44 @@ let }; in -stdenv.mkDerivation { - name = "nixpkgs.xctoolchain"; - buildInputs = [ xcbuild makeWrapper ]; +runCommand "nixpkgs.xctoolchain" { + nativeBuildInputs = [ makeWrapper ]; +} ('' + mkdir -p $out + install -D ${writeText "ToolchainInfo.plist" (toPLIST ToolchainInfo)} $out/ToolchainInfo.plist - ## cctools should build on Linux but it doesn't currently + mkdir -p $out/usr/include + mkdir -p $out/usr/lib + mkdir -p $out/usr/libexec + mkdir -p $out/usr/share + mkdir -p $out/usr/bin - buildCommand = '' - mkdir -p $out - plutil -convert xml1 -o $out/ToolchainInfo.plist ${writeText "ToolchainInfo.plist" (builtins.toJSON ToolchainInfo)} + for bin in ${getBin stdenv.cc}/bin/*; do + ln -s $bin $out/usr/bin + done - mkdir -p $out/usr/include - mkdir -p $out/usr/lib - mkdir -p $out/usr/libexec - mkdir -p $out/usr/share + for bin in ${getBin stdenv.cc.bintools.bintools}/bin/*; do + if ! [ -e "$out/usr/bin/$(basename $bin)" ]; then + ln -s $bin $out/usr/bin + fi + done - mkdir -p $out/usr/bin - cd $out/usr/bin - ln -s ${stdenv.cc}/bin/cpp - ln -s ${stdenv.cc}/bin/c++ - ln -s ${stdenv.cc}/bin/cc - ln -s c++ clang++ - ln -s cc clang + ln -s ${buildPackages.yacc}/bin/yacc $out/usr/bin/yacc + ln -s ${buildPackages.yacc}/bin/bison $out/usr/bin/bison + ln -s ${buildPackages.flex}/bin/flex $out/usr/bin/flex + ln -s ${buildPackages.flex}/bin/flex++ $out/usr/bin/flex++ + ln -s $out/bin/flex $out/usr/bin/lex - ln -s ${llvm}/bin/llvm-cov - ln -s ${llvm}/bin/llvm-dsymutil - ln -s ${llvm}/bin/llvm-dwarfdump - ln -s ${llvm}/bin/llvm-nm - ln -s ${llvm}/bin/llvm-objdump - ln -s ${llvm}/bin/llvm-otool - ln -s ${llvm}/bin/llvm-profdata - ln -s ${llvm}/bin/llvm-size + ln -s ${buildPackages.m4}/bin/m4 $out/usr/bin/m4 + ln -s $out/usr/bin/m4 $out/usr/bin/gm4 - ln -s ${yacc}/bin/yacc - ln -s ${yacc}/bin/bison - ln -s ${flex}/bin/flex - ln -s ${flex}/bin/flex++ + ln -s ${buildPackages.unifdef}/bin/unifdef $out/usr/bin/unifdef + ln -s ${buildPackages.unifdef}/bin/unifdefall $out/usr/bin/unifdefall - ln -s flex lex - - ln -s ${m4}/bin/m4 - ln -s m4 gm4 - - ln -s ${unifdef}/bin/unifdef - ln -s ${unifdef}/bin/unifdefall - - ln -s ${gperf}/bin/gperf - ln -s ${indent}/bin/indent - ln -s ${ctags}/bin/ctags - '' + stdenv.lib.optionalString stdenv.isDarwin '' - ln -s ${bootstrap_cmds}/bin/mig - ln -s ${binutils}/bin/lipo - - ln -s ${cctools}/bin/ar - ln -s ${cctools}/bin/as - ln -s ${cctools}/bin/nm - ln -s ${cctools}/bin/nmedit - ln -s ${cctools}/bin/ld - ln -s ${cctools}/bin/libtool - ln -s ${cctools}/bin/strings - ln -s ${cctools}/bin/strip - ln -s ${cctools}/bin/install_name_tool - ln -s ${cctools}/bin/bitcode_strip - ln -s ${cctools}/bin/codesign_allocate - ln -s ${cctools}/bin/dsymutil - ln -s ${cctools}/bin/dyldinfo - ln -s ${cctools}/bin/otool - ln -s ${cctools}/bin/unwinddump - ln -s ${cctools}/bin/size - ln -s ${cctools}/bin/segedit - ln -s ${cctools}/bin/pagestuff - ln -s ${cctools}/bin/ranlib - ln -s ${cctools}/bin/redo_prebinding - - ln -s ${xib2nib}/bin/ibtool - '' + - # No point including the entire gcc closure if we don't already have it - (if stdenv.cc.isClang then '' - ln -s ${stdenv.cc.cc.llvm}/bin/llvm-cov gcov - ln -s ${mkdep-darwin-src} mkdep - '' else '' - ln -s ${gcc}/bin/gcov - ln -s ${gcc}/bin/mkdep - ''); -} - -# other commands in /bin/ -# asa -# cmpdylib (in cctools) -# ctf_insert (in cctools) -# dwarfdump -# lorder -# rebase -# rpcgen (in developer_cmds) -# what - - -# swift: see #11463 -# swift -# swift-compress -# swift-demangle -# swift-stdlib-tool -# swift-update -# swiftc + ln -s ${buildPackages.gperf}/bin/gperf $out/usr/bin/gperf + ln -s ${buildPackages.indent}/bin/indent $out/usr/bin/indent + ln -s ${buildPackages.ctags}/bin/ctags $out/usr/bin/ctags +'' + optionalString stdenv.isDarwin '' + ln -s ${buildPackages.darwin.bootstrap_cmds}/bin/mig $out/usr/bin + ln -s ${mkdep-darwin-src} $out/usr/bin/mkdep +'') diff --git a/pkgs/development/tools/xcbuild/wrapper.nix b/pkgs/development/tools/xcbuild/wrapper.nix index 06c48ec0a73..cfa855e23cd 100644 --- a/pkgs/development/tools/xcbuild/wrapper.nix +++ b/pkgs/development/tools/xcbuild/wrapper.nix @@ -1,5 +1,5 @@ -{ stdenv, callPackage, makeWrapper, writeText, CoreServices, ImageIO, CoreGraphics -, cctools, bootstrap_cmds, binutils}: +{ stdenv, buildPackages, makeWrapper, writeText, runCommand +, CoreServices, ImageIO, CoreGraphics }: let @@ -7,20 +7,20 @@ let platformName = "com.apple.platform.macosx"; sdkName = "macosx10.10"; - xcbuild = callPackage ./default.nix { + xcbuild = buildPackages.callPackage ./default.nix { inherit CoreServices ImageIO CoreGraphics; }; - toolchain = callPackage ./toolchain.nix { - inherit cctools bootstrap_cmds toolchainName xcbuild binutils stdenv; + toolchain = buildPackages.callPackage ./toolchain.nix { + inherit toolchainName; }; - sdk = callPackage ./sdk.nix { - inherit toolchainName sdkName xcbuild; + sdk = buildPackages.callPackage ./sdk.nix { + inherit toolchainName sdkName; }; - platform = callPackage ./platform.nix { - inherit sdk platformName xcbuild; + platform = buildPackages.callPackage ./platform.nix { + inherit sdk platformName; }; xcconfig = writeText "nix.xcconfig" '' @@ -32,7 +32,7 @@ in stdenv.mkDerivation { name = "xcbuild-wrapper-${xcbuild.version}"; - buildInputs = [ xcbuild makeWrapper ]; + nativeBuildInputs = [ makeWrapper ]; setupHook = ./setup-hook.sh; @@ -40,22 +40,21 @@ stdenv.mkDerivation { installPhase = '' mkdir -p $out/bin - cd $out/bin/ for file in ${xcbuild}/bin/*; do - ln -s $file + ln -s $file $out/bin done - mkdir $out/usr + mkdir -p $out/usr ln -s $out/bin $out/usr/bin - mkdir -p $out/Library/Xcode/ + mkdir -p $out/Library/Xcode ln -s ${xcbuild}/Library/Xcode/Specifications $out/Library/Xcode/Specifications - mkdir -p $out/Platforms/ + mkdir -p $out/Platforms ln -s ${platform} $out/Platforms/nixpkgs.platform - mkdir -p $out/Toolchains/ + mkdir -p $out/Toolchains ln -s ${toolchain} $out/Toolchains/nixpkgs.xctoolchain wrapProgram $out/bin/xcodebuild \ diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8b4997706b2..d358fe37106 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8570,8 +8570,7 @@ with pkgs; xcbuild = callPackage ../development/tools/xcbuild/wrapper.nix { inherit (darwin.apple_sdk.frameworks) CoreServices CoreGraphics ImageIO; - inherit (darwin) cctools bootstrap_cmds binutils; - stdenv = clangStdenv; + stdenv = buildPackages.clangStdenv; }; xmlindent = callPackage ../development/web/xmlindent {}; From bceb29f177e17117edc8cb21510a12992d09061f Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 27 Jun 2018 16:45:52 -0400 Subject: [PATCH 3/6] unixtools: add killall --- pkgs/top-level/all-packages.nix | 2 +- pkgs/top-level/unix-tools.nix | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d358fe37106..95331ff8482 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -21731,7 +21731,7 @@ with pkgs; unixtools = recurseIntoAttrs (callPackages ./unix-tools.nix { }); inherit (unixtools) hexdump ps logger eject umount mount wall hostname more sysctl getconf - getent locale; + getent locale killall; fts = if hostPlatform.isMusl then netbsd.fts else null; diff --git a/pkgs/top-level/unix-tools.nix b/pkgs/top-level/unix-tools.nix index c1bd46ad68d..a46d2897f4e 100644 --- a/pkgs/top-level/unix-tools.nix +++ b/pkgs/top-level/unix-tools.nix @@ -81,6 +81,10 @@ let linux = pkgs.nettools; darwin = pkgs.darwin.network_cmds; }; + killall = { + linux = pkgs.psmisc; + darwin = pkgs.darwin.shell_cmds; + }; locale = { linux = pkgs.glibc; darwin = pkgs.netbsd.locale; From 161414063fa9a87b61e5460c61ab1125c9e68e55 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 27 Jun 2018 16:47:21 -0400 Subject: [PATCH 4/6] treewide: use killall --- pkgs/applications/networking/syncthing-gtk/default.nix | 7 +++++-- pkgs/servers/http/myserver/default.nix | 4 ++-- pkgs/tools/misc/xfstests/default.nix | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/networking/syncthing-gtk/default.nix b/pkgs/applications/networking/syncthing-gtk/default.nix index be574acc8c7..9d720bee05e 100644 --- a/pkgs/applications/networking/syncthing-gtk/default.nix +++ b/pkgs/applications/networking/syncthing-gtk/default.nix @@ -1,4 +1,7 @@ -{ stdenv, fetchFromGitHub, fetchpatch, libnotify, librsvg, darwin, psmisc, gtk3, libappindicator-gtk3, substituteAll, syncthing, wrapGAppsHook, gnome3, buildPythonApplication, dateutil, pyinotify, pygobject3, bcrypt, gobjectIntrospection }: +{ stdenv, fetchFromGitHub, fetchpatch, libnotify, librsvg, killall +, gtk3, libappindicator-gtk3, substituteAll, syncthing, wrapGAppsHook +, gnome3, buildPythonApplication, dateutil, pyinotify, pygobject3 +, bcrypt, gobjectIntrospection }: buildPythonApplication rec { version = "0.9.4"; @@ -35,7 +38,7 @@ buildPythonApplication rec { }) (substituteAll { src = ./paths.patch; - killall = "${if stdenv.isDarwin then darwin.shell_cmds else psmisc}/bin/killall"; + killall = "${killall}/bin/killall"; syncthing = "${syncthing}/bin/syncthing"; }) ]; diff --git a/pkgs/servers/http/myserver/default.nix b/pkgs/servers/http/myserver/default.nix index fa3b57a0b22..a18ac202a4a 100644 --- a/pkgs/servers/http/myserver/default.nix +++ b/pkgs/servers/http/myserver/default.nix @@ -1,5 +1,5 @@ { lib, fetchurl, stdenv, libgcrypt, libevent, libidn, gnutls -, libxml2, zlib, guile, texinfo, cppunit, psmisc }: +, libxml2, zlib, guile, texinfo, cppunit, killall }: let version = "0.11"; in @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { # On GNU/Linux the `test_suite' process sometimes stays around, so # forcefully terminate it. - postCheck = lib.optionalString stdenv.isLinux "${psmisc}/bin/killall test_suite || true"; + postCheck = "${killall}/bin/killall test_suite || true"; meta = { description = "GNU MyServer, a powerful and easy to configure web server"; diff --git a/pkgs/tools/misc/xfstests/default.nix b/pkgs/tools/misc/xfstests/default.nix index e6c67ddb9bb..80a728747fe 100644 --- a/pkgs/tools/misc/xfstests/default.nix +++ b/pkgs/tools/misc/xfstests/default.nix @@ -1,5 +1,6 @@ -{ stdenv, acl, attr, autoconf, automake, bash, bc, coreutils, e2fsprogs, fetchgit, fio, gawk, keyutils -, lib, libaio, libcap, libtool, libuuid, libxfs, lvm2, openssl, perl, procps, psmisc, quota, su +{ stdenv, acl, attr, autoconf, automake, bash, bc, coreutils, e2fsprogs +, fetchgit, fio, gawk, keyutils, killall, lib, libaio, libcap, libtool +, libuuid, libxfs, lvm2, openssl, perl, procps, quota, su , time, utillinux, which, writeScript, xfsprogs }: stdenv.mkDerivation { @@ -90,7 +91,9 @@ stdenv.mkDerivation { ln -s @out@/lib/xfstests/$f $f done - export PATH=${lib.makeBinPath [acl attr bc e2fsprogs fio gawk keyutils libcap lvm2 perl procps psmisc quota utillinux which xfsprogs]}:$PATH + export PATH=${lib.makeBinPath [acl attr bc e2fsprogs fio gawk keyutils + libcap lvm2 perl procps killall quota + utillinux which xfsprogs]}:$PATH exec ./check "$@" ''; From d361371d236c90bfb550e827124b5350deeadbda Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 28 Jun 2018 11:11:19 -0400 Subject: [PATCH 5/6] generators: refactor toPLIST --- lib/generators.nix | 84 ++++++++++---------- pkgs/development/tools/xcbuild/platform.nix | 10 +-- pkgs/development/tools/xcbuild/sdk.nix | 4 +- pkgs/development/tools/xcbuild/toolchain.nix | 2 +- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index aab4498f9c6..14332981583 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -176,51 +176,51 @@ rec { else abort "toPretty: should never happen (v = ${v})"; # PLIST handling + toPLIST = {}: v: let + pprExpr = ind: x: with builtins; + if isNull x then "" else + if isBool x then pprBool ind x else + if isInt x then pprInt ind x else + if isString x then pprStr ind x else + if isList x then pprList ind x else + if isAttrs x then pprAttrs ind x else + abort "pprExpr: should never happen (v = ${v})"; - toPLIST = x: '' + pprLiteral = ind: x: ind + x; + + pprBool = ind: x: pprLiteral ind (if x then "" else ""); + pprInt = ind: x: pprLiteral ind "${toString x}"; + pprStr = ind: x: pprLiteral ind "${x}"; + pprKey = ind: x: pprLiteral ind "${x}"; + + pprIndent = ind: pprExpr "\t${ind}"; + + pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); + + pprList = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprItem ind x) + (pprLiteral ind "") + ]; + + pprAttrs = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprAttr ind x) + (pprLiteral ind "") + ]; + + pprAttr = let attrFilter = name: value: name != "_module" && value != null; + in ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList + (name: value: lib.optional (attrFilter name value) [ + (pprKey "\t${ind}" name) + (pprExpr "\t${ind}" value) + ]) x)); + + in '' - '' + pprExpr "" x - + "\n"; - - pprExpr = ind: x: with builtins; - if isNull x then "" else - if isBool x then pprBool ind x else - if isInt x then pprInt ind x else - if isString x then pprStr ind x else - if isList x then pprList ind x else - if isAttrs x then pprAttrs ind x else - throw "invalid plist type"; - - pprLiteral = ind: x: ind + x; - - pprBool = ind: x: pprLiteral ind (if x then "" else ""); - pprInt = ind: x: pprLiteral ind "${toString x}"; - pprStr = ind: x: pprLiteral ind "${x}"; - pprKey = ind: x: pprLiteral ind "${x}"; - - pprIndent = ind: pprExpr "\t${ind}"; - - pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); - - pprList = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprItem ind x) - (pprLiteral ind "") - ]; - - pprAttrs = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprAttr ind x) - (pprLiteral ind "") - ]; - - attrFilter = name: value: name != "_module" && value != null; - - pprAttr = ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ - (pprKey "\t${ind}" name) - (pprExpr "\t${ind}" value) - ]) x)); + ${pprExpr "" v} + ''; } diff --git a/pkgs/development/tools/xcbuild/platform.nix b/pkgs/development/tools/xcbuild/platform.nix index e3fb83edc67..502c3bcdbc8 100644 --- a/pkgs/development/tools/xcbuild/platform.nix +++ b/pkgs/development/tools/xcbuild/platform.nix @@ -286,11 +286,11 @@ let in runCommand "MacOSX.platform" {} '' - install -D ${writeText "Info.plist" (toPLIST Info)} $out/Info.plist - install -D ${writeText "version.plist" (toPLIST Version)} $out/version.plist - install -D ${writeText "Architectures.xcspec" (toPLIST Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec - install -D ${writeText "PackageTypes.xcspec" (toPLIST PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec - install -D ${writeText "ProductTypes.xcspec" (toPLIST ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec + install -D ${writeText "Info.plist" (toPLIST {} Info)} $out/Info.plist + install -D ${writeText "version.plist" (toPLIST {} Version)} $out/version.plist + install -D ${writeText "Architectures.xcspec" (toPLIST {} Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec + install -D ${writeText "PackageTypes.xcspec" (toPLIST {} PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec + install -D ${writeText "ProductTypes.xcspec" (toPLIST {} ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec mkdir -p $out/Developer/SDKs/ cd $out/Developer/SDKs/ diff --git a/pkgs/development/tools/xcbuild/sdk.nix b/pkgs/development/tools/xcbuild/sdk.nix index 2d43347da03..5fdfe587722 100644 --- a/pkgs/development/tools/xcbuild/sdk.nix +++ b/pkgs/development/tools/xcbuild/sdk.nix @@ -24,6 +24,6 @@ in runCommand "MacOSX${version}.sdk" { inherit version; } '' - install -D ${writeText "SDKSettings.plist" (toPLIST SDKSettings)} $out/SDKSettings.plist - install -D ${writeText "SystemVersion.plist" (toPLIST SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist + install -D ${writeText "SDKSettings.plist" (toPLIST {} SDKSettings)} $out/SDKSettings.plist + install -D ${writeText "SystemVersion.plist" (toPLIST {} SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist '' diff --git a/pkgs/development/tools/xcbuild/toolchain.nix b/pkgs/development/tools/xcbuild/toolchain.nix index d8c80b53831..ed5730abddf 100644 --- a/pkgs/development/tools/xcbuild/toolchain.nix +++ b/pkgs/development/tools/xcbuild/toolchain.nix @@ -24,7 +24,7 @@ runCommand "nixpkgs.xctoolchain" { nativeBuildInputs = [ makeWrapper ]; } ('' mkdir -p $out - install -D ${writeText "ToolchainInfo.plist" (toPLIST ToolchainInfo)} $out/ToolchainInfo.plist + install -D ${writeText "ToolchainInfo.plist" (toPLIST {} ToolchainInfo)} $out/ToolchainInfo.plist mkdir -p $out/usr/include mkdir -p $out/usr/lib From 337b58950b9f945933eb82b46c9c4ceb1af3f997 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 28 Jun 2018 11:12:39 -0400 Subject: [PATCH 6/6] generators: refactor toPlist Address PR comments Refactors - Rename toPLIST -> toPlist --- lib/generators.nix | 65 ++++++++++---------- pkgs/development/tools/xcbuild/platform.nix | 12 ++-- pkgs/development/tools/xcbuild/sdk.nix | 6 +- pkgs/development/tools/xcbuild/toolchain.nix | 4 +- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index 14332981583..073bb6982e1 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -173,54 +173,53 @@ rec { fna); in if fna == {} then "<λ>" else "<λ:{${showFnas}}>" - else abort "toPretty: should never happen (v = ${v})"; + else abort "generators.toPretty: should never happen (v = ${v})"; # PLIST handling - toPLIST = {}: v: let - pprExpr = ind: x: with builtins; + toPlist = {}: v: let + expr = ind: x: with builtins; if isNull x then "" else - if isBool x then pprBool ind x else - if isInt x then pprInt ind x else - if isString x then pprStr ind x else - if isList x then pprList ind x else - if isAttrs x then pprAttrs ind x else - abort "pprExpr: should never happen (v = ${v})"; + if isBool x then bool ind x else + if isInt x then int ind x else + if isString x then str ind x else + if isList x then list ind x else + if isAttrs x then attrs ind x else + abort "generators.toPlist: should never happen (v = ${v})"; - pprLiteral = ind: x: ind + x; + literal = ind: x: ind + x; - pprBool = ind: x: pprLiteral ind (if x then "" else ""); - pprInt = ind: x: pprLiteral ind "${toString x}"; - pprStr = ind: x: pprLiteral ind "${x}"; - pprKey = ind: x: pprLiteral ind "${x}"; + bool = ind: x: literal ind (if x then "" else ""); + int = ind: x: literal ind "${toString x}"; + str = ind: x: literal ind "${x}"; + key = ind: x: literal ind "${x}"; - pprIndent = ind: pprExpr "\t${ind}"; + indent = ind: expr "\t${ind}"; - pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); + item = ind: libStr.concatMapStringsSep "\n" (indent ind); - pprList = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprItem ind x) - (pprLiteral ind "") + list = ind: x: libStr.concatStringsSep "\n" [ + (literal ind "") + (item ind x) + (literal ind "") ]; - pprAttrs = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprAttr ind x) - (pprLiteral ind "") + attrs = ind: x: libStr.concatStringsSep "\n" [ + (literal ind "") + (attr ind x) + (literal ind "") ]; - pprAttr = let attrFilter = name: value: name != "_module" && value != null; + attr = let attrFilter = name: value: name != "_module" && value != null; in ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ - (pprKey "\t${ind}" name) - (pprExpr "\t${ind}" value) + (key "\t${ind}" name) + (expr "\t${ind}" value) ]) x)); - in '' - - - - ${pprExpr "" v} - ''; + in '' + + +${expr "" v} +''; } diff --git a/pkgs/development/tools/xcbuild/platform.nix b/pkgs/development/tools/xcbuild/platform.nix index 502c3bcdbc8..bb91df474aa 100644 --- a/pkgs/development/tools/xcbuild/platform.nix +++ b/pkgs/development/tools/xcbuild/platform.nix @@ -2,7 +2,7 @@ let - inherit (lib.generators) toPLIST; + inherit (lib.generators) toPlist; Info = { CFBundleIdentifier = platformName; @@ -286,11 +286,11 @@ let in runCommand "MacOSX.platform" {} '' - install -D ${writeText "Info.plist" (toPLIST {} Info)} $out/Info.plist - install -D ${writeText "version.plist" (toPLIST {} Version)} $out/version.plist - install -D ${writeText "Architectures.xcspec" (toPLIST {} Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec - install -D ${writeText "PackageTypes.xcspec" (toPLIST {} PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec - install -D ${writeText "ProductTypes.xcspec" (toPLIST {} ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec + install -D ${writeText "Info.plist" (toPlist {} Info)} $out/Info.plist + install -D ${writeText "version.plist" (toPlist {} Version)} $out/version.plist + install -D ${writeText "Architectures.xcspec" (toPlist {} Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec + install -D ${writeText "PackageTypes.xcspec" (toPlist {} PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec + install -D ${writeText "ProductTypes.xcspec" (toPlist {} ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec mkdir -p $out/Developer/SDKs/ cd $out/Developer/SDKs/ diff --git a/pkgs/development/tools/xcbuild/sdk.nix b/pkgs/development/tools/xcbuild/sdk.nix index 5fdfe587722..c97d17d739b 100644 --- a/pkgs/development/tools/xcbuild/sdk.nix +++ b/pkgs/development/tools/xcbuild/sdk.nix @@ -1,7 +1,7 @@ { runCommand, lib, toolchainName, sdkName, writeText }: let - inherit (lib.generators) toPLIST; + inherit (lib.generators) toPlist; # TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here. version = "10.10"; @@ -24,6 +24,6 @@ in runCommand "MacOSX${version}.sdk" { inherit version; } '' - install -D ${writeText "SDKSettings.plist" (toPLIST {} SDKSettings)} $out/SDKSettings.plist - install -D ${writeText "SystemVersion.plist" (toPLIST {} SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist + install -D ${writeText "SDKSettings.plist" (toPlist {} SDKSettings)} $out/SDKSettings.plist + install -D ${writeText "SystemVersion.plist" (toPlist {} SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist '' diff --git a/pkgs/development/tools/xcbuild/toolchain.nix b/pkgs/development/tools/xcbuild/toolchain.nix index ed5730abddf..51bc5d60bcf 100644 --- a/pkgs/development/tools/xcbuild/toolchain.nix +++ b/pkgs/development/tools/xcbuild/toolchain.nix @@ -4,7 +4,7 @@ let inherit (lib) getBin optionalString; - inherit (lib.generators) toPLIST; + inherit (lib.generators) toPlist; ToolchainInfo = { Identifier = toolchainName; @@ -24,7 +24,7 @@ runCommand "nixpkgs.xctoolchain" { nativeBuildInputs = [ makeWrapper ]; } ('' mkdir -p $out - install -D ${writeText "ToolchainInfo.plist" (toPLIST {} ToolchainInfo)} $out/ToolchainInfo.plist + install -D ${writeText "ToolchainInfo.plist" (toPlist {} ToolchainInfo)} $out/ToolchainInfo.plist mkdir -p $out/usr/include mkdir -p $out/usr/lib