-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
138 lines (133 loc) · 5.08 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
description = "Inference Combinators";
inputs = rec {
flake-utils.url = "github:numtide/flake-utils";
devshell.url = "github:numtide/devshell";
nixpkgs.url = "github:NixOS/nixpkgs/29b0d4d0b600f8f5dd0b86e3362a33d4181938f9";
mach-nix.url = "github:DavHau/mach-nix";
mach-nix.inputs.flake-utils.follows = "flake-utils";
mach-nix.inputs.nixpkgs.follows = "nixpkgs";
probtorch.url = "github:probtorch/probtorch/combinators-dev";
probtorch.flake = false;
};
outputs = { self, nixpkgs, flake-utils, mach-nix, probtorch, devshell }:
flake-utils.lib.eachSystem ["x86_64-linux"] (system:
let
inherit (mach-nix.lib.${system}) mkPython;
with-jupyter = false;
dev-profile = false;
with-simulator = true;
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlay ];
};
inherit (pkgs) lib mkShell;
in rec {
# FIXME: make this buildPythonApplication and move this to devShell only
packages.combinatorsPy = mkPython { # Package {
#src = ./.;
requirements = (builtins.readFile ./requirements.txt) + lib.strings.concatStringsSep "\n" ([
] ++ (lib.optionals with-simulator ["imageio" "scikit-image"])
++ (lib.optionals with-jupyter ["jupyterlab" "ipywidgets" "seaborn"])
++ (lib.optionals dev-profile ["filprofiler"]))
;
packagesExtra = [
probtorch
];
providers = {
_default = "nixpkgs,wheel";
torch = "wheel";
tqdm = "wheel";
torchvision = "wheel";
protobuf = "wheel"; # ...otherwise infinite recursion.
};
};
defaultPackage = packages.combinatorsPy;
devShell = pkgs.devshell.mkShell {
packages = with pkgs; [
packages.combinatorsPy
gnused
watchexec
rsync
];
# applying patch: https://github.com/microsoft/pyright/issues/565
bash.extra = ''
export PYTHONPATH="$(git rev-parse --show-toplevel):$PYTHONPATH"
export PYTHONBREAKPOINT='IPython.core.debugger.set_trace'
'';
bash.interactive = ''
VENV_NAME="$(echo ${packages.combinatorsPy} | sed -E 's/\/nix\/store\/(.*)-env/\1/')-env"
if [ -f pyrightconfig.json ]; then
DETECTED=$(\grep -oP "[^\"]\w+-python3-[23].[0-9].[0-9](-env)?" pyrightconfig.json)
if [ "$DETECTED" != "$VENV_NAME" ]; then
cp pyrightconfig.json{,.bk}
echo "detected venv $DETECTED in pyrightconfig.json, patching venv with $VENV_NAME"
sed -E -i "s/(\"venv\": \")\w+-python3-[23].[0-9].[0-9](-env)?/\1$VENV_NAME/" pyrightconfig.json
else
echo "detected matching venv $DETECTED in pyrightconfig.json"
fi
else
echo "did not detect pyrightconfig.json, generating new venv with $VENV_NAME"
cat > pyrightconfig.json << EOF
{
"pythonVersion": "3.8",
"pythonPlatform": "Linux",
"venv": "$VENV_NAME",
"venvPath": "/nix/store"
}
EOF
fi
'' + (lib.optionalString true ''
temp_dir=$(mktemp -d)
cat <<'EOF' >"$temp_dir/.zshrc"
if [ -e ~/.zshrc ]; then . ~/.zshrc; fi
if [ -e ~/.config/zsh/.zshrc ]; then . ~/.config/zsh/.zshrc; fi
menu
EOF
ZDOTDIR=$temp_dir zsh -i
'');
commands = let
watchexec = "${pkgs.watchexec}/bin/watchexec";
mk = category: {name, command}:
{ inherit category name;
command = command + "\n";
};
smoke-test = mk "smoke tests";
watcher = mk "watchers";
in [
(smoke-test {
name = "smoke-annealing";
command = "make RUN_FLAGS=\"--iterations 10\" ex/annealing";
})
(watcher {
name = "watch-annealing-dev";
command = "${watchexec} -e py '(cd ./experiments/annealing/ && echo \"=========================\" && python ./main.py --pdb)'";
})
(watcher {
name = "watch-short";
command = ''${watchexec} -e py "make RUN_FLAGS='--iterations 10' ex/$1"'';
})
(watcher {
name = "watch-rsync";
command = ''${watchexec} -e py "rsync-dev $1"'';
})
{
category = "deployment";
name = "rsync-dev";
command = ''
${pkgs.rsync}/bin/rsync -Paurzvh . $1""
'';
}
{
category = "deployment";
name = "upload-to-cachix";
command = ''
nix flake archive --json \
| ${pkgs.jq}/bin/jq -r '.path,(.inputs|to_entries[].value.path)' \
| cachix push combinators
'';
}
];
};
});
}