Initial commit

main
Bill Ewanick 2023-02-20 19:32:14 -05:00
commit dcca5da865
11 changed files with 354 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Nix related
.direnv
result
# Elm related
elm-stuff
public/main.js

24
elm.json Normal file
View File

@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

43
flake.lock Normal file
View File

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1672580127,
"narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=",
"owner": "NixOs",
"repo": "nixpkgs",
"rev": "0874168639713f547c05947c76124f78441ea46c",
"type": "github"
},
"original": {
"owner": "NixOs",
"ref": "nixos-22.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1676283394,
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

76
flake.nix Normal file
View File

@ -0,0 +1,76 @@
{
description = "Template for an Elm app defined by a Nix flake";
inputs = {
nixpkgs.url = "github:NixOs/nixpkgs/nixos-22.05";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
debugMode = false;
in
{
packages.elm-nix-template = pkgs.stdenv.mkDerivation {
name = "elm-nix-template";
version = "0.1.0";
src = ./.;
buildInputs = with pkgs.elmPackages; [
elm
pkgs.nodePackages.uglify-js
];
configurePhase = pkgs.elmPackages.fetchElmDeps {
elmVersion = "0.19.1";
elmPackages = import ./nix/elm-srcs.nix;
registryDat = ./nix/registry.dat;
};
buildPhase =
if debugMode then ''
elm make src/Main.elm --debug --output=$out/debug.js
'' else ''
elm make src/Main.elm --output=$out/main.js --optimize
uglifyjs $out/main.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \
| uglifyjs --mangle --output $out/main.min.js
rm $out/main.js
'';
installPhase = ''
mkdir -p $out
cp public/main.css $out
${if debugMode then ''
cp public/index.debug.html $out/index.html
''
else ''
cp public/index.html $out
''}
'';
};
packages.default = self.packages.${system}.elm-nix-template;
devShells.default = pkgs.mkShell {
buildInputs = with pkgs;
[
elmPackages.elm
elmPackages.nodejs
elmPackages.elm-xref
elmPackages.elm-test
elmPackages.elm-live
elmPackages.elm-json
elmPackages.elm-review
elmPackages.elm-format
elmPackages.elm-upgrade
elmPackages.elm-analyse
elmPackages.elm-language-server
elm2nix
];
};
});
}

37
nix/elm-srcs.nix Normal file
View File

@ -0,0 +1,37 @@
{
"elm/browser" = {
sha256 = "0nagb9ajacxbbg985r4k9h0jadqpp0gp84nm94kcgbr5sf8i9x13";
version = "1.0.2";
};
"elm/core" = {
sha256 = "19w0iisdd66ywjayyga4kv2p1v9rxzqjaxhckp8ni6n8i0fb2dvf";
version = "1.0.5";
};
"elm/html" = {
sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k";
version = "1.0.0";
};
"elm/json" = {
sha256 = "0kjwrz195z84kwywaxhhlnpl3p251qlbm5iz6byd6jky2crmyqyh";
version = "1.1.3";
};
"elm/time" = {
sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1";
version = "1.0.0";
};
"elm/url" = {
sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4";
version = "1.0.0";
};
"elm/virtual-dom" = {
sha256 = "1yvb8px2z62xd578ag2q0r5hd1vkz9y7dfkx05355iiy1d7jwq4v";
version = "1.0.3";
};
}

BIN
nix/registry.dat Normal file

Binary file not shown.

23
public/index.debug.html Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>DEBUG ENABLED - Elm App using Nix Starter Template</title>
<link rel="stylesheet" href="main.css">
<script src="debug.js"></script>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script>var app = Elm.Main.init({ node: document.getElementById("root") });</script>
</body>
</html>

23
public/index.html Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>Elm App using Nix Starter Template</title>
<link rel="stylesheet" href="main.css">
<script src="main.min.js"></script>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script>var app = Elm.Main.init({ node: document.getElementById("root") });</script>
</body>
</html>

86
public/main.css Normal file
View File

@ -0,0 +1,86 @@
html,
body {
height: 100%;
}
body {
background-color: #fff1e5;
font-size: 20px;
color: #070707;
margin: 0px;
font-family: 'IBM Plex Sans', sans-serif;
}
h1 {
display: block;
font-size: 2em;
font-weight: bold;
margin: 0em 0em 1em 0em;
}
a {
color: #070707;
border-bottom: 1px dashed #070707;
padding-bottom: 0px;
text-decoration: none;
transition: padding 0.25s;
}
a:hover {
padding-bottom: 2px;
}
#hwaet {
padding: 2em;
max-width: 1000px;
margin-right: auto;
margin-left: auto;
}
#controls {
display: flex
}
.control {
margin-right: 1em;
display: flex;
flex-direction: column;
width: 10em;
font-size: 0.75em;
text-align: center;
}
input[type="range"] {
width: 100%;
margin-bottom: 1em;
}
input[type=range] {
-webkit-appearance: none;
}
input[type=range]::-webkit-slider-runnable-track {
height: .35em;
background: #070707;
border: none;
border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 1.1em;
width: 1.1em;
border-radius: 50%;
background: #070707;
margin-top: -4px;
}
input[type=range]:focus {
outline: none;
}
#footer {
font-size: 0.8em;
}

34
src/Main.elm Normal file
View File

@ -0,0 +1,34 @@
module Main exposing (Msg(..), main, update, view)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
main : Program () Int Msg
main =
Browser.sandbox { init = 0, update = update, view = view }
type Msg
= Increment
| Decrement
update : Msg -> number -> number
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
view : Int -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (String.fromInt model) ]
, button [ onClick Increment ] [ text "+" ]
]