Commit 64f255db authored by Yamada Hiroyuki's avatar Yamada Hiroyuki
Browse files

Merge branch 'Feature_nix'

parents 5288e05e 4d9bbde8
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
build
dist
wheelhouse
result
*egg-info
*.so
*.c
+11 −79
Original line number Diff line number Diff line
stages:
  - export_org
  - build
  - page_build
  - page_deploy


.build_template: &build_env
  image: python:3.12
site:
  stage: page_build
  image: nixos/nix
  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip"
    GIT_SUBMODULE_STRATEGY: recursive
  cache:
    - key:
        files:
          - pyproject.toml
          - setup.py
      paths:
        - "$PIP_CACHE_DIR"


cpprb_build:
  <<: *build_env
  stage: build
  needs:
    - README_MD
  script:
    - pip wheel . -w dist --no-deps
  artifacts:
    paths:
      - dist/*.whl
      - src/cpprb/*.html

emacs:
  image: iquiw/alpine-emacs
  stage: export_org
  script:
    - emacs --batch README.org -l site/init.el --eval '(setq debug-on-error t)' --eval '(org-hugo-export-wim-to-md :all-subtrees nil t)'
    - emacs --batch CHANGELOG.org -l site/init.el --eval '(org-hugo-export-wim-to-md :all-subtrees nil t)'
    - cd site
    - emacs --batch site.org -l init.el --eval '(org-hugo-export-wim-to-md :all-subtrees nil t)'
  artifacts:
    paths:
      - site/content
  except:
    - schedules

README_MD:
  image: iquiw/alpine-emacs
  stage: export_org
  script:
    - emacs --batch README.org --eval '(org-md-export-to-markdown)'
  artifacts:
    paths:
      - README.md
  except:
    - schedules

hugo:
  image: registry.gitlab.com/pages/hugo:latest
  stage: page_build
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
  environment: production
  script:
    - hugo version
    - cd site
    - hugo -c content --logLevel info
  artifacts:
          - flake.nix
          - flake.lock
      paths:
      - public
  needs:
    - emacs
  except:
    - schedules

sphinx:
  <<: *build_env
  stage: page_build
  environment: production
        - /nix/store
  script:
    - pip install $(echo dist/*.whl) "sphinx" "sphinx_rtd_theme" "sphinx-automodapi"
    - sphinx-build -b html sphinx public/api
    - nix --experimental-features 'nix-command flakes' build .?submodules=1#site
    - cp -r result/public public
  artifacts:
    paths:
      - sphinx/*.rst
      - public
  needs:
    - cpprb_build
  except:
    - schedules

pages:
  image: alpine
@@ -100,5 +32,5 @@ pages:
      - public
  only:
    - master
  except:
    - schedules
  needs:
    - site

cpprb.nix

0 → 100644
+36 −0
Original line number Diff line number Diff line
{
  pkgs,
  lib,
  ps,
  readme,
}: ps.buildPythonPackage {
  pname = "cpprb";

  version = "11.0.0";

  doCheck = false;

  pyproject = true;

  build-system = [
    ps.setuptools
    ps.wheel
    ps.cython
    ps.numpy_2
  ];

  src = lib.fileset.toSource {
    root = ./.;
    fileset = lib.fileset.unions [
      ./pyproject.toml
      ./setup.py
      ./LICENSE
      ./MANIFEST.in
      ./src
    ];
  };

  patchPhase = ''
    cp ${readme}/README.md ./README.md
  '';
}

flake.lock

0 → 100644
+61 −0
Original line number Diff line number Diff line
{
  "nodes": {
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1731533236,
        "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1733935885,
        "narHash": "sha256-xyiHLs6KJ1fxeGmcCxKjJE4yJknVJxbC8Y/ZRYyC8WE=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "5a48e3c2e435e95103d56590188cfed7b70e108c",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": "nixpkgs"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

flake.nix

0 → 100644
+105 −0
Original line number Diff line number Diff line
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = nixpkgs.legacyPackages.${system};
      lib = nixpkgs.lib;
      export = "(progn (require 'ox) (require 'ox-hugo) (setq org-src-preserve-indentation t) (org-hugo-export-wim-to-md :all-subtrees nil t))";
    in
      {
        packages = rec {
          readme = pkgs.stdenv.mkDerivation {
            name = "cpprb-readme";

            src = lib.fileset.toSource {
              root = ./.;
              fileset = lib.fileset.unions [
                ./README.org
                ./LICENSE
              ];
            };

            nativeBuildInputs = [
              pkgs.emacs
            ];

            buildPhase = ''
              emacs --batch README.org --eval "(org-md-export-to-markdown)"
            '';

            installPhase = ''
              mkdir -p $out
              cp ./README.md $out/README.md
            '';
          };

          python-311 = pkgs.callPackage ./cpprb.nix {
            inherit pkgs;
            inherit lib;
            ps = pkgs.python311Packages;
            readme = readme;
          };

          python-312 = pkgs.callPackage ./cpprb.nix {
            inherit pkgs;
            inherit lib;
            ps = pkgs.python312Packages;
            readme = readme;
          };

          site = pkgs.stdenv.mkDerivation {
            name = "cpprb-site";

            src = lib.fileset.toSource {
              root = ./.;
              fileset = lib.fileset.unions [
                ./README.org
                ./CHANGELOG.org
                ./LICENSE
                ./site
                ./sphinx
                ./example
              ];
            };

            nativeBuildInputs = [
              pkgs.graphviz
              pkgs.hugo
              (pkgs.emacs.pkgs.withPackages (epkgs: (with epkgs.melpaStablePackages; [
                ox-hugo
              ])))
              (pkgs.python312.withPackages (ps: (with ps; [
                numpy
                sphinx
                sphinx-rtd-theme
                sphinx-automodapi
                python-312
              ])))
            ];

            buildPhase = ''
              emacs --batch README.org --eval "${export}"
              emacs --batch CHANGELOG.org --eval "${export}"
              cd site
              emacs --batch site.org --eval "${export}"
              hugo -c content --logLevel info
              cd ../

              mkdir -p public/api
              sphinx-build -b html sphinx public/api
            '';

            installPhase = ''
              mkdir -p $out/public
              cp -r public $out/
            '';
          };
        };
      }
  );
}