commit e9f538ed921f60f2820b24f537623b8b27f11e52 Author: xtrm Date: Wed Feb 19 13:05:06 2025 +0100 🔨 chore: initial commit Signed-off-by: xtrm diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b42106 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b8b9974 --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2025 kiroussa + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6385cb7 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# [inception-of-things](https://projects.intra.42.fr/projects/inception-of-things) + +> This project aims to introduce you to kubernetes from a developer perspective. You will have to set up small clusters and discover the mechanics of continuous integration. At the end of this project you will be able to have a working cluster in docker and have a usable continuous integration for your applications. + +## License + +This project is licensed under the [ISC License](LICENSE). diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a2c510a --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1739736696, + "narHash": "sha256-zON2GNBkzsIyALlOCFiEBcIjI4w38GYOb+P+R4S8Jsw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d74a2335ac9c133d6bbec9fc98d91a77f1604c1f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1680978846, + "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", + "owner": "nix-systems", + "repo": "x86_64-linux", + "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "x86_64-linux", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7b15aad --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + description = "Inception of Things"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + systems.url = "github:nix-systems/x86_64-linux"; + }; + + outputs = + { self, nixpkgs, ... }@inputs: + let + inherit (self) outputs; + systems = (import inputs.systems); + forAllSystems = nixpkgs.lib.genAttrs systems; + in + { + devShells = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = (import ./shell.nix) { inherit pkgs; }; + } + ); + }; +} + diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..daf6226 --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +{ + pkgs ? import { }, +}: + +pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + nixos-generators + ]; +} + +# vim: ts=2 sw=2 et diff --git a/vm/.gitignore b/vm/.gitignore new file mode 100644 index 0000000..8b5b4fa --- /dev/null +++ b/vm/.gitignore @@ -0,0 +1,3 @@ +*.qcow +*.qcow2 +result diff --git a/vm/aliases.nix b/vm/aliases.nix new file mode 100644 index 0000000..61d8606 --- /dev/null +++ b/vm/aliases.nix @@ -0,0 +1,12 @@ +{ + v = "nvim"; + vi = "nvim"; + vim = "nvim"; + ls = "eza --color=auto --group-directories-first"; + l = "ls -la --no-git"; + ll = "ls -la"; + cat = "bat"; + gs = "git status"; + gd = "git diff"; + gds = "git diff --staged"; +} diff --git a/vm/cleanup.sh b/vm/cleanup.sh new file mode 100755 index 0000000..ec906f4 --- /dev/null +++ b/vm/cleanup.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +rm -v nixos.qcow2 +rm -vfr result diff --git a/vm/configuration.nix b/vm/configuration.nix new file mode 100644 index 0000000..fa89dfc --- /dev/null +++ b/vm/configuration.nix @@ -0,0 +1,63 @@ +{ config, pkgs, modulesPath, hostname, ... }: + +{ + imports = [ + (modulesPath + "/profiles/minimal.nix") + ]; + + networking.hostName = hostname; + + nixpkgs.config.allowUnfree = true; + + # Since `fileSystems` is ignored by nixos-generators, we need to be creative + systemd.services.mount-iot = { + description = "Mount the IOT shared folder"; + + # fstab entry: + # host0 /wherever 9p trans=virtio,version=9p2000.L 0 0 + script = '' + mkdir -p /iot + /run/wrappers/bin/mount -t 9p -o trans=virtio,version=9p2000.L host0 /iot + ''; + + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + }; + + users.users.root = { + password = "toor"; + shell = pkgs.zsh; + }; + + services = { + getty.autologinUser = "root"; + }; + + programs = { + zsh = { + autosuggestions.enable = true; + syntaxHighlighting.enable = true; + enable = true; + enableBashCompletion = true; + shellAliases = (import ./aliases.nix); + }; + }; + + environment = { + systemPackages = with pkgs; [ + vagrant + git + zip + neovim + eza + bat + ]; + }; + + system.stateVersion = "24.11"; +} diff --git a/vm/flake.lock b/vm/flake.lock new file mode 100644 index 0000000..19e041f --- /dev/null +++ b/vm/flake.lock @@ -0,0 +1,80 @@ +{ + "nodes": { + "nixlib": { + "locked": { + "lastModified": 1736643958, + "narHash": "sha256-tmpqTSWVRJVhpvfSN9KXBvKEXplrwKnSZNAoNPf/S/s=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "1418bc28a52126761c02dd3d89b2d8ca0f521181", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixos-generators": { + "inputs": { + "nixlib": "nixlib", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737057290, + "narHash": "sha256-3Pe0yKlCc7EOeq1X/aJVDH0CtNL+tIBm49vpepwL1MQ=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "d002ce9b6e7eb467cd1c6bb9aef9c35d191b5453", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-generators", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1739736696, + "narHash": "sha256-zON2GNBkzsIyALlOCFiEBcIjI4w38GYOb+P+R4S8Jsw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d74a2335ac9c133d6bbec9fc98d91a77f1604c1f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixos-generators": "nixos-generators", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1680978846, + "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", + "owner": "nix-systems", + "repo": "x86_64-linux", + "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "x86_64-linux", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/vm/flake.nix b/vm/flake.nix new file mode 100644 index 0000000..fff73d0 --- /dev/null +++ b/vm/flake.nix @@ -0,0 +1,70 @@ +{ + description = "A NixOS configuration for the Inception of Things"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + systems.url = "github:nix-systems/x86_64-linux"; + nixos-generators = { + url = "github:nix-community/nixos-generators"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + nixos-generators, + ... + }@inputs: + let + inherit (self) outputs; + systems = (import inputs.systems); + forAllSystems = nixpkgs.lib.genAttrs systems; + hostname = "iot-box"; + in + { + packages = forAllSystems ( + system: + let + vm = nixos-generators.nixosGenerate { + inherit system; + specialArgs = { + inherit hostname; + }; + modules = [ + ./configuration.nix + ]; + format = "vm"; + }; + in + { + inherit vm; + default = vm; + } + ); + + apps = forAllSystems ( + system: + let + vm = { + type = "app"; + program = "${self.packages.${system}.vm}/bin/run-${hostname}-vm"; + programArgs = [ "-enable-kvm" ]; + }; + in + { + inherit vm; + default = vm; + } + ); + + formatter = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + pkgs.nixfmt-rfc-style + ); + }; +} diff --git a/vm/run.sh b/vm/run.sh new file mode 100755 index 0000000..82cc610 --- /dev/null +++ b/vm/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -euo pipefail + +nix run . -- -virtfs local,path=$(pwd)/..,mount_tag=host0,security_model=passthrough,id=host0