From dc017a0cab40cb2f33a01b420bb1b04038abb875 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 4 Oct 2021 18:27:57 +0200 Subject: Build Garage with Nix --- nix/build_index.nix | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++ nix/common.nix | 27 ++++++++++ nix/kaniko.nix | 23 +++++++++ nix/nix.conf | 7 +++ 4 files changed, 203 insertions(+) create mode 100644 nix/build_index.nix create mode 100644 nix/common.nix create mode 100644 nix/kaniko.nix create mode 100644 nix/nix.conf (limited to 'nix') diff --git a/nix/build_index.nix b/nix/build_index.nix new file mode 100644 index 00000000..5107324e --- /dev/null +++ b/nix/build_index.nix @@ -0,0 +1,146 @@ +{ + path ? "/../aws-list.txt", +}: + +with import ./common.nix; +let + pkgs = import pkgsSrc {}; + lib = pkgs.lib; + + /* Converts a key list and a value list to a set + + Example: + listToSet [ "name" "version" ] [ "latex" "3.14" ] + => { name = "latex"; version = "3.14"; } + */ + listToSet = keys: values: + builtins.listToAttrs + (lib.zipListsWith + (a: b: { name = a; value = b; }) + keys + values); + + /* Says if datetime a is more recent than datetime b + + Example: + cmpDate { date = "2021-09-10"; time = "22:12:15"; } { date = "2021-02-03"; time = "23:54:12"; } + => true + */ + cmpDate = a: b: + let da = (builtins.head a.builds).date; + db = (builtins.head b.builds).date; + in + if da == db then (builtins.head a.builds).time > (builtins.head b.builds).time + else da > db; + + /* Pretty platforms */ + prettyPlatform = name: + if name == "aarch64-unknown-linux-musl" then "linux/arm64" + else if name == "armv6l-unknown-linux-musleabihf" then "linux/arm" + else if name == "x86_64-unknown-linux-musl" then "linux/amd64" + else if name == "i686-unknown-linux-musl" then "linux/386" + else name; + + /* Parsing */ + list = builtins.readFile (./. + path); + entries = lib.splitString "\n" list; + + elems = builtins.filter + (e: (builtins.length e) == 4) + (map + (x: builtins.filter (e: e != "") (lib.splitString " " x)) + entries); + + keys = ["date" "time" "size" "path"]; + parsed = map (entry: listToSet keys entry) elems; + + subkeys = ["root" "version" "platform" "binary" ]; + builds = map (entry: entry // listToSet subkeys (lib.splitString "/" entry.path)) parsed; + + /* Aggregation */ + builds_per_version = lib.foldl (acc: v: acc // { ${v.version} = if builtins.hasAttr v.version acc then acc.${v.version} ++ [ v ] else [ v ]; }) {} builds; + + versions = builtins.attrNames builds_per_version; + versions_release = builtins.filter (x: builtins.match "v[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?" x != null) versions; + versions_commit = builtins.filter (x: builtins.match "[0-9a-f]{40}" x != null) versions; + versions_extra = lib.subtractLists (versions_release ++ versions_commit) versions; + + sorted_builds = [ + { + name = "Release"; + hide = false; + type = "tag"; + description = "Release builds are the official builds, they are tailored for productions and are the most tested."; + builds = builtins.sort (a: b: a.version > b.version) (map (x: { version = x; builds = builtins.getAttr x builds_per_version; }) versions_release); + } + { + name = "Extra"; + hide = true; + type = "tag"; + description = "Extra builds are built on demand to test a specific feature or a specific need."; + builds = builtins.sort cmpDate (map (x: { version = x; builds = builtins.getAttr x builds_per_version; }) versions_extra); + } + { + name = "Development"; + hide = true; + type = "commit"; + description = "Development builds are built periodically. Use them if you want to test a specific feature that is not yet released."; + builds = builtins.sort cmpDate (map (x: { version = x; builds = builtins.getAttr x builds_per_version; }) versions_commit); + } + ]; + +in + pkgs.writeText "index.html" '' + + + + + Garage releases + + + + ${ builtins.toString (lib.forEach sorted_builds (r: '' +
+

${r.name} builds

+ +

${r.description}

+ + ${if r.hide then "
Show ${r.name} builds" else ""} + ${ builtins.toString (lib.forEach r.builds (x: '' +

${x.version} (${(builtins.head x.builds).date})

+

See this build on

+

Binaries: +

+

Sources: +

+ '')) } + ${ if builtins.length r.builds == 0 then "There is no build for this category" else "" } + ${if r.hide then "
" else ""} +
+ ''))} + + +'' diff --git a/nix/common.nix b/nix/common.nix new file mode 100644 index 00000000..aee38bd8 --- /dev/null +++ b/nix/common.nix @@ -0,0 +1,27 @@ +rec { + /* + * Fixed dependencies + */ + pkgsSrc = fetchTarball { + # As of 2021-10-04 + url ="https://github.com/NixOS/nixpkgs/archive/b27d18a412b071f5d7991d1648cfe78ee7afe68a.tar.gz"; + sha256 = "1xy9zpypqfxs5gcq5dcla4bfkhxmh5nzn9dyqkr03lqycm9wg5cr"; + }; + cargo2nixSrc = fetchGit { + # As of 2021-10-06 + url = "https://github.com/superboum/cargo2nix"; + rev = "1364752cd784764db2ef5b1e1248727cebfae2ce"; + }; + rustOverlaySrc = fetchGit { + # As of 2021-10-05 + url = "https://github.com/oxalica/rust-overlay"; + rev = "9c2fc6a62ccbc6f420d71ecac6bf0b84dbbee64f"; + }; + + /* + * Shared objects + */ + rustOverlay = import rustOverlaySrc; + cargo2nix = import cargo2nixSrc; + cargo2nixOverlay = import "${cargo2nixSrc}/overlay"; +} diff --git a/nix/kaniko.nix b/nix/kaniko.nix new file mode 100644 index 00000000..140328b8 --- /dev/null +++ b/nix/kaniko.nix @@ -0,0 +1,23 @@ +pkgs: +pkgs.buildGoModule rec { + pname = "kaniko"; + version = "1.6.0"; + + src = pkgs.fetchFromGitHub { + owner = "GoogleContainerTools"; + repo = "kaniko"; + rev = "v${version}"; + sha256 = "1fnclr556avxay6pvgw5ya3xbxfnf2gv4njq2hr4fd6fcjyslq5h"; + }; + + vendorSha256 = null; + + checkPhase = "true"; + + meta = with pkgs.lib; { + description = "kaniko is a tool to build container images from a Dockerfile, inside a container or Kubernetes cluster."; + homepage = "https://github.com/GoogleContainerTools/kaniko"; + license = licenses.asl20; + platforms = platforms.linux; + }; +} diff --git a/nix/nix.conf b/nix/nix.conf new file mode 100644 index 00000000..8764eb3e --- /dev/null +++ b/nix/nix.conf @@ -0,0 +1,7 @@ +substituters = https://cache.nixos.org https://nix.web.deuxfleurs.fr +trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix.web.deuxfleurs.fr:eTGL6kvaQn6cDR/F9lDYUIP9nCVR/kkshYfLDJf1yKs= +max-jobs = auto +cores = 4 + +# required for containers +sandbox = false -- cgit v1.2.3