diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2d692e9..7f10ba0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,34 +1,20 @@ -name: "Test" +name: "Publish GH Pages" on: - pull_request: push: + branches: + - main jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v13 - with: - nix_path: nixpkgs=channel:nixos-20.09 - - run: nix-build --attr pages - - name: Artifact pages - uses: actions/upload-artifact@v2 - with: - name: pages - path: result/docs - deploy: - if: github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - needs: [build] - steps: - - uses: actions/checkout@v2.3.4 - - name: Download artifact - uses: actions/download-artifact@v2 - with: - name: pages - path: result/docs - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@4.1.4 - with: - branch: gh-pages - folder: result/docs + - uses: actions/checkout@v3 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Build the website (Nix) 🔧 + run: nix build .#website + - name: Deploy to gh-pages 🚀 + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./result/ + cname: changemetrics.io diff --git a/default.nix b/default.nix deleted file mode 100644 index af47e74..0000000 --- a/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -let - pkgs = (import (fetchTarball { - url = - "https://github.com/NixOS/nixpkgs/archive/6f3e97e3f8cca69ad2528c8459682900a9b34a2f.tar.gz"; - sha256 = "1gb59awicr84p68nnqkdmd9mdsnpar28jbskanrd71vsp5nw7c2p"; - })) { }; - gitignore = pkgs.nix-gitignore.gitignoreSource [ ] ./.; - drv = pkgs.haskellPackages.callCabal2nix "changemetrics-io" gitignore { }; -in { - drv = drv; - pages = pkgs.stdenv.mkDerivation { - name = "changemetrics.io-pages"; - buildInputs = [ drv ]; - src = drv.src; - # https://github.com/jaspervdj/hakyll/issues/614 - # https://github.com/NixOS/nix/issues/318#issuecomment-52986702 - # https://github.com/MaxDaten/brutal-recipes/blob/source/default.nix#L24 - LOCALE_ARCHIVE = - pkgs.lib.optionalString (pkgs.buildPlatform.libc == "glibc") - "${pkgs.glibcLocales}/lib/locale/locale-archive"; - LANG = "en_US.UTF-8"; - - buildPhase = '' - changemetrics-io build - ''; - installPhase = '' - mkdir -p "$out/docs" - cp -r ./_site/* "$out/docs" - ''; - }; - shell = pkgs.haskellPackages.shellFor { - packages = p: [ drv ]; - buildInputs = with pkgs.haskellPackages; [ cabal-install ]; - }; -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3a54715 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1704752602, + "narHash": "sha256-dXXXInXxfkfiuA5qOKHCky+woYSeg0KV+GBhU63bQzE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4770e67ec9d0d86389d339e8498f9e509f97fa86", + "type": "github" + }, + "original": { + "owner": "NixOS", + "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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e0e095b --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + description = "hakyll-website"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = inputs: + inputs.flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import inputs.nixpkgs { inherit system; }; + # the name of the cabal package and command line + name = "changemetrics-io"; + + haskellExtend = hpFinal: hpPrev: { + ${name} = + hpPrev.callCabal2nix name inputs.self { }; + }; + hsPkgs = pkgs.haskellPackages.extend haskellExtend; + + website = pkgs.stdenv.mkDerivation { + name = "${name}-pages"; + buildInputs = [ hsPkgs.${name} ]; + src = inputs.self; + # https://github.com/jaspervdj/hakyll/issues/614 + # https://github.com/NixOS/nix/issues/318#issuecomment-52986702 + # https://github.com/MaxDaten/brutal-recipes/blob/source/default.nix#L24 + LOCALE_ARCHIVE = + pkgs.lib.optionalString (pkgs.buildPlatform.libc == "glibc") + "${pkgs.glibcLocales}/lib/locale/locale-archive"; + LANG = "en_US.UTF-8"; + + buildPhase = '' + ${name} build + ''; + installPhase = '' + mv _site $out + ''; + }; + in { + packages.website = website; + devShell = hsPkgs.shellFor { + packages = p: [ p.${name} ]; + buildInputs = [ pkgs.cabal-install ]; + }; + }); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index af299aa..0000000 --- a/shell.nix +++ /dev/null @@ -1 +0,0 @@ -(import ./default.nix).shell