diff --git a/.github/actions/build_nix/action.yml b/.github/actions/build_nix/action.yml new file mode 100644 index 0000000..c39d7c9 --- /dev/null +++ b/.github/actions/build_nix/action.yml @@ -0,0 +1,84 @@ +name: Build/Cache Nix +description: Builds default devShell for a platform, caching the results (if applicable) +inputs: + cachix_cache: + description: "The name of the Cachix cache to download to and/or upload from" + required: true + default: "openlane" + cachix_token: + description: "An authentication token for Cachix" + required: false + default: "" + shell: + description: "Shell to use" + required: true + default: "bash" + nix_system: + description: "The nix platform string to build for" + required: true + default: "x86_64-linux" + local_cache_key: + description: Key to use for the cache + required: false + default: "" + run_tests: + description: Whether to run unit tests and the smoke test + required: false + default: "false" +runs: + using: "composite" + steps: + - id: cache + name: Cache Derivation + uses: actions/cache@v3 + with: + key: ${{ inputs.local_cache_key }}-${{ inputs.nix_system }} + path: /tmp/${{ inputs.local_cache_key }} + - id: Build + name: Build + shell: ${{ inputs.shell }} + run: | + substituters='https://${{ inputs.cachix_cache }}.cachix.org https://cache.nixos.org' + if [ '${{ inputs.local_cache_key }}' = '' ]; then + substituters="file:///tmp/${{ inputs.local_cache_key }} $substituters" + fi + echo "#################################################################" + outPath=$(nix build\ + --print-out-paths\ + --no-link\ + --accept-flake-config\ + --option system ${{ inputs.nix_system }}\ + --extra-platforms ${{ inputs.nix_system }}\ + --option substituters "$substituters"\ + .#devShells.${{ inputs.nix_system }}.default) + echo "out-path=$outPath" >> $GITHUB_OUTPUT + sudo du -hs /nix/store/* | sort -h | tail -n 20 + - name: Unit/Step Tests + shell: ${{ inputs.shell }} + if: inputs.run_tests == 'true' + run: echo TODO + - name: Smoke Test + shell: ${{ inputs.shell }} + if: inputs.run_tests == 'true' + run: | + echo "#################################################################" + nix run\ + --option system ${{ inputs.nix_system }}\ + --extra-platforms ${{ inputs.nix_system }}\ + --accept-flake-config\ + .#packages.${{ inputs.nix_system }}.cace -- --help + - name: Push to local cache + shell: ${{ inputs.shell }} + if: inputs.local_cache_key != '' && steps.cache.outputs.cache-hit != 'true' + run: | + nix copy\ + --to 'file:///tmp/${{ inputs.local_cache_key }}?compression=zstd¶llel-compression=true'\ + ${{ steps.build.outputs.out-path }} + - name: Install + Push to Cachix + shell: ${{ inputs.shell }} + if: ${{ inputs.cachix_token != '' }} + run: | + echo "#################################################################" + nix-env -iA cachix -f https://cachix.org/api/v1/install + cachix authtoken ${{ inputs.cachix_token }} + cachix push ${{ inputs.cachix_cache }} ${{ steps.build.outputs.out-path }} diff --git a/.github/actions/check_space/action.yml b/.github/actions/check_space/action.yml new file mode 100644 index 0000000..b34312f --- /dev/null +++ b/.github/actions/check_space/action.yml @@ -0,0 +1,22 @@ +name: Check Space +description: Reusable step that prints disk usage information +runs: + using: "composite" + steps: + - name: Check Space + shell: bash + run: | + if test -d /nix/store; then + sudo du -hs /nix/store/* | sort -h | tail -n 10 + fi + echo =============== + df -h + echo =============== + du -hs ~/* | sort -h + echo =============== + du -hs * | sort -h + echo =============== + du -hs /home/runner/runners/* | sort -h + echo =============== + du -hs /home/runner/work/* | sort -h + echo =============== diff --git a/.github/actions/setup_env/action.yml b/.github/actions/setup_env/action.yml new file mode 100644 index 0000000..a5ac222 --- /dev/null +++ b/.github/actions/setup_env/action.yml @@ -0,0 +1,28 @@ +name: Set up environment +description: Sets up a number of environment variables that are useful for publishing +runs: + using: "composite" + steps: + - name: Export Repo URL + shell: bash + run: echo "REPO_URL=https://github.com/${{ github.repository }}.git" >> $GITHUB_ENV + + - name: Export Branch Name + shell: bash + run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV + + - name: Set default for env.NEW_TAG + shell: bash + run: echo "NEW_TAG=NO_NEW_TAG" >> $GITHUB_ENV + + - name: Check for new version + if: ${{ github.event_name == 'push' && env.BRANCH_NAME == 'main' }} + shell: bash + run: | + python3 ./.github/scripts/generate_tag.py + + - name: Publish + if: ${{ github.event_name == 'push' && env.BRANCH_NAME == 'main' && env.NEW_TAG != 'NO_NEW_TAG' }} + shell: bash + run: | + echo "PUBLISH=1" >> $GITHUB_ENV diff --git a/.github/workflows/ci_nix.yml b/.github/workflows/ci_nix.yml new file mode 100644 index 0000000..f05ab5c --- /dev/null +++ b/.github/workflows/ci_nix.yml @@ -0,0 +1,285 @@ +name: CI-Nix + +# Events that trigger workflow +on: + # Runs on all pushes to branches + push: + # Runs on all PRs + pull_request: + # Runs every day at midnight UTC + schedule: + - cron: "0 0 * * *" + # Manual Dispatch + workflow_dispatch: + +jobs: + prepare-pdks: + name: Cache PDKs + runs-on: ubuntu-22.04 + outputs: + opdks_rev: ${{ steps.set-rev.outputs.opdks_rev }} + steps: + - uses: actions/checkout@v3 + - name: Python Dependencies + run: | + python3 -m pip install -r ./requirements.txt + - name: Get Open PDKs Revision + id: set-rev + run: | + echo "opdks_rev=$(cat ./cace/open_pdks_rev)" >> $GITHUB_OUTPUT + - name: Cache sky130 PDK + uses: actions/cache@v3 + with: + path: ${{ github.workspace }}/.volare-sky130 + key: cache-sky130-pdk-${{ steps.set-rev.outputs.opdks_rev }} + - name: Enable sky130 PDK + run: | + export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + volare enable --pdk sky130 --pdk-root ${{ github.workspace }}/.volare-sky130 ${{ steps.set-rev.outputs.opdks_rev }} + - name: Cache gf180mcu PDK + uses: actions/cache@v3 + with: + path: ${{ github.workspace }}/.volare-gf180mcu + key: cache-gf180mcu-pdk-${{ steps.set-rev.outputs.opdks_rev }} + - name: Enable gf180mcu PDK + run: | + export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + volare enable --pdk gf180mcu --pdk-root ${{ github.workspace }}/.volare-gf180mcu ${{ steps.set-rev.outputs.opdks_rev }} + - name: Checkout submodules + uses: actions/checkout@v3 + with: + submodules: true + lint: + name: Lint + runs-on: ubuntu-22.04 + steps: + - name: Check out repo + uses: actions/checkout@v3 + - name: Set Up Python + uses: actions/setup-python@v4 + with: + python-version: "3.8" + - name: Install Dependencies + run: make dependencies + - name: Lint + run: | + make lint + build-py: + runs-on: ubuntu-22.04 + needs: [lint, prepare-pdks] + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + fail-fast: false + name: Build and Unit Test (Python ${{ matrix.python-version }}) + steps: + - name: Check out repo + uses: actions/checkout@v3 + - name: Set Up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Cache sky130 PDK + id: cache-sky130-pdk + uses: actions/cache@v3 + with: + path: ${{ github.workspace }}/.volare-sky130 + key: cache-sky130-pdk-${{ needs.prepare-pdks.outputs.opdks_rev }} + - name: Enable sky130 PDK + if: steps.cache-sky130-pdk.outputs.cache-hit != 'true' + run: | + pip3 install -r ./requirements.txt + export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + volare enable --pdk sky130 --pdk-root ${{ github.workspace }}/.volare-sky130 ${{ needs.prepare-pdks.outputs.opdks_rev }} + - name: Run Unit Tests + run: echo TODO + build-linux-amd64: + needs: lint + runs-on: ubuntu-22.04 + name: Build (Nix on Linux/amd64) + steps: + - uses: actions/checkout@v3 + - name: Set up GITHUB_TOKEN + run: | + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + - name: Install Nix + run: | + sh <(curl -L https://nixos.org/nix/install) --yes --daemon --nix-extra-conf-file /dev/stdin <> $GITHUB_ENV + - name: Build with Nix + uses: ./.github/actions/build_nix + with: + nix_system: x86_64-linux + local_cache_key: derivation-${{ github.run_id }} + cachix_cache: ${{ vars.CACHIX_CACHE || 'openlane' }} + cachix_token: "${{ secrets.CACHIX_TOKEN }}" + run_tests: "true" + build-linux-aarch64: + needs: lint + runs-on: ubuntu-22.04 + name: Build (Nix on Linux/aarch64) + steps: + - uses: docker/setup-qemu-action@v1 + - uses: actions/checkout@v3 + - name: Set up GITHUB_TOKEN + run: | + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + - uses: DeterminateSystems/nix-installer-action@main # Using the DS Nix installer because it also sets up binfmt + - name: Build with Nix + uses: ./.github/actions/build_nix + with: + nix_system: aarch64-linux + local_cache_key: derivation-${{ github.run_id }} + cachix_cache: ${{ vars.CACHIX_CACHE || 'openlane' }} + cachix_token: "${{ secrets.CACHIX_TOKEN }}" + run_tests: "true" + build-mac-amd64: + needs: lint + runs-on: macos-12 + name: Build (Nix on macOS/amd64) + steps: + - uses: actions/checkout@v3 + - name: Set up GITHUB_TOKEN + run: | + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + - name: Install Nix + run: | + sh <(curl -L https://nixos.org/nix/install) --yes --nix-extra-conf-file /dev/stdin <> $GITHUB_ENV + - name: Build with Nix + uses: ./.github/actions/build_nix + with: + nix_system: x86_64-darwin + local_cache_key: derivation-${{ github.run_id }} + cachix_cache: ${{ vars.CACHIX_CACHE || 'openlane' }} + cachix_token: "${{ secrets.CACHIX_TOKEN }}" + shell: "zsh {0}" + run_tests: "true" + build-docker: + runs-on: ubuntu-22.04 + strategy: + matrix: + arch: ["amd64", "aarch64"] + needs: [build-linux-amd64, build-linux-aarch64] + name: Build Docker Image (${{ matrix.arch }}) + steps: + - name: Maximize build space + uses: easimon/maximize-build-space@master + with: + remove-dotnet: "true" + remove-android: "true" + remove-haskell: "true" + remove-codeql: "true" + remove-docker-images: "true" + root-reserve-mb: 20480 + - name: Check out repo + uses: actions/checkout@v3 + + - uses: docker/setup-qemu-action@v1 + - name: Set Nix System + run: | + nix_system=x86_64-linux + if [ "${{ matrix.arch }}" == "aarch64" ]; then + nix_system=aarch64-linux + fi + echo "NIX_SYSTEM=$nix_system" >> $GITHUB_ENV + - uses: DeterminateSystems/nix-installer-action@main + - name: Build with Nix + uses: ./.github/actions/build_nix + with: + nix_system: ${{ env.NIX_SYSTEM }} + local_cache_key: derivation-${{ github.run_id }} + cachix_cache: ${{ vars.CACHIX_CACHE || 'openlane' }} + + - name: Build Docker Image + run: | + IMAGE_PATH=$(nix build\ + --print-out-paths\ + --no-link\ + --accept-flake-config\ + --option system ${{ env.NIX_SYSTEM }}\ + --extra-platforms ${{ env.NIX_SYSTEM }}\ + .#packages.${{ env.NIX_SYSTEM }}.cace-docker) + echo "IMAGE_PATH=$IMAGE_PATH" >> $GITHUB_ENV + cat $IMAGE_PATH | docker load + - name: Set Up Python + uses: actions/setup-python@v4 + with: + python-version: "3.8" + - name: Install Dependencies + run: make dependencies + # Do not cache the PDK. We want to test the typical Docker flow here. + - name: Smoke-Test Docker Image + run: echo TODO + - name: Upload Docker Artifact + uses: actions/upload-artifact@v3 + with: + name: docker-image-${{ matrix.arch }} + path: ${{ env.IMAGE_PATH }} + test: + runs-on: ubuntu-22.04 + needs: [build-linux-amd64, prepare-pdks] + name: Test Design ${{ matrix.test_name }} (${{ matrix.pdk }}) + strategy: + fail-fast: false + matrix: + test_name: ["test"] + pdk: ["sky130A"] + pdk_family: ["sky130"] + steps: + - name: Maximize build space + uses: easimon/maximize-build-space@master + with: + remove-dotnet: "true" + remove-android: "true" + remove-haskell: "true" + remove-codeql: "true" + remove-docker-images: "true" + root-reserve-mb: 20480 + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Check if Git + run: | + git status || true + tree .git || true + + - uses: DeterminateSystems/nix-installer-action@main + + - name: Build with Nix + uses: ./.github/actions/build_nix + with: + nix_system: x86_64-linux + local_cache_key: derivation-${{ github.run_id }} + cachix_cache: ${{ vars.CACHIX_CACHE || 'openlane' }} + + - name: Check Nix + run: | + sudo du -hs /nix/store/* | sort -h | tail -n 10 + sudo tree /nix/store/*-openlane2 || true + - name: Cache PDKs + id: cache-pdks + uses: actions/cache@v3 + with: + path: ${{ github.workspace }}/.volare-${{ matrix.pdk_family }} + key: cache-${{ matrix.pdk_family }}-pdk-${{ needs.prepare-pdks.outputs.opdks_rev }} + + - name: Enable PDKs + if: steps.cache-pdks.outputs.cache-hit != 'true' + run: | + pip3 install -r ./requirements.txt + volare enable --pdk ${{ matrix.pdk_family }} \ + --pdk-root ${{ github.workspace }}/.volare-${{ matrix.pdk_family }} \ + ${{ needs.prepare-pdks.outputs.opdks_rev }} diff --git a/cace/open_pdks_rev b/cace/open_pdks_rev new file mode 100644 index 0000000..49ce447 --- /dev/null +++ b/cace/open_pdks_rev @@ -0,0 +1 @@ +4d5af10bfee4dab799566aaf903bb22aee69bac9 diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..b27765f --- /dev/null +++ b/default.nix @@ -0,0 +1,99 @@ +# Copyright 2024 Efabless Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + lib, + nix-gitignore, + buildPythonPackage, + setuptools, + setuptools_scm, + + # Tools + klayout, + klayout-pymod, + magic, + netgen, + volare, + octave, + xschem, + ngspice, + + # PIP + matplotlib, + numpy, + pillow, + tkinter, +}: +buildPythonPackage rec { + name = "cace"; + format = "pyproject"; + + version_file = builtins.readFile ./cace/__version__.py; + version_list = builtins.match ''.+''\n__version__ = '([^']+)'.+''\n.+''$'' version_file; + version = builtins.head version_list; + + src = [ + ./README.md + ./pyproject.toml + (nix-gitignore.gitignoreSourcePure "__pycache__" ./cace) + ./requirements.txt + ]; + + unpackPhase = '' + echo $src + for file in $src; do + BASENAME=$(python3 -c "import os; print('$file'.split('-', maxsplit=1)[1], end='$EMPTY')") + cp -r $file $PWD/$BASENAME + done + ls -lah + ''; + + buildInputs = [ + setuptools + setuptools_scm + ]; + + includedTools = [ + klayout + magic + netgen + octave + ngspice + xschem + ]; + + propagatedBuildInputs = [ + # Python + matplotlib + numpy + pillow + volare + tkinter + ] + ++ includedTools; + + computed_PATH = lib.makeBinPath propagatedBuildInputs; + + # Make PATH available to OpenLane subprocesses + makeWrapperArgs = [ + "--prefix PATH : ${computed_PATH}" + ]; + + meta = with lib; { + description = "Circuit Automatic Characterization Engine"; + homepage = "https://github.com/efabless/cace"; + license = licenses.asl20; + mainProgram = "cace"; + platforms = platforms.linux ++ platforms.darwin; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..689881b --- /dev/null +++ b/flake.lock @@ -0,0 +1,80 @@ +{ + "nodes": { + "flake-compat": { + "locked": { + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "nix-eda": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1715762084, + "narHash": "sha256-ho3bgzv4DnahsMrMIYIk8dVIyp35+oEzCx18p27BmSc=", + "owner": "efabless", + "repo": "nix-eda", + "rev": "facd74ff9583bc876b608aaa17e6fa6ab7a7ba7b", + "type": "github" + }, + "original": { + "owner": "efabless", + "repo": "nix-eda", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "narHash": "sha256-C36QmoJd5tdQ5R9MC1jM7fBkZW9zBUqbUCsgwS6j4QU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c1be43e8e837b8dbee2b3665a007e761680f0c3d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "nix-eda": "nix-eda", + "volare": "volare" + } + }, + "volare": { + "inputs": { + "nixpkgs": [ + "nix-eda", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1715167549, + "narHash": "sha256-QzMKToqiDQzMjBM2TW1VGMUxSLj70Uk4IdJVjIdkd5c=", + "owner": "efabless", + "repo": "volare", + "rev": "b72ce150b80f67278d4c6b025183fb3941cab993", + "type": "github" + }, + "original": { + "owner": "efabless", + "repo": "volare", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..10c50d6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,90 @@ +# Copyright 2024 Efabless Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + nixConfig = { + extra-substituters = [ + "https://openlane.cachix.org" + ]; + extra-trusted-public-keys = [ + "openlane.cachix.org-1:qqdwh+QMNGmZAuyeQJTH9ErW57OWSvdtuwfBKdS254E=" + ]; + }; + + inputs = { + nix-eda.url = github:efabless/nix-eda; + volare.url = github:efabless/volare; + flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; + }; + + inputs.volare.inputs.nixpkgs.follows = "nix-eda/nixpkgs"; + + outputs = { + self, + nix-eda, + volare, + ... + }: let + package-config = { + current = self; + withInputs = [nix-eda volare]; + }; + in { + # Helper functions + createCaceShell = import ./nix/create-shell.nix; + + # Outputs + packages = nix-eda.forAllSystems package-config (util: + with util; + rec { + colab-env = callPackage ./nix/colab-env.nix {}; + cace = callPythonPackage ./default.nix {}; + default = cace; + } + // (pkgs.lib.optionalAttrs (pkgs.stdenv.isLinux) {cace-docker = callPackage ./nix/docker.nix {createDockerImage = nix-eda.createDockerImage;};})); + + devShells = nix-eda.forAllSystems package-config ( + util: + with util; rec { + default = + callPackage (self.createCaceShell { + }) {}; + notebook = callPackage (self.createCaceShell { + extra-packages = with pkgs; [ + jupyter + ]; + }) {}; + dev = callPackage (self.createCaceShell { + extra-packages = with pkgs; [ + ]; + extra-python-packages = with pkgs.python3.pkgs; [ + setuptools + build + twine + black # blue + ]; + }) {}; + docs = callPackage (self.createCaceShell { + extra-packages = with pkgs; [ + ]; + extra-python-packages = with pkgs.python3.pkgs; [ + sphinx + myst-parser + furo + sphinx-autobuild + ]; + }) {}; + } + ); + }; +} diff --git a/nix/colab-env.nix b/nix/colab-env.nix new file mode 100644 index 0000000..c42d588 --- /dev/null +++ b/nix/colab-env.nix @@ -0,0 +1,23 @@ +# Copyright 2024 Efabless Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + system, + cace, + python3, + symlinkJoin, +}: +symlinkJoin { + name = "cace-colab-env"; + paths = cace.includedTools; +} diff --git a/nix/create-shell.nix b/nix/create-shell.nix new file mode 100644 index 0000000..4a130aa --- /dev/null +++ b/nix/create-shell.nix @@ -0,0 +1,63 @@ +# Copyright 2024 Efabless Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + extra-packages ? [], + extra-python-packages ? [] +}: ({ + lib, + cace, + git, + zsh, + delta, + neovim, + gtkwave, + coreutils, + graphviz, + python3, + mkShell, +}: let + cace-env = ( + python3.withPackages (pp: + with pp; + [ + cace + ] + ++ extra-python-packages) + ); + cace-env-sitepackages = "${cace-env}/${cace-env.sitePackages}"; +in + mkShell { + name = "cace-shell"; + + propagatedBuildInputs = + [ + cace-env + + # Conveniences + git + zsh + delta + neovim + gtkwave + coreutils + graphviz + ] + ++ extra-packages + ++ cace.includedTools; + + PYTHONPATH = "${cace-env-sitepackages}"; # Allows venvs to work properly + shellHook = '' + export PS1="\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] "; + ''; + }) diff --git a/nix/docker.nix b/nix/docker.nix new file mode 100644 index 0000000..de90a64 --- /dev/null +++ b/nix/docker.nix @@ -0,0 +1,82 @@ +# Copyright 2024 Efabless Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +{ + createDockerImage, + dockerTools, + system, + pkgs, + lib, + python3, + cace, + git, + neovim, + zsh, + silver-searcher, + coreutils, +}: let + # # We're fetchurl-ing this one so we don't want to use a fixed-output derivation + # # like fetchFromGitHub + # # See https://nixos.org/manual/nix/stable/language/import-from-derivation + # nix-docker-image-script = builtins.fetchurl { + # url = "https://raw.githubusercontent.com/NixOS/nix/master/docker.nix"; + # sha256 = "sha256:0kpj0ms09v7ss86cayf3snpsl6pnjgjzk5wcsfp16ggvr2as80ai"; + # }; + cace-env = python3.withPackages (ps: with ps; [cace]); + cace-env-sitepackages = "${cace-env}/${cace-env.sitePackages}"; + cace-env-bin = "${cace-env}/bin"; +in + createDockerImage { + inherit pkgs; + inherit lib; + name = "cace"; + tag = "tmp-${system}"; + extraPkgs = with dockerTools; [ + git + zsh + neovim + silver-searcher + + cace-env + ]; + nixConf = { + extra-experimental-features = "nix-command flakes repl-flake"; + }; + maxLayers = 2; + channelURL = "https://nixos.org/channels/nixos-23.11"; + + image-created = "now"; + image-extraCommands = '' + mkdir -p ./etc + cat < ./etc/zshrc + autoload -U compinit && compinit + autoload -U promptinit && promptinit && prompt suse && setopt prompt_sp + autoload -U colors && colors + + export PS1=$'%{\033[31m%}CACE Container (${cace.version})%{\033[0m%}:%{\033[32m%}%~%{\033[0m%}%% '; + HEREDOC + ''; + image-config-cmd = ["${zsh}/bin/zsh"]; + image-config-extra-env = [ + "LANG=C.UTF-8" + "LC_ALL=C.UTF-8" + "LC_CTYPE=C.UTF-8" + "EDITOR=nvim" + "PYTHONPATH=${cace-env-sitepackages}" + "TMPDIR=/tmp" + ]; + image-config-extra-path = [ + "${cace-env-bin}" + "${cace.computed_PATH}" + ]; + } diff --git a/requirements.txt b/requirements.txt index 1ecc395..82f3a80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ matplotlib>=3.6.0 numpy>=1.20.0 pillow>=10.1.0 +volare>=0.16.0 diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d7c46b9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,14 @@ +( + import + ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + {src = ./.;} +) +.shellNix