[Nix-dev] Pass arguments to 'required' configs
Nicolas Pierron
nicolas.b.pierron at gmail.com
Tue Nov 17 15:55:23 CET 2015
Hi Sergey,
If you are not using the proxy_port and proxy_host values for
selecting the modules, I suggest you use the module system instead.
This means that your previous example would become something like the
example below. This solution is a bit more verbose, but you might be
able to introspect these options with nixos-option command line tool
and NixUI.
// configuration.nix
{
require = [
/etc/nixos/configuration.nix
./include/global_bash_aliases.nix
];
custom.go.proxy.port = 4343;
custom.go.proxy.host = "myproxy.local";
…
}
// ./include/global_bash_aliases.nix
{ config, pkgs, lib, ... } :
with lib;
{
options = {
custom.go.proxy.port = mkOption {
default = 4242;
example = 4343;
type = types.uniq types.int;
description = ''
port number used by the goproxy shell alias command.
'';
};
custom.go.proxy.host = mkOption {
example = "example.com";
type = types.uniq types.str;
description = ''
host name used by the goproxy shell alias command.
'';
};
};
config = {
environment = {
extraInit = with config.custom.go.proxy ''
alias goproxy "nc ${port} ${host}
'';
};
};
}
On Tue, Nov 17, 2015 at 2:17 PM, Sergey Mironov <grrwlf at gmail.com> wrote:
> Hi. This is a follow-up to my previous letter about Private NixOS modules.
>
> Another thing I am missing is the ability to pass arguments to
> 'required' configuration modules. Below is the illustration of the
> idea. Could you please give me some advice on this?
>
> Regards,
> Sergey
>
>
> // configuration.nix
>
> {config, pkgs, ...}:
> let
> proxy_port = "4343";
> proxy_host = "myproxy.local";
> in
> {
> require = [
> /etc/nixos/hardware-configuration.nix
> ..
> (withArguments ./include/global_bash_aliases.nix { inherit
> proxy_port proxy_host; })
> ..
> ];
> ...
>
> }
>
>
> //./include/global_bash_aliases.nix
>
> { proxy_port, proxy_host} :
> { config, pkgs, ... } :
> {
> environment = rec {
>
> extraInit = ''
> alias goproxy "nc ${proxy_port} ${proxy_host}
> '';
> };
>
> }
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
--
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron - http://nbp.name/
More information about the nix-dev
mailing list