mykiwi/mykiwi.blogpublic Fork 0
b9bda7a8b01c38c6369f1e073f36bb851049f34b
Commits
Clone
git clone https://git.rickub.com/mykiwi/mykiwi.blog.git
git clone ssh://git@rickub.com/mykiwi/mykiwi.blog.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Add Spanish (es) language support 479f7e2 · on b9bda7a8b01c38c6369f1e073f36bb851049f34b · Romain Gautier · 8h ago
flake.nix · 103 lines · 3.6 KBNix Blame HistoryRaw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
{
  description = "mykiwi.blog dev shell";

  inputs.multiverse.url = "github:fzakaria/nixpkgs-multiverse";

  outputs = { self, multiverse }:
    let
      system = "x86_64-linux";
      pin = multiverse.multiverse.${system};
      pkgs = pin.tip;
      hugo = pin.version "hugo" "0.166.0";
      dart-sass = pin.version "dart-sass" "1.104.0";
      opentofu = pin.version "opentofu" "1.12.6";
      wrangler = pin.version "wrangler" "4.129.0";
    in
    {
      packages.${system}.default = pkgs.stdenvNoCC.mkDerivation {
        name = "mykiwi.blog";
        src = ./blog;
        nativeBuildInputs = [ hugo dart-sass ];
        buildPhase = ''
          HUGO_PARAMS_NIXSTOREPATH="$out" hugo --minify --destination "$out"
        '';
        dontInstall = true;
      };

      devShells.${system} = {
        default = pkgs.mkShell {
          name = "mykiwi-blog";

          packages = [
            hugo
            dart-sass
          ];

          shellHook = ''
            dim=$'\033[2m'
            reset=$'\033[0m'
            printf '%-11s%-9s%s%s%s\n' "Hugo" "$(hugo version | sed -n 's/.*v\([0-9.]*\)+.*/\1/p')" "$dim" "https://github.com/gohugoio/hugo/releases" "$reset"
            printf '%-11s%-9s%s%s%s\n' "Dart Sass" "$(sass --version)" "$dim" "https://github.com/sass/dart-sass/releases" "$reset"
          '';
        };

        # Cloudflare provisioning (infra/) - kept separate from the default
        # shell so writing a blog post doesn't require pulling in tofu/wrangler.
        infra = pkgs.mkShell {
          name = "mykiwi-blog-infra";

          packages = [
            opentofu
            wrangler
          ];

          shellHook = ''
            dim=$'\033[2m'
            reset=$'\033[0m'
            printf '%-11s%-9s%s%s%s\n' "OpenTofu" "$(tofu version | sed -n 's/OpenTofu v\([0-9.]*\)/\1/p')" "$dim" "https://github.com/opentofu/opentofu/releases" "$reset"
            printf '%-11s%-9s%s%s%s\n' "Wrangler" "$(wrangler --version)" "$dim" "https://github.com/cloudflare/workers-sdk/releases" "$reset"
          '';
        };
      };

      apps.${system} = {
        # `nix run .#infra -- plan` / `nix run .#infra -- apply` (or any
        # other tofu subcommand) against infra/, from wherever in the repo
        # you happen to be.
        infra = {
          type = "app";
          program = "${pkgs.writeShellApplication {
            name = "mykiwi-blog-infra";
            runtimeInputs = [ opentofu pkgs.git ];
            text = ''
              root="$(git rev-parse --show-toplevel)"
              tofu -chdir="$root/infra" init
              tofu -chdir="$root/infra" "$@"
            '';
          }}/bin/mykiwi-blog-infra";
        };

        # `nix run .#deploy` - builds the site (the same `packages.default`
        # derivation `nix build` uses) and pushes each language's output
        # folder to its matching Cloudflare Pages project. Needs
        # CLOUDFLARE_API_TOKEN, same as `infra`.
        deploy = {
          type = "app";
          program = "${pkgs.writeShellApplication {
            name = "mykiwi-blog-deploy";
            runtimeInputs = [ wrangler pkgs.git pkgs.nix ];
            text = ''
              root="$(git rev-parse --show-toplevel)"
              link="$(mktemp -d)/result"
              nix build "$root#default" --out-link "$link"
              for lang in en fr pt ja es; do
                project="mykiwi-blog-$lang"
                echo "==> deploying $lang -> $project"
                wrangler pages deploy "$link/$lang" --project-name="$project" --branch=main
              done
            '';
          }}/bin/mykiwi-blog-deploy";
        };
      };
    };
}