Skip to content

Instantly share code, notes, and snippets.

@tfc
Created July 15, 2025 07:44
Show Gist options
  • Save tfc/970a050e3ac814270545489f85431efb to your computer and use it in GitHub Desktop.
Save tfc/970a050e3ac814270545489f85431efb to your computer and use it in GitHub Desktop.
{ pkgs, ... }:
{
imports = [
./hello-as-a-service.nix
];
# variante A
# nixpkgs.overlays = [
# (final: prev: {
# hello = prev.hello.overrideAttrs (old: {
# doCheck = false;
# prePatch = ''
# substituteInPlace src/hello.c --replace-fail ", world" ", BWI"
# '';
# });
# })
# ];
# variante B
services.hello.package = pkgs.hello.overrideAttrs (old: {
doCheck = false;
prePatch = ''
substituteInPlace src/hello.c --replace-fail ", world" ", BWI"
'';
});
services.hello.enable = true;
networking.firewall.enable = true;
system.stateVersion = "22.11";
}
let
sources = import ./npins;
pkgs = import sources.nixpkgs { };
nixosEvaluation = pkgs.nixos [
./configuration.nix
./qemu-vm.nix
./hello-foo.nix
];
in
nixosEvaluation.config.system.build.vm
{ config, pkgs, lib, ... }:
let
cfg = config.services.hello;
in
{
options.services.hello = {
enable = lib.mkEnableOption "GNU-Hello as a Service";
port = lib.mkOption {
type = lib.types.port;
default = 8081;
description = "Port to listen on";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.hello;
};
};
config = lib.mkIf cfg.enable {
systemd.services.hello = {
description = "Friendly GNU-Hello as a Service Daemon";
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = ''${pkgs.socat}/bin/socat \
TCP4-LISTEN:${builtins.toString cfg.port},reuseaddr,fork \
EXEC:${cfg.package}/bin/hello
'';
};
};
}
{ pkgs, lib, ... }: {
services.hello.package = lib.mkForce (pkgs.hello.overrideAttrs (old: {
doCheck = false;
prePatch = ''
substituteInPlace src/hello.c --replace-fail ", world" ", foobar"
'';
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment