Skip to content

Instantly share code, notes, and snippets.

@fogti
Created January 12, 2022 06:42
Show Gist options
  • Save fogti/6deb7b6dfcc3d4b94d38fb3ceea675b6 to your computer and use it in GitHub Desktop.
Save fogti/6deb7b6dfcc3d4b94d38fb3ceea675b6 to your computer and use it in GitHub Desktop.
DS-G19 2021 Nix stuff
# Copyright (C) 2021 Alain Zscheile
# License: CC BY-SA 4.0
{
description = "PVLs by DS-G19";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
yz-flake-utils.url = "github:YZITE/flake-utils";
flake-utils.url = "github:numtide/flake-utils";
# needed for default.nix, shell.nix
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, yz-flake-utils, ... }:
let
systems = [ "aarch64-linux" "i686-linux" "x86_64-linux" ];
inherit (nixpkgs) lib;
PVLs-expanded = with builtins; lib.pipe ./. [
readDir
(lib.attrsets.filterAttrs (n: v: v == "directory"))
attrNames
(map (dir: rec {
inherit dir;
path = ./. + ("/" + dir);
finf = path + "/final.txt";
}))
(filter ({ finf, ... }: pathExists finf))
(map ({ dir, path, finf }: {
inherit dir path;
id = lib.strings.removePrefix "0" dir;
final = readFile finf;
}))
];
pyPVLs-expanded = builtins.filter (i: i.final == "Python\n") PVLs-expanded;
virt-PVLs-id-map = src: f: builtins.map
({ id, ... }: rec { name = f id; value = src.${name}; });
in
{
hydraJobs = yz-flake-utils.lib.eachSystem systems (system: self.legacyPackages.${system}.G19checks);
checks = builtins.listToAttrs (builtins.map
(system: { name = system; value = self.legacyPackages.${system}.G19checks; })
systems);
}
// yz-flake-utils.lib.mkFlake
{
prevpkgs = nixpkgs;
inherit systems;
defaultProgName = "dsg19-all-PVLs";
overlay = final: prev:
let
inherit (final) callPackage;
inherit (prev) system;
cur = self.legacyPackages.${system};
myPyOverride = {
packageOverrides = self: super:
let
G19pythonMock = callPackage ./PythonMock.nix {
inherit (super) buildPythonPackage pytestCheckHook;
};
in
# nix shell python37.pkgs.PVLx_G19
# nix-shell 'python37.withPackages(ps: [ps.PVLx_G19])'
builtins.listToAttrs (builtins.map
(xp: {
name = "PVL${xp.id}_G19";
value = G19pythonMock xp;
})
pyPVLs-expanded);
};
in
rec {
# PVL 01
G19automat-ml = callPackage ./01/ml { };
python3 = prev.python3.override myPyOverride;
python37 = prev.python37.override myPyOverride;
G19checks = {
inherit python37;
} // builtins.listToAttrs (
# add the to-be-submitted PVLs to the cache
(virt-PVLs-id-map cur (id: "PVL${id}-zip") PVLs-expanded)
# python packages
++ (virt-PVLs-id-map cur.python37.pkgs (id: "PVL${id}_G19") pyPVLs-expanded)
);
dsg19-all-PVLs = prev.runCommandNoCC "dsg19-all-PVLs"
{
passAsFile = [ "paths" ];
paths = builtins.attrValues G19checks;
}
''
mkdir -p $out
for i in $(cat $pathsPath); do
if [ -d $i ]; then
${prev.xorg.lndir}/bin/lndir -silent $i $out
else
ln -s -t $out $i
fi
done
rm -rf $out/nix-support
'';
} // (builtins.listToAttrs (builtins.map
({ id, dir, ... }: {
name = "PVL${id}-zip";
value = prev.runCommandNoCC "PVL${id}_G19.zip"
{ }
''
SDIR="${./. + "/${dir}"}"
FIN="$(< "$SDIR/final.txt")"
mkdir -p tmp
cp -fT ${./README_template.txt} "tmp/ReadMe"
cp -rfT "$SDIR/$FIN" "tmp/$FIN"
cd tmp
${final.zip}/bin/zip -l -r $out *
'';
})
PVLs-expanded));
};
}
{ buildPythonPackage
, lib
, pytestCheckHook
, runCommandNoCC
, xorg
}:
pvl:
let
ppvl = "PVL${pvl.id}";
homepage = "https://git.ytrizja.de/DatastructG19/PVLs/src/branch/main/${pvl.dir}/Python";
base_src = runCommandNoCC "${ppvl}-base-source" { } ''
mkdir -p $out
cd $out
${xorg.lndir}/bin/lndir -silent ${pvl.path}/Python .
cat > setup.cfg <<EOF
[metadata]
name = ${ppvl}
version = 0.0.0
author = G19
description = DS-G19 ${ppvl} implementation in Python
url = ${homepage}
classifiers =
Programming Language :: Python :: 3
License :: Oo :: CC-BY-SA-4.0 License
[options]
package_dir =
= src
packages = find:
python_requires = >=3.7
[options.packages.find]
where = src
EOF
cat > setup.py << EOF
import setuptools
setuptools.setup()
EOF
mkdir dist
for i in $out/PVL*; do
touch "$i/__init__.py"
done
mkdir -p src
mv -t $out/src $out/PVL*
'';
in
buildPythonPackage rec {
pname = "${ppvl}_G19";
version = "unstable";
src = base_src;
checkInputs = [ pytestCheckHook ];
doCheck = true;
meta = with lib; {
description = "DS-G19 ${ppvl} implementation in Python";
inherit homepage;
license = licenses.cc-by-sa-40;
maintainers = maintainers.zseri;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment