mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-10-26 15:23:14 +03:00
Add simple Racket builder
This commit is contained in:
parent
c17d995e8d
commit
c849f31434
@ -10,6 +10,7 @@
|
||||
nodejs = "granular";
|
||||
python = "simple-builder";
|
||||
php = "granular";
|
||||
racket = "simple";
|
||||
};
|
||||
|
||||
# TODO
|
||||
|
@ -11,6 +11,7 @@
|
||||
php = "granular-php";
|
||||
haskell = "simple-haskell";
|
||||
debian = "simple-debian";
|
||||
racket = "simple-racket";
|
||||
};
|
||||
loader = b: b // {build = callPackageDream b.build {};};
|
||||
funcs = config.functions.subsystem-loading;
|
||||
|
110
src/subsystems/racket/builders/simple-racket/default.nix
Normal file
110
src/subsystems/racket/builders/simple-racket/default.nix
Normal file
@ -0,0 +1,110 @@
|
||||
{...}: {
|
||||
type = "pure";
|
||||
|
||||
build = {
|
||||
lib,
|
||||
pkgs,
|
||||
stdenv,
|
||||
# dream2nix inputs
|
||||
externals,
|
||||
...
|
||||
}: {
|
||||
### FUNCTIONS
|
||||
# AttrSet -> Bool) -> AttrSet -> [x]
|
||||
getCyclicDependencies, # name: version: -> [ {name=; version=; } ]
|
||||
getDependencies, # name: version: -> [ {name=; version=; } ]
|
||||
getSource, # name: version: -> store-path
|
||||
# to get information about the original source spec
|
||||
getSourceSpec, # name: version: -> {type="git"; url=""; hash="";}
|
||||
### ATTRIBUTES
|
||||
subsystemAttrs, # attrset
|
||||
defaultPackageName, # string
|
||||
defaultPackageVersion, # string
|
||||
# all exported (top-level) package names and versions
|
||||
# attrset of pname -> version,
|
||||
packages,
|
||||
# all existing package names and versions
|
||||
# attrset of pname -> versions,
|
||||
# where versions is a list of version strings
|
||||
packageVersions,
|
||||
# function which applies overrides to a package
|
||||
# It must be applied by the builder to each individual derivation
|
||||
# Example:
|
||||
# produceDerivation name (mkDerivation {...})
|
||||
produceDerivation,
|
||||
...
|
||||
} @ args: let
|
||||
l = lib // builtins;
|
||||
|
||||
# packages to export
|
||||
exportedPackages =
|
||||
{default = exportedPackages.${defaultPackageName};}
|
||||
// (lib.mapAttrs
|
||||
(name: version: {
|
||||
"${version}" = buildRacketWithPackages name;
|
||||
})
|
||||
args.packages);
|
||||
|
||||
allPackageSourceAttrs = l.pipe packageVersions [
|
||||
(l.mapAttrsToList (name: versions: (l.map
|
||||
(ver: let
|
||||
src = getSource name ver;
|
||||
srcDir = src.original or src;
|
||||
in
|
||||
l.nameValuePair name srcDir)
|
||||
versions)))
|
||||
l.flatten
|
||||
l.listToAttrs
|
||||
];
|
||||
|
||||
# Many of the details mimic https://github.com/Warbo/nix-helpers,
|
||||
# the license of which permits copying as long as we don't try to
|
||||
# patent anything.
|
||||
buildRacketWithPackages = name:
|
||||
produceDerivation "racket-with-${name}-env"
|
||||
(pkgs.runCommandCC "racket-with-${name}-env"
|
||||
{
|
||||
inherit (pkgs) racket;
|
||||
buildInputs = with pkgs; [makeWrapper racket];
|
||||
} ''
|
||||
${l.toShellVars {"allDepSrcs" = allPackageSourceAttrs;}}
|
||||
|
||||
mkdir -p $TMP/unpack
|
||||
|
||||
for p in ''${!allDepSrcs[@]}
|
||||
do
|
||||
mkdir $TMP/unpack/$p
|
||||
cp -R ''${allDepSrcs[$p]}/. $TMP/unpack/$p
|
||||
done
|
||||
|
||||
export PLTCONFIGDIR=$out/etc
|
||||
mkdir -p $PLTCONFIGDIR
|
||||
|
||||
cp $racket/etc/racket/config.rktd $PLTCONFIGDIR
|
||||
|
||||
$racket/bin/racket -t ${./make-new-config.rkt}
|
||||
|
||||
export TMP_RACO_HOME=$out/tmp-raco-home
|
||||
mkdir -p $TMP_RACO_HOME
|
||||
|
||||
chmod +w -R $TMP/unpack
|
||||
HOME=$TMP_RACO_HOME $racket/bin/raco pkg install --copy $(ls -d $TMP/unpack/*/)
|
||||
|
||||
for SUBPATH in $(ls -d $TMP_RACO_HOME/.local/share/racket/*/); # there is only one SUBPATH (whose name is the version number of Racket)
|
||||
do
|
||||
cp -r -t $PLTCONFIGDIR $SUBPATH/*
|
||||
done
|
||||
|
||||
rm -rf $TMP_RACO_HOME
|
||||
|
||||
mkdir -p $out/bin
|
||||
for EXE in $racket/bin/* $out/etc/bin/*;
|
||||
do
|
||||
NAME=$(basename "$EXE")
|
||||
makeWrapper "$EXE" "$out/bin/$NAME" --set PLTCONFIGDIR "$PLTCONFIGDIR"
|
||||
done
|
||||
'');
|
||||
in {
|
||||
packages = exportedPackages;
|
||||
};
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#lang racket
|
||||
|
||||
(require setup/dirs)
|
||||
|
||||
(let* ([config-rktd-path (cleanse-path (build-path (find-config-dir) "config.rktd"))]
|
||||
[old-config-ht (with-input-from-file config-rktd-path read)]
|
||||
[property-alist '((bin-search-dirs . "bin/")
|
||||
(collects-search-dirs . "collects/")
|
||||
(doc-search-dirs . "doc/")
|
||||
(include-search-dirs . "include/")
|
||||
(lib-search-dirs . "lib/")
|
||||
(links-search-files . "links.rktd")
|
||||
(man-search-dirs . "man/")
|
||||
(pkgs-search-dirs . "pkgs/")
|
||||
(share-search-dirs . "share/"))]
|
||||
[make-path-string (lambda (subpath)
|
||||
(path->string (cleanse-path (build-path (find-config-dir) subpath))))]
|
||||
[final-config-ht (foldl (match-lambda**
|
||||
[((cons key subpath) accum)
|
||||
(hash-update accum
|
||||
key
|
||||
(curry cons (make-path-string subpath))
|
||||
'(#f))])
|
||||
old-config-ht
|
||||
property-alist)])
|
||||
(with-output-to-file config-rktd-path
|
||||
(lambda () (write final-config-ht))
|
||||
#:exists 'replace))
|
Loading…
Reference in New Issue
Block a user