Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NixOS documentation to use package/module in nixpkgs #2220

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 10 additions & 93 deletions reposilite-site/data/guides/infrastructure/nixos.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,22 @@ title: NixOS
community: true
---

You can install Reposilite on NixOS using the following configuration.
[nixpkgs](https://github.com/NixOS/nixpkgs) contains a package and NixOS module for Reposilite.

Create a package expression in `/etc/nixos/reposilite-bin.nix` file (adjust JDK package
and JVM properties to your needs):

```nix
{ pkgs, ... }:
let
jdk = pkgs.openjdk17_headless;
stdenv = pkgs.stdenv;
in
stdenv.mkDerivation rec {
pname = "reposilite-bin";
version = "3.3.2";

jar = builtins.fetchurl {
url="https://maven.reposilite.com/releases/com/reposilite/reposilite/${version}/reposilite-${version}-all.jar";
sha256="369345847c98033ff2546d76e74702b859b41d05135997b4740d8e925f361a85";
};

dontUnpack = true;

nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
runHook preInstall
makeWrapper ${jdk}/bin/java $out/bin/reposilite \
--add-flags "-Xmx40m -jar $jar" \
--set JAVA_HOME ${jdk}
runHook postInstall
'';
}
```

Put the Reposilite configuration in `/etc/nixos/reposilite.nix` (adjust `cfg.user`, `cfg.group`
etc. to your needs):
You can enable and configure it via `services.reposilite` in your NixOS configuration (e.g. `/etc/nixos/configuration.nix`):

```nix
{ config, pkgs, ... }:
let
reposilite = (import ./reposilite-bin.nix { inherit pkgs; });
cfg = {
user = "reposilite";
group = "reposilite";
home = "/var/lib/reposilite";
pkg = reposilite;
port = 8084;
};
in
{
environment.systemPackages = [
cfg.pkg
];

users.groups.${cfg.group} = {
name = cfg.group;
};

users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
home = cfg.home;
createHome = true;
};

systemd.services."reposilite" = {
description = "Reposilite - Maven repository";

wantedBy = [ "multi-user.target" ];

script = "${cfg.pkg}/bin/reposilite --working-directory ${cfg.home} --port ${toString cfg.port}";
# ...

serviceConfig = {
User = cfg.user;
Group = cfg.group;
};
services.reposilite = {
enable = true;
openFirewall = false;
tokens = [
"tokenName:tokenSecret" # It is recommended to use a secret management strategy such as sops-nix here.
];
settings = { }; # Add settings that would usually go in the Reposilite config (`reposilite.cdn`) here, e.g. `sslEnabled = true`
};
}
```
Add Reposilite to NixOS e.g. in `/etc/nixos/configuration.nix`:

```nix
{ config, pkgs, ... }:
{
imports = [
# ...
./reposilite.nix
];
# ...
}
```

### Reposilite CLI

The configuration above adds Reposilite to the system path, which may be needed to configure
Reposilite. For example:

```bash
systemctl stop reposilite.service
runuser -u reposilite -g reposilite -- reposilite --working-directory /var/lib/reposilite --port 8084
```

When started from a terminal, Reposilite's console can be used to add users and tokens.
Loading