NixOS modules: Difference between revisions
imported>Tv |
imported>Makefu add example module |
||
Line 73: | Line 73: | ||
{ | { | ||
# ... | # ... | ||
} | |||
</syntaxhighlight> | |||
== Example Module == | |||
put into <code>hello.nix</code> in the same folder as your <code>configuration.nix</code>. | |||
<syntaxhighlight lang="nix"> | |||
{ lib, pkgs, config, ... }: | |||
with lib; | |||
let | |||
cfg = config.services.hello; | |||
in { | |||
options.services.hello = { | |||
enable = mkEnableOption "hello service"; | |||
greeter = mkOption { | |||
type = types.string; | |||
default = "world"; | |||
}; | |||
}; | |||
config = lib.mkIf cfg.enable { | |||
systemd.services.hello = { | |||
wantedBy = [ "multi-user.target" ]; | |||
serviceConfig.ExecStart = "${pkgs.hello}/bin/hello -g'Hello, ${escapeShellArg cfg.greeter}!'"; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight> | |||
Add the following to your <code>configuration.nix</code> | |||
<syntaxhighlight lang=nix> | |||
{ | |||
imports = [ ./hello.nix ]; | |||
... | |||
services.hello = { | |||
enable = true; | |||
greeter = "Bob"; | |||
}; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |