From 6b4d8bb98390d06a04d8afa0643a75c6762b179e Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Wed, 30 Jan 2019 19:14:40 +0100 Subject: [PATCH] Force and infer executable names --- snack-lib/build.nix | 14 +++++++++----- snack-lib/default.nix | 5 ++++- snack-lib/package-spec.nix | 10 +++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/snack-lib/build.nix b/snack-lib/build.nix index 87d2060..7d46829 100644 --- a/snack-lib/build.nix +++ b/snack-lib/build.nix @@ -27,15 +27,19 @@ rec { buildLibrary = ghcWith: modSpecs: buildModulesRec ghcWith {} modSpecs; - linkMainModule = ghcWith: mod: # main module + linkMainModule = + { ghcWith + , moduleSpec # The module to build + , name # The name to give the executable + }: let - objAttrs = buildMain ghcWith mod; + objAttrs = buildMain ghcWith moduleSpec; objList = lib.attrsets.mapAttrsToList (x: y: y) objAttrs; - deps = allTransitiveDeps [mod]; + deps = allTransitiveDeps [moduleSpec]; ghc = ghcWith deps; - ghcOptsArgs = lib.strings.escapeShellArgs mod.moduleGhcOpts; + ghcOptsArgs = lib.strings.escapeShellArgs moduleSpec.moduleGhcOpts; packageList = map (p: "-package ${p}") deps; - relExePath = "bin/${lib.strings.toLower mod.moduleName}"; + relExePath = "bin/${name}"; drv = runCommand "linker" {} '' mkdir -p $out/bin diff --git a/snack-lib/default.nix b/snack-lib/default.nix index 94f0c1d..d7d53fe 100644 --- a/snack-lib/default.nix +++ b/snack-lib/default.nix @@ -41,7 +41,10 @@ let buildLibrary ghcWith (libraryModSpecs pkgSpec); buildAsExecutable = pkgSpec: - let drv = linkMainModule ghcWith (executableMainModSpec pkgSpec); + let + moduleSpec = executableMainModSpec pkgSpec; + name = pkgSpec.packageName; + drv = linkMainModule { inherit moduleSpec name ghcWith; }; in { out = drv.out; exe_path = "${drv.out}/${drv.relExePath}"; diff --git a/snack-lib/package-spec.nix b/snack-lib/package-spec.nix index 4aa2674..76ea49c 100644 --- a/snack-lib/package-spec.nix +++ b/snack-lib/package-spec.nix @@ -18,8 +18,16 @@ rec { , extra-directories ? [] , packages ? [] }: + with + rec { + isExe = ! builtins.isNull main; + pName = + if isExe && builtins.isNull name + then lib.strings.toLower main + else name; + }; { packageIsExe = ! builtins.isNull main; - packageName = name; + packageName = pName; packageMain = main; packageSourceDirs = if builtins.isList src