2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

flake: format using alejandra

This commit is contained in:
Charlie Root 2024-12-13 22:19:49 +01:00 committed by Sébastien Bourdeauducq
parent db293d5ecd
commit 9a8338d71b

199
flake.nix
View File

@ -38,10 +38,21 @@
}; };
}; };
outputs = { self, nixpkgs, rust-overlay, sipyco, src-pythonparser, artiq-comtools, src-migen, src-misoc }: outputs = {
let self,
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import rust-overlay) ]; }; nixpkgs,
pkgs-aarch64 = import nixpkgs { system = "aarch64-linux"; }; rust-overlay,
sipyco,
src-pythonparser,
artiq-comtools,
src-migen,
src-misoc,
}: let
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [(import rust-overlay)];
};
pkgs-aarch64 = import nixpkgs {system = "aarch64-linux";};
artiqVersionMajor = 9; artiqVersionMajor = 9;
artiqVersionMinor = self.sourceInfo.revCount or 0; artiqVersionMinor = self.sourceInfo.revCount or 0;
@ -58,24 +69,25 @@
}; };
rust = pkgs.rust-bin.nightly."2021-09-01".default.override { rust = pkgs.rust-bin.nightly."2021-09-01".default.override {
extensions = [ "rust-src" ]; extensions = ["rust-src"];
targets = [ ]; targets = [];
}; };
rustPlatform = pkgs.makeRustPlatform { rustPlatform = pkgs.makeRustPlatform {
rustc = rust; rustc = rust;
cargo = rust; cargo = rust;
}; };
vivadoDeps = pkgs: with pkgs; let vivadoDeps = pkgs:
with pkgs; let
# Apply patch from https://github.com/nix-community/nix-environments/pull/54 # Apply patch from https://github.com/nix-community/nix-environments/pull/54
# to fix ncurses libtinfo.so's soname issue # to fix ncurses libtinfo.so's soname issue
ncurses' = ncurses5.overrideAttrs (old: { ncurses' = ncurses5.overrideAttrs (old: {
configureFlags = old.configureFlags ++ [ "--with-termlib" ]; configureFlags = old.configureFlags ++ ["--with-termlib"];
postFixup = ""; postFixup = "";
}); });
in [ in [
libxcrypt-legacy libxcrypt-legacy
(ncurses'.override { unicodeSupport = false; }) (ncurses'.override {unicodeSupport = false;})
zlib zlib
libuuid libuuid
xorg.libSM xorg.libSM
@ -94,7 +106,7 @@
version = "1.4"; version = "1.4";
src = src-pythonparser; src = src-pythonparser;
doCheck = false; doCheck = false;
propagatedBuildInputs = with pkgs.python3Packages; [ regex ]; propagatedBuildInputs = with pkgs.python3Packages; [regex];
}; };
qasync = pkgs.python3Packages.buildPythonPackage rec { qasync = pkgs.python3Packages.buildPythonPackage rec {
@ -110,17 +122,17 @@
postPatch = '' postPatch = ''
rm qasync/_windows.py # Ignoring it is not taking effect and it will not be used on Linux rm qasync/_windows.py # Ignoring it is not taking effect and it will not be used on Linux
''; '';
buildInputs = [ pkgs.python3Packages.poetry-core ]; buildInputs = [pkgs.python3Packages.poetry-core];
propagatedBuildInputs = [ pkgs.python3Packages.pyqt6 ]; propagatedBuildInputs = [pkgs.python3Packages.pyqt6];
checkInputs = [ pkgs.python3Packages.pytestCheckHook ]; checkInputs = [pkgs.python3Packages.pytestCheckHook];
pythonImportsCheck = [ "qasync" ]; pythonImportsCheck = ["qasync"];
disabledTestPaths = [ "tests/test_qeventloop.py" ]; disabledTestPaths = ["tests/test_qeventloop.py"];
}; };
libartiq-support = pkgs.stdenv.mkDerivation { libartiq-support = pkgs.stdenv.mkDerivation {
name = "libartiq-support"; name = "libartiq-support";
src = self; src = self;
buildInputs = [ rust ]; buildInputs = [rust];
buildPhase = '' buildPhase = ''
rustc $src/artiq/test/libartiq_support/lib.rs -Cpanic=unwind -g rustc $src/artiq/test/libartiq_support/lib.rs -Cpanic=unwind -g
''; '';
@ -144,7 +156,7 @@
rev = "v${version}"; rev = "v${version}";
sha256 = "sha256-5QBSRDb28Bui9IOhGofj+c7Rk7J5fNv5nPksEPY/O5o="; sha256 = "sha256-5QBSRDb28Bui9IOhGofj+c7Rk7J5fNv5nPksEPY/O5o=";
}; };
nativeBuildInputs = [ pkgs.llvm_15 ]; nativeBuildInputs = [pkgs.llvm_15];
# Disable static linking # Disable static linking
# https://github.com/numba/llvmlite/issues/93 # https://github.com/numba/llvmlite/issues/93
postPatch = '' postPatch = ''
@ -162,16 +174,16 @@
version = artiqVersion; version = artiqVersion;
src = self; src = self;
preBuild = preBuild = ''
''
export VERSIONEER_OVERRIDE=${version} export VERSIONEER_OVERRIDE=${version}
export VERSIONEER_REV=${artiqRev} export VERSIONEER_REV=${artiqRev}
''; '';
nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ]; nativeBuildInputs = [pkgs.qt6.wrapQtAppsHook];
# keep llvm_x and lld_x in sync with llvmlite # keep llvm_x and lld_x in sync with llvmlite
propagatedBuildInputs = [ pkgs.llvm_15 pkgs.lld_15 sipyco.packages.x86_64-linux.sipyco pythonparser llvmlite-new pkgs.qt6.qtsvg artiq-comtools.packages.x86_64-linux.artiq-comtools ] propagatedBuildInputs =
++ (with pkgs.python3Packages; [ pyqtgraph pygit2 numpy dateutil scipy prettytable pyserial levenshtein h5py pyqt6 qasync tqdm lmdb jsonschema platformdirs ]); [pkgs.llvm_15 pkgs.lld_15 sipyco.packages.x86_64-linux.sipyco pythonparser llvmlite-new pkgs.qt6.qtsvg artiq-comtools.packages.x86_64-linux.artiq-comtools]
++ (with pkgs.python3Packages; [pyqtgraph pygit2 numpy dateutil scipy prettytable pyserial levenshtein h5py pyqt6 qasync tqdm lmdb jsonschema platformdirs]);
dontWrapQtApps = true; dontWrapQtApps = true;
postFixup = '' postFixup = ''
@ -180,8 +192,7 @@
wrapQtApp "$out/bin/artiq_session" wrapQtApp "$out/bin/artiq_session"
''; '';
preFixup = preFixup = ''
''
# Ensure that wrapProgram uses makeShellWrapper rather than makeBinaryWrapper # Ensure that wrapProgram uses makeShellWrapper rather than makeBinaryWrapper
# brought in by wrapQtAppsHook. Only makeShellWrapper supports --run. # brought in by wrapQtAppsHook. Only makeShellWrapper supports --run.
wrapProgram() { wrapProgramShell "$@"; } wrapProgram() { wrapProgramShell "$@"; }
@ -196,7 +207,7 @@
# FIXME: automatically propagate lld_15 llvm_15 dependencies # FIXME: automatically propagate lld_15 llvm_15 dependencies
# cacert is required in the check stage only, as certificates are to be # cacert is required in the check stage only, as certificates are to be
# obtained from system elsewhere # obtained from system elsewhere
nativeCheckInputs = with pkgs; [ lld_15 llvm_15 lit outputcheck cacert ] ++ [ libartiq-support ]; nativeCheckInputs = with pkgs; [lld_15 llvm_15 lit outputcheck cacert] ++ [libartiq-support];
checkPhase = '' checkPhase = ''
python -m unittest discover -v artiq.test python -m unittest discover -v artiq.test
@ -206,17 +217,18 @@
''; '';
}; };
artiq = artiq-upstream // { artiq =
withExperimentalFeatures = features: artiq-upstream.overrideAttrs(oa: artiq-upstream
{ patches = map (f: ./experimental-features/${f}.diff) features; }); // {
withExperimentalFeatures = features: artiq-upstream.overrideAttrs (oa: {patches = map (f: ./experimental-features/${f}.diff) features;});
}; };
migen = pkgs.python3Packages.buildPythonPackage rec { migen = pkgs.python3Packages.buildPythonPackage rec {
name = "migen"; name = "migen";
src = src-migen; src = src-migen;
format = "pyproject"; format = "pyproject";
nativeBuildInputs = [ pkgs.python3Packages.setuptools ]; nativeBuildInputs = [pkgs.python3Packages.setuptools];
propagatedBuildInputs = [ pkgs.python3Packages.colorama ]; propagatedBuildInputs = [pkgs.python3Packages.colorama];
}; };
asyncserial = pkgs.python3Packages.buildPythonPackage rec { asyncserial = pkgs.python3Packages.buildPythonPackage rec {
@ -228,13 +240,13 @@
rev = version; rev = version;
sha256 = "sha256-ZHzgJnbsDVxVcp09LXq9JZp46+dorgdP8bAiTB59K28="; sha256 = "sha256-ZHzgJnbsDVxVcp09LXq9JZp46+dorgdP8bAiTB59K28=";
}; };
propagatedBuildInputs = [ pkgs.python3Packages.pyserial ]; propagatedBuildInputs = [pkgs.python3Packages.pyserial];
}; };
misoc = pkgs.python3Packages.buildPythonPackage { misoc = pkgs.python3Packages.buildPythonPackage {
name = "misoc"; name = "misoc";
src = src-misoc; src = src-misoc;
propagatedBuildInputs = with pkgs.python3Packages; [ jinja2 numpy migen pyserial asyncserial ]; propagatedBuildInputs = with pkgs.python3Packages; [jinja2 numpy migen pyserial asyncserial];
}; };
microscope = pkgs.python3Packages.buildPythonPackage rec { microscope = pkgs.python3Packages.buildPythonPackage rec {
@ -246,7 +258,7 @@
rev = "c21afe7a53258f05bde57e5ebf2e2761f3d495e4"; rev = "c21afe7a53258f05bde57e5ebf2e2761f3d495e4";
sha256 = "sha256-jzyiLRuEf7p8LdhmZvOQj/dyQx8eUE8p6uRlwoiT8vg="; sha256 = "sha256-jzyiLRuEf7p8LdhmZvOQj/dyQx8eUE8p6uRlwoiT8vg=";
}; };
propagatedBuildInputs = with pkgs.python3Packages; [ pyserial prettytable msgpack migen ]; propagatedBuildInputs = with pkgs.python3Packages; [pyserial prettytable msgpack migen];
}; };
vivadoEnv = pkgs.buildFHSEnv { vivadoEnv = pkgs.buildFHSEnv {
@ -261,10 +273,15 @@
runScript = "vivado"; runScript = "vivado";
}; };
makeArtiqBoardPackage = { target, variant, buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}", experimentalFeatures ? [] }: makeArtiqBoardPackage = {
target,
variant,
buildCommand ? "python -m artiq.gateware.targets.${target} -V ${variant}",
experimentalFeatures ? [],
}:
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
name = "artiq-board-${target}-${variant}"; name = "artiq-board-${target}-${variant}";
phases = [ "buildPhase" "checkPhase" "installPhase" ]; phases = ["buildPhase" "checkPhase" "installPhase"];
cargoDeps = rustPlatform.importCargoLock { cargoDeps = rustPlatform.importCargoLock {
lockFile = ./artiq/firmware/Cargo.lock; lockFile = ./artiq/firmware/Cargo.lock;
outputHashes = { outputHashes = {
@ -273,7 +290,7 @@
}; };
}; };
nativeBuildInputs = [ nativeBuildInputs = [
(pkgs.python3.withPackages(ps: [ migen misoc (artiq.withExperimentalFeatures experimentalFeatures) ps.packaging ])) (pkgs.python3.withPackages (ps: [migen misoc (artiq.withExperimentalFeatures experimentalFeatures) ps.packaging]))
rust rust
pkgs.llvmPackages_15.clang-unwrapped pkgs.llvmPackages_15.clang-unwrapped
pkgs.llvm_15 pkgs.llvm_15
@ -281,8 +298,7 @@
vivado vivado
rustPlatform.cargoSetupHook rustPlatform.cargoSetupHook
]; ];
buildPhase = buildPhase = ''
''
ARTIQ_PATH=`python -c "import artiq; print(artiq.__path__[0])"` ARTIQ_PATH=`python -c "import artiq; print(artiq.__path__[0])"`
ln -s $ARTIQ_PATH/firmware/Cargo.lock . ln -s $ARTIQ_PATH/firmware/Cargo.lock .
cargoSetupPostUnpackHook cargoSetupPostUnpackHook
@ -290,8 +306,7 @@
${buildCommand} ${buildCommand}
''; '';
doCheck = true; doCheck = true;
checkPhase = checkPhase = ''
''
# Search for PCREs in the Vivado output to check for errors # Search for PCREs in the Vivado output to check for errors
check_log() { check_log() {
grep -Pe "$1" artiq_${target}/${variant}/gateware/vivado.log && exit 1 || true grep -Pe "$1" artiq_${target}/${variant}/gateware/vivado.log && exit 1 || true
@ -299,8 +314,7 @@
check_log "\d+ constraint not met\." check_log "\d+ constraint not met\."
check_log "Timing constraints are not met\." check_log "Timing constraints are not met\."
''; '';
installPhase = installPhase = ''
''
mkdir $out mkdir $out
cp artiq_${target}/${variant}/gateware/top.bit $out cp artiq_${target}/${variant}/gateware/top.bit $out
if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ] if [ -e artiq_${target}/${variant}/software/bootloader/bootloader.bin ]
@ -330,25 +344,45 @@
sha256 = "1zqv47kzgvbn4c8cr019a6wcja7gn5h1z4kvw5bhpc72fyhagal9"; sha256 = "1zqv47kzgvbn4c8cr019a6wcja7gn5h1z4kvw5bhpc72fyhagal9";
}; };
phases = ["installPhase"]; phases = ["installPhase"];
installPhase = installPhase = ''
''
mkdir -p $out/share/bscan-spi-bitstreams mkdir -p $out/share/bscan-spi-bitstreams
cp $src/*.bit $out/share/bscan-spi-bitstreams cp $src/*.bit $out/share/bscan-spi-bitstreams
''; '';
}; };
in pkgs.buildEnv { in
pkgs.buildEnv {
name = "openocd-bscanspi"; name = "openocd-bscanspi";
paths = [ pkgs.openocd bscan_spi_bitstreams-pkg ]; paths = [pkgs.openocd bscan_spi_bitstreams-pkg];
}; };
latex-artiq-manual = pkgs.texlive.combine { latex-artiq-manual = pkgs.texlive.combine {
inherit (pkgs.texlive) inherit
scheme-basic latexmk cmap collection-fontsrecommended fncychap (pkgs.texlive)
titlesec tabulary varwidth framed fancyvrb float wrapfig parskip scheme-basic
upquote capt-of needspace etoolbox booktabs pgf pgfplots; latexmk
cmap
collection-fontsrecommended
fncychap
titlesec
tabulary
varwidth
framed
fancyvrb
float
wrapfig
parskip
upquote
capt-of
needspace
etoolbox
booktabs
pgf
pgfplots
;
}; };
artiq-frontend-dev-wrappers = pkgs.runCommandNoCC "artiq-frontend-dev-wrappers" {} artiq-frontend-dev-wrappers =
pkgs.runCommandNoCC "artiq-frontend-dev-wrappers" {}
'' ''
mkdir -p $out/bin mkdir -p $out/bin
for program in ${self}/artiq/frontend/*.py; do for program in ${self}/artiq/frontend/*.py; do
@ -379,10 +413,17 @@
name = "artiq-manual-html-${version}"; name = "artiq-manual-html-${version}";
version = artiqVersion; version = artiqVersion;
src = self; src = self;
buildInputs = with pkgs.python3Packages; [ buildInputs = with pkgs.python3Packages;
sphinx sphinx_rtd_theme sphinxcontrib-tikz [
sphinx-argparse sphinxcontrib-wavedrom sphinx
] ++ [ latex-artiq-manual artiq-comtools.packages.x86_64-linux.artiq-comtools sphinx_rtd_theme
sphinxcontrib-tikz
sphinx-argparse
sphinxcontrib-wavedrom
]
++ [
latex-artiq-manual
artiq-comtools.packages.x86_64-linux.artiq-comtools
pkgs.pdf2svg pkgs.pdf2svg
]; ];
buildPhase = '' buildPhase = ''
@ -401,10 +442,17 @@
name = "artiq-manual-pdf-${version}"; name = "artiq-manual-pdf-${version}";
version = artiqVersion; version = artiqVersion;
src = self; src = self;
buildInputs = with pkgs.python3Packages; [ buildInputs = with pkgs.python3Packages;
sphinx sphinx_rtd_theme sphinxcontrib-tikz [
sphinx-argparse sphinxcontrib-wavedrom sphinx
] ++ [ latex-artiq-manual artiq-comtools.packages.x86_64-linux.artiq-comtools sphinx_rtd_theme
sphinxcontrib-tikz
sphinx-argparse
sphinxcontrib-wavedrom
]
++ [
latex-artiq-manual
artiq-comtools.packages.x86_64-linux.artiq-comtools
pkgs.pdf2svg pkgs.pdf2svg
]; ];
buildPhase = '' buildPhase = ''
@ -424,7 +472,7 @@
inherit qtPaths makeArtiqBoardPackage openocd-bscanspi-f; inherit qtPaths makeArtiqBoardPackage openocd-bscanspi-f;
packages.x86_64-linux.default = pkgs.python3.withPackages(_: [ packages.x86_64-linux.artiq ]); packages.x86_64-linux.default = pkgs.python3.withPackages (_: [packages.x86_64-linux.artiq]);
formatter.x86_64-linux = pkgs.alejandra; formatter.x86_64-linux = pkgs.alejandra;
@ -435,7 +483,8 @@
# are added to PATH. # are added to PATH.
default = pkgs.mkShell { default = pkgs.mkShell {
name = "artiq-dev-shell"; name = "artiq-dev-shell";
packages = with pkgs; [ packages = with pkgs;
[
git git
lit lit
lld_15 lld_15
@ -450,9 +499,9 @@
python3Packages.sphinxcontrib-wavedrom python3Packages.sphinxcontrib-wavedrom
python3Packages.sphinx_rtd_theme python3Packages.sphinx_rtd_theme
(python3.withPackages(ps: [ migen misoc microscope ps.packaging ps.paramiko ] ++ artiq.propagatedBuildInputs )) (python3.withPackages (ps: [migen misoc microscope ps.packaging ps.paramiko] ++ artiq.propagatedBuildInputs))
] ++ ]
[ ++ [
latex-artiq-manual latex-artiq-manual
rust rust
artiq-frontend-dev-wrappers artiq-frontend-dev-wrappers
@ -485,7 +534,7 @@
packages.x86_64-linux.vivado packages.x86_64-linux.vivado
packages.x86_64-linux.openocd-bscanspi packages.x86_64-linux.openocd-bscanspi
(pkgs.python3.withPackages(ps: [ migen misoc artiq ps.packaging ps.paramiko ])) (pkgs.python3.withPackages (ps: [migen misoc artiq ps.packaging ps.paramiko]))
]; ];
}; };
}; };
@ -499,11 +548,10 @@
gateware-sim = pkgs.stdenvNoCC.mkDerivation { gateware-sim = pkgs.stdenvNoCC.mkDerivation {
name = "gateware-sim"; name = "gateware-sim";
buildInputs = [ buildInputs = [
(pkgs.python3.withPackages(ps: with packages.x86_64-linux; [ migen misoc artiq ])) (pkgs.python3.withPackages (ps: with packages.x86_64-linux; [migen misoc artiq]))
]; ];
phases = [ "buildPhase" ]; phases = ["buildPhase"];
buildPhase = buildPhase = ''
''
python -m unittest discover -v artiq.gateware.test python -m unittest discover -v artiq.gateware.test
touch $out touch $out
''; '';
@ -516,19 +564,22 @@
#__impure = true; # Nix 2.8+ #__impure = true; # Nix 2.8+
buildInputs = [ buildInputs = [
(pkgs.python3.withPackages(ps: with packages.x86_64-linux; [ (pkgs.python3.withPackages (
ps:
with packages.x86_64-linux;
[
artiq artiq
ps.paramiko ps.paramiko
] ++ ps.paramiko.optional-dependencies.ed25519 ]
++ ps.paramiko.optional-dependencies.ed25519
)) ))
pkgs.llvm_15 pkgs.llvm_15
pkgs.lld_15 pkgs.lld_15
pkgs.openssh pkgs.openssh
packages.x86_64-linux.openocd-bscanspi # for the bscanspi bitstreams packages.x86_64-linux.openocd-bscanspi # for the bscanspi bitstreams
]; ];
phases = [ "buildPhase" ]; phases = ["buildPhase"];
buildPhase = buildPhase = ''
''
export HOME=`mktemp -d` export HOME=`mktemp -d`
mkdir $HOME/.ssh mkdir $HOME/.ssh
cp /opt/hydra_id_ed25519 $HOME/.ssh/id_ed25519 cp /opt/hydra_id_ed25519 $HOME/.ssh/id_ed25519