Skip to content

Commit

Permalink
Provide nix build from source
Browse files Browse the repository at this point in the history
Changes build slightly to allow building webapp and server parts
separately.
  • Loading branch information
eikek committed Feb 12, 2024
1 parent ffcfc56 commit f100dd8
Show file tree
Hide file tree
Showing 24 changed files with 862 additions and 2,912 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ name: CI
on:
pull_request:
jobs:
nix-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- run: nix build
ci-matrix:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ local/
elm-stuff/
result
*.qcow2
node_modules/
node_modules/
.direnv/
8 changes: 6 additions & 2 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ fiddle with dependencies. If you have nix installed, you can create an
environment with all the tools available:

``` bash
$ nix-shell project/microsite.nix
$ nix develop
```

Alternatively, additionally to nix, install
[direnv](https://direnv.net/) which will take care of that whenever
entering the project directory.

Run the above in two terminals. Then in one, run `sbt` to generate the site:
```
$ sbt
Expand All @@ -51,7 +55,7 @@ In the other terminal run jekyll, for example:
$ jekyll serve -s modules/microsite/target/site --baseurl /sharry
```

If you use `nix-shell`, there is a shortcut `jekyll-sharry`.
If you use `nix`, there is a shortcut `jekyll-sharry` in scope.

Then see the site at `http://localhost:4000/sharry`. You need to run
`microsite/makeMicrosite` after a change and then reload the page.
Expand Down
52 changes: 36 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import scala.sys.process._
import com.github.sbt.git.SbtGit.GitKeys._

val elmCompileMode = settingKey[ElmCompileMode]("How to compile elm sources")
val elmCompileSkip = settingKey[Boolean]("Whether to skip compiling elm files")
val webjarSkip = settingKey[Boolean]("Skip copying webjar files")

val scalafixSettings = Seq(
semanticdbEnabled := true, // enable SemanticDB
Expand Down Expand Up @@ -38,16 +40,21 @@ val testSettingsMUnit = Seq(
)

val elmSettings = Seq(
elmCompileSkip := false,
elmCompileMode := ElmCompileMode.Debug,
Compile / resourceGenerators += Def.task {
compileElm(
streams.value.log,
(Compile / baseDirectory).value,
(Compile / resourceManaged).value,
name.value,
version.value,
elmCompileMode.value
)
val logger = streams.value.log
val skip = elmCompileSkip.value
if (skip) Seq.empty
else
compileElm(
logger,
(Compile / baseDirectory).value,
(Compile / resourceManaged).value,
name.value,
version.value,
elmCompileMode.value
)
}.taskValue,
watchSources += Watched.WatchSource(
(Compile / sourceDirectory).value / "elm",
Expand All @@ -62,14 +69,19 @@ val stylesSettings = Seq(
)

val webjarSettings = Seq(
webjarSkip := false,
Compile / resourceGenerators += Def.task {
copyWebjarResources(
Seq((Compile / sourceDirectory).value / "webjar"),
(Compile / resourceManaged).value,
name.value,
version.value,
streams.value.log
)
val logger = streams.value.log
val skip = webjarSkip.value
if (skip) Seq.empty
else
copyWebjarResources(
Seq((Compile / sourceDirectory).value / "webjar"),
(Compile / resourceManaged).value,
name.value,
version.value,
logger
)
}.taskValue,
watchSources += Watched.WatchSource(
(Compile / sourceDirectory).value / "webjar",
Expand Down Expand Up @@ -445,7 +457,15 @@ def createWebjarSource(wj: Seq[ModuleID], out: File): Seq[File] = {

addCommandAlias(
"make",
";set webapp/elmCompileMode := ElmCompileMode.Production; set webapp/stylesMode := StylesMode.Prod ;root/openapiCodegen ;root/test:compile"
";set webapp/elmCompileMode := ElmCompileMode.Production; set webapp/stylesMode := StylesMode.Prod ;root/openapiCodegen ;root/Test/compile"
)
addCommandAlias(
"make-without-webapp",
"; set webapp/webjarSkip := true ;set webapp/elmCompileSkip := true ;set webapp/stylesSkipBuild := true; root/compile"
)
addCommandAlias(
"make-webapp-only",
";set webapp/elmCompileMode := ElmCompileMode.Production; set webapp/stylesMode := StylesMode.Prod; set webapp/webjarSkip := false ;set webapp/elmCompileSkip := false ;set webapp/stylesSkipBuild := false ;webapp/openapiCodegen ;webapp/compile ;webapp/package"
)
addCommandAlias("make-zip", ";restserver/Universal/packageBin")
addCommandAlias("make-deb", ";restserver/Debian/packageBin")
Expand Down
65 changes: 59 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 71 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,76 @@
{
description = "Sharry allows to share files with others in a simple way";

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
let
release = import nix/release.nix;
in
{
overlays.default = final: prev: {
sharryVersions = builtins.mapAttrs (_: cfg: final.callPackage (release.pkg cfg) { }) release.cfg;
sharry = final.callPackage release.currentPkg { };
};
nixosModules.default = release.module;
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
in
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
sbt.url = "github:zaninime/sbt-derivation";
};

outputs = inputs@{ self, nixpkgs, flake-utils, sbt }:
{
packages = {
inherit (pkgs) sharry;
default = self.packages."${system}".sharry;
} // pkgs.sharryVersions;
}
);
overlays.default = final: prev: {
sharry = import ./nix/package.nix {
inherit (final) pkgs;
inherit sbt;
lib = final.pkgs.lib;
};
};
nixosModules.default = import ./nix/module.nix;

nixosConfigurations.test-vm =
let
system = "x86_64-linux";
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};

in
nixpkgs.lib.nixosSystem {
inherit pkgs system;
specialArgs = inputs;
modules = [
self.nixosModules.default
./nix/configuration-test.nix
];
};
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
in
{
packages = {
inherit (pkgs) sharry;
default = self.packages."${system}".sharry;
};

formatter = pkgs.nixpkgs-fmt;

devShells.default =
let
run-jekyll = pkgs.writeScriptBin "jekyll-sharry" ''
jekyll serve -s modules/microsite/target/site --baseurl /sharry
'';
in
pkgs.mkShell {
buildInputs = with pkgs; [
pkgs.sbt

# frontend
tailwindcss
elmPackages.elm

# for debian packages
dpkg
fakeroot

# microsite
jekyll
nodejs_18
run-jekyll
];
};
}
);
}
Loading

0 comments on commit f100dd8

Please sign in to comment.