Break the functionalities into local modules

This commit is contained in:
Sameer Rahmani 2024-02-08 21:02:10 +00:00
parent dd87e0a620
commit 7f153092e9
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
7 changed files with 256 additions and 234 deletions

View File

@ -1,72 +1,24 @@
{
"nodes": {
"agenix": {
"flake_utils": {
"inputs": {
"darwin": "darwin",
"home-manager": "home-manager",
"nixpkgs": [
"nixpkgs"
],
"systems": "systems"
},
"locked": {
"lastModified": 1703433843,
"narHash": "sha256-nmtA4KqFboWxxoOAA6Y1okHbZh+HsXaMPFkYHsoDRDw=",
"owner": "ryantm",
"repo": "agenix",
"rev": "417caa847f9383e111d1397039c9d4337d024bf0",
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"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",
"owner": "numtide",
"repo": "flake-utils",
"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"
@ -171,13 +123,12 @@
},
"root": {
"inputs": {
"agenix": "agenix",
"home-manager": "home-manager_2",
"flake_utils": "flake_utils",
"home-manager": "home-manager",
"nixos-generators": "nixos-generators",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs",
"sops-nix": "sops-nix",
"utils": "utils"
"sops-nix": "sops-nix"
}
},
"sops-nix": {
@ -215,39 +166,6 @@
"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",

View File

@ -33,12 +33,7 @@
inputs.nixpkgs.follows = "nixpkgs";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
utils.url = "github:numtide/flake-utils";
flake_utils.url = "github:numtide/flake-utils";
# TODO: Checkout hercules
# hercules-ci-agent.url = "github:hercules-ci/hercules-ci-agent";
@ -47,77 +42,37 @@
# impermanence.url = "github:nix-community/impermanence";
};
outputs = { self, nixpkgs, utils, ... } @ inputs:
outputs = { self, nixpkgs, ... } @ 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
'';
bootImage = image: (pkgs.writeScriptBin "boot-${image.name}" ''
#!${pkgs.stdenv.shell}
qemu-system-x86_64 -enable-kvm -m 2048 -boot d \
-cdrom ${image} -hda vdisk1 -vga std \
-net user,hostfwd=tcp::2222-:22 -net nic
'');
scripts = pkgs.symlinkJoin {
name = "universe_scripts";
paths = [
create-disk
];
};
utils = pkgs.callPackage ./utils {};
modules = pkgs.callPackage ./modules { inherit (inputs) nixos-generators; };
nativeBuildInputs = with pkgs; [
qemu
fish
zstd
scripts
utils.scripts
sops
];
modules = pkgs.callPackage ./modules { inherit (inputs) nixos-generators; };
in rec{
inherit pkgs;
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 = nixosConfigurations.majin.config.formats.iso;
boot-majin = bootImage packages.${system}.majin;
inherit create-disk;
boot-majin = utils.bootImage packages.${system}.majin;
inherit (utils) create-disk;
};
nixosConfigurations = {
majin = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
"${nixpkgs}/nixos/modules/profiles/minimal.nix"
./worlds/majin/configuration.nix
modules.generator
inputs.home-manager.nixosModules.home-manager
./worlds/base.nix
#hercules-ci-agent.nixosModules.multi-agent-service
];
specialArgs = { inherit inputs; };
majin = import ./worlds/majin.nix {
inherit nixpkgs inputs system;
mods = modules;
};
};

View File

@ -1,18 +1,162 @@
{ nixos-generators }:
# Universe - The big bang to my universe
#
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
params:
{
# A single nixos config outputting multiple formats.
# Alternatively put this in a configuration.nix.
generator = {config, ...}: {
imports = [
nixos-generators.nixosModules.all-formats
];
imports = [
params.nixos-generators.nixosModules.all-formats
];
nixpkgs.hostPlatform = "x86_64-linux";
nixpkgs.hostPlatform = "x86_64-linux";
# customize an existing format
formatConfigs.iso = {config, ...}: {
services.openssh.enable = true;
# customize an existing format
formatConfigs.iso = {config, ...}: {
services.openssh.enable = true;
};
};
base = {config, lib, pkgs, ...}: {
# Neverever change this value
system.stateVersion = "23.11";
# Include some utilities that are useful for installing or repairing
# the system.
environment.systemPackages = [
pkgs.w3m-nographics # needed for the manual anyway
pkgs.testdisk # useful for repairing boot problems
pkgs.ms-sys # for writing Microsoft boot sectors / MBRs
pkgs.efibootmgr
pkgs.efivar
pkgs.parted
pkgs.gptfdisk
pkgs.ddrescue
pkgs.ccrypt
pkgs.cryptsetup # needed for dm-crypt volumes
# Some networking tools.
pkgs.fuse
pkgs.fuse3
pkgs.sshfs-fuse
pkgs.socat
pkgs.screen
pkgs.tcpdump
# Hardware-related tools.
pkgs.sdparm
pkgs.hdparm
pkgs.smartmontools # for diagnosing hard disks
pkgs.pciutils
pkgs.usbutils
pkgs.nvme-cli
# Some compression/archiver tools.
pkgs.unzip
pkgs.zip
pkgs.wget
pkgs.curl
pkgs.htop
];
environment.variables.EDITOR = "emacs";
nix.settings = {
experimental-features = lib.mkDefault "nix-command flakes";
};
i18n.defaultLocale = "en_US.UTF-8";
# Enter keyboard layout
services.xserver.xkb.layout = "us";
# Include support for various filesystems and tools to create / manipulate them.
boot.supportedFilesystems =
[ "btrfs" "cifs" "f2fs" "vfat" "xfs" ];
};
desktop = { pkgs, lib, ... }: {
environment.noXlibs = lib.mkForce false;
services.xserver = {
enable = true;
displayManager = {
gdm = {
enable = true;
wayland = false;
banner = "test tset tshnetht";
};
startx = {
enable = true;
};
};
libinput.enable = true; # for touchpad support
videoDrivers = [
"modesetting"
"fbdev"
"amdgpu"
];
};
# Enable sound in virtualbox appliances.
hardware.pulseaudio.enable = true;
hardware.opengl = {
enable = true;
setLdLibraryPath = true;
package = pkgs.mesa_drivers;
};
environment.systemPackages = [
pkgs.glxinfo
pkgs.emacs
];
};
users = {config, ...}: {
users = {
users.lxsameer = {
password = "123123";
isNormalUser = true;
extraGroups = [
"wheel"
"networkmanager"
];
};
};
nix.settings = {
trusted-users = [ "root" "@wheel" "lxsameer" ];
};
};
bootable = {lib, pkgs, ...}: {
boot = {
kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
loader = {
generic-extlinux-compatible.enable = lib.mkDefault true;
grub.enable = lib.mkDefault true;
};
};
};
}

40
utils/default.nix Normal file
View File

@ -0,0 +1,40 @@
# Universe - The big bang to my universe
#
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{ lib, stdenv, writeScriptBin, symlinkJoin }:
rec {
# Add a command to the shell to create the disk
create-disk = writeScriptBin "create-disk" ''
#!${stdenv.shell}
qemu-img create -f qcow2 vdisk1 10G
'';
bootImage = image: (writeScriptBin "boot-${image.name}" ''
#!${stdenv.shell}
qemu-system-x86_64 -enable-kvm -m 2048 -boot d \
-cdrom ${image} -hda vdisk1 -vga std \
-net user,hostfwd=tcp::2222-:22 -net nic
'');
scripts = symlinkJoin {
name = "universe_scripts";
paths = [
create-disk
];
};
}

View File

@ -1,50 +0,0 @@
{ 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";
};
users = {
users.lxsameer = {
password = "123123";
isNormalUser = true;
extraGroups = [ "wheel" ];
};
};
time.timeZone = lib.mkDefault "Europe/Dublin";
# Enter keyboard layout
services.xserver.xkb.layout = "us";
environment.systemPackages = with pkgs; [
emacs
git
zsh
wget
curl
];
environment.variables.EDITOR = "emacs";
boot = {
kernelPackages = lib.mkDefault 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" ];
};
}

42
worlds/majin.nix Normal file
View File

@ -0,0 +1,42 @@
# Universe - The big bang to my universe
#
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{ nixpkgs, mods, system, inputs }:
let
this = { pkgs, config, lib, ... }: {
time.timeZone = lib.mkDefault "Europe/Dublin";
environment.systemPackages = with pkgs; [
git
zsh
];
};
in nixpkgs.lib.nixosSystem {
inherit system;
modules = (with mods; [
"${nixpkgs}/nixos/modules/profiles/minimal.nix"
"${nixpkgs}/nixos/modules/profiles/qemu-guest.nix"
bootable
base
users
desktop
generator
inputs.home-manager.nixosModules.home-manager
]);
specialArgs = { inherit inputs; };
}

View File

@ -1,27 +0,0 @@
{ pkgs, config, lib, inputs, ... }:
{
environment.systemPackages = with pkgs; [ emacs git zsh ];
services.openssh.enable = true;
networking.hostName = "majin";
imports = [
inputs.sops-nix.nixosModules.sops
];
sops.defaultSopsFile = ../../secrets/secrets.yaml;
sops.defaultSopsFormat = "yaml";
sops.age.keyFile = "/home/lxsameer/.config/sops/age/keys.txt";
sops.secrets."default_user/user" = {};
sops.secrets."default_user/pass" = {};
# networking = {
# interfaces."wlan0".useDHCP = true;
# wireless = {
# interfaces = [ "wlan0" ];
# enable = true;
# networks = {
# networkSSID.psk = "password";
# };
# };
# };
}