kiwiirc icon indicating copy to clipboard operation
kiwiirc copied to clipboard

Add a Nix Flake as a build system

Open MatthewCroughan opened this issue 2 years ago • 2 comments

This adds a Nix flake which provides many outputs that can be built with nix build. The main outputs that can be built are:

.#kiwiirc        .#kiwiirc_distributeStatic
.#webircgateway  .#kiwiirc-desktop

For example, running nix build .#kiwiirc will produce a result:

❯ nix build .#kiwiirc_distributeStatic
❯ ls result/
f66bb623-kiwiirc_darwin_amd64.zip  f66bb623-kiwiirc_linux_armel.zip
f66bb623-kiwiirc_darwin_arm64.zip  f66bb623-kiwiirc_linux_armhf.zip
f66bb623-kiwiirc_linux_386.zip     f66bb623-kiwiirc_linux_riscv64.zip
f66bb623-kiwiirc_linux_amd64.zip   f66bb623-kiwiirc_windows_386.zip
f66bb623-kiwiirc_linux_arm64.zip   f66bb623-kiwiirc_windows_amd64.zip

❯ nix build .#kiwiirc
❯ ls result/www/
index.html  LICENSE  static

For example, users may now run nix build github:kiwiirc/kiwiirc#kiwiirc-desktop to build the desktop client from source, reproducibly, on any Linux machine with nix available. nix can be used on any Linux distribution.

The log of work done to produce this is here https://github.com/ngi-nix/kiwiirc/pull/2

Nix builds are reproducible and deterministic. They do not use the host's environment for any reason, as they are sandboxed. A build on my machine will result in the same hash on your machine, as on another machine every time, since all inputs are controlled. This is the goal, and it is successful at this in the majority of cases. There are some exceptions with Java and reading system time, but issues like these are easily identified and worked around.

The Nix thesis can be read here: https://edolstra.github.io/pubs/phd-thesis.pdf

Co-authored-by: DieracDelta [email protected] Co-authored-by: Malte [email protected] Co-authored-by: Las Safin [email protected]

MatthewCroughan avatar Oct 15 '21 17:10 MatthewCroughan

Testing this PR can be done on any Linux distribution, or on macOS, or on the WSL1/2 if you're running Windows. Simply install Nix:

curl -L https://nixos.org/nix/install | sh

That will work in WSL1/2, macOS or on any Linux distribution.

If this still scares you, you can use Docker to run Nix and test the majority of this PR. Just know that this is not necessary, and I encourage you not to attempt to use Docker/Github Actions to perform CI with Nix, since you will receive none of the caching benefits that Nix provides.

  1. Get nix inside of a Docker container: docker run -it nixos/nix sh
  2. Once inside, get nix 2.4: nix-shell -p nixUnstable
  3. Test this PR: nix build github:ngi-nix/kiwiirc/flake#kiwiirc --experimental-features 'nix-command flakes' nix build github:ngi-nix/kiwiirc/flake#kiwiirc_distributeStatic --experimental-features 'nix-command flakes'

MatthewCroughan avatar Oct 26 '21 17:10 MatthewCroughan

@ItsOnlyBinary it has been almost a year since we last spoke about this, but it'd be great if you could review it and consider using Nix. The Summer of Nix 2021 was the reason I created this, as NLNet/NGI are packaging various open source projects using Nix, so that they meet standards of long-term reproducibility. If there's been any advancements to Kiwiirc's packaging that are not taken into account by this PR, let me know and I'll add those outputs that are missing, since the Summer of Nix 2022 is now active and I'm looking back on the previous year of work :smile:

MatthewCroughan avatar Jul 28 '22 12:07 MatthewCroughan