So i’ve been using NixOs for half a year now. Reading up on the Nix language / library really proves to be hard to me. Best resource has been nixpkgs repo so far. But only having done some non-functional programming in my life, nix really messes with my head.
Currently i have this in my flake.nix for my client, so i can add more clients in the future.
nixosConfigurations =
let
mkHost =
hostname:
{
system ? "x86_64-linux",
}:
nixpkgs.lib.nixosSystem {
specialArgs = {
inherit hostname system;
unstable = import nixpkgs-unstable {
inherit system;
config.allowUnfree = allowUnfree;
};
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = allowUnfree;
};
};
modules = [ ./clients/${hostname} ];
};
in
nixpkgs.lib.mapAttrs mkHost { tux = { }; }
This works perfectly fine. One thing i don’t understand about it though is how it nixosConfigrations.“…” is set with this mkHost function. Does it just apply the first function parameter? Also, is there a way to avoid having to inherit system everywhere?
No I’ve been trying to get a similar thing going for server infrastructure using deploy-rs, since i really don’t want to retype hostnames all the time, just set it in one place and forget about it. Currently I’m typing the hostname in 6 different places, which is way to many times.
nixosConfigurations.nc = nixpkgs.lib.nixosSystem {
system = "x86-64-linux";
specialArgs = {
hostname = "nc";
};
modules = [ ./hosts/nc ];
};
deploy.nodes.nc = {
hostname = "nc.${domain}";
profiles.system = {
user = "root";
sshUser = "admin";
path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.nc;
};
};
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
};
So how could i streamline this so that i only have to type the hostname once, like in the first example. I’m having a really hard time figuring this stuff out.
I’v Looked at the “Nix Language: Learning resources” and they helped me understand the basics, but this stuff just goes over my head. I also can’t comprehend what the “checks” value would possibly be evaluated to.
Any help is greatly appreciated.
Cheers!
BTW just made this account and didn’t expect to get my name, there’s always a first i guess