commit 8c7bdaf9f791c36ab2be153f4ccb9d1a274438fe Author: ChaotiCryptidz Date: Mon Dec 20 23:48:26 2021 +0000 I'm Sorry diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a975f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +networking.nix +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3bbab9c --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1639891275, + "narHash": "sha256-2IMLVTtOHV9kBsirGPRpo8NE48Mjq20iXN7l7uy0YjE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "3db603677509eb0b8c396a3234b1d4b70d023894", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1640012693, + "narHash": "sha256-D07/CBpeqsbXKb96NQliVqgB3ytLL3XfBGBrm/eaUxU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7dcb25726b3a5ed3896fe38362f631ca5bed4a6e", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1639966735, + "narHash": "sha256-FmVGFiyqE+pjQUTCTY0H75hqrnBnbEf3VVRB4dsd4KI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d87b72206aadebe6722944f541f55d33fd7046fb", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3b3bd90 --- /dev/null +++ b/flake.nix @@ -0,0 +1,10 @@ +{ + description = "NixOS configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager"; + }; + + outputs = { ... }@inputs: import ./outputs.nix inputs; +} diff --git a/home/base/example.nix b/home/base/example.nix new file mode 100644 index 0000000..c915eb0 --- /dev/null +++ b/home/base/example.nix @@ -0,0 +1 @@ +{ ... }: { } diff --git a/home/default.nix b/home/default.nix new file mode 100644 index 0000000..d9631f7 --- /dev/null +++ b/home/default.nix @@ -0,0 +1,18 @@ +{ lib, tree, ... }: with lib; let + wrapImports = imports: mapAttrs + (_: paths: { config, ... }: { + config.home-manager.users.chaoticryptidz = { + imports = singleton paths; + }; + }) + imports; + dirImports = wrapImports tree.prev; +in +dirImports // { + base = { + imports = [ + dirImports.base + tree.prev.nixos + ]; + }; +} diff --git a/home/gui/gtk.nix b/home/gui/gtk.nix new file mode 100644 index 0000000..7ba5335 --- /dev/null +++ b/home/gui/gtk.nix @@ -0,0 +1,13 @@ +{ config, pkgs, ... }: { + gtk = { + enable = true; + iconTheme = { + name = "Papirus-Dark"; + package = pkgs.papirus-icon-theme; + }; + theme = { + name = "Adementary-dark"; + package = pkgs.adementary-theme; + }; + }; +} diff --git a/home/network_manager/nm.nix b/home/network_manager/nm.nix new file mode 100644 index 0000000..ebf4992 --- /dev/null +++ b/home/network_manager/nm.nix @@ -0,0 +1,6 @@ +{ config, ... }: { + xsession.preferStatusNotifierItems = true; + services = { + network-manager-applet.enable = true; + }; +} diff --git a/home/nixos.nix b/home/nixos.nix new file mode 100644 index 0000000..fcb90a8 --- /dev/null +++ b/home/nixos.nix @@ -0,0 +1,6 @@ +{ config, ... }: { + users.users.chaoticryptidz = { + isNormalUser = true; + extraGroups = [ "wheel" ]; + }; +} diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..a6640bc --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,19 @@ +{ home-manager, nixpkgs, tree, ... }@inputs: let + defaultModules = [ + home-manager.nixosModules.home-manager + tree.impure.profiles.base + ]; + defaultSpecialArgs = { + tree = tree.impure; + pureTree = tree.pure; + inherit inputs; + }; +in { + nixos = nixpkgs.lib.nixosSystem { + specialArgs = defaultSpecialArgs; + system = "x86_64-linux"; + modules = defaultModules ++ [ + ./nixos.nix + ]; + }; +} diff --git a/hosts/nixos.nix b/hosts/nixos.nix new file mode 100644 index 0000000..3068114 --- /dev/null +++ b/hosts/nixos.nix @@ -0,0 +1,44 @@ +{ tree, config, pkgs, lib, ... }: + +{ + imports = with tree; [ + profiles.dev + profiles.gui + profiles.x11 + profiles.xfce + profiles.laptop + profiles.pulse + profiles.network_manager + home.gui + home.network_manager + ]; + + boot = { + loader = { + systemd-boot.enable = true; + efi.canTouchEfiVariables = true; + }; + initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; + kernelModules = [ "kvm-intel" ]; + }; + + powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + hardware.enableRedistributableFirmware = true; + + networking.hostName = "nixos"; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/491ec94c-5e6a-4d23-a2a6-bcf4971a6e7b"; + fsType = "ext4"; + }; + "/boot" = { + device = "/dev/disk/by-uuid/61F3-FD84"; + fsType = "vfat"; + }; + }; + + system.stateVersion = "21.11"; +} + diff --git a/outputs.nix b/outputs.nix new file mode 100644 index 0000000..3561d56 --- /dev/null +++ b/outputs.nix @@ -0,0 +1,18 @@ +{ nixpkgs, home-manager, ... }@inputs: let + mkTree = import ./tree.nix { inherit (nixpkgs) lib; }; + tree = mkTree { + inherit inputs; + folder = ./.; + config = { + "profiles/*".functor.enable = true; + "home".evaluateDefault = true; + "home/*".functor.enable = true; + }; + }; +in { + legacyPackages.tree = tree; + nixosConfigurations = import ./hosts { + nixosSystem = nixpkgs.lib.nixosSystem; + inherit nixpkgs home-manager tree; + }; +} diff --git a/overlay/comic-code/default.nix b/overlay/comic-code/default.nix new file mode 100644 index 0000000..96616d7 --- /dev/null +++ b/overlay/comic-code/default.nix @@ -0,0 +1,11 @@ +{ fetchzip }: fetchzip { + name="comic-code-1.0"; + + url = "https://cdn.discordapp.com/attachments/780878889924165652/919700644347142214/COCOD.ZIP"; + sha256 = "sha256-MzEkMAopjpQBk24nRVDAtGNeF6f61XGww4rya2cU8TU="; + + postFetch = '' + mkdir -p $out/share/fonts + unzip -j $downloadedFile \*.otf -d $out/share/fonts/truetype + ''; +} diff --git a/overlay/default.nix b/overlay/default.nix new file mode 100644 index 0000000..0ec3b38 --- /dev/null +++ b/overlay/default.nix @@ -0,0 +1,3 @@ +final: prev: { + comic-code = final.callPackage ./comic-code { }; +} diff --git a/profiles/base/access.nix b/profiles/base/access.nix new file mode 100644 index 0000000..0e2d3bb --- /dev/null +++ b/profiles/base/access.nix @@ -0,0 +1,7 @@ +{ tree, config, lib, ... }: { + security.sudo.wheelNeedsPassword = lib.mkForce false; + + imports = with tree; [ + home.base + ]; +} diff --git a/profiles/base/hardware.nix b/profiles/base/hardware.nix new file mode 100644 index 0000000..2789950 --- /dev/null +++ b/profiles/base/hardware.nix @@ -0,0 +1,3 @@ +{ ... }: { + hardware.enableRedistributableFirmware = true; +} diff --git a/profiles/base/home.nix b/profiles/base/home.nix new file mode 100644 index 0000000..18974db --- /dev/null +++ b/profiles/base/home.nix @@ -0,0 +1,17 @@ +{ inputs, tree, config, lib, ... }: with lib; { + options.home-manager.users = mkOption { + type = types.attrsOf (types.submoduleWith { + modules = [ ]; + specialArgs = { + inherit inputs tree; + nixos = config; + }; + }); + }; + config = { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + }; + }; +} diff --git a/profiles/base/locale.nix b/profiles/base/locale.nix new file mode 100644 index 0000000..2c59d38 --- /dev/null +++ b/profiles/base/locale.nix @@ -0,0 +1,7 @@ +{ config, ... }: { + i18n.defaultLocale = "en_GB.UTF-8"; + console = { + font = "Lat2-Terminus16"; + keyMap = "uk"; + }; +} diff --git a/profiles/base/nix.nix b/profiles/base/nix.nix new file mode 100644 index 0000000..f1f7ceb --- /dev/null +++ b/profiles/base/nix.nix @@ -0,0 +1,19 @@ +{ inputs, config, lib, ... }: { + nix = { + nixPath = [ + "nixpkgs=${inputs.nixpkgs}" + ]; + extraOptions = lib.optionalString (lib.versionAtLeast config.nix.package.version "2.4") '' + experimental-features = nix-command flakes + ''; + trustedUsers = [ "root" "@wheel" ]; + }; + nixpkgs = { + config = { + allowUnfree = true; + }; + overlays = [ + (import ../../overlay) + ]; + }; +} diff --git a/profiles/base/programs.nix b/profiles/base/programs.nix new file mode 100644 index 0000000..19b9e06 --- /dev/null +++ b/profiles/base/programs.nix @@ -0,0 +1,3 @@ +{ config, ... }: { + programs.mtr.enable = true; +} diff --git a/profiles/dev/default.nix b/profiles/dev/default.nix new file mode 100644 index 0000000..c915eb0 --- /dev/null +++ b/profiles/dev/default.nix @@ -0,0 +1 @@ +{ ... }: { } diff --git a/profiles/gui/default.nix b/profiles/gui/default.nix new file mode 100644 index 0000000..d3d003b --- /dev/null +++ b/profiles/gui/default.nix @@ -0,0 +1,18 @@ +{ config, pkgs, ... }: { + fonts.fonts = with pkgs; [ + iosevka + comic-code + ]; + + environment.systemPackages = with pkgs; [ + git + nano + curl + wget + vscode + tdesktop + vivaldi + vivaldi-ffmpeg-codecs + vivaldi-widevine + ]; +} diff --git a/profiles/laptop/default.nix b/profiles/laptop/default.nix new file mode 100644 index 0000000..32a227e --- /dev/null +++ b/profiles/laptop/default.nix @@ -0,0 +1,3 @@ +{ config, ... }: { + services.xserver.libinput.enable = true; +} diff --git a/profiles/network_manager/nm.nix b/profiles/network_manager/nm.nix new file mode 100644 index 0000000..bd8a938 --- /dev/null +++ b/profiles/network_manager/nm.nix @@ -0,0 +1,10 @@ +{ config, lib, ... }: { + networking = { + networkmanager = { + enable = true; + connectionConfig = { + "ipv6.ip6-privacy" = lib.mkForce 0; + }; + }; + }; +} diff --git a/profiles/pulse/default.nix b/profiles/pulse/default.nix new file mode 100644 index 0000000..5de6875 --- /dev/null +++ b/profiles/pulse/default.nix @@ -0,0 +1,4 @@ +{ config, ... }: { + sound.enable = true; + hardware.pulseaudio.enable = true; +} diff --git a/profiles/x11/default.nix b/profiles/x11/default.nix new file mode 100644 index 0000000..51b11de --- /dev/null +++ b/profiles/x11/default.nix @@ -0,0 +1,4 @@ +{ config, ... }: { + services.xserver.enable = true; + services.xserver.layout = "gb"; +} diff --git a/profiles/xfce/default.nix b/profiles/xfce/default.nix new file mode 100644 index 0000000..3b8165a --- /dev/null +++ b/profiles/xfce/default.nix @@ -0,0 +1,6 @@ +{ config, ... }: { + services.xserver = { + desktopManager.xfce.enable = true; + displayManager.defaultSession = "xfce"; + }; +} diff --git a/rebuild.sh b/rebuild.sh new file mode 100755 index 0000000..2d67b4b --- /dev/null +++ b/rebuild.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -x + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +FIRST_ARG="${1:-switch}" + +shift + +nixos-rebuild --flake "${SCRIPT_DIR}#$(hostname)" ${FIRST_ARG} $@ diff --git a/tree.nix b/tree.nix new file mode 100644 index 0000000..0268415 --- /dev/null +++ b/tree.nix @@ -0,0 +1,121 @@ +{ lib }: { config, folder, inputs, ... }@args: with lib; let + pureTreeGrab = { base, path }: let + realPath = toString path; + dirContents = builtins.readDir path; + isDirectory = entry: dirContents."${entry}" == "directory"; + isHidden = entry: hasPrefix "." entry; + isDir = entry: _: (isDirectory entry) && !(isHidden entry); + directories = filterAttrs isDir dirContents; + isNixFile = entry: _: let + result = builtins.match "(.*)\\.nix" entry; + in result != null && builtins.length result > 0; + nixFiles = filterAttrs isNixFile dirContents; + getPath = entry: "${realPath}/${entry}"; + getPaths = entries: mapAttrs' (n: v: + nameValuePair (removeSuffix ".nix" n) (getPath n) + ) entries; + nixFilePaths = getPaths nixFiles; + dirPaths = getPaths directories; + recursedPaths = mapAttrs (_: fullPath: pureTreeGrab { + inherit base; + path = fullPath; + }) dirPaths; + contents = recursedPaths // nixFilePaths; + in contents; + configTreeStruct = { config, ... }: { + options.treeConfig = mkOption { + type = with types; attrsOf (submodule ({ name, options, config, ... }: { + options = { + evaluateDefault = mkOption { + type = types.bool; + description = "Replace the contents of this branch or leaf with those provided by the evaluation of default.nix."; + default = false; + }; + aliasDefault = mkOption { + type = types.bool; + description = "Replace the contents of this branch or leaf with the default.nix."; + default = false; + }; + excludes = mkOption { + type = types.listOf types.str; + description = "Exclude files or folders from the recurser."; + default = []; + }; + functor = { + enable = mkOption { + type = types.bool; + description = "Provide a functor for the path provided"; + default = false; + }; + external = mkOption { + type = types.listOf types.unspecified; + description = "Add external imports into the functor."; + default = []; + }; + excludes = mkOption { + type = types.listOf types.str; + description = "Exclude files or folders from the functor."; + default = []; + }; + }; + }; + })); + }; + config.treeConfig = { + "*" = {}; + }; + }; + configTree.treeConfig = config; + configTreeModule = (evalModules { + modules = [ + configTreeStruct + configTree + ]; + }).config.treeConfig; + mapAttrsRecursive = f: set: let + recurse = path: set: let + g = name: value: if isAttrs value + then f (path ++ [name]) (recurse (path ++ [name]) value) + else f (path ++ [name]) value; + in mapAttrs g set; + in recurse [] set; + getPathString = path: concatStringsSep "/" path; + getConfig = path: default: configTreeModule.${getPathString path} or default; + revtail = path: sublist 0 (length path - 1) path; + getConfigRecursive = path: let + parentPath = revtail path; + in getConfig (path ++ singleton "*") (getConfigRecursive parentPath); + processLeaves = tree: config: mapAttrsRecursive (path: value: let + pathString = getPathString path; + leafConfig = getConfig path (getConfigRecursive (revtail path)); + processConfig = path: value: let + processFunctor = prev: prev // { + __functor = self: { ... }: { + imports = attrValues (removeAttrs prev leafConfig.functor.excludes) ++ leafConfig.functor.external; + }; + }; + processAliasDefault = prev: prev.default; + processDefault = prev: import prev.default (args // { + inherit lib; + tree = { + prev = removeAttrs prev (singleton "default"); + pure = pureTree; + impure = impureTree; + }; + }); + processExcludes = prev: removeAttrs prev leafConfig.excludes; + processes = optionals (isAttrs value) ( + optional (leafConfig.excludes != []) processExcludes + ++ optional leafConfig.evaluateDefault processDefault + ++ optional leafConfig.aliasDefault processAliasDefault + ++ optional leafConfig.functor.enable processFunctor + ); + in pipe value processes; + in processConfig path value) tree; + pureTree = pureTreeGrab { base = folder; path = folder; }; + impureTree = processLeaves pureTree configTreeModule; +in { + config = configTreeModule; + pure = pureTree; + impure = impureTree; +}