diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..39a36bb --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "My NixOS Configurations Flake"; + + inputs = { + # Source: https://github.com/NixOS/nixpkgs + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + nixpkgs-old.url = "github:nixos/nixpkgs/nixos-24.11"; + nixpkgs-latest.url = "github:nixos/nixpkgs"; + + # Source: https://github.com/nix-community/home-manager + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # Source: https://github.com/NixOS/nixos-hardware + nixos-hardware.url = "github:nixos/nixos-hardware"; + + # Source: https://github.com/Mic92/sops-nix + sops-nix.url = "github:mic92/sops-nix"; + }; + + outputs = + { + nixpkgs, + nixpkgs-old, + nixpkgs-latest, + ... + }@inputs: + let + # + in + { + # + }; +} diff --git a/lib/config.nix b/lib/config.nix new file mode 100644 index 0000000..601c7ad --- /dev/null +++ b/lib/config.nix @@ -0,0 +1,88 @@ +{ + inputs, + nixpkgs, + nixpkgs-old, + nixpkgs-latest, +}: +deviceName: +{ + hostName, + userName, + additionalOverlays ? [ ], + systemArch ? builtins.currentSystem, +}: +let + inherit (nixpkgs) lib; + + customFunctions = import ./utils.nix { inherit lib; }; + + baseOverlays = + import ../overlays { + inherit + systemArch + nixpkgs-old + nixpkgs-latest + packagesConfig + ; + } + |> builtins.attrValues; + overlays = baseOverlays ++ additionalOverlays; + + DeviceConfig = ../devices/${deviceName}; + HostConfig = ../users/${hostName}/host; + HomeConfig = ../users/${userName}/home; + + userData = import ../users/${userName}/data.nix { + inherit + deviceName + hostName + userName + systemArch + ; + }; + + userPackagesConfig = import ../users/${hostName}/packages-config.nix { inherit lib; }; + + additionalArgs = { inherit inputs customFunctions userData; }; + + sops = { + defaultSopsFormat = "yaml"; + defaultSopsFile = ../secrets/main.yaml; + age.keyFile = "${userData.paths.sopsKeyFile}"; + }; +in +lib.nixosSystem { + system = systemArch; + specialArgs = additionalArgs; + + modules = [ + DeviceConfig + HostConfig + + { + nixpkgs = { + inherit overlays; + config = userPackagesConfig; + }; + } + + inputs.home-manager.nixosModules.home-manager + { + home-manager = { + users.${userName} = import HomeConfig; + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = additionalArgs; + sharedModules = [ + inputs.sops-nix.homeManagerModules.sops + ]; + }; + } + + inputs.sops-nix.nixosModules.sops + { + inherit sops; + home-manager.users.${userName} = { inherit sops; }; + } + ]; +} diff --git a/lib/utils.nix b/lib/utils.nix new file mode 100644 index 0000000..02d0723 --- /dev/null +++ b/lib/utils.nix @@ -0,0 +1,51 @@ +# This function is copied from: +# https://github.com/yunfachi/nypkgs/blob/master/lib/umport.nix +# +# !!! REMOVING THIS NOTICE VIOLATES THE MIT LICENSE OF THE UMPORT PROJECT !!! +# This notice must be retained in all copies of this function, including modified versions! +# The MIT License can be found here: +# https://github.com/yunfachi/nypkgs/blob/master/LICENSE + +{ lib, ... }: +let + umport = + inputs@{ + path ? null, + paths ? [ ], + include ? [ ], + exclude ? [ ], + recursive ? true, + }: + with lib; + with fileset; + let + excludedFiles = filter (path: pathIsRegularFile path) exclude; + excludedDirs = filter (path: pathIsDirectory path) exclude; + isExcluded = + path: + if elem path excludedFiles then + true + else + (filter (excludedDir: lib.path.hasPrefix excludedDir path) excludedDirs) != [ ]; + in + unique ( + (filter + (file: pathIsRegularFile file && hasSuffix ".nix" (builtins.toString file) && !isExcluded file) + ( + concatMap ( + _path: + if recursive then + toList _path + else + mapAttrsToList ( + name: type: _path + (if type == "directory" then "/${name}/default.nix" else "/${name}") + ) (builtins.readDir _path) + ) (unique (if path == null then paths else [ path ] ++ paths)) + ) + ) + ++ (if recursive then concatMap (path: toList path) (unique include) else unique include) + ); +in +{ + scan = umport; +}