2022-12-19 00:26:14 -08:00
|
|
|
{
|
|
|
|
description = "Reproducible Environment for Grasp server";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
2023-04-26 22:09:01 -07:00
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
2022-12-19 00:26:14 -08:00
|
|
|
flake-utils.lib.eachDefaultSystem
|
|
|
|
(system:
|
|
|
|
let
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.grasp = pkgs.stdenv.mkDerivation rec {
|
|
|
|
pname = "grasp";
|
2022-12-19 18:25:22 -08:00
|
|
|
version = "v0.6.7";
|
|
|
|
src = ./.;
|
2022-12-19 00:26:14 -08:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cp -r server/* $out/bin/
|
|
|
|
'';
|
|
|
|
};
|
2023-04-26 22:09:01 -07:00
|
|
|
packages.default = self.packages.${system}.grasp;
|
2022-12-19 00:26:14 -08:00
|
|
|
devShell = pkgs.mkShell {
|
|
|
|
buildInputs = [ pkgs.python3 ];
|
|
|
|
};
|
|
|
|
}) // {
|
|
|
|
nixosModule = { options, lib, config, pkgs, ... }:
|
|
|
|
let
|
2022-12-19 18:25:22 -08:00
|
|
|
graspConfig = config.services.grasp;
|
2022-12-19 00:26:14 -08:00
|
|
|
|
|
|
|
options = {
|
|
|
|
enable = lib.mkEnableOption "Grasp service";
|
|
|
|
path = lib.mkOption rec {
|
|
|
|
type = lib.types.path;
|
|
|
|
default = "/var/lib/grasp/";
|
|
|
|
example = "/var/lib/grasp";
|
|
|
|
description = "Where to run Grasp from";
|
|
|
|
};
|
|
|
|
#port = lib.mkOption rec {
|
|
|
|
# type = lib.types.int;
|
|
|
|
# default = 12212;
|
|
|
|
# example = 12212;
|
|
|
|
# description = "Port to run the server on";
|
|
|
|
#};
|
|
|
|
user = lib.mkOption rec {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "";
|
|
|
|
example = "nixos";
|
|
|
|
description = "User to run the service as";
|
|
|
|
};
|
|
|
|
#template = mkOption rec {
|
|
|
|
# type = types.str;
|
|
|
|
# default = "12212";
|
|
|
|
# example = "12212";
|
|
|
|
# description = "Template to use";
|
|
|
|
#};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2023-04-26 22:18:59 -07:00
|
|
|
options.services.grasp = options;
|
2022-12-19 00:26:14 -08:00
|
|
|
config = lib.mkIf graspConfig.enable {
|
|
|
|
systemd.services.grasp-server = {
|
|
|
|
description = ''
|
|
|
|
A grasp server module
|
|
|
|
'';
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
#DynamicUser = true; # Probably should default to this if no user supplied
|
|
|
|
User = "${graspConfig.user}";
|
|
|
|
RuntimeDirectory = "${graspConfig.path}";
|
|
|
|
RuntimeDirectoryMode = "0755";
|
|
|
|
StateDirectory = "${graspConfig.path}";
|
|
|
|
StateDirectoryMode = "0700";
|
|
|
|
};
|
|
|
|
path = with pkgs; [ nix python3 ] ++ [ ];
|
|
|
|
script = ''
|
|
|
|
${self.packages.${pkgs.system}.grasp}/bin/grasp_server.py --path ${graspConfig.path}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
# Allow nginx through the firewall
|
|
|
|
networking.firewall.allowedTCPPorts = [ 12212 ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# Test container
|
|
|
|
nixosConfigurations."test" = nixpkgs.lib.nixosSystem {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
modules = [
|
|
|
|
self.nixosModule
|
|
|
|
({ pkgs, ... }: {
|
|
|
|
# Only allow this to boot as a container
|
|
|
|
boot.isContainer = true;
|
|
|
|
networking.hostName = "grasp";
|
2022-12-19 18:25:22 -08:00
|
|
|
services.grasp.enable = true;
|
|
|
|
services.grasp.user = "anish";
|
|
|
|
services.grasp.path = "/home/anish/grasp/capture.org";
|
2022-12-19 00:26:14 -08:00
|
|
|
# I think I actually created the above folder as well in the container
|
|
|
|
# I figured dynamic user with their own text file seems less useful
|
|
|
|
# I didn't know how to default to a
|
|
|
|
users.users.anish = {
|
|
|
|
isNormalUser = true;
|
|
|
|
password = "password";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|