Skip to content

Commit

Permalink
feat: nixification (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
bddvlpr authored Jan 24, 2024
1 parent 9bee748 commit 5a54a3b
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 51 deletions.
53 changes: 35 additions & 18 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
{pkgs ? import <nixpkgs> {}}:
with pkgs;
mkYarnPackage rec {
pname = "untis-ics-sync";
version = "0.5.10";
{
mkYarnPackage,
fetchYarnDeps,
makeWrapper,
lib,
nodejs,
}:
mkYarnPackage rec {
pname = "untis-ics-sync";
version = "0.6.0";

src = ./.;
src = ./.;

offlineCache = fetchYarnDeps {
yarnLock = src + "/yarn.lock";
hash = "sha256-NHghkf5Nziyz3M7E4941sV5JFqY7RYMTlZqYsQPZLpU=";
};
offlineCache = fetchYarnDeps {
yarnLock = src + "/yarn.lock";
hash = "sha256-NHghkf5Nziyz3M7E4941sV5JFqY7RYMTlZqYsQPZLpU=";
};

packageJSON = ./package.json;
yarnLock = ./yarn.lock;
nativeBuildInputs = [makeWrapper];

buildPhase = ''
export HOME=$(mktemp -d)
yarn --offline build
'';
packageJSON = ./package.json;
yarnLock = ./yarn.lock;

distPhase = "true";
}
buildPhase = ''
yarn --offline run build
'';

postInstall = ''
makeWrapper ${lib.getExe nodejs} "$out/bin/untis-ics-sync" \
--add-flags "$out/libexec/untis-ics-sync/deps/untis-ics-sync/dist/main.js"
'';

meta = with lib; {
description = "Serves a calendar API (ICS) for events provided from Untis";
homepage = "https://github.com/bddvlpr/untis-ics-sync";
license = licenses.bsd3;
maintainers = with maintainers; [bddvlpr];
mainProgram = "untis-ics-sync";
};
}
50 changes: 44 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 32 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs = {nixpkgs, ...}: let
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];
in {
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
outputs = inputs @ {
self,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];

packages = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = import ./default.nix {inherit pkgs;};
}
);
perSystem = {pkgs, ...}: {
formatter = pkgs.alejandra;

devShell = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.mkShell {
packages = rec {
default = pkgs.callPackage ./default.nix {};
untis-ics-sync = default;
};

devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [nodejs yarn nest-cli];
}
);
};
};
};

flake = {
nixosModules = rec {
default = import ./module.nix self;
untis-ics-sync = default;
};
};
};
}
57 changes: 57 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
self: {
config,
lib,
pkgs,
...
}: let
cfg = config.services.untis-ics-sync;
in {
options.services.untis-ics-sync = let
inherit (lib) mkEnableOption mkPackageOption mkOption types;
inherit (pkgs.stdenv.hostPlatform) system;
in {
enable = mkEnableOption "Untis ICS Sync";
package = mkPackageOption self.packages.${system} "default" {};

envFile = mkOption {
type = types.path;
description = "The environment file with credentials.";
};

user = mkOption {
type = types.str;
default = "untis-ics-sync";
description = "The user to run untis-ics-sync under.";
};
group = mkOption {
type = types.str;
default = "untis-ics-sync";
description = "The group to run untis-ics-sync under.";
};
};

config = lib.mkIf cfg.enable {
systemd.services.untis-ics-sync = {
description = "untis-ics-sync";
wantedBy = ["multi-user.target"];
wants = ["network-online.target"];
after = ["network-online.target"];

serviceConfig = {
Restart = "on-failure";
ExecStart = "${lib.getExe cfg.package}";
EnvironmentFile = cfg.envFile;
User = cfg.user;
Group = cfg.group;
};
};

users = {
users.untis-ics-sync = lib.mkIf (cfg.user == "untis-ics-sync") {
isSystemUser = true;
group = cfg.group;
};
groups.untis-ics-sync = lib.mkIf (cfg.group == "untis-ics-sync") {};
};
};
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "untis-ics-sync",
"version": "0.5.10",
"version": "0.6.0",
"description": "Serves a calendar API (ICS) for events provided from Untis.",
"author": "Luna Simons <[email protected]> (https://bddvlpr.com)",
"bin": "dist/main.js",
"license": "BSD-3-Clause",
"private": true,
"scripts": {
Expand Down

0 comments on commit 5a54a3b

Please sign in to comment.