Skip to content

Commit

Permalink
Uproszczone ustawienia asdf
Browse files Browse the repository at this point in the history
Wcześniej podpinałem pliki conf z użyciem klauzuli :include. Niestety w ten
sposób wymagana jest wyczyszczenie konfiguracji asdf żeby podłapać system nowo
dodane do profilu.

(Jak się potem okazało, nawet z dodaniem całego katalogu i tak trzeba resetować
konfigurację)

Zamiast tego mogę przetłumaczyć na sztywno cały katalog systems na fasl. Wymaga
to zachowania konwencji gdzie są fasle. Niestety w tym przypadku wymagana jest
pełna kopia a nie symlink, chyba że ustawi się asdf:*resolve-symlinks*.

Ustawienie samych linków do asdków wymagałoby użycia truename na symlinku,
jednak nie wiem jak by to działało gdyby pliki źródłowe znajdowały się w
katalogu wyżej niż sam asd.

Teraz problemem jest to, że zainstalowanie tej samej biblioteki do profilu kilka
razy pod rząd postępująco nadpisuje wcześniejsze pliki - to znaczy że nie są
wykrywane konflikty. Może ostatecznie będzie trzeba kopiować źródła.
  • Loading branch information
kgalkowski-comscore authored and Kasper Gałkowski committed Jul 13, 2024
1 parent 9c0dcc9 commit 3ceabab
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 66 deletions.
25 changes: 10 additions & 15 deletions asdf-nix.patch
Original file line number Diff line number Diff line change
@@ -1,54 +1,49 @@
diff --git a/output-translations.lisp b/output-translations.lisp
index d2512ba0..af750f38 100644
--- a/output-translations.lisp
+++ b/output-translations.lisp
@@ -146,6 +146,7 @@ and the order is by decreasing length of namestring of the source pathname.")
@@ -146,6 +146,7 @@
'(environment-output-translations
user-output-translations-pathname
user-output-translations-directory-pathname
+ nix-profile-output-translations
system-output-translations-pathname
system-output-translations-directory-pathname))

@@ -184,6 +185,14 @@ and the order is by decreasing length of namestring of the source pathname.")
@@ -184,6 +185,14 @@
:direction direction))
(defun environment-output-translations ()
(getenv "ASDF_OUTPUT_TRANSLATIONS"))
+ (defun nix-profile-output-translations ()
+ `(:output-translations
+ ,@(loop :for profile :in (reverse (split-string (or (getenv "NIX_PROFILES") "")))
+ :for share := (subpathname (ensure-directory-pathname profile) "share/")
+ :for conf := (subpathname share *output-translations-directory*)
+ :when (probe-file* conf)
+ :collect `(:include ,conf))
+ :for sysdir := (namestring (subpathname share "common-lisp/systems/"))
+ :for fasldir := (namestring (subpathname share "common-lisp/fasl/"))
+ :collect `(,sysdir (,fasldir :implementation)))
+ :inherit-configuration))


;;; Processing the configuration.
diff --git a/source-registry.lisp b/source-registry.lisp
index a086cc88..cc317591 100644

--- a/source-registry.lisp
+++ b/source-registry.lisp
@@ -187,6 +187,7 @@ after having found a .asd file? True by default.")
@@ -187,6 +187,7 @@
user-source-registry
user-source-registry-directory
default-user-source-registry
+ nix-profile-source-registry
system-source-registry
system-source-registry-directory
default-system-source-registry)
@@ -227,6 +228,14 @@ after having found a .asd file? True by default.")
@@ -227,5 +228,11 @@
:direction direction))
(defun environment-source-registry ()
(getenv "CL_SOURCE_REGISTRY"))
+ (defun nix-profile-source-registry ()
+ `(:source-registry
+ ,@(loop :for profile :in (reverse (split-string (or (getenv "NIX_PROFILES") "")))
+ :for share := (subpathname (ensure-directory-pathname profile) "share/")
+ :for conf := (subpathname share *source-registry-directory*)
+ :when (probe-file* conf)
+ :collect `(:include ,conf))
+ :collect `(:tree ,(namestring (subpathname share (parse-unix-namestring "common-lisp/systems/")))))
+ :inherit-configuration))


;;; Process the source-registry configuration
;;; Process the source-registry configuration
15 changes: 12 additions & 3 deletions builder.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
;; "user cache" via an additional runtime output translation configuration.

(defvar *pwd* (namestring (uiop:getcwd)))
(defvar *src* (namestring (uiop:getenv "src")))
(defvar *out* (namestring (uiop:getenv "out")))
(defvar *pname* (format nil "~a/" (uiop:getenv "pname")))

(setf asdf:*resolve-symlinks* nil)

(asdf:initialize-source-registry
`(:source-registry :inherit-configuration (:tree ,*pwd*)))
`(:source-registry :inherit-configuration (:tree ,*src*)))

(asdf:initialize-output-translations
`(:output-translations
:disable-cache
("/nix/store/" "/nix/store/")
(,*pwd* (,*pwd* "__tmpfasl__"))
(,*src* (,*out* "share" "common-lisp" "fasl" :implementation ,*pname*))
:inherit-configuration))

(defvar *declared-systems* (uiop:split-string (uiop:getenv "systems")))
Expand All @@ -36,12 +41,16 @@
;; (defmethod asdf:operate :before (o c &key)
;; (format t "[INFO] Checking... ~A ~A ~A ~A~%" o c *system* (asdf:output-files o c)))

(defvar *out* (uiop:getenv "out"))

(defun out-path-p (path)
(or (uiop:string-prefix-p *pwd* (namestring path))
(uiop:string-prefix-p *out* (namestring path))))

(defmethod asdf:perform :before ((o asdf:prepare-op) (c asdf:file-component))
(let ((path (asdf:component-relative-pathname c))
(path2 (asdf:component-pathname c)))
(format t "FOOOOOOO: ~A >>> ~A~%" path path2)))

(defmethod asdf:perform :before ((o asdf:compile-op) (c asdf:source-file))
(let ((out (asdf:output-files o c)))
(format t "[INFO] [OUT] Checking... ~A ~A ~A ~A~%" o c *system* out)
Expand Down
50 changes: 16 additions & 34 deletions nix-cl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -212,45 +212,17 @@ let
concatMapStringsSep "\\|" (replaceStrings ["." "+"] ["[.]" "[+]"]) systems;
in
''
cat <<EOF | ${pkg}/bin/${program} ${flags}
(load "$asdfFasl")
(with-open-file (f "/tmp/implementation-identifier" :direction :output)
(format f "~a" (asdf:implementation-identifier)))
EOF
mkdir -pv $out/share/common-lisp/systems/
mkdir -pv $out/share/common-lisp/fasl/$(cat /tmp/implementation-identifier)/
mkdir -pv $out/share/common-lisp/asdf-output-translations.conf.d/
mkdir -pv $out/share/common-lisp/source-registry.conf.d/
cat > $out/share/common-lisp/asdf-output-translations.conf.d/10-${pname}.conf <<EOF
(("$out/share/common-lisp/systems/${pname}/")
("$out/share/common-lisp/fasl/" :implementation "${pname}/"))
EOF
cat > $out/share/common-lisp/source-registry.conf.d/10-${pname}.conf <<EOF
(:tree "$out/share/common-lisp/systems/${pname}/")
EOF
mkdir -p __tmpfasl__
mv __tmpfasl__ $out/share/common-lisp/fasl/$(cat /tmp/implementation-identifier)/${pname}
# TODO this is a hack at best. Fix osicat and others using cffi-grovel
# by setting a different output translation for shared objects
if [ -n "$(find $out -name '*.so' -print -quit)" ]; then
mkdir -p $out/lib
fi
find $out -name '*.so' -exec ln -s "{}" $out/lib \;
cp -r $(pwd) $out/share/common-lisp/systems/${pname}
declare -a asds
mkdir -pv $out/share/common-lisp/systems/
for s in $systems; do
asds+="\"$(find -type f -name $s.asd)\""
ln -s $src $out/share/common-lisp/systems/$s
done
# TODO assert equal number of systems to asds
cat <<EOF > $out/share/common-lisp/systems/${pname}/.cl-source-registry.cache
(:source-registry-cache $asds)
EOF
'';

dontPatchShebangs = true;
Expand All @@ -262,10 +234,20 @@ let
setupHook = ./setup-hook.sh;

} // (args // rec {
src = if builtins.length (args.patches or []) > 0
then pkgs.applyPatches { inherit (args) src patches; }
else args.src;
src = pkgs.applyPatches {
inherit (args) src;
systems = args.systems or [ args.pname ];
patches = args.patches or [];
postPatch = ''
declare -a asds=()
for s in $systems; do
asds+="\"$(find -name $s.asd -type f -print -quit)\""
done
echo "(:source-registry-cache ''${asds[@]})" > .cl-source-registry.cache
'' + args.postPatch or "";
};
patches = [];
postPatch = "";
propagatedBuildInputs = args.propagatedBuildInputs or []
++ lispLibs ++ javaLibs ++ nativeLibs;
propagatedUserEnvPkgs = propagatedBuildInputs;
Expand Down Expand Up @@ -324,7 +306,7 @@ let
--add-flags "${o.flags}" \
--set ASDF "${o.asdfFasl}" \
--prefix CL_SOURCE_REGISTRY : "$CL_SOURCE_REGISTRY" \
--prefix ASDF_OUTPUT_TRANSLATIONS : "$(echo $CL_SOURCE_REGISTRY | sed s,//:,::,g):" \
--prefix ASDF_OUTPUT_TRANSLATIONS : "$ASDF_OUTPUT_TRANSLATIONS" \
--prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH" \
--prefix DYLD_LIBRARY_PATH : "$DYLD_LIBRARY_PATH" \
--prefix CLASSPATH : "$CLASSPATH" \
Expand Down
19 changes: 5 additions & 14 deletions setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@
# How about nix-shell/dev shell? Is it fine to create files there, somewhere like /tmp?

addAsdfSourceRegistry () {
if test -z "${CL_SOURCE_REGISTRY:-}"; then
export CL_SOURCE_REGISTRY="(:source-registry :ignore-inherited-configuration)"
fi
if test -d "$1/share/common-lisp/source-registry.conf.d/"; then
if [[ ! "$CL_SOURCE_REGISTRY" =~ "$1/share/common-lisp/source-registry.conf.d/" ]]; then
export CL_SOURCE_REGISTRY="(:source-registry :ignore-inherited-configuration (:include \"$1/share/common-lisp/source-registry.conf.d/\")${CL_SOURCE_REGISTRY:49}"
fi
if test -d "$1/share/common-lisp"; then
addToSearchPath CL_SOURCE_REGISTRY "$1/share/common-lisp/systems//"
fi
}

addAsdfOutputTranslation () {
if test -z "${ASDF_OUTPUT_TRANSLATIONS:-}"; then
export ASDF_OUTPUT_TRANSLATIONS="(:output-translations :ignore-inherited-configuration)"
fi
if test -d "$1/share/common-lisp/asdf-output-translations.conf.d/"; then
if [[ ! "$ASDF_OUTPUT_TRANSLATIONS" =~ "$1/share/common-lisp/asdf-output-translations.conf.d/" ]]; then
export ASDF_OUTPUT_TRANSLATIONS="(:output-translations :ignore-inherited-configuration (:include \"$1/share/common-lisp/asdf-output-translations.conf.d/\")${ASDF_OUTPUT_TRANSLATIONS:53}"
fi
if test -d "$1/share/common-lisp"; then
addToSearchPath ASDF_OUTPUT_TRANSLATIONS "$1/share/common-lisp/systems/"
addToSearchPath ASDF_OUTPUT_TRANSLATIONS "$(find $1/share/common-lisp/fasl/ -mindepth 1 -maxdepth 1 -print -quit)/"
fi
}

Expand Down

0 comments on commit 3ceabab

Please sign in to comment.