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

chore: add nixos config #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
86 changes: 68 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,74 @@
};

outputs = { self, nixpkgs, naersk, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
naerskLib = pkgs.callPackage naersk { };
in
{
defaultPackage = naerskLib.buildPackage ./.;

devShell = with pkgs; mkShell {
buildInputs = [ cargo rustc rustfmt rustPackages.clippy ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
naerskLib = pkgs.callPackage naersk { };
in
{
packages = rec {
corn-api = naerskLib.buildPackage ./.;
default = corn-api;
};
}) // {
nixosModules.default = { config, pkgs, ... }:
let
cfg = config.services.corn-api;
lib = pkgs.lib;
defaultPkg = self.packages.${pkgs.hostPlatform.system}.default;
in
{
options.services.corn-api = {
enable = lib.mkEnableOption "Web API for Corn configuration language";

package = lib.mkOption {
type = lib.types.package;
default = defaultPkg;
description = "The package to use";
};

host = lib.mkOption {
type = lib.types.str;
description = "The hostname to listen on";
default = "127.0.0.1";
};

port = lib.mkOption {
type = lib.types.port;
description = "The port number to listen on";
default = 5050;
};
};

config = let pkg = cfg.package; in {
systemd.services.corn-api = lib.mkIf cfg.enable {
description = "Web API for Corn configuration language";
documentation = [ "https://github.com/corn-config/corn-api" ];

nixConfig = {
extra-substituters = [ "https://cache.garnix.io" ];
extra-trusted-public-keys =
[ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
serviceConfig = {
ExecStart = "${pkg}/bin/corn-api";
Restart = "on-failure";
};

environment.HOST = cfg.host;
environment.PORT = toString cfg.port;

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

devShell = with nixpkgs; mkShell {
buildInputs = [ cargo rustc rustfmt rustPackages.clippy ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};

nixConfig = {
extra-substituters = [ "https://cache.garnix.io" ];
extra-trusted-public-keys =
[ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
};
};
}