Skip to content

Commit a40dfcc

Browse files
committed
Provide nix build from source
Changes build slightly to allow building webapp and server parts separately.
1 parent 8ee8040 commit a40dfcc

27 files changed

+617
-447
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/ci.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ name: CI
22
on:
33
pull_request:
44
jobs:
5+
nix-build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- uses: cachix/install-nix-action@v25
10+
- run: nix build
511
ci-matrix:
6-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-latest
713
strategy:
814
fail-fast: false
915
matrix:
@@ -18,6 +24,10 @@ jobs:
1824
- uses: bahmutov/npm-install@v1
1925
with:
2026
working-directory: modules/webapp
27+
- uses: cachix/install-nix-action@v25
28+
- name: Install tailwindcss cli
29+
run: |
30+
nix profile install nixpkgs#tailwindcss
2131
- name: Fetch tags
2232
run: git fetch --depth=100 origin +refs/tags/*:refs/tags/*
2333
- uses: olafurpg/setup-scala@v14

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ local/
44
elm-stuff/
55
result
66
*.qcow2
7-
node_modules/
7+
node_modules/
8+
.direnv/

Contributing.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ fiddle with dependencies. If you have nix installed, you can create an
3737
environment with all the tools available:
3838

3939
``` bash
40-
$ nix-shell project/microsite.nix
40+
$ nix develop
4141
```
4242

43+
Alternatively, additionally to nix, install
44+
[direnv](https://direnv.net/) which will take care of that whenever
45+
entering the project directory.
46+
4347
Run the above in two terminals. Then in one, run `sbt` to generate the site:
4448
```
4549
$ sbt
@@ -51,7 +55,7 @@ In the other terminal run jekyll, for example:
5155
$ jekyll serve -s modules/microsite/target/site --baseurl /sharry
5256
```
5357

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

5660
Then see the site at `http://localhost:4000/sharry`. You need to run
5761
`microsite/makeMicrosite` after a change and then reload the page.

build.sbt

+36-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import scala.sys.process._
33
import com.github.sbt.git.SbtGit.GitKeys._
44

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

79
val scalafixSettings = Seq(
810
semanticdbEnabled := true, // enable SemanticDB
@@ -38,16 +40,21 @@ val testSettingsMUnit = Seq(
3840
)
3941

4042
val elmSettings = Seq(
43+
elmCompileSkip := false,
4144
elmCompileMode := ElmCompileMode.Debug,
4245
Compile / resourceGenerators += Def.task {
43-
compileElm(
44-
streams.value.log,
45-
(Compile / baseDirectory).value,
46-
(Compile / resourceManaged).value,
47-
name.value,
48-
version.value,
49-
elmCompileMode.value
50-
)
46+
val logger = streams.value.log
47+
val skip = elmCompileSkip.value
48+
if (skip) Seq.empty
49+
else
50+
compileElm(
51+
logger,
52+
(Compile / baseDirectory).value,
53+
(Compile / resourceManaged).value,
54+
name.value,
55+
version.value,
56+
elmCompileMode.value
57+
)
5158
}.taskValue,
5259
watchSources += Watched.WatchSource(
5360
(Compile / sourceDirectory).value / "elm",
@@ -62,14 +69,19 @@ val stylesSettings = Seq(
6269
)
6370

6471
val webjarSettings = Seq(
72+
webjarSkip := false,
6573
Compile / resourceGenerators += Def.task {
66-
copyWebjarResources(
67-
Seq((Compile / sourceDirectory).value / "webjar"),
68-
(Compile / resourceManaged).value,
69-
name.value,
70-
version.value,
71-
streams.value.log
72-
)
74+
val logger = streams.value.log
75+
val skip = webjarSkip.value
76+
if (skip) Seq.empty
77+
else
78+
copyWebjarResources(
79+
Seq((Compile / sourceDirectory).value / "webjar"),
80+
(Compile / resourceManaged).value,
81+
name.value,
82+
version.value,
83+
logger
84+
)
7385
}.taskValue,
7486
watchSources += Watched.WatchSource(
7587
(Compile / sourceDirectory).value / "webjar",
@@ -445,7 +457,15 @@ def createWebjarSource(wj: Seq[ModuleID], out: File): Seq[File] = {
445457

446458
addCommandAlias(
447459
"make",
448-
";set webapp/elmCompileMode := ElmCompileMode.Production; set webapp/stylesMode := StylesMode.Prod ;root/openapiCodegen ;root/test:compile"
460+
";set webapp/elmCompileMode := ElmCompileMode.Production; set webapp/stylesMode := StylesMode.Prod ;root/openapiCodegen ;root/Test/compile"
461+
)
462+
addCommandAlias(
463+
"make-without-webapp",
464+
"; set webapp/webjarSkip := true ;set webapp/elmCompileSkip := true ;set webapp/stylesSkipBuild := true; root/compile"
465+
)
466+
addCommandAlias(
467+
"make-webapp-only",
468+
";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"
449469
)
450470
addCommandAlias("make-zip", ";restserver/Universal/packageBin")
451471
addCommandAlias("make-deb", ";restserver/Debian/packageBin")

flake.lock

+59-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+72-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,77 @@
11
{
22
description = "Sharry allows to share files with others in a simple way";
33

4-
inputs.flake-utils.url = "github:numtide/flake-utils";
5-
6-
outputs = { self, nixpkgs, flake-utils }:
7-
let
8-
release = import nix/release.nix;
9-
in
10-
{
11-
overlays.default = final: prev: {
12-
sharryVersions = builtins.mapAttrs (_: cfg: final.callPackage (release.pkg cfg) { }) release.cfg;
13-
sharry = final.callPackage release.currentPkg { };
14-
};
15-
nixosModules.default = release.module;
16-
} // flake-utils.lib.eachDefaultSystem (system:
17-
let
18-
pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
19-
in
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
sbt.url = "github:zaninime/sbt-derivation";
8+
};
9+
10+
outputs = inputs@{ self, nixpkgs, flake-utils, sbt }:
2011
{
21-
packages = {
22-
inherit (pkgs) sharry;
23-
default = self.packages."${system}".sharry;
24-
} // pkgs.sharryVersions;
25-
}
26-
);
12+
overlays.default = final: prev: {
13+
sharry = import ./nix/package.nix {
14+
inherit (final) pkgs;
15+
inherit sbt;
16+
lib = final.pkgs.lib;
17+
};
18+
sharry-bin = prev.pkgs.callPackage (import ./nix/package-bin.nix) { };
19+
};
20+
nixosModules.default = import ./nix/module.nix;
21+
22+
nixosConfigurations.test-vm =
23+
let
24+
system = "x86_64-linux";
25+
pkgs = import inputs.nixpkgs {
26+
inherit system;
27+
overlays = [ self.overlays.default ];
28+
};
29+
30+
in
31+
nixpkgs.lib.nixosSystem {
32+
inherit pkgs system;
33+
specialArgs = inputs;
34+
modules = [
35+
self.nixosModules.default
36+
./nix/configuration-test.nix
37+
];
38+
};
39+
} // flake-utils.lib.eachDefaultSystem (system:
40+
let
41+
pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
42+
in
43+
{
44+
packages = {
45+
inherit (pkgs) sharry sharry-bin;
46+
default = self.packages."${system}".sharry;
47+
};
48+
49+
formatter = pkgs.nixpkgs-fmt;
50+
51+
devShells.default =
52+
let
53+
run-jekyll = pkgs.writeScriptBin "jekyll-sharry" ''
54+
jekyll serve -s modules/microsite/target/site --baseurl /sharry
55+
'';
56+
in
57+
pkgs.mkShell {
58+
buildInputs = with pkgs; [
59+
pkgs.sbt
60+
61+
# frontend
62+
tailwindcss
63+
elmPackages.elm
64+
65+
# for debian packages
66+
dpkg
67+
fakeroot
68+
69+
# microsite
70+
jekyll
71+
nodejs_18
72+
run-jekyll
73+
];
74+
};
75+
}
76+
);
2777
}

0 commit comments

Comments
 (0)