bringup: add semantics to start NixOS support
RFC 1/1 bringup: add semantics to start NixOS support
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
- playbooks/bringup_nixos.yml
- playbooks/update_ssh_config_nixos.yml
We can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
--- Kconfig | 8 ++ kconfigs/Kconfig.bringup | 47 +++++++++++ kconfigs/Kconfig.kdevops | 2 + playbooks/roles/gen_nodes/defaults/main.yml | 6 ++ playbooks/roles/gen_nodes/tasks/main.yml | 21 ++++- .../roles/gen_nodes/templates/nixos.nix.j2 | 34 ++++++++ scripts/nixos.Makefile | 77 +++++++++++++++++++ 7 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 playbooks/roles/gen_nodes/templates/nixos.nix.j2 create mode 100644 scripts/nixos.Makefile
Kconfig +8 -0
@@ -67,18 +67,26 @@ menu "Bring up methods" source "kconfigs/Kconfig.bringup" endmenu +if KDEVOPS_SUPPORTS_BRINGUP menu "Bring up goals" source "kconfigs/Kconfig.bringup.goals" endmenu +endif +if KDEVOPS_SUPPORTS_SYSCTL menu "Node sysctl configuration" source "kconfigs/Kconfig.sysctl" endmenu +endif +if KDEVOPS_SUPPORTS_WORKFLOWS menu "Target workflows" source "kconfigs/workflows/Kconfig" endmenu +endif +if KDEVOPS_SUPPORTS_CONFIG menu "Kdevops configuration" source "kconfigs/Kconfig.kdevops" endmenu +endif
kconfigs/Kconfig.bringup +47 -0
71 lines not on this page · raw message
kconfigs/Kconfig.kdevops +2 -0
@@ -192,6 +192,8 @@ menu "Ansible post-bring up provisioning configuration" source "kconfigs/Kconfig.ansible_provisioning" endmenu +if KDEVOPS_SUPPORTS_LEGACY_KERNELCI menu "Kernel continous integration configuration" source "kconfigs/Kconfig.kernel-ci" endmenu +endif
playbooks/roles/gen_nodes/defaults/main.yml +6 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier GPL-2.0+ --- +kdevops_generate_nodes: False +kdevops_enable_nixos: False kdevops_enable_guestfs: False kdevops_enable_terraform: False kdevops_enable_vagrant: False
@@ -19,6 +21,10 @@ kdevops_smbd_enable: False kdevops_krb5_enable: False kdevops_enable_iscsi: false + +kdevops_node_path: "" +nixos_path: "{{ topdir_path }}/nixos" + virtualbox_provider: False libvirt_provider: False
playbooks/roles/gen_nodes/tasks/main.yml +20 -1
@@ -18,6 +18,18 @@ command: "id -g -n" register: my_group +- name: Create NixOS directory + ansible.builtin.file: + path: "{{ kdevops_nix_path }}" + state: directory + when: kdevops_enable_nixos|bool + +- name: Generate NixOS devshell.nix + template: + src: devshell.nix.j2 + dest: "{{ kdevops_nix_path }}" + when: kdevops_enable_nixos|bool + - name: Fail if kdevops_host_prefix contains a dash fail: msg: "Invalid kdevops_host_prefix '{{ kdevops_host_prefix }}'. The prefix cannot contain a dash ('-')."
@@ -544,7 +556,14 @@ include_vars: "{{ topdir_path }}/{{ kdevops_nodes }}" ignore_errors: yes when: - - kdevops_enable_guestfs|bool + - kdevops_generate_nodes|bool + +- name: Create local directories for each of the guests + ansible.builtin.file: + path: "{{ kdevops_node_path }}/{{ item.name }}" + state: directory + with_items: "{{ guestfs_nodes }}" + when: kdevops_enable_guestfs|bool - name: Create local directories for each of the guests ansible.builtin.file:
playbooks/roles/gen_nodes/templates/nixos.nix.j2 new file +34 -0
@@ -0,0 +1,34 @@ +{ config, pkgs, ... }: + +{ + imports = [ ./hardware-configuration.nix ]; + + networking.hostName = "{{ guest_hostname }}"; + networking.useDHCP = false; + + networking.interfaces.enp1s0.ipv4.addresses = [{ + address = "{{ guest_ip }}"; + prefixLength = 24; + }]; + networking.defaultGateway = "{{ guest_gateway }}"; + networking.nameservers = [ "{{ guest_dns }}" ]; + + time.timeZone = "UTC"; + + environment.systemPackages = with pkgs; [ + git + htop + sysbench + docker + ]; + + services.openssh.enable = true; + + users.users.kdevops = { + isNormalUser = true; + extraGroups = [ "wheel" ]; + password = "kdevops"; # for testing only; better to use hashedPassword + }; + + system.stateVersion = "24.05"; +}
scripts/nixos.Makefile new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.47.2
Quoted 10 lines · Luis Chamberlain
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
-
playbooks/bringup_nixos.yml
-playbooks/update_ssh_config_nixos.ymlWe can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
Quoted 8 lines
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
Signed-off-by Luis Chamberlain <[email protected]>
I have a WIP branch with some cleanup needed for this:
https://github.com/dkruces/kdevops/commits/nixos/
* kdevops: add nixos support
This simply makes kdevops runnable in NixOS by
chaning all the shebangs in scripts/.
* Makefile.kdevops: drop ansible_python_intepreter
Once ansible cfg series are merged, I think we an get rid of the python interperter in the ansible calls and configure that in Kconfig -> ansible.cfg.
* shell.nix
Just to launch a Nix shell with all kdevops dependencies.
* libvirt_user: add nixos support
Generates a kdevops/ in your Nix configuration/ folder. Output:
https://github.com/dkruces/nixos-config/tree/main/kdevops
My initial idea was to generate NixOS configuration with Ansible [1]. But Joel tried something different with flakes I think. Adding him to get more feeback on it.
One thing he found was the need of a hack to be able to launch virt-builder [2]:
virt-builder
virt-builder is installed with libguestfs, but has some issues from its packaging.
It is possible to work around those issues without modifying the package (when a pristine nixpkgs is needed).
$ mkdir -p ~/.config/virt-builder
$ cd ~/.config/virt-builder
$ ln -s /run/current-system/sw/etc/xdg/virt-builder/repos.d $ cd ~/.config
$ ln -s virt-builder/ .virt-builder-wrapped
This will make your user use the shipped repo configurations, and works around the fact that virt-builder reads its executable name to build its configuration
path. The executable being wrapped, it is named differently. error: cannot find
any suitable libguestfs supermin
Use use the package libguestfs-with-appliance. See
https://github.com/NixOS/nixpkgs/issues/37540
The description looks like changes are needed in the package upstream. Not sure why this is not merged and how it differs from other distros, though.
Here the output for libguestfs nix package:
https://github.com/NixOS/nixpkgs/blob/nixos-24.11/pkgs/by-name/li/libguestfs/package.nix#L141
[1]
https://github.com/dkruces/kdevops/commit/2ef75c9913aafe88f5c454dab51908d0ad172b17
[2] https://nixos.wiki/wiki/Libvirt
Quoted 15 lines · Daniel Gomez
Quoted 14 lines · Luis Chamberlain
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
-
playbooks/bringup_nixos.yml
-playbooks/update_ssh_config_nixos.ymlWe can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Quoted 8 lines
Quoted 4 lines
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
Signed-off-by Luis Chamberlain <[email protected]>I have a WIP branch with some cleanup needed for this:
OK that and this patch can likely get us going somewhere fast.
Quoted 8 lines
* kdevops: add nixos support
This simply makes kdevops runnable in NixOS by
chaning all the shebangs inscripts/.* Makefile.kdevops: drop
ansible_python_intepreter
Once ansible cfg series are merged, I think we an get rid of the python interperter in the ansible calls and configure that inKconfig-> ansible.cfg.
Quoted 8 lines
* shell.nix
Just to launch a Nix shell with all kdevops dependencies.*
libvirt_user: add nixos support
Generates a kdevops/ in your Nix configuration/ folder. Output:
https://github.com/dkruces/nixos-config/tree/main/kdevopsMy initial idea was to generate NixOS configuration with Ansible [1].
If folks don't want to use libvirt they can just a config yaml entry describing their qemu junk, and Kconfig should be able then to read that in and populate pool crap and all that. Do nixos users with virtualization who are on debian use session URI or system URI? I ask as system URI crap requires privileges, which is why we do tons of hoops with sudo for system URI.
Fedora based distros use session URI by default
Debian based distros use system URI by default
What do we want to assume for nix os users?
Quoted 5 lines
But Joel
tried something different with flakes I think. Adding him to get more feeback on it.One thing he found was the need of a hack to be able to launch virt-builder [2]:
Hrm, so the use case was to use virt-builder with nix? Is that the nixy way to deal with things?
Luis
Quoted 51 lines · Luis Chamberlain
Quoted 15 lines · Daniel Gomez
Quoted 14 lines · Luis Chamberlain
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
-
playbooks/bringup_nixos.yml
-playbooks/update_ssh_config_nixos.ymlWe can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Quoted 8 lines
Quoted 4 lines
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
Signed-off-by Luis Chamberlain <[email protected]>I have a WIP branch with some cleanup needed for this:
OK that and this patch can likely get us going somewhere fast.
Quoted 8 lines
* kdevops: add nixos support
This simply makes kdevops runnable in NixOS by
chaning all the shebangs inscripts/.* Makefile.kdevops: drop
ansible_python_intepreter
Once ansible cfg series are merged, I think we an get rid of the python interperter in the ansible calls and configure that inKconfig-> ansible.cfg.Quoted 8 lines
* shell.nix
Just to launch a Nix shell with all kdevops dependencies.*
libvirt_user: add nixos support
Generates a kdevops/ in your Nix configuration/ folder. Output:
https://github.com/dkruces/nixos-config/tree/main/kdevopsMy initial idea was to generate NixOS configuration with Ansible [1].
If folks don't want to use libvirt they can just a config yaml entry describing their qemu junk, and
Kconfigshould be able then to read that in and populate pool crap and all that. Do nixos users with virtualization who are on debian use session URI or system URI? I ask as system URI crap requires privileges, which is why we do tons of hoops with sudo for system URI.
Quoted 2 lines
Fedora based distros use session URI by default
Debian based distros use system URI by default
My feedback and patches aim to enable kdevops on NixOS hosts, but I now realize this changes are for guests.
Sorry for the noise.
Quoted 11 lines
What do we want to assume for nix os users?
Quoted 5 lines
But Joel
tried something different with flakes I think. Adding him to get more feeback on it.One thing he found was the need of a hack to be able to launch virt-builder [2]:
Hrm, so the use case was to use virt-builder with nix? Is that the nixy way to deal with things?
I can't generalize, but nix approach, whether host or guest, it's quite different. For packages, user, groups etc, it would be enough to add a file in kdevops repository to statically define package dependencies and permissions needed.
Quoted 2 lines
Luis
Quoted 69 lines · Daniel Gomez
Quoted 51 lines · Luis Chamberlain
Quoted 15 lines · Daniel Gomez
Quoted 14 lines · Luis Chamberlain
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
-
playbooks/bringup_nixos.yml
-playbooks/update_ssh_config_nixos.ymlWe can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Quoted 8 lines
Quoted 4 lines
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
Signed-off-by Luis Chamberlain <[email protected]>I have a WIP branch with some cleanup needed for this:
OK that and this patch can likely get us going somewhere fast.
Quoted 8 lines
* kdevops: add nixos support
This simply makes kdevops runnable in NixOS by
chaning all the shebangs inscripts/.* Makefile.kdevops: drop
ansible_python_intepreter
Once ansible cfg series are merged, I think we an get rid of the python interperter in the ansible calls and configure that inKconfig-> ansible.cfg.Quoted 8 lines
* shell.nix
Just to launch a Nix shell with all kdevops dependencies.*
libvirt_user: add nixos support
Generates a kdevops/ in your Nix configuration/ folder. Output:
https://github.com/dkruces/nixos-config/tree/main/kdevopsMy initial idea was to generate NixOS configuration with Ansible [1].
If folks don't want to use libvirt they can just a config yaml entry describing their qemu junk, and
Kconfigshould be able then to read that in and populate pool crap and all that. Do nixos users with virtualization who are on debian use session URI or system URI? I ask as system URI crap requires privileges, which is why we do tons of hoops with sudo for system URI.Quoted 2 lines
Fedora based distros use session URI by default
Debian based distros use system URI by defaultMy feedback and patches aim to enable kdevops on NixOS hosts, but I now realize this changes are for guests.
Sorry for the noise.
Quoted 9 lines
What do we want to assume for nix os users?
Quoted 5 lines
But Joel
tried something different with flakes I think. Adding him to get more feeback on it.One thing he found was the need of a hack to be able to launch virt-builder [2]:
Quoted 7 lines
Quoted 2 lines
Hrm, so the use case was to use virt-builder with nix? Is that the nixy way to deal with things?
I can't generalize, but nix approach, whether host or guest, it's quite different. For packages, user, groups etc, it would be enough to add a file in kdevops repository to statically define package dependencies and permissions needed.
No need for virt-builder or similar tools with nix virtual machines. You can simply mount the nix store into the vm with virtiofs and go. No image required.
You probably want to generate a nix expression describing your vm from your kconfig settings. Seems like you might want to use ansible to do this, but really a small piece of shell script or python could do this for you.
If you need any input on how to make this work, I can give you some input. I am booting a nixos vm in this way for my development workflow.
Best regards,
Andreas Hindborg
Quoted 19 lines · Luis Chamberlain
Quoted 18 lines · Daniel Gomez
Quoted 17 lines · Luis Chamberlain
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
-
playbooks/bringup_nixos.yml
-playbooks/update_ssh_config_nixos.ymlWe can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
Quoted 18 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Luis Chamberlain <[email protected]>I have a WIP branch with some cleanup needed for this:
OK that and this patch can likely get us going somewhere fast.
Quoted 10 lines
* kdevops: add nixos support
This simply makes kdevops runnable in NixOS by
chaning all the shebangs inscripts/.* Makefile.kdevops: drop
ansible_python_intepreter
Once ansible cfg series are merged, I think we an get rid of the python interperter in the ansible calls and configure that inKconfig-> ansible.cfg.* shell.nix
Just to launch a Nix shell with all kdevops dependencies.
Would be cool if that was a flake with a devshell.
Quoted 19 lines
Quoted 6 lines
*
libvirt_user: add nixos support
Generates a kdevops/ in your Nix configuration/ folder. Output:
https://github.com/dkruces/nixos-config/tree/main/kdevopsMy initial idea was to generate NixOS configuration with Ansible [1].
If folks don't want to use libvirt they can just a config yaml entry describing their qemu junk, and
Kconfigshould be able then to read that in and populate pool crap and all that. Do nixos users with virtualization who are on debian use session URI or system URI? I ask as system URI crap requires privileges, which is why we do tons of hoops with sudo for system URI.Fedora based distros use session URI by default
Debian based distros use system URI by defaultWhat do we want to assume for nix os users?
Quoted 8 lines
Quoted 5 lines
But Joel
tried something different with flakes I think. Adding him to get more feeback on it.One thing he found was the need of a hack to be able to launch virt-builder [2]:
Hrm, so the use case was to use virt-builder with nix? Is that the nixy way to deal with things?
I would suggest just spawning qemu directly with user mode networking. No need for root for any of this. Specifically, no need for virsh for just piecing together a few command line arguments.
Best regards,
Andreas Hindborg
Quoted 35 lines · Daniel Gomez
Quoted 10 lines · Luis Chamberlain
Tons still left to do... but hey, at least we get to trim clutter out and can aim for a simple setup. TODO:
-
playbooks/bringup_nixos.yml
-playbooks/update_ssh_config_nixos.ymlWe can probably just trim nixos.nix.j2 so to at least bring up a libvirt guest first, and then the second step is to use process a set of target nodes under a simple workflow.
Quoted 8 lines
So the only thing here this does is show how we need to first add tons of "support" bools and make terraform and guestfs to select them. That should probably just be its own patch before all this.
Then the makefile shows the bare bones bringup we need. But we can probably simplify that more.
Signed-off-by Luis Chamberlain <[email protected]>I have a WIP branch with some cleanup needed for this:
https://github.com/dkruces/kdevops/commits/nixos/
* kdevops: add nixos support
This simply makes kdevops runnable in NixOS by
chaning all the shebangs inscripts/.* Makefile.kdevops: drop
ansible_python_intepreter
Once ansible cfg series are merged, I think we an get rid of the python interperter in the ansible calls and configure that inKconfig-> ansible.cfg.* shell.nix
Just to launch a Nix shell with all kdevops dependencies.
Quoted 7 lines
*
libvirt_user: add nixos support
Generates a kdevops/ in your Nix configuration/ folder. Output:
https://github.com/dkruces/nixos-config/tree/main/kdevopsMy initial idea was to generate NixOS configuration with Ansible [1]. But Joel tried something different with flakes I think. Adding him to get more feeback on it.
I did not get too far with it. It all broke when I could not find an available virt-builder package. So I stopped trying.
After failing with my nix flake, I tested kdevops in a newly installed debian.
Best
Quoted 34 lines
One thing he found was the need of a hack to be able to launch virt-builder [2]:
virt-builder
virt-builder is installed with libguestfs, but has some issues from its packaging.
It is possible to work around those issues without modifying the package (when a pristine nixpkgs is needed).
$ mkdir -p ~/.config/virt-builder
$ cd ~/.config/virt-builder
$ ln -s/run/current-system/sw/etc/xdg/virt-builder/repos.d$ cd ~/.config
$ ln -s virt-builder/ .virt-builder-wrappedThis will make your user use the shipped repo configurations, and works around the fact that virt-builder reads its executable name to build its configuration
path. The executable being wrapped, it is named differently. error: cannot find
any suitable libguestfs superminUse use the package libguestfs-with-appliance. See
https://github.com/NixOS/nixpkgs/issues/37540The description looks like changes are needed in the package upstream. Not sure why this is not merged and how it differs from other distros, though.
Here the output for libguestfs nix package:
https://github.com/NixOS/nixpkgs/blob/nixos-24.11/pkgs/by-name/li/libguestfs/package.nix#L141[1]
https://github.com/dkruces/kdevops/commit/2ef75c9913aafe88f5c454dab51908d0ad172b17
[2] https://nixos.wiki/wiki/Libvirt
Signature · 1 line
Joel Granados