-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
122 lines (109 loc) · 3.28 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
description = "jnsgruk's personal website and blog";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs =
{ self, nixpkgs, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-darwin"
];
pkgsForSystem = system: (import nixpkgs { inherit system; });
in
{
packages = forAllSystems (
system:
let
inherit (pkgsForSystem system)
buildEnv
buildGo122Module
cacert
dockerTools
hugo
lib
;
version = self.shortRev or (builtins.substring 0 7 self.dirtyRev);
rev = self.rev or self.dirtyRev;
in
{
default = self.packages.${system}.jnsgruk;
jnsgruk = buildGo122Module {
inherit version;
pname = "jnsgruk";
src = lib.cleanSource ./.;
vendorHash = "sha256-o5RY4sAxqW/tFVSVb1SdCr2QFo4LLYITA2yyQasUYmE=";
buildInputs = [ cacert ];
nativeBuildInputs = [ hugo ];
# Nix doesn't play well with Hugo's "GitInfo" module, so disable it and inject
# the revision from the flake.
postPatch = ''
substituteInPlace ./site/layouts/shortcodes/gitinfo.html \
--replace "{{ .Page.GitInfo.Hash }}" "${rev}" \
--replace "{{ .Page.GitInfo.AbbreviatedHash }}" "${version}"
substituteInPlace ./site/config/_default/config.yaml \
--replace "enableGitInfo: true" "enableGitInfo: false"
'';
# Generate the Hugo site before building the Go application which embeds the
# built site.
preBuild = ''
go generate ./...
'';
ldflags = [ "-X main.commit=${rev}" ];
# Rename the main executable in the output directory
postInstall = ''
mv $out/bin/jnsgr.uk $out/bin/jnsgruk
'';
meta.mainProgram = "jnsgruk";
};
jnsgruk-container = dockerTools.buildImage {
name = "jnsgruk/jnsgr.uk";
tag = version;
created = "now";
copyToRoot = buildEnv {
name = "image-root";
paths = [
self.packages.${system}.jnsgruk
cacert
];
pathsToLink = [
"/bin"
"/etc/ssl/certs"
];
};
config = {
Entrypoint = [ "${lib.getExe self.packages.${system}.jnsgruk}" ];
Expose = [
8080
8801
];
User = "10000:10000";
};
};
}
);
devShells = forAllSystems (
system:
let
pkgs = pkgsForSystem system;
in
{
default = pkgs.mkShell {
name = "jnsgruk";
NIX_CONFIG = "experimental-features = nix-command flakes";
nativeBuildInputs = with pkgs; [
go_1_22
go-tools
gofumpt
gopls
hugo
flyctl
zsh
];
shellHook = "exec zsh";
};
}
);
};
}