mirror of
https://github.com/khuedoan/homelab.git
synced 2025-07-08 23:08:40 +07:00
refactor(tools): switch to Nix
- Nix is more reproducible (pinned to a specific hash) - Faster rebuild after changing the package list (due to /nix caching in volume) - Users can still use make tools (wrapped in Docker) without installing Nix - Using nix-shell will work if you have nix installed.
This commit is contained in:
15
Makefile
15
Makefile
@ -27,7 +27,20 @@ post-install:
|
|||||||
@./scripts/hacks
|
@./scripts/hacks
|
||||||
|
|
||||||
tools:
|
tools:
|
||||||
make -C tools
|
@docker run \
|
||||||
|
--rm \
|
||||||
|
--interactive \
|
||||||
|
--tty \
|
||||||
|
--network host \
|
||||||
|
--env "KUBECONFIG=${KUBECONFIG}" \
|
||||||
|
--volume "/var/run/docker.sock:/var/run/docker.sock" \
|
||||||
|
--volume $(shell pwd):$(shell pwd) \
|
||||||
|
--volume ${HOME}/.ssh:/root/.ssh \
|
||||||
|
--volume ${HOME}/.terraform.d:/root/.terraform.d \
|
||||||
|
--volume homelab-tools-cache:/root/.cache \
|
||||||
|
--volume homelab-tools-nix:/nix \
|
||||||
|
--workdir $(shell pwd) \
|
||||||
|
nixos/nix nix-shell
|
||||||
|
|
||||||
test:
|
test:
|
||||||
make -C test
|
make -C test
|
||||||
|
@ -2,9 +2,17 @@
|
|||||||
|
|
||||||
Open the tools container, which includes all the tools needed:
|
Open the tools container, which includes all the tools needed:
|
||||||
|
|
||||||
```sh
|
=== "Docker"
|
||||||
make tools
|
|
||||||
```
|
```sh
|
||||||
|
make tools
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Nix"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
|
|
||||||
|
@ -2,9 +2,17 @@
|
|||||||
|
|
||||||
Open the tools container if you haven't already:
|
Open the tools container if you haven't already:
|
||||||
|
|
||||||
```sh
|
=== "Docker"
|
||||||
make tools
|
|
||||||
```
|
```sh
|
||||||
|
make tools
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Nix"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
Build the lab:
|
Build the lab:
|
||||||
|
|
||||||
|
@ -39,9 +39,17 @@ git checkout dev
|
|||||||
|
|
||||||
Open the tools container, which includes all the tools needed:
|
Open the tools container, which includes all the tools needed:
|
||||||
|
|
||||||
```sh
|
=== "Docker"
|
||||||
make tools
|
|
||||||
```
|
```sh
|
||||||
|
make tools
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Nix"
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
Build a development cluster and bootstrap it:
|
Build a development cluster and bootstrap it:
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ markdown_extensions:
|
|||||||
- name: mermaid
|
- name: mermaid
|
||||||
class: mermaid
|
class: mermaid
|
||||||
format: !!python/name:pymdownx.superfences.fence_code_format
|
format: !!python/name:pymdownx.superfences.fence_code_format
|
||||||
|
- pymdownx.tabbed:
|
||||||
|
alternate_style: true
|
||||||
|
|
||||||
nav:
|
nav:
|
||||||
- Home: index.md
|
- Home: index.md
|
||||||
|
2
scripts/configure
vendored
2
scripts/configure
vendored
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# WIP
|
# WIP
|
||||||
# TODO clean this up
|
# TODO clean this up
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Quick and dirty script for things that I can't/don't have time to do properly yet
|
Quick and dirty script for things that I can't/don't have time to do properly yet
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# WIP
|
# WIP
|
||||||
# - [x] take screenshot
|
# - [x] take screenshot
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
40
shell.nix
Normal file
40
shell.nix
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# https://status.nixos.org
|
||||||
|
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/f034b5693a26625f56068af983ed7727a60b5f8b.tar.gz") {} }:
|
||||||
|
|
||||||
|
let
|
||||||
|
python-packages = pkgs.python3.withPackages (p: with p; [
|
||||||
|
jinja2
|
||||||
|
kubernetes
|
||||||
|
netaddr
|
||||||
|
rich
|
||||||
|
]);
|
||||||
|
in
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
ansible
|
||||||
|
ansible-lint
|
||||||
|
bmake
|
||||||
|
diffutils
|
||||||
|
docker
|
||||||
|
docker-compose_1 # TODO upgrade to version 2
|
||||||
|
git
|
||||||
|
go
|
||||||
|
grc
|
||||||
|
iproute2
|
||||||
|
k9s
|
||||||
|
kube3d
|
||||||
|
kubectl
|
||||||
|
kubernetes-helm
|
||||||
|
kustomize
|
||||||
|
libisoburn
|
||||||
|
neovim
|
||||||
|
openssh
|
||||||
|
p7zip
|
||||||
|
pre-commit
|
||||||
|
shellcheck
|
||||||
|
terraform
|
||||||
|
yamllint
|
||||||
|
|
||||||
|
python-packages
|
||||||
|
];
|
||||||
|
}
|
@ -1,16 +1,32 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gruntwork-io/terratest/modules/docker"
|
"github.com/gruntwork-io/terratest/modules/docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestToolsContainer(t *testing.T) {
|
func TestToolsContainer(t *testing.T) {
|
||||||
tag := "homelab-tools"
|
image := "nixos/nix"
|
||||||
buildOptions := &docker.BuildOptions{
|
projectRoot, _ := filepath.Abs("../")
|
||||||
Tags: []string{tag},
|
|
||||||
|
options := &docker.RunOptions{
|
||||||
|
Remove: true,
|
||||||
|
Volumes: []string{
|
||||||
|
fmt.Sprintf("%s:%s", projectRoot, projectRoot),
|
||||||
|
"homelab-tools-cache:/root/.cache",
|
||||||
|
"homelab-tools-nix:/nix",
|
||||||
|
},
|
||||||
|
OtherOptions: []string{
|
||||||
|
"--workdir", projectRoot,
|
||||||
|
},
|
||||||
|
Command: []string{
|
||||||
|
"nix-shell",
|
||||||
|
"--command", "exit",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
docker.Build(t, "../tools", buildOptions)
|
docker.Run(t, image, options)
|
||||||
}
|
}
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
FROM archlinux
|
|
||||||
|
|
||||||
# Sort mirrors by speed
|
|
||||||
RUN pacman --sync --refresh --noconfirm \
|
|
||||||
reflector \
|
|
||||||
&& reflector \
|
|
||||||
--save /etc/pacman.d/mirrorlist \
|
|
||||||
--protocol https \
|
|
||||||
--latest 20 \
|
|
||||||
--sort rate
|
|
||||||
|
|
||||||
RUN pacman --sync --refresh --noconfirm \
|
|
||||||
ansible \
|
|
||||||
ansible-lint \
|
|
||||||
diffutils \
|
|
||||||
docker \
|
|
||||||
docker-compose \
|
|
||||||
git \
|
|
||||||
go \
|
|
||||||
graphviz \
|
|
||||||
grc \
|
|
||||||
helm \
|
|
||||||
k9s \
|
|
||||||
kubectl \
|
|
||||||
kustomize \
|
|
||||||
libisoburn \
|
|
||||||
make \
|
|
||||||
mdbook \
|
|
||||||
neovim \
|
|
||||||
openssh \
|
|
||||||
p7zip \
|
|
||||||
python \
|
|
||||||
python-jinja \
|
|
||||||
python-kubernetes \
|
|
||||||
python-netaddr \
|
|
||||||
python-pip \
|
|
||||||
python-pre-commit \
|
|
||||||
python-rich \
|
|
||||||
shellcheck \
|
|
||||||
sudo \
|
|
||||||
terraform \
|
|
||||||
yamllint
|
|
||||||
|
|
||||||
RUN curl -L https://github.com/k3d-io/k3d/releases/latest/download/k3d-linux-amd64 -o /usr/local/bin/k3d -s \
|
|
||||||
&& chmod +x /usr/local/bin/k3d
|
|
||||||
|
|
||||||
# TODO https://github.com/ansible-collections/community.docker/issues/216
|
|
||||||
RUN pip install docker-compose
|
|
@ -1,25 +0,0 @@
|
|||||||
.POSIX:
|
|
||||||
|
|
||||||
TAG = homelab-tools
|
|
||||||
|
|
||||||
default: build run
|
|
||||||
|
|
||||||
build:
|
|
||||||
@docker build . --tag ${TAG}
|
|
||||||
|
|
||||||
run:
|
|
||||||
@docker run \
|
|
||||||
--rm \
|
|
||||||
--interactive \
|
|
||||||
--tty \
|
|
||||||
--network host \
|
|
||||||
--env "TERM=${TERM}" \
|
|
||||||
--env "HOME=${HOME}" \
|
|
||||||
--env "KUBECONFIG=${KUBECONFIG}" \
|
|
||||||
--volume "${HOME}:${HOME}" \
|
|
||||||
--volume "/var/run/docker.sock:/var/run/docker.sock" \
|
|
||||||
--volume "/etc/passwd:/etc/passwd" \
|
|
||||||
--user "$(shell id -u ${USER}):$(shell id -g ${USER})" \
|
|
||||||
--group-add "$(shell getent group docker | cut -d ':' -f 3)" \
|
|
||||||
--workdir "$(shell pwd)/.." \
|
|
||||||
${TAG}
|
|
Reference in New Issue
Block a user