-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
74 lines (70 loc) · 2.68 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
description = "marijan's website";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;
website-builder.url = "git+https://git.sr.ht/~marijan/website-builder";
};
outputs = inputs@{ flake-parts, treefmt-nix, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
imports = [
treefmt-nix.flakeModule
];
perSystem = { self', inputs', pkgs, lib, ... }:
{
treefmt = {
projectRootFile = ".git/config";
programs.nixpkgs-fmt.enable = true;
};
apps.gh-deploy = {
type = "app";
program = "${lib.getExe (pkgs.writeShellApplication {
name = "gh-deploy";
runtimeInputs = [ pkgs.coreutils ];
text = ''
cp --no-preserve=mode -r ${self'.packages.dist}/* docs
'';
})}";
};
apps.srht-deploy = {
type = "app";
program = "${lib.getExe (pkgs.writeShellApplication {
name = "srht-deploy";
runtimeInputs = with pkgs; [ coreutils gnutar gnupg curl ];
text = ''
echo "Decrypting access-token"
TOKEN=$(gpg --decrypt ${./secrets/sourcehut-pages-access-token.gpg})
echo "Compressing website data (docs directory) ..."
tar -C ${self'.packages.dist} -cvz . > site.tar.gz
echo "Deploying website ..."
curl --oauth2-bearer "$TOKEN" \
https://pages.sr.ht/publish/marijan.pro
rm site.tar.gz
echo "Done."
'';
})}";
};
packages = {
dist =
let
npmlock2nix = import inputs.npmlock2nix { inherit pkgs; };
in
pkgs.runCommand "dist" { LANG = "en_US.UTF-8"; nativeBuildInputs = [ pkgs.nodePackages.tailwindcss ]; } ''
mkdir -p $out
cp -r ${./src}/* .
${lib.getExe inputs'.website-builder.packages.default} build
cp -r docs/* $out/
export NODE_PATH=${npmlock2nix.v2.node_modules { src = ./.; nodejs = pkgs.nodejs; }}/node_modules
cd $out
tailwindcss -c ${./tailwind.config.js} -i css/style.css -o css/style.css
'';
};
};
};
}