[nix] expose a nixos module
This commit is contained in:
parent
062a76c8ba
commit
ae7ba0141e
47
flake.nix
47
flake.nix
@ -20,7 +20,7 @@
|
||||
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
|
||||
|
||||
# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
|
||||
packageName = "quptes-api";
|
||||
packageName = "quotes-api";
|
||||
in {
|
||||
packages.${packageName} = haskellPackages.callCabal2nix packageName self
|
||||
rec {
|
||||
@ -30,10 +30,53 @@
|
||||
packages.default = self.packages.${system}.${packageName};
|
||||
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 {
|
||||
buildInputs = with pkgs; [
|
||||
haskellPackages.haskell-language-server # you must build it with your ghc to work
|
||||
haskellPackages.hoogle
|
||||
ghcid
|
||||
hlint
|
||||
ghc
|
||||
|
Loading…
Reference in New Issue
Block a user