Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gleam proxy #21

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json', '**/elm.json') }}
- uses: cachix/install-nix-action@v21
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/fc541b860a28.tar.gz
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/1e9c7c0203be.tar.gz
- uses: cachix/cachix-action@v12
with:
name: marco-daniels
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json', '**/elm.json') }}
- uses: cachix/install-nix-action@v21
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/fc541b860a28.tar.gz
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/1e9c7c0203be.tar.gz
- uses: cachix/cachix-action@v12
with:
name: marco-daniels
Expand Down
9 changes: 9 additions & 0 deletions buildWebsite.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
let
pkgs = (import ./nix/shared.nix).pkgs;

buildValidate = pkgs.writeScriptBin "buildValidate" ''
if [ ! -f ./dist/elm.js ]; then
echo "Elm build not found"
exit 1
fi
'';

buildWebsite = pkgs.writeScriptBin "buildWebsite" ''
${pkgs.elmPackages.elm-pages}/bin/elm-pages build --debug
${pkgs.elmPackages.elm-pages}/bin/elm-pages build || true
${buildValidate}/bin/buildValidate
'';

in pkgs.mkShell {
Expand Down
6 changes: 3 additions & 3 deletions nix/shared.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let
pkgs = import (fetchTarball {
name = "nixpkgs-23.05-darwin";
url = "https://github.com/NixOS/nixpkgs/archive/fc541b860a28.tar.gz";
sha256 = "0929i9d331zgv86imvsdzyfsrnr7zwhb7sdh8sw5zzsp7qsxycja";
name = "nixpkgs-23.05-darwin-2023-10-05";
url = "https://github.com/NixOS/nixpkgs/archive/1e9c7c0203be.tar.gz";
sha256 = "10qbybc9k3dj1xap9n0i3z7pc3svzwhclgsyfzzsf8cfh8l518pn";
}) { };

jsHandler = pkgs.writeShellScriptBin "jsHandler" ''
Expand Down
61 changes: 22 additions & 39 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,28 @@ let
jsHandler = (import ./nix/shared.nix).jsHandler;

cockpitProxy = let
proxyName = "cockpit-proxy";
proxyVersion = "1.0.0";
proxySrc = fetchGit {
url = "https://github.com/MarcoDaniels/cockpit-cms-proxy.git";
rev = "7ae8b96057d1b67dfb2e5ff226f76be91fbc1777";
};
proxyElm = pkgs.stdenv.mkDerivation {
name = "${proxyName}-elm-dep";
proxyName = "cockpit-proxy";
proxyVersion = "2.0.1";
nixGleamSrc = pkgs.stdenv.mkDerivation {
name = "nix-gleam";
src = fetchGit {
url = "https://github.com/arnarg/nix-gleam.git";
rev = "d1d2d6bcc5be6ea6a2d31e48aa55e7ea3bd41a1f";
};
installPhase = ''
mkdir -p $out
cp $src/builder/default.nix $out
'';
};
nixGleam = (pkgs.callPackage nixGleamSrc {});
in nixGleam.buildGleamApplication {
pname = proxyName;
version = proxyVersion;
src = proxySrc;
buildInputs = [ pkgs.elm2nix pkgs.nix pkgs.cacert ];
buildPhase = ''
${pkgs.elm2nix}/bin/elm2nix convert > default.nix
${pkgs.elm2nix}/bin/elm2nix snapshot
'';
installPhase = ''
mkdir -p $out
cp default.nix registry.dat $out
'';
};
in pkgs.stdenv.mkDerivation {
name = proxyName;
version = proxyVersion;
src = proxySrc;
buildInputs = [ pkgs.elmPackages.elm pkgs.nix pkgs.cacert ];
configurePhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import proxyElm;
elmVersion = "0.19.1";
registryDat = "${proxyElm}/registry.dat";
src = fetchGit {
url = "https://github.com/MarcoDaniels/cockpit-cms-proxy.git";
ref = "refs/tags/v${proxyVersion}";
};
};
buildPhase = ''
elm make --optimize src/Main.elm --output=dist/elm.js
sed -e '1i\#!/usr/bin/env node' src/index.js > dist/${proxyName}
'';
installPhase = ''
mkdir -p $out/bin
cp -a dist/. $out/bin/
chmod +x $out/bin/${proxyName}
'';
};

dot2Env = pkgs.stdenv.mkDerivation {
name = "dot2Env";
Expand All @@ -61,7 +43,7 @@ let

# concurrently Pages with Proxy & Preview
start = pkgs.writeShellScriptBin "start" ''
${pkgs.concurrently}/bin/concurrently "${pkgs.elmPackages.elm-pages}/bin/elm-pages dev" "${cockpitProxy}/bin/cockpit-proxy"
${pkgs.concurrently}/bin/concurrently "${pkgs.elmPackages.elm-pages}/bin/elm-pages dev" cockpit_cms_proxy
'';

# to include flags: buildLambda AssetRequest "{flags:{token:'123',domain:'abc'}}"
Expand Down Expand Up @@ -100,6 +82,7 @@ in pkgs.mkShell {
pkgs.elmPackages.elm-pages
pkgs.elm2nix

cockpitProxy
dot2Env
testLambda
jsHandler
Expand Down