[WIP] flakes

This commit is contained in:
Astro 2021-03-03 20:35:30 +01:00
parent b8a803a64f
commit a8288923d4
4 changed files with 404 additions and 25 deletions

View File

@ -1,9 +1,11 @@
{ pkgs ? import <nixpkgs> {} { pkgs ? import <nixpkgs> {}
, artiq-fast ? <artiq-fast> , artiq-fast ? <artiq-fast>
, sinaraSystemsSrc ? <sinaraSystemsSrc>
, sinaraSystemsRev ? null
, sinaraSystemsHash ? null
}: }:
let let
sinaraSystemsSrc = <sinaraSystemsSrc>;
generatedNix = pkgs.runCommand "generated-nix" { buildInputs = [ pkgs.nix pkgs.git ]; } generatedNix = pkgs.runCommand "generated-nix" { buildInputs = [ pkgs.nix pkgs.git ]; }
'' ''
mkdir $out mkdir $out
@ -11,14 +13,21 @@ let
cp ${../artiq-full/artiq-targets.nix} $out/artiq-targets.nix cp ${../artiq-full/artiq-targets.nix} $out/artiq-targets.nix
cp -a ${artiq-fast} $out/fast cp -a ${artiq-fast} $out/fast
${if sinaraSystemsRev != null && sinaraSystemsHash != null
then ''
REV=${sinaraSystemsRev}
HASH=${sinaraSystemsHash}
'' else ''
REV=`git --git-dir ${sinaraSystemsSrc}/.git rev-parse HEAD` REV=`git --git-dir ${sinaraSystemsSrc}/.git rev-parse HEAD`
echo -n $REV > $out/sinara-rev.txt
SINARA_SRC_CLEAN=`mktemp -d` SINARA_SRC_CLEAN=`mktemp -d`
cp -a ${sinaraSystemsSrc}/. $SINARA_SRC_CLEAN cp -a ${sinaraSystemsSrc}/. $SINARA_SRC_CLEAN
chmod -R 755 $SINARA_SRC_CLEAN/.git chmod -R 755 $SINARA_SRC_CLEAN/.git
chmod 755 $SINARA_SRC_CLEAN chmod 755 $SINARA_SRC_CLEAN
rm -rf $SINARA_SRC_CLEAN/.git rm -rf $SINARA_SRC_CLEAN/.git
HASH=`nix-hash --type sha256 --base32 $SINARA_SRC_CLEAN` HASH=`nix-hash --type sha256 --base32 $SINARA_SRC_CLEAN`
''}
echo -n $REV > $out/sinara-rev.txt
echo -n $HASH > $out/sinara-hash.txt echo -n $HASH > $out/sinara-hash.txt
cat > $out/default.nix << EOF cat > $out/default.nix << EOF

View File

@ -1,22 +1,25 @@
{ pkgs ? import <nixpkgs> {} { pkgs ? import <nixpkgs> {}
, a6p ? <a6p> , a6p ? <a6p>
}: , artiq-board-generated ? <artiq-board-generated>
, sinaraSystemsRev ? builtins.readFile (artiq-board-generated + "/sinara-rev.txt")
let , sinaraSystemsHash ? builtins.readFile (artiq-board-generated + "/sinara-hash.txt")
sinaraSystemsRev = builtins.readFile <artiq-board-generated/sinara-rev.txt>; , sinaraSystemsSrc ? (
sinaraSystemsHash = builtins.readFile <artiq-board-generated/sinara-hash.txt>;
sinaraSystemsSrc =
if a6p if a6p
then pkgs.fetchgit { then pkgs.fetchgit {
url = "https://git.m-labs.hk/M-Labs/sinara-systems.git"; url = "https://git.m-labs.hk/M-Labs/sinara-systems.git";
rev = sinaraSystemsRev; rev = sinaraSystemsRev;
sha256 = sinaraSystemsHash; sha256 = sinaraSystemsHash;
} }
else <sinaraSystemsSrc>; else <sinaraSystemsSrc>
artiq-fast = )
, artiq-fast ? (
if a6p if a6p
then <artiq-board-generated/fast> then <artiq-board-generated/fast>
else <artiq-fast>; else <artiq-fast>
)
}:
let
artiqVersion = import (artiq-fast + "/pkgs/artiq-version.nix") { artiqVersion = import (artiq-fast + "/pkgs/artiq-version.nix") {
inherit (pkgs) stdenv git fetchgit; inherit (pkgs) stdenv git fetchgit;
}; };
@ -49,10 +52,10 @@ let
${if a6p ${if a6p
then '' then ''
cp -a ${<artiq-board-generated>} $out/board-generated cp -a ${artiq-board-generated} $out/board-generated
ln -s board-generated/fast $out/fast ln -s board-generated/fast $out/fast
'' ''
else "cp -a ${<artiq-fast>} $out/fast"} else "cp -a ${artiq-fast} $out/fast"}
cp ${./artiq-full}/artiq-board-vivado.nix $out cp ${./artiq-full}/artiq-board-vivado.nix $out
cp ${./artiq-full}/generate-identifier.py $out cp ${./artiq-full}/generate-identifier.py $out
cp ${./artiq-full}/conda-artiq-board.nix $out cp ${./artiq-full}/conda-artiq-board.nix $out
@ -109,7 +112,9 @@ let
inherit pkgs vivado; inherit pkgs vivado;
} }
''}; ''};
conda-artiq-board = import ./conda-artiq-board.nix { inherit pkgs; }; conda-artiq-board = import ./conda-artiq-board.nix {
inherit pkgs;
};
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "https://git.m-labs.hk/M-Labs/sinara-systems.git"; url = "https://git.m-labs.hk/M-Labs/sinara-systems.git";
rev = "$REV"; rev = "$REV";

97
flake.lock Normal file
View File

@ -0,0 +1,97 @@
{
"nodes": {
"artiq-beta-src": {
"flake": false,
"locked": {
"lastModified": 1614216430,
"narHash": "sha256-iP/3vaXTjuIh7zhWpEsC2LKArB7GUttTwMZ1tg/hQI4=",
"owner": "M-Labs",
"repo": "artiq",
"rev": "e577542f6b621bebbb7a5e46b1dbab86ffbe1c11",
"type": "github"
},
"original": {
"owner": "M-Labs",
"repo": "artiq",
"type": "github"
}
},
"artiq-legacy-src": {
"flake": false,
"locked": {
"lastModified": 1613549523,
"narHash": "sha256-FgX/W+y8N4/6DLLTJuJVg5gUr3zk/5DxmSIxA4I6ZvE=",
"owner": "M-Labs",
"repo": "artiq",
"rev": "10c9842fc8844b524811336c6a529c648a2d2fde",
"type": "github"
},
"original": {
"owner": "M-Labs",
"ref": "release-5",
"repo": "artiq",
"type": "github"
}
},
"artiq-src": {
"flake": false,
"locked": {
"lastModified": 1613555154,
"narHash": "sha256-D/43YVvMNkcXV6sBBxAqxcmtEO3TagIQEQl0zsGE+ag=",
"owner": "M-Labs",
"repo": "artiq",
"rev": "c22482787ef806eb8e48d59b6ded7d93c7677c81",
"type": "github"
},
"original": {
"owner": "M-Labs",
"ref": "release-6",
"repo": "artiq",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1614338965,
"narHash": "sha256-2HPgL9171Dhlg9lS4Ep5aeh4ejRCED+gNmU9tYzgyic=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "113092f5531ef38a45046990199873755a372646",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "release-20.09",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"artiq-beta-src": "artiq-beta-src",
"artiq-legacy-src": "artiq-legacy-src",
"artiq-src": "artiq-src",
"nixpkgs": "nixpkgs",
"sinara-systems": "sinara-systems"
}
},
"sinara-systems": {
"flake": false,
"locked": {
"lastModified": 1614310919,
"narHash": "sha256-hHHEAUMbwATSExViuGM5foGt29Aq0Xwc0uDNF/x5Kt0=",
"ref": "master",
"rev": "52141a3fef08ee88227c48395bc8e32b5140c938",
"revCount": 200,
"type": "git",
"url": "https://git.m-labs.hk/M-Labs/sinara-systems.git"
},
"original": {
"type": "git",
"url": "https://git.m-labs.hk/M-Labs/sinara-systems.git"
}
}
},
"root": "root",
"version": 7
}

268
flake.nix Normal file
View File

@ -0,0 +1,268 @@
# let
# system = "x86_64-linux";
# in
{
description = "ARTIQ";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-20.09";
artiq-beta-src = {
url = "github:M-Labs/artiq";
flake = false;
};
artiq-src = {
url = "github:M-Labs/artiq/release-6";
flake = false;
};
artiq-legacy-src = {
url = "github:M-Labs/artiq/release-5";
flake = false;
};
sinara-systems = {
url = "git+https://git.m-labs.hk/M-Labs/sinara-systems.git";
flake = false;
};
};
outputs = sources@{ self, nixpkgs, ... }:
let
systems = [
"x86_64-linux"
];
forAllSystems = f:
builtins.foldl' (systems: system:
systems // { ${system} = f system; }
) {} systems;
in rec {
packages = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
artiq-fast-src = artiqInputName:
let
# locked = (builtins.fromJSON (
# builtins.readFile ./flake.lock
# )).nodes.${artiqInputName}.locked;
inherit (sources.${artiqInputName}) lastModified rev narHash;
hash = builtins.replaceStrings ["sha256-"] [""] narHash;
artiqSrc = sources.${artiqInputName}.outPath;
in pkgs.runCommand "generated-nix" { buildInputs = [ pkgs.nix pkgs.git ]; } ''
cp --no-preserve=mode,ownership -R ${./artiq-fast} $out
MAJOR_VERSION=`cat ${artiqSrc}/MAJOR_VERSION`
if [ -e ${artiqSrc}/BETA ]; then
SUFFIX=".beta"
else
SUFFIX=""
fi
cat > $out/pkgs/artiq-src.nix << EOF
{ fetchgit }:
fetchgit {
url = "git://github.com/m-labs/artiq.git";
rev = "${rev}";
sha256 = "${hash}";
}
EOF
echo "{ stdenv, git, fetchgit }: \"$MAJOR_VERSION.`cut -c1-8 <<< ${rev}`$SUFFIX\"" > $out/pkgs/artiq-version.nix
echo "{ stdenv, git, fetchgit }: \"${toString lastModified}\"" > $out/pkgs/artiq-timestamp.nix
'';
artiq-fast = artiqInputName:
import (artiq-fast-src artiqInputName) {
inherit pkgs;
};
artiq-board-generated = artiqInputName:
(import ./artiq-board-generated {
inherit pkgs;
sinaraSystemsSrc = null; #sources.sinara-systems.outPath;
sinaraSystemsRev = sources.sinara-systems.rev;
sinaraSystemsHash = builtins.replaceStrings ["sha256-"] [""]
sources.sinara-systems.narHash;
artiq-fast = artiq-fast-src artiqInputName;
}).generated-nix;
artiq-full = artiqInputName: a6p:
import ./artiq-full.nix {
inherit pkgs;
inherit a6p;
artiq-board-generated = artiq-board-generated artiqInputName;
sinaraSystemsSrc = sources.sinara-systems.outPath;
artiq-fast = artiq-fast-src artiqInputName;
};
# artiq-full1 = artiqInputName: a6p:
# let
# pythonDeps = import ./artiq-full/python-deps.nix { inherit pkgs; };
# ddbDeps = [
# artiq-fast.artiq
# (pkgs.python3.withPackages (ps: [ ps.jsonschema ]))
# ];
# artiqVersion = (artiq-fast artiqInputName).artiq.version;
# targets = import ./artiq-full/artiq-targets.nix {
# inherit pkgs artiqVersion;
# sinaraSystemsSrc = sources.sinara-systems.outPath;
# };
# kasliVariants = map ({ variant, ... }: variant) (
# builtins.filter ({ target, ... }: target == "kasli") (
# builtins.attrValues targets
# )
# );
# standaloneVariants = map ({ variant, ... }: variant) (
# builtins.filter ({ target, standalone ? false, ... }: target == "kasli" && standalone) (
# builtins.attrValues targets
# )
# );
# vivado = import ./artiq-fast/vivado.nix {
# inherit pkgs;
# };
# artiq-board =
# if a6p
# then
# import ./artiq-full/artiq-board-vivado.nix {
# inherit pkgs vivado;
# version = artiqVersion;
# board-generated = artiq-board-generated artiqInputName;
# }
# else
# import ./artiq-fast/artiq-board.nix {
# inherit pkgs vivado;
# };
# conda-artiq-board = import ./artiq-full/conda-artiq-board.nix {
# inherit pkgs;
# };
# artiq-targets = pkgs.lib.lists.foldr (conf: start:
# let
# inherit (conf) target variant;
# json = sources.sinara-systems.outPath + "/${variant}.json";
# boardBinaries = artiq-board (conf // {
# src = json;
# });
# in
# start // {
# "artiq-board-${target}-${variant}" = boardBinaries;
# "conda-artiq-board-${target}-${variant}" = conda-artiq-board {
# boardBinaries = boardBinaries;
# inherit target variant;
# };
# } // (pkgs.lib.optionalAttrs (
# target == "kasli" &&
# builtins.elem variant standaloneVariants
# ) {
# "device-db-${target}-${variant}" = pkgs.stdenv.mkDerivation {
# name = "device-db-${target}-${variant}";
# buildInputs = ddbDeps;
# phases = [ "buildPhase" ];
# buildPhase = "
# mkdir \$out
# artiq_ddb_template ${json} -o \$out/device_db.py
# mkdir \$out/nix-support
# echo file device_db_template \$out/device_db.py >> \$out/nix-support/hydra-build-products
# ";
# };
# })
# ) {} (builtins.attrValues targets);
# drtio-systems =
# if a6p then {
# berkeley3 = {
# master = "berkeley3master";
# satellites = {
# "1" = "berkeley3satellite";
# };
# };
# bonn1 = {
# master = "bonn1master";
# satellites = {
# "1" = "bonn1satellite";
# };
# };
# hw2 = {
# master = "hw2master";
# satellites = {
# "1" = "hw2satellite";
# };
# };
# ptb3 = {
# master = "ptb3master";
# satellites = {
# "1" = "ptb3satellite";
# };
# };
# purdue = {
# master = "purduemaster";
# satellites = {
# "1" = "purduesatellite";
# };
# };
# stfc = {
# master = "stfcmaster";
# satellites = {
# "1" = "stfcsatellite";
# };
# };
# wipm7 = {
# master = "wipm7master";
# satellites = {
# "1" = "wipm7satellite";
# };
# };
# }
# else {};
# drtio-ddbs = pkgs.lib.attrsets.mapAttrs'
# (system: crates: pkgs.lib.attrsets.nameValuePair ("device-db-" + system)
# (pkgs.stdenv.mkDerivation {
# name = "device-db-${system}";
# buildInputs = ddbDeps;
# phases = [ "buildPhase" ];
# buildPhase = ''
# mkdir \$out
# artiq_ddb_template \
# ${pkgs.lib.strings.concatStringsSep " " (pkgs.lib.attrsets.mapAttrsToList (dest: desc: "-s " + dest + " " + (sources.sinara-systems.outPath + "/${desc}.json")) crates.satellites) } \
# ${sources.sinara-systems.outPath}/${crates.master}.json -o \$out/device_db.py
# mkdir \$out/nix-support
# echo file device_db_template \$out/device_db.py >> \$out/nix-support/hydra-build-products
# '';
# })) drtio-systems;
# extras = import ./artiq-full/extras.nix { inherit pkgs; inherit (artiq-fast artiqInputName) sipyco asyncserial artiq; };
# artiq-full = artiq-targets // drtio-ddbs // extras // rec {
# conda-artiq-board-kasli-tester = conda-artiq-board {
# target = "kasli";
# variant = "tester";
# boardBinaries = artiq-fast.artiq-board-kasli-tester;
# };
# conda-artiq-board-kc705-nist_clock = conda-artiq-board {
# target = "kc705";
# variant = "nist_clock";
# boardBinaries = artiq-fast.artiq-board-kc705-nist_clock;
# };
# };
# sipycoManualPackages = import ./artiq-full/sipyco-manual.nix {
# inherit (pkgs) stdenv lib python3Packages texlive texinfo;
# inherit (import artiq-fast { inherit pkgs; }) sipyco;
# };
# artiqManualPackages = import ./artiq-full/artiq-manual.nix {
# inherit (pkgs) stdenv lib fetchgit git python3Packages texlive texinfo;
# inherit (pythonDeps) sphinxcontrib-wavedrom;
# inherit artiq-fast;
# };
# exampleUserEnv = import ./artiq-full/example-user-env.nix { inherit pkgs artiq-full; };
# jobs = artiq-full // sipycoManualPackages // artiqManualPackages // exampleUserEnv;
# in
# jobs;
allPackages = artiqInputName: a6p:
(artiq-fast artiqInputName) //
#(artiq-board-generated artiqInputName);
(artiq-full artiqInputName a6p);
in allPackages "artiq-beta-src" true
);
defaultPackage = forAllSystems (system: self.packages.${system}.artiq);
};
}