From d23ae91b74c30e90d44c0c53b297af5a40909f63 Mon Sep 17 00:00:00 2001 From: Histausse Date: Sat, 20 May 2023 23:11:08 +0200 Subject: [PATCH] add flake support --- TODO.md | 2 +- .../.woodpecker.yml | 12 +++++++ {{ cookiecutter.project_slug }}/README.md | 25 ++++++++++++- {{ cookiecutter.project_slug }}/flake.nix | 36 +++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 {{ cookiecutter.project_slug }}/flake.nix diff --git a/TODO.md b/TODO.md index 924f353..038ff67 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,4 @@ # TODO: -- add flake +- publish to gitea repo: [container](https://docs.gitea.io/en-us/usage/packages/container/) [badge](https://docs.gitea.io/en-us/usage/packages/generic/) - use bool value for `generate_gitea_project` when the feature is available diff --git a/{{ cookiecutter.project_slug }}/.woodpecker.yml b/{{ cookiecutter.project_slug }}/.woodpecker.yml index 8fe54b3..d00a7e9 100644 --- a/{{ cookiecutter.project_slug }}/.woodpecker.yml +++ b/{{ cookiecutter.project_slug }}/.woodpecker.yml @@ -1,5 +1,6 @@ pipeline: test: + group: test image: python:${PYTHON_VERSION} pull: true environment: @@ -9,6 +10,17 @@ pipeline: - poetry install - poetry run pytest + nix: + group: test + image: nixos/nix:latest + pull: true + commands: + - nix build --experimental-features 'nix-command flakes' + - nix build --experimental-features 'nix-command flakes' .#docker + when: + matrix: + PYTHON_VERSION: {{ cookiecutter. python_min_version}} # Still not sure about how to make flake for different python version + matrix: PYTHON_VERSION: - {{ cookiecutter. python_min_version}} diff --git a/{{ cookiecutter.project_slug }}/README.md b/{{ cookiecutter.project_slug }}/README.md index 1d18504..91f75a7 100644 --- a/{{ cookiecutter.project_slug }}/README.md +++ b/{{ cookiecutter.project_slug }}/README.md @@ -1,19 +1,42 @@ {% set is_open_source = cookiecutter.open_source_license != 'Proprietary' -%} {% set repo = "/".join(cookiecutter.git_origin.removesuffix(".git").split(":")[-1].split("/")[-2:]) %} # {{ cookiecutter.project_name }} -{% if cookiecutter.configure_ci %}[![CI status badge]({{ cookiecutter.woodpecker_server }}/api/badges/{{ repo }}/status.svg)](https://ci.pains-perdus.fr/histausse/test_ci_template){% endif %} +{% if cookiecutter.configure_ci == "True" %}[![CI status badge]({{ cookiecutter.woodpecker_server }}/api/badges/{{ repo }}/status.svg)](https://ci.pains-perdus.fr/histausse/test_ci_template){% endif %} {{ cookiecutter.project_short_description }} ## Install + +### With pip + This project can be installed using pip: ``` pip install git+{{ cookiecutter.project_url }}.git ``` +### With Nix + +There is a `flake.nix`, so you can clone the repo and use `nix shell` if you want. + +### Docker/Podman + +You can build a container image using nix. To build the image, in the repo, run: + +``` +nix build -o {{ cookiecutter.project_slug }}.img .#docker +``` + +You can then load the image with: + +``` +podman load < {{ cookiecutter.project_slug }}.img +``` + +(If you want to use the image, notice it uses nix and is very minimal). + {% if is_open_source %} ## License diff --git a/{{ cookiecutter.project_slug }}/flake.nix b/{{ cookiecutter.project_slug }}/flake.nix new file mode 100644 index 0000000..fbaaabc --- /dev/null +++ b/{{ cookiecutter.project_slug }}/flake.nix @@ -0,0 +1,36 @@ +{ + description = "{{ cookiecutter.project_short_description }}"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.poetry2nix = { + url = "github:nix-community/poetry2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, flake-utils, poetry2nix }: + flake-utils.lib.eachDefaultSystem (system: + let + inherit (poetry2nix.legacyPackages.${system}) mkPoetryApplication; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages = { + {{ cookiecutter.project_slug }} = mkPoetryApplication { projectDir = self; }; + docker = pkgs.dockerTools.buildImage { + name = "{{ cookiecutter.project_slug }}"; + tag = "latest"; + copyToRoot = pkgs.buildEnv { + name = "{{ cookiecutter.project_slug }}_root_img"; + paths = [ self.packages.${system}.{{ cookiecutter.project_slug }} ]; + pathsToLink = [ "/bin" ]; + }; + }; + default = self.packages.${system}.{{ cookiecutter.project_slug }}; + }; + + devShells.default = pkgs.mkShell { + packages = [ poetry2nix.packages.${system}.poetry ]; + }; + }); +}