[nix] expose a nixos module

This commit is contained in:
Dhananjay Balan 2023-11-11 16:48:55 +01:00
parent 062a76c8ba
commit ae7ba0141e

View File

@ -20,7 +20,7 @@
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; })); pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw` # DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
packageName = "quptes-api"; packageName = "quotes-api";
in { in {
packages.${packageName} = haskellPackages.callCabal2nix packageName self packages.${packageName} = haskellPackages.callCabal2nix packageName self
rec { rec {
@ -30,10 +30,53 @@
packages.default = self.packages.${system}.${packageName}; packages.default = self.packages.${system}.${packageName};
defaultPackage = self.packages.${system}.default; defaultPackage = self.packages.${system}.default;
nixosModules = {
quotes-api = { config, lib, pkgs, ... }:
with lib;
let cfg = config.services.quotes-api;
in {
options.services.quotes-api = {
enable = mkEnableOption "Enables quotes api service";
port = mkOption rec {
type = types.int;
default = 8123;
example = default;
description = "bind port";
};
dbpath = mkOption rec {
type = types.string;
default = "/tmp/sqlite.db";
example = default;
description = "Path to sqlite database";
};
};
config = mkIf cfg.enable {
systemd.services."quotes-api" = {
wantedBy = [ "multi-user.target" ];
serviceConfig =
let pkg = self.packages.${pkgs.system}.default;
in {
Restart = "on-failure";
ExecStart = "${pkg}/bin/quotes-api --port ${
builtins.toString cfg.port
} --dbpath ${cfg.dbpath}";
};
};
};
};
};
nixosModule = self.nixosModules.${system}.quotes-api;
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
haskellPackages.haskell-language-server # you must build it with your ghc to work haskellPackages.haskell-language-server # you must build it with your ghc to work
haskellPackages.hoogle
ghcid ghcid
hlint hlint
ghc ghc