Skip to content

Instantly share code, notes, and snippets.

@Cloudef
Last active October 18, 2022 15:45
Show Gist options
  • Save Cloudef/aeb761f4393f267646bfd0a0edb51326 to your computer and use it in GitHub Desktop.
Save Cloudef/aeb761f4393f267646bfd0a0edb51326 to your computer and use it in GitHub Desktop.
Nix file for InvokeAI for M1 mac
{ pkgs ? import <nixpkgs> {}
, lib ? pkgs.lib
, stdenv ? pkgs.stdenv
, fetchurl ? pkgs.fetchurl
, runCommand ? pkgs.runCommand
, makeWrapper ? pkgs.makeWrapper
, mkShell ? pkgs.mkShell
, installationPath ? (builtins.toString ./.) + "/.conda"
, frameworks ? pkgs.darwin.apple_sdk.frameworks
}:
let
version = "4.12.0";
src = fetchurl {
url = "https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh";
sha256 = "4bd112168cc33f8a4a60d3ef7e72b52a85972d588cd065be803eb21d73b625ef";
};
conda = (
runCommand "conda-install" { nativeBuildInputs = [ makeWrapper ]; }
''
mkdir -p $out/bin
cp ${src} $out/bin/miniconda-installer.sh
chmod +x $out/bin/miniconda-installer.sh
makeWrapper \
$out/bin/miniconda-installer.sh \
$out/bin/conda-install \
--add-flags "-p ${installationPath}" \
--add-flags "-b"
'');
in mkShell {
packages = with pkgs; [
conda
cmake
protobuf
libiconv
rustc
cargo
rustPlatform.bindgenHook
] ++ lib.optional (stdenv.isDarwin) [
frameworks.Security
];
shellHook = ''
conda-install
# Add conda to PATH
export PATH=${installationPath}/bin:$PATH
# Paths for gcc if compiling some C sources with pip
export NIX_CFLAGS_COMPILE="-I${installationPath}/include"
export NIX_CFLAGS_LINK="-L${installationPath}/lib $BINDGEN_EXTRA_CLANG_ARGS"
# Allows `conda activate` to work properly
source ${installationPath}/etc/profile.d/conda.sh
# rust-onig fails (think it writes config.h to wrong location)
cat <<'EOF' > ${installationPath}/include/config.h
#define HAVE_PROTOTYPES 1
#define STDC_HEADERS 1
#define HAVE_STRING_H 1
#define HAVE_STDARG_H 1
#define HAVE_STDLIB_H 1
#define HAVE_LIMITS_H 1
#define HAVE_INTTYPES_H 1
#define SIZEOF_INT 4
#define SIZEOF_SHORT 2
#define SIZEOF_LONG 8
#define SIZEOF_VOIDP 8
#define SIZEOF_LONG_LONG 8
EOF
# do InvokeAI setup
PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-arm64 conda env create -f environment-mac.yml
PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-arm64 conda env update --prune -f environment-mac.yml
conda activate invokeai
'';
meta = with pkgs.lib; {
homepage = "https://anaconda.com";
description = "Conda is a package manager for Python";
license = lib.licenses.bsd3;
# Might work straight out of box with linux too as long as src is changed
# Not tested thus, darwin only
platforms = lib.platforms.darwin;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment