-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
140 lines (136 loc) · 4.89 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Documentation: https://nixos.wiki/wiki/Flakes
# Documentation: https://yuanwang.ca/posts/getting-started-with-flakes.html
{
description = "NixOS docker image";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
nixpkgs-unstable,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
# pkgs = import nixpkgs { system = system; config.allowUnfree = true; };
# unstable = import nixpkgs-unstable { system = system; config.allowUnfree = true; };
unstable = nixpkgs-unstable.legacyPackages.${system};
did_web_server_pkg = unstable.callPackage ./default.nix { };
manifest = pkgs.lib.importJSON ./manifest.json;
pkgVersionsEqual =
x: y:
let
attempt = builtins.tryEval (
assert builtins.substring 0 (builtins.stringLength x) y == x;
y
);
in
if attempt.success then
attempt.value
else
# Version can be bumped in the prerelease or build version to create a
# custom local revision, see https://semver.org/
abort "Version mismatch: ${y} doesn't start with ${x}";
version = pkgVersionsEqual "${did_web_server_pkg.version}" manifest.version;
in
rec {
# Development environment: nix develop
devShells.default = pkgs.mkShell {
name = manifest.name;
nativeBuildInputs = with pkgs; [
deno
gh
git-cliff
just
unstable.cargo-watch
unstable.nushell
unstable.skopeo
did_web_server_pkg.nativeBuildInputs
];
};
devShells.ci = pkgs.mkShell {
name = manifest.name;
nativeBuildInputs = with pkgs; [
just
unstable.nushell
unstable.skopeo
];
};
packages.docker = pkgs.dockerTools.streamLayeredImage {
# Documentation: https://ryantm.github.io/nixpkgs/builders/images/dockertools/
name = "${manifest.registry.name}/${manifest.name}";
tag = version;
# created = "now";
# author = "not yet supported";
maxLayers = 125;
contents = with pkgs; [
dockerTools.usrBinEnv
dockerTools.binSh
dockerTools.caCertificates
# dockerTools.fakeNss
# busybox
# nix
# coreutils
# gnutar
# gzip
# gnugrep
# which
# curl
# less
# findutils
did_web_server_pkg
# entrypoint
];
enableFakechroot = true;
fakeRootCommands = ''
set -exuo pipefail
mkdir -p /run/dws
# chown 65534:65534 /run/dws
# mkdir /tmp
# chmod 1777 /tmp
'';
config = {
# Valid values, see: https://github.com/moby/docker-image-spec
# and https://oci-playground.github.io/specs-latest/
ExposedPorts = {
"8000/tcp" = { };
};
Entrypoint = [
"${pkgs.tini}/bin/tini"
"--"
];
Cmd = [ "${did_web_server_pkg}/bin/did-web-server" ];
# Env = ["VARNAME=xxx"];
WorkingDir = "/run/dws";
# User 'nobody' and group 'nogroup'
User = "65534";
Group = "65534";
Labels = {
# Well-known annotations: https://github.com/opencontainers/image-spec/blob/main/annotations.md
"org.opencontainers.image.ref.name" =
"${manifest.registry.name}/${manifest.name}:${manifest.version}";
"org.opencontainers.image.licenses" = manifest.license;
"org.opencontainers.image.description" = manifest.description;
"org.opencontainers.image.documentation" = manifest.registry.url;
"org.opencontainers.image.version" = manifest.version;
"org.opencontainers.image.vendor" = manifest.author;
"org.opencontainers.image.authors" = builtins.elemAt manifest.contributors 0;
"org.opencontainers.image.url" = manifest.homepage;
"org.opencontainers.image.source" = manifest.repository.url;
"org.opencontainers.image.revision" = manifest.version;
# "org.opencontainers.image.base.name" =
# "${manifest.registry.url}/${manifest.name}/${manifest.version}";
};
};
};
# The default package when a specific package name isn't specified: nix build
packages.default = packages.docker;
}
);
}