add flake support

This commit is contained in:
Histausse 2023-05-20 23:11:08 +02:00
parent fc90b3fb71
commit d23ae91b74
4 changed files with 73 additions and 2 deletions

View file

@ -1,4 +1,4 @@
# TODO: # 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 - use bool value for `generate_gitea_project` when the feature is available

View file

@ -1,5 +1,6 @@
pipeline: pipeline:
test: test:
group: test
image: python:${PYTHON_VERSION} image: python:${PYTHON_VERSION}
pull: true pull: true
environment: environment:
@ -9,6 +10,17 @@ pipeline:
- poetry install - poetry install
- poetry run pytest - 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: matrix:
PYTHON_VERSION: PYTHON_VERSION:
- {{ cookiecutter. python_min_version}} - {{ cookiecutter. python_min_version}}

View file

@ -1,19 +1,42 @@
{% set is_open_source = cookiecutter.open_source_license != 'Proprietary' -%} {% set is_open_source = cookiecutter.open_source_license != 'Proprietary' -%}
{% set repo = "/".join(cookiecutter.git_origin.removesuffix(".git").split(":")[-1].split("/")[-2:]) %} {% set repo = "/".join(cookiecutter.git_origin.removesuffix(".git").split(":")[-1].split("/")[-2:]) %}
# {{ cookiecutter.project_name }} # {{ 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 }} {{ cookiecutter.project_short_description }}
## Install ## Install
### With pip
This project can be installed using pip: This project can be installed using pip:
``` ```
pip install git+{{ cookiecutter.project_url }}.git 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 %} {% if is_open_source %}
## License ## License

View file

@ -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 ];
};
});
}