tazjin / nixery

Container registry which transparently builds images using the Nix package manager. Canonical repository is https://cs.tvl.fyi/depot/-/tree/tools/nixery
https://nixery.dev/
Apache License 2.0
1.8k stars 67 forks source link

NixOS module? #155

Open mikepurvis opened 2 years ago

mikepurvis commented 2 years ago

Hey, this is a super nifty project— it looks like the native/supported deployment mechanism for it is via a container, but I'm wondering if there'd be any interest in supplying a flake file and NixOS module such that this could be deployed declaratively on NixOS using the standard configuration.nix, similar to how Hydra works.

tazjin commented 2 years ago

Hey!

We do have a NixOS module for Nixery in TVL: https://cs.tvl.fyi/depot/-/blob/ops/modules/nixery.nix

This actually runs the public nixery.dev instance.

It only supports local storage at the moment, but could be expanded to cover more config options. It currently assumes that Nixery is built in-tree, but could have an option for specifying the nixery package to use instead (would always be required as Nixery is not currently in nixpkgs).

I'd be happy to see that module extended for supporting these things, maybe it should even be moved into the Nixery source tree (which lives under /tools/nixery in our upstream repo), and we'd definitely accept changes for these.

Note that this repository on Github is just a mirror. We use Gerrit at cl.tvl.fyi for our actual development. It's configured to allow login via Github and some other things, so if you're interested in contributing this you can log in there and propose a change.

There are some contribution guidelines here: https://cs.tvl.fyi/depot/-/blob/docs/CONTRIBUTING.md

And some information about code review flows: https://cs.tvl.fyi/depot/-/blob/docs/REVIEWS.md

If you're decide to contribute and get stuck on anything, you can also reach us via chat:

We mostly hang out on IRC. You can find us in #tvl on hackint, which is also reachable via XMPP at #tvl@irc.hackint.org (sic!) and via Matrix at #tvl:hackint.org.

(Also the stuff I wrote here should probably be in a contributing guidelines doc in the Nixery source tree, but there's too little time and people to keep everything up to date at the moment :/)

And finally, we have a strict policy against experimental features and stick to Nix 2.3 while working on Tvix, so a flake file would not be accepted - but it should also not be necessary if we're just polishing the module.

adrian-gierakowski commented 2 years ago

And finally, we have a strict policy against experimental features and stick to Nix 2.3

May I ask why?

mikepurvis commented 1 year ago

Okay, thanks for the pointer on this! For anyone else who wants to run Nixery on a flake-based NixOS machine, here's as far as I made it:

# to the inputs section of flake.nix
    nixery-flake = {
      type = "github";
      owner = "tazjin";
      repo = "nixery";
      flake = false;
    };

# to the outputs section of flake.nix
      specialArgs = {
        nixery-pkgs = import nixery-flake.outPath {
          pkgs = import nixpkgs {
            inherit system;
          };
        };
      };

And then in the main configuration:

{ nixery-pkgs, nix, pkgs, ... }:

let
  description = "Nixery";
  storagePath = "/var/lib/nixery";

  nixery = nixery-pkgs.nixery.overrideAttrs(old: {
    # Drop the nix-1p documentation page as it doesn't build in pure evaluation.
    postInstall = ''
      wrapProgram $out/bin/server \
        --prefix PATH : ${nixery-pkgs.nixery-prepare-image}/bin \
        --prefix PATH : ${nix}/bin
    '';
  });

in
{
  systemd.services.nixery = {
    inherit description;
    wantedBy = [ "multi-user.target" ];

    serviceConfig = {
      DynamicUser = true;
      StateDirectory = "nixery";
      Restart = "always";
      ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p ${storagePath}";
      ExecStart = "${nixery}/bin/server";
    };

    environment = {
      PORT = "8080";
      NIXERY_PKGS_PATH = pkgs.path;
      NIXERY_STORAGE_BACKEND = "filesystem";
      NIX_TIMEOUT = "60";
      STORAGE_PATH = storagePath;
      WEB_DIR = "/dev/null";
    };
  };
}
Janik-Haag commented 1 year ago

are there plans to upstream a nixery module/package to nixpkgs at somepoint?