[Nix-dev] Re: NixOS: New scheme
Ludovic Courtès
ludo at gnu.org
Tue Nov 18 22:49:48 CET 2008
Hi,
Marc Weber <marco-oweber at gmx.de> writes:
>> too coarse-grain, and it breaks the principle of least authority. I
>
> In general this is good.
No it's not. :-)
> I really fail to see what difference it makes as
> - the jobs are run as root anyway
> - the jobs can run rm -fr / as root as well..
This is not what I had in mind. I was referring to PoLA in the context
of our "program" code, i.e., the Nix code in the NixOS repository.
If we were to make an analogy with a language like C, passing `pkgs'
and `config' to every function amounts to passing arguments using global
variables.
That is, instead of
int
do_things (pkg_t foo, pkg_t bar)
{
...
}
you would write:
struct
{
pkg_t foo; pkg_t bar; pkg_t baz; pkg_t chbouib; ...
} pkgs;
int
do_things (void)
{
/* Use `pkgs.foo', etc. */
...
}
As a functional programmer, you will surely agree that this is bad
programming style. ;-)
A practical consequence is that it makes it very hard to read the code
and understand what a function does since it takes input data
implicitly, from "the environment". It also makes it impossible to
"virtualize" functions: the second version of `do_things ()' will always
use the global `pkgs.foo' and cannot be told to use something else as
`foo'. In the context of the Nix interpreter, it probably prevents
optimizations since it's as if every Upstart job depended on *all*
packages (perhaps Eelco can comment on this).
Thanks,
Ludo'.
More information about the nix-dev
mailing list