nixos - override services in nixpkgs for nixops deployment -
using nixops
1 can configure services like:
{ network.description = "web server"; webserver = { config, pkgs, ... }: { services.mysql = { enable = true; package = pkgs.mysql51; };
but want extend services
. example using override
done pkgs
below:
let myfoo = callpackage ... in pkgs = pkgs.override { overrides = self: super: { myfoo-core = myfoo; }; }
question
how services
?
adding service requires first write service definition service. is, nix file declares options of service , provides implementation.
let's our service called foo
, write service definition save file foo.nix
:
{ config, lib, pkgs, ... }: lib; # use functions lib, such mkif let # values of options set service user of service foocfg = config.services.foo; in { ##### interface. here define options users of our service can specify options = { # options our service located under services.foo services.foo = { enable = mkoption { type = types.bool; default = false; description = '' whether enable foo. ''; }; baroption = { type = types.str; default = "qux"; description = '' bar option foo. ''; }; }; }; ##### implementation config = mkif foocfg.enable { # apply following settings if enabled # here options can specified in configuration.nix may used # configure systemd services # add system users # write config files, example here: environment.etc."foo-bar" = { text = foocfg.bar; # can use values of options service here }; };
for example, hydra, file can found here: https://github.com/nixos/hydra/blob/dd32033657fc7d6a755c2feae1714148ee43fc7e/hydra-module.nix.
after having written service definition, can use our main configuration this:
{ network.description = "web server"; webserver = { config, pkgs, ... }: { imports = [ ./foo.nix ]; # import our service services.mysql = { enable = true; package = pkgs.mysql51; }; services.foo = { enable = true; bar = "hello nixos modules!"; }; };
}
disclaimer: there might typos in this, have not tested it.
Comments
Post a Comment