artiq-extrapkg/flake.nix

164 lines
5.5 KiB
Nix

{
description = "Additional packages for ARTIQ";
inputs.artiq.url = git+https://github.com/m-labs/artiq.git;
outputs = { self, artiq }:
let
pkgs = import artiq.inputs.nixpkgs { system = "x86_64-linux"; };
condaDeps = with pkgs; [ zlib xorg.libSM xorg.libICE xorg.libX11 xorg.libXau xorg.libXi xorg.libXrender libselinux libGL ];
# Use the full Anaconda distribution, which already contains conda-build and its many dependencies.
condaInstaller = pkgs.fetchurl {
url = "https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh";
sha256 = "sha256-/t+eNAA5VX97XoqKhq/6nSmfXpggFEvXuSrp9+4IrGA=";
};
condaInstallerEnv = pkgs.buildFHSUserEnv {
name = "conda-installer-env";
targetPkgs = pkgs: condaDeps;
};
condaInstalled = pkgs.stdenvNoCC.mkDerivation {
name = "conda-installed";
src = condaInstaller;
buildInputs = [ condaInstallerEnv ];
phases = [ "buildPhase" "installPhase" ];
buildPhase =
''
cp $src conda-installer.sh
chmod +x conda-installer.sh
# keep the same file length to avoid breaking embedded payload offsets
sed -i 0,/unset\ LD_LIBRARY_PATH/s//\#nset\ LD_LIBRARY_PATH/ conda-installer.sh
'';
installPhase =
''
conda-installer-env -c "./conda-installer.sh -p $out -b"
substituteInPlace $out/lib/python3.9/site-packages/conda/gateways/disk/__init__.py \
--replace "os.chmod(path, 0o2775)" "pass"
'';
};
condaBuilderEnv = pkgs.buildFHSUserEnv {
name = "conda-builder-env";
targetPkgs = pkgs: condaDeps ++ [ condaInstalled ];
};
makeCondaRecipe = (constituent:
''
# conda build breaks if write permissions aren't set on source files.
cp --no-preserve=mode,ownership -R ${constituent.src} workaround-conda
cd workaround-conda
tar cf ../${constituent.name}.tar .
cd ..
rm -rf workaround-conda
mkdir -p conda/${constituent.name}
cat << EOF > conda/${constituent.name}/meta.yaml
package:
name: ${constituent.name}
version: ${constituent.version}
source:
url: ../../${constituent.name}.tar
{% set data = load_setup_py_data() %}
build:
noarch: python
entry_points:
# NOTE: conda-build cannot distinguish between console and gui scripts
{% for entry_point_type, entry_points in data.get("entry_points", dict()).items() -%}
{% for entry_point in entry_points -%}
- {{ entry_point }}
{% endfor %}
{% endfor %}
ignore_prefix_files: True
requirements:
run:
${pkgs.lib.concatStringsSep "\n" (map (s: " - ${s}") constituent.dependencies)}
EOF
cat << EOF > conda/${constituent.name}/build.sh
#!/bin/bash
set -e
${constituent.preSetup or ""}
python setup.py install \
--prefix=\$PREFIX \
--single-version-externally-managed \
--record=record.txt \
--no-compile
EOF
chmod 755 conda/${constituent.name}/build.sh
''
);
makeCondaChannel = constituents: pkgs.stdenvNoCC.mkDerivation {
name = "conda-channel";
buildInputs = [ condaBuilderEnv ];
phases = [ "buildPhase" "installPhase" ];
buildPhase = pkgs.lib.concatStringsSep "\n" (map makeCondaRecipe constituents);
installPhase =
''
HOME=`pwd`
mkdir $out
conda-builder-env -c "
${pkgs.lib.concatStringsSep "\n"
(map (constituent: "conda build --no-anaconda-upload --no-test --output-folder $out conda/${constituent.name}") constituents)}
"
mkdir $out/nix-support
for package in $out/*/*.tar.bz2; do
echo file conda $package >> $out/nix-support/hydra-build-products
done
'';
};
in rec {
packages.x86_64-linux = {
condaChannel = makeCondaChannel [
{
name = "sipyco";
version = artiq.inputs.sipyco.packages.x86_64-linux.sipyco.version;
src = artiq.inputs.sipyco.packages.x86_64-linux.sipyco.src;
dependencies = [ "numpy" "pybase64" ];
}
{
name = "pythonparser";
version = artiq.packages.x86_64-linux.pythonparser.version;
src = artiq.packages.x86_64-linux.pythonparser.src;
dependencies = [ "regex" ];
}
{
name = "artiq";
version = artiq.packages.x86_64-linux.artiq.version;
src = artiq.packages.x86_64-linux.artiq.src;
preSetup =
''
export VERSIONEER_OVERRIDE=${artiq.packages.x86_64-linux.artiq.version}
export VERSIONEER_REV=${artiq.sourceInfo.rev}
'';
dependencies = [
"pythonparser"
"scipy"
"numpy"
"prettytable"
"h5py"
"python-dateutil"
"pyqt"
"qasync"
"pyqtgraph"
"pygit2"
"python-levenshtein"
"sipyco"
"llvmlite"
"llvm-tools"
"lld"
];
}
];
};
hydraJobs = {
inherit (packages.x86_64-linux) condaChannel;
};
};
}