I’m trying to create a Flake that does the following:
builds and packages a Rust executable
exposes a NixOS module that provides a systemd service to run that executable (In my real project, it’s an HTTP server, but for this example it’s just a simple ‘Hello world!’).
I think I have managed the first step, but I’m struggling with the second step.
Please could I have some pointers on how to do this properly? I would also really appreciate links to example flakes that package an application + NixOS service module, because I would ideally like to figure out how to not only get this working, but also how to do it idiomatically/cleanly as well :-).
There are README.md files in nix_flake and nix_flake/test_vm with the commands I’m using to build/test; crucially what I’m doing to test my module is:
cd nix_flake/test_vm
nix flake update
nix build .#nixosConfigurations.testvm.config.system.build.vm -j8
./result/bin/run-nixos-vm
nix-foundryvtt is a flake that packages Foundry VTT and provides a service module for NixOS. The way I handle making foundryvtt available to the module is by adding an extra argument to the module for the flake.
# flake.nix
# ...
nixosModules.foundryvtt = import ./modules/foundryvtt self;
# ...
# modules/foundryvtt/default.nix
flake: { config, lib, pkgs, ... }:
# ...
inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) foundryvtt;
# ...
package = mkOption {
type = types.package;
default = foundryvtt;
description = ''
The Foundry package to use with the service.
'';
};
# ...
ExecStart = "${cfg.package}/bin/foundryvtt --headless --noupdate --dataPath=\"${dataDir}\"";
# ...
I then access my foundryvtt package via flake.packages.<system>.foundryvtt. You’re encountering an error because pkgs refers to nixpkgs, which does not include your hallo package (it’s in your flake’s packages).
Eureka! Thanks! That (plus a bit of tweaking to my package crate, which somehow failed to build the package when depended on by another flake) works :-).
I’m not sure, but I don’t think so. Unfortunately I don’t really remember very well or understand much; I’ve tried a lot of things to try and get something working