From 0ed126564a76de197935c29b8512ee013d9b05be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 13 Nov 2023 18:27:17 +0100 Subject: [PATCH] add new entry about Nix --- .github/workflows/hugo.yaml | 78 +++++++++++++++++++ archetypes/default.md | 6 ++ config.toml | 4 +- ...23-11-13 Nix recipe for python projects.md | 58 ++++++++++++++ 4 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/hugo.yaml create mode 100644 archetypes/default.md create mode 100644 content/post/2023-11-13 Nix recipe for python projects.md diff --git a/.github/workflows/hugo.yaml b/.github/workflows/hugo.yaml new file mode 100644 index 0000000..23fcb75 --- /dev/null +++ b/.github/workflows/hugo.yaml @@ -0,0 +1,78 @@ +# Sample workflow for building and deploying a Hugo site to GitHub Pages +name: Deploy Hugo site to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: + - hugo + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +# Default to bash +defaults: + run: + shell: bash + +jobs: + # Build job + build: + runs-on: ubuntu-latest + env: + HUGO_VERSION: 0.120.3 + steps: + - name: Install Hugo CLI + run: | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Install Dart Sass + run: sudo snap install dart-sass + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + - name: Setup Pages + id: pages + uses: actions/configure-pages@v3 + - name: Install Node.js dependencies + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" + - name: Build with Hugo + env: + # For maximum backward compatibility with Hugo modules + HUGO_ENVIRONMENT: production + HUGO_ENV: production + run: | + hugo \ + --gc \ + --minify \ + --baseURL "${{ steps.pages.outputs.base_url }}/" + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: ./public + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/archetypes/default.md b/archetypes/default.md new file mode 100644 index 0000000..bc4096a --- /dev/null +++ b/archetypes/default.md @@ -0,0 +1,6 @@ +--- +date: '{{ .Date }}' +draft: true +title: '{{ replace .File.ContentBaseName `-` ` ` | title }}' +--- + diff --git a/config.toml b/config.toml index 0e8f670..6af4b77 100644 --- a/config.toml +++ b/config.toml @@ -20,7 +20,7 @@ copyright = "This work is licensed under a Creative Commons Attribution-ShareAli tag = "tags" post = "posts" -[Author] +[params.author] name = "J. Fernando Sánchez" profile = "http://balkian.com" @@ -161,4 +161,4 @@ copyright = "This work is licensed under a Creative Commons Attribution-ShareAli startLevel = 1 [markup.goldmark.renderer] -unsafe= true \ No newline at end of file +unsafe= true diff --git a/content/post/2023-11-13 Nix recipe for python projects.md b/content/post/2023-11-13 Nix recipe for python projects.md new file mode 100644 index 0000000..d7b7732 --- /dev/null +++ b/content/post/2023-11-13 Nix recipe for python projects.md @@ -0,0 +1,58 @@ +--- +date: '2023-11-13T18:21:46+01:00' +title: 'Nix Recipe for Python Projects' +--- + + +This is a quick and easy recipe to add a `default.nix` to any Python project with a `requirements.txt` file: + + +```nix +with import { }; + +let + pythonPackages = python311Packages; +in pkgs.mkShell rec { + name = "impurePythonEnv"; + venvDir = "./.venv"; + buildInputs = [ + # A python interpreter including the 'venv' module is required to bootstrap + # the environment. + pythonPackages.python + + # This execute some shell code to initialize a venv in $venvDir before + # dropping into the shell + pythonPackages.venvShellHook + + # Those are dependencies that we would like to use from nixpkgs, which will + # add them to PYTHONPATH and thus make them accessible from within the venv. + pythonPackages.numpy + pythonPackages.requests + + # In this particular example, in order to compile any binary extensions they may + # require, the python modules listed in the hypothetical requirements.txt need + # the following packages to be installed locally: + taglib + openssl + git + libxml2 + libxslt + libzip + zlib + ]; + + # Now we can execute any commands within the virtual environment. + # This is optional and can be left out to run pip manually. + postShellHook = '' + pip install -r requirements.txt + ''; + +} +``` + + +Now, you will get a clean environment by running: + +``` +nix-shell +```