From 0e9789cca55ae7593d72f08176339c52e0e971c5 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Fri, 2 Feb 2024 22:57:50 +0000 Subject: [PATCH] Setup a very basic development env --- .gitignore | 1 + flake.lock | 180 +++++++++++++++++++++++++++++++++ flake.nix | 95 +++++++++++++++++ worlds/base.nix | 26 +++++ worlds/majin/configuration.nix | 23 +++++ worlds/x1/configuration.nix | 0 6 files changed, 325 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 worlds/base.nix create mode 100644 worlds/majin/configuration.nix create mode 100644 worlds/x1/configuration.nix diff --git a/.gitignore b/.gitignore index c3561b3..998e454 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ result-* # Undo-tree save-files *.~undo-tree +vdisk1 \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..99b8a86 --- /dev/null +++ b/flake.lock @@ -0,0 +1,180 @@ +{ + "nodes": { + "agenix": { + "inputs": { + "darwin": "darwin", + "home-manager": "home-manager", + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems" + }, + "locked": { + "lastModified": 1703433843, + "narHash": "sha256-nmtA4KqFboWxxoOAA6Y1okHbZh+HsXaMPFkYHsoDRDw=", + "owner": "ryantm", + "repo": "agenix", + "rev": "417caa847f9383e111d1397039c9d4337d024bf0", + "type": "github" + }, + "original": { + "owner": "ryantm", + "repo": "agenix", + "type": "github" + } + }, + "darwin": { + "inputs": { + "nixpkgs": [ + "agenix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1700795494, + "narHash": "sha256-gzGLZSiOhf155FW7262kdHo2YDeugp3VuIFb4/GGng0=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "4b9b83d5a92e8c1fbfd8eb27eda375908c11ec4d", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "agenix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703113217, + "narHash": "sha256-7ulcXOk63TIT2lVDSExj7XzFx09LpdSAPtvgtM7yQPE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "3bfaacf46133c037bb356193bd2f1765d9dc82c1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "home-manager_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1706798041, + "narHash": "sha256-BbvuF4CsVRBGRP8P+R+JUilojk0M60D7hzqE0bEvJBQ=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "4d53427bce7bf3d17e699252fd84dc7468afc46e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixos-hardware": { + "locked": { + "lastModified": 1706834982, + "narHash": "sha256-3CfxA7gZ+DVv/N9Pvw61bV5Oe/mWfxYPyVQGqp9TMJA=", + "owner": "nixos", + "repo": "nixos-hardware", + "rev": "83e571bb291161682b9c3ccd48318f115143a550", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixos-hardware", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1706732774, + "narHash": "sha256-hqJlyJk4MRpcItGYMF+3uHe8HvxNETWvlGtLuVpqLU0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b8b232ae7b8b144397fdb12d20f592e5e7c1a64d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "agenix": "agenix", + "home-manager": "home-manager_2", + "nixos-hardware": "nixos-hardware", + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..17a0f9d --- /dev/null +++ b/flake.nix @@ -0,0 +1,95 @@ +{ + description = "lxsameer's universe"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixos-hardware.url = "github:nixos/nixos-hardware"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + agenix = { + url = "github:ryantm/agenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + utils.url = "github:numtide/flake-utils"; + + + # TODO: Checkout hercules + # hercules-ci-agent.url = "github:hercules-ci/hercules-ci-agent"; + # To build and android image + # robotnix.url = "github:danielfullmer/robotnix"; + # impermanence.url = "github:nix-community/impermanence"; + }; + + outputs = { self, home-manager, nixpkgs, agenix, nixos-hardware, utils } @ inputs: + let + # I just use linux and currently only x86_64 + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + + + # Add a command to the shell to create the disk + create-disk = pkgs.writeScriptBin "create-disk" '' + #!${pkgs.stdenv.shell} + + qemu-img create -f qcow2 vdisk1 10G + ''; + + + scripts = pkgs.symlinkJoin { + name = "universe_scripts"; + paths = [ + create-disk + ]; + }; + + nativeBuildInputs = with pkgs; [ + qemu + fish + zstd + scripts + ]; + + in rec{ + images = { + majin = (nixosConfigurations.majin.extendModules { + modules = [ + "${pkgs}/nixos/modules/installer/sd-card/sd-image-x86_64.nix" + { + disabledModules = [ "profiles/base.nix" ]; + } + ]; + }).config.system.build.sdImage; + }; + + packages.${system}.majin = images.majin; + + + nixosConfigurations = { + majin = pkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + "${pkgs}/nixos/modules/profiles/minimal.nix" + ./worlds/majin/configuration.nix + home-manager.nixosModules.home-manager + agenix.nixosModules.age + ./worlds/base.nix + #hercules-ci-agent.nixosModules.multi-agent-service + ]; + specialArgs = { inherit inputs; }; + }; + }; + + devShells.${system}.default = pkgs.mkShell { + inherit nativeBuildInputs; + + shellHook = '' + fish && exit + ''; + }; + + }; +} diff --git a/worlds/base.nix b/worlds/base.nix new file mode 100644 index 0000000..708fbd7 --- /dev/null +++ b/worlds/base.nix @@ -0,0 +1,26 @@ +{ pkgs, config, lib, ... }: +{ + # This causes an overlay which causes a lot of rebuilding + environment.noXlibs = lib.mkForce false; + + # "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" creates a + # disk with this label on first boot. Therefore, we need to keep it. It is the + # only information from the installer image that we need to keep persistent + fileSystems."/" = + { device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + }; + + boot = { + kernelPackages = lib.mkForce pkgs.linuxPackages_latest; + loader = { + generic-extlinux-compatible.enable = lib.mkDefault true; + grub.enable = lib.mkDefault false; + }; + }; + + nix.settings = { + experimental-features = lib.mkDefault "nix-command flakes"; + trusted-users = [ "root" "@wheel" "lxsameer" ]; + }; +} diff --git a/worlds/majin/configuration.nix b/worlds/majin/configuration.nix new file mode 100644 index 0000000..73fded6 --- /dev/null +++ b/worlds/majin/configuration.nix @@ -0,0 +1,23 @@ +{ pkgs, config, lib, ... }: +{ + environment.systemPackages = with pkgs; [ emacs git ]; + services.openssh.enable = true; + networking.hostName = "majin"; + users = { + users.lxsameer = { + password = "123123"; + isNormalUser = true; + extraGroups = [ "wheel" ]; + }; + }; + # networking = { + # interfaces."wlan0".useDHCP = true; + # wireless = { + # interfaces = [ "wlan0" ]; + # enable = true; + # networks = { + # networkSSID.psk = "password"; + # }; + # }; + # }; +} diff --git a/worlds/x1/configuration.nix b/worlds/x1/configuration.nix new file mode 100644 index 0000000..e69de29