Compare commits

..

4 commits

Author SHA1 Message Date
Yehowshua d4745bc9d8 Merge pull request 'Add flake' (#1) from Artturin/example-spa-elm-app:addflake1 into convert_to_actix
Reviewed-on: Yehowshua/example-spa-elm-app#1
Reviewed-by: Yehowshua <yehowshua@joyofhardware.com>
2025-01-04 03:53:27 +00:00
Artturin 21627fb3b9 Make the port configurable 2025-01-04 01:20:22 +02:00
Artturin 9ebdbdb36a Makefile: fix frontend build
Its make was moved to `serve` target in ccec612687, but we can't use `serve` target in the nix build

It's also run after `frontend` target is already built which probably causes the `frontend` target to build.
2025-01-04 01:08:26 +02:00
Artturin 2b49ed618d Add flake 2025-01-04 00:56:19 +02:00
8 changed files with 373 additions and 3 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ frontend/package.json
backend/target
public/*
elm-stuff/*
result

View file

@ -29,6 +29,7 @@ $(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)
.PHONY: frontend backend
frontend: $(PUBLIC_DIR)/index.html $(PUBLIC_DIR)
make -C $(FRONTEND_DIR)
cp $(FRONTEND_DIR)/elm.min.js $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/
mkdir -p $(PUBLIC_DIR)/assets
@ -37,7 +38,6 @@ backend:
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
serve: frontend backend
make -C $(FRONTEND_DIR)
ifeq ($(DEBUG),1)
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml
else ifeq ($(RELEASE),1)

View file

@ -67,7 +67,10 @@ async fn main() -> std::io::Result<()> {
env_logger::init();
let address = "127.0.0.1";
let port = 8080;
let port = std::env::var("EXAMPLE_ELM_APP_PORT")
.unwrap_or("8080".to_string())
.parse()
.unwrap();
info!("Starting server at http://{}:{}", address, port);

25
default.nix Normal file
View file

@ -0,0 +1,25 @@
{
system ? builtins.currentSystem,
}:
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
root = lock.nodes.${lock.root};
inherit (lock.nodes.${root.inputs.flake-compat}.locked)
owner
repo
rev
narHash
;
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.defaultNix

197
flake.lock Normal file
View file

@ -0,0 +1,197 @@
{
"nodes": {
"elm-spa": {
"inputs": {
"nixpkgs": [
"mkElmDerivation",
"nixpkgs"
]
},
"locked": {
"lastModified": 1706301604,
"narHash": "sha256-n6LDjnPCTLbKTrRgeZhlLTfY6V45xNYcb4NYEMuO4jg=",
"owner": "jeslie0",
"repo": "elm-spa",
"rev": "4c82e18d5fcf9d4c027f0ef0e89204dd87584f7f",
"type": "github"
},
"original": {
"owner": "jeslie0",
"repo": "elm-spa",
"type": "github"
}
},
"elm-watch": {
"inputs": {
"nixpkgs": [
"mkElmDerivation",
"nixpkgs"
],
"npm-fix": "npm-fix",
"npmlock2nix": "npmlock2nix"
},
"locked": {
"lastModified": 1706304401,
"narHash": "sha256-992cypnhoRbsGkDc5/X241rafBML4EP0EuT6cBcaY/8=",
"owner": "jeslie0",
"repo": "elm-watch",
"rev": "2f1c6c0e69b163c15e2ce66f543c38021b2a0ea3",
"type": "github"
},
"original": {
"owner": "jeslie0",
"repo": "elm-watch",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"mkElmDerivation": {
"inputs": {
"elm-spa": "elm-spa",
"elm-watch": "elm-watch",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1735436157,
"narHash": "sha256-G7gF5z0HEQVaLJuygUoCSJs27wQdautyMsciFYdpNCo=",
"owner": "jeslie0",
"repo": "mkElmDerivation",
"rev": "f369fd6ff78205821c3f409814e840691be645e7",
"type": "github"
},
"original": {
"owner": "jeslie0",
"repo": "mkElmDerivation",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1696757521,
"narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "2646b294a146df2781b1ca49092450e8a32814e1",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1735821806,
"narHash": "sha256-cuNapx/uQeCgeuhUhdck3JKbgpsml259sjUQnWM7zW8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d6973081434f88088e5321f83ebafe9a1167c367",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"npm-fix": {
"inputs": {
"nixpkgs": [
"mkElmDerivation",
"elm-watch",
"nixpkgs"
]
},
"locked": {
"lastModified": 1706304213,
"narHash": "sha256-XN9ESRSOANR0iFbEMMY1C1jvgZlYJsXQYVAHxxRmn+c=",
"owner": "jeslie0",
"repo": "npm-lockfile-fix",
"rev": "e9851274afa12b04d98e694ed089aa9cde8d7349",
"type": "github"
},
"original": {
"owner": "jeslie0",
"repo": "npm-lockfile-fix",
"type": "github"
}
},
"npmlock2nix": {
"flake": false,
"locked": {
"lastModified": 1673447413,
"narHash": "sha256-sJM82Sj8yfQYs9axEmGZ9Evzdv/kDcI9sddqJ45frrU=",
"owner": "nix-community",
"repo": "npmlock2nix",
"rev": "9197bbf397d76059a76310523d45df10d2e4ca81",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "npmlock2nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"mkElmDerivation": "mkElmDerivation",
"nixpkgs": "nixpkgs_2",
"utils": "utils"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"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"
}
}
},
"root": "root",
"version": 7
}

119
flake.nix Normal file
View file

@ -0,0 +1,119 @@
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
utils.url = "github:numtide/flake-utils";
mkElmDerivation.url = "github:jeslie0/mkElmDerivation";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs =
inputs:
inputs.utils.lib.eachDefaultSystem (
system:
let
pkgs = import inputs.nixpkgs {
localSystem = system;
overlays = [
inputs.mkElmDerivation.overlays.default
(final: prev: {
example-spa-elm-app = prev.callPackage (
{
stdenv,
lib,
elmPackages,
uglify-js,
rustPlatform,
cargo,
rustc,
}:
stdenv.mkDerivation (
let
allPackagesJsonPath = "${inputs.mkElmDerivation}/mkElmDerivation/all-packages.json";
elmHashesJsonPath = "${inputs.mkElmDerivation}/mkElmDerivation/elm-hashes.json";
snapshot = import "${inputs.mkElmDerivation}/src/snapshot/default.nix" (
prev.haskellPackages // { inherit lib; }
);
elmJson = ./frontend/elm.json;
in
{
pname = "example-spa-elm-app";
version = "0.1.0";
src = inputs.self;
nativeBuildInputs = [
elmPackages.elm
uglify-js
rustPlatform.cargoSetupHook
cargo
rustc
];
cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./backend/Cargo.lock;
allowBuiltinFetchGit = true;
};
cargoRoot = "backend";
makeFlags = [
"RELEASE=1"
"frontend"
"backend"
];
postPatch = ''
patchShebangs ./frontend/build.sh
'';
preBuild = ''
(
cd frontend
${
(import "${inputs.mkElmDerivation}/nix/lib.nix" {
inherit
stdenv
lib
snapshot
allPackagesJsonPath
;
}).mkDotElmCommand
elmHashesJsonPath
elmJson
}
)
export ELM_HOME=$PWD/frontend/.elm
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r ./public $out/
cp ./backend/target/debug/backend $out/
runHook postInstall
'';
}
)
) { };
})
];
};
in
{
packages = {
default = inputs.self.packages."${system}".example-spa-elm-app;
example-spa-elm-app = pkgs.example-spa-elm-app;
};
devShells.default =
with pkgs;
mkShell {
inputsFrom = [ example-spa-elm-app ];
};
}
);
}

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex

25
shell.nix Normal file
View file

@ -0,0 +1,25 @@
{
system ? builtins.currentSystem,
}:
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
root = lock.nodes.${lock.root};
inherit (lock.nodes.${root.inputs.flake-compat}.locked)
owner
repo
rev
narHash
;
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.shellNix