Hello everyone, I’m trying to design a github repo that leverages github actions to create custom ISO nix images. By custom, I mean including SSH keys, setting the hostname, username, etc. I’m evaluating different design ideas for the template system, but as I’m relatively new to nix, I thought of asking here for different (ideally better) approaches.
How does it work?
I want a user to fork the repo, click on the github action, fill the inputs (username, hostname, public ssh, etc), and the image would be created.
I have all of that done, but I’m doubting how to give those inputs to the nix configuration.
Current idea
To think of every file inside nixosModules
as a string and use string interpolation. For example (a rough sketch):
nixosModules/user.nix
as:
{ inputs, ... }@flakeContext:
{ config, lib, pkgs, ... }:
let
ssh_pub_files = lib.filterAttrs (k: v: v == "regular" && lib.hasSuffix ".pub" k) (builtins.readDir ../authorized_keys);
in
{
config = {
users = {
users = {
${username} = {
isNormalUser = true;
initialPassword = "nixos";
extraGroups = [ ${groups} ];
openssh.authorizedKeys.keys = lib.mapAttrsToList (k: v: builtins.readFile "${../authorized_keys}/${k}") ssh_pub_files;
};
};
};
};
}
and then in another nix file, I would import that “template”, use getEnv
to get the inputs from the github action and then output new files, that nix would use to build the images.
Is there a better way?
Thanks
This is the repo: GitHub - woile/ganix-iso: Generate Nix ISO images using github actions and flakes