Add simple Racket builder

This commit is contained in:
Brian Leung 2022-09-16 15:58:30 -07:00
parent c17d995e8d
commit c849f31434
No known key found for this signature in database
GPG Key ID: 2D86D6A94C8BB3B1
4 changed files with 140 additions and 0 deletions

View File

@ -10,6 +10,7 @@
nodejs = "granular";
python = "simple-builder";
php = "granular";
racket = "simple";
};
# TODO

View File

@ -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;

View 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;
};
}

View File

@ -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))