This commit is contained in:
Elnu 2023-11-13 10:19:04 -08:00
parent a4a69a89fd
commit 23ec580178
8 changed files with 377 additions and 26 deletions

View file

@ -1,6 +1,6 @@
/*
TODO
1. Find and replace "helloworld" with your package name for **ALL FILES IN REPOSITORY**
1. Find and replace "dorm-controller" with your package name for **ALL FILES IN REPOSITORY**
2. Add a flake description that describes the workspace on line 27
3. Add a package description on line 70
4. (optional) uncomment `nativeBuildInputs` and `buildInputs` on lines 43 and 44 if you need openssl
@ -13,8 +13,8 @@ TODO
Some utility commands:
- `nix flake update --commit-lock-file`
- `nix flake lock update-input <input>`
- `nix build .#helloworld` or `nix build .`
- `nix run .#helloworld` or `nix run .`
- `nix build .#dorm-controller` or `nix build .`
- `nix run .#dorm-controller` or `nix run .`
*/
{
@ -34,8 +34,8 @@ Some utility commands:
};
rustSettings = with pkgs; {
src = ./.;
#nativeBuildInputs = [ pkg-config ];
#buildInputs = [ openssl ];
nativeBuildInputs = [ pkg-config ];
buildInputs = [ libudev-zero ];
cargoHash = nixpkgs.lib.fakeHash;
};
meta = with nixpkgs.lib; {
@ -53,14 +53,14 @@ Some utility commands:
cargo-edit
bacon
];
inputsFrom = with self.packages.${system}; [ helloworld ];
inputsFrom = with self.packages.${system}; [ dorm-controller ];
};
packages.${system} = {
default = self.packages.${system}.helloworld;
helloworld = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "helloworld";
default = self.packages.${system}.dorm-controller;
dorm-controller = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "dorm-controller";
version = "0.1.0";
buildAndTestSubdir = "helloworld";
buildAndTestSubdir = "dorm-controller";
cargoHash = "sha256-+TaGIiKf+Pz2bTABeG8aCZz0/ZTCKl5398+qbas4Nvo=";
meta = meta // {
description = "";
@ -71,14 +71,14 @@ Some utility commands:
nixosModules.default = { config, ... }: let
lib = nixpkgs.lib;
in {
options.services.helloworld = {
enable = lib.mkEnableOption (lib.mdDoc "helloworld service");
options.services.dorm-controller = {
enable = lib.mkEnableOption (lib.mdDoc "dorm-controller service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.helloworld;
defaultText = "pkgs.helloworld";
default = self.packages.${system}.dorm-controller;
defaultText = "pkgs.dorm-controller";
description = lib.mdDoc ''
The helloworld package that should be used.
The dorm-controller package that should be used.
'';
};
port = lib.mkOption {
@ -89,16 +89,16 @@ Some utility commands:
'';
};
};
config.systemd.services.helloworld = let
cfg = config.services.helloworld;
pkg = self.packages.${system}.helloworld;
config.systemd.services.dorm-controller = let
cfg = config.services.dorm-controller;
pkg = self.packages.${system}.dorm-controller;
in lib.mkIf cfg.enable {
description = pkg.meta.description;
after = [ "network.target" ];
wantedBy = [ "network.target" ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/helloworld --port ${builtins.toString cfg.port}
${cfg.package}/bin/dorm-controller --port ${builtins.toString cfg.port}
'';
Restart = "always";
DynamicUser = true;