From e7594ef2eb73da96344a650252c9886d9a4b65d8 Mon Sep 17 00:00:00 2001 From: efim Date: Mon, 26 Jun 2023 20:52:44 +0000 Subject: [PATCH] feat: nix build enabled --- .gitignore | 2 + 11-single-price-grid-component/.gitignore | 12 ++++++ 11-single-price-grid-component/default.nix | 39 ++++++++++++++++++ .../src/main/scala/pricegrid/App.scala | 4 +- flake.lock | 39 +++++++++++++++++- flake.nix | 40 +++++++++++-------- 6 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 11-single-price-grid-component/.gitignore create mode 100644 11-single-price-grid-component/default.nix diff --git a/.gitignore b/.gitignore index 5af4e6e..b7e9d40 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ */project/.bloop */project/target/ */target/ + +*/result diff --git a/11-single-price-grid-component/.gitignore b/11-single-price-grid-component/.gitignore new file mode 100644 index 0000000..5af4e6e --- /dev/null +++ b/11-single-price-grid-component/.gitignore @@ -0,0 +1,12 @@ +.bsp/ +.scala-build/ +.metals/ +.direnv +*/dist/ +/11-single-price-grid-component/.bloop/ + +*/project/project/ +*/project/metals.sbt +*/project/.bloop +*/project/target/ +*/target/ diff --git a/11-single-price-grid-component/default.nix b/11-single-price-grid-component/default.nix new file mode 100644 index 0000000..8852b71 --- /dev/null +++ b/11-single-price-grid-component/default.nix @@ -0,0 +1,39 @@ +{ pkgs, sbt-derivation }: + +let + package = sbt-derivation.lib.mkSbtDerivation { + inherit pkgs; + # ...and the rest of the arguments + pname = "price-grid-app"; + version = "0.0.1"; + src = pkgs.nix-gitignore.gitignoreSource [] ./.; + nativeBuildInputs = [ pkgs.nodePackages.tailwindcss ]; + buildPhase = '' + sbt assembly + tailwindcss -i ./src/input.css -o ./output.css + ''; + # css path different from ordinary development, + # because .gitignore makes it unavailable during nix build + # anyway copied to correct place + installPhase = '' + mkdir -p $out/bin + cp target/scala-*/priceGrid-assembly-*.jar $out/bin/ + mkdir -p $out/bin/dist + cp ./output.css $out/bin/dist/output.css + cp -r public $out/bin/public + ''; + + depsSha256 = "sha256-aWLqnPXvchtNqpSfXo5sWyK2QFNn1GqToy58cWrML3U="; + }; + + module = { config, pkgs, ... }: { + services.price-grid-app = { + enable = true; + package = package; + }; + }; +in +{ + package = package; + module = module; +} diff --git a/11-single-price-grid-component/src/main/scala/pricegrid/App.scala b/11-single-price-grid-component/src/main/scala/pricegrid/App.scala index 0888e53..67afad0 100644 --- a/11-single-price-grid-component/src/main/scala/pricegrid/App.scala +++ b/11-single-price-grid-component/src/main/scala/pricegrid/App.scala @@ -33,10 +33,10 @@ case class AppRoutes()(implicit cc: castor.Context, def index() = Page.wholePageMarkup @cask.staticFiles("/dist") // this is what path gets matched - def distFiles() = "dist" // this is os path where files are looked up, for the generated files + def distFiles() = "dist" @cask.staticFiles("/public") // this is what path gets matched - def publicFiles() = "public" // this is os path where files are looked up, for the committed files + def publicFiles() = "public" initialize() } diff --git a/flake.lock b/flake.lock index 7405967..f9bfc50 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,21 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1687695299, @@ -36,7 +51,29 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "sbt-derivation": "sbt-derivation" + } + }, + "sbt-derivation": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1675083208, + "narHash": "sha256-+sSFhSpV2jckr1qYlX/SaxQ6IdpagD6o4rru/3HAl0I=", + "owner": "zaninime", + "repo": "sbt-derivation", + "rev": "92d6d6d825e3f6ae5642d1cce8ff571c3368aaf7", + "type": "github" + }, + "original": { + "owner": "zaninime", + "repo": "sbt-derivation", + "type": "github" } }, "systems": { diff --git a/flake.nix b/flake.nix index 0c6da0b..b392dd6 100644 --- a/flake.nix +++ b/flake.nix @@ -2,22 +2,30 @@ description = "learning htmx"; inputs.nixpkgs.url = "github:nixos/nixpkgs"; inputs.flake-utils.url = "github:numtide/flake-utils"; + # add this line + inputs.sbt-derivation.url = "github:zaninime/sbt-derivation"; + # recommended for first style of usage documented below, but not necessary + inputs.sbt-derivation.inputs.nixpkgs.follows = "nixpkgs"; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem - (system: - let pkgs = nixpkgs.legacyPackages.${system}; in - { - devShells.default = pkgs.mkShell { - buildInputs = [ - pkgs.scala-cli - pkgs.sbt - pkgs.scalafmt - pkgs.nodePackages.tailwindcss - pkgs.jdk - ]; - }; - } - ); + outputs = { self, nixpkgs, flake-utils, sbt-derivation }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + price-grid = import ./11-single-price-grid-component/default.nix { + inherit pkgs sbt-derivation; + }; + in { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.scala-cli + pkgs.sbt + pkgs.scalafmt + pkgs.nodePackages.tailwindcss + pkgs.jdk + ]; + }; + packages.price-grid-app = price-grid.package; + nixosModules.price-grid-app = price-grid.module; + }); # see https://serokell.io/blog/practical-nix-flakes }