This commit is contained in:
2023-02-28 13:12:27 +00:00
parent d8394373ec
commit 8db4eaaacf
2 changed files with 155 additions and 134 deletions

View File

@@ -44,41 +44,62 @@
}; };
outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, home-manager,... }:
outputs = { self, nixpkgs, home-manager, ignore, filter, library,... }@inputs:
let let
inherit (self) outputs;
inherit (lib.my) mapModules mapModulesRec mapHosts; inherit (lib.my) mapModules mapModulesRec mapHosts;
forEachSystem = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
platforms = ["x86_64-linux"];
forEachPkgs = f: forEachSystem (sys: f nixpkgs.legacyPackages.${sys}); # outputs = { self, nixpkgs, home-manager, ignore, filter, library,... }@inputs:
system = "x86_64-linux";
mkPkgs = pkgs: extraOverlays: import pkgs {
inherit system;
config.allowUnfree = true; # forgive me Stallman senpai
overlays = extraOverlays ++ (lib.attrValues self.overlays);
};
pkgs = mkPkgs nixpkgs [ self.overlay ];
pkgs' = mkPkgs nixpkgs-unstable [];
lib = nixpkgs.lib.extend lib = nixpkgs.lib.extend
(self: super: { my = import ./lib { inherit nixpkgs inputs; lib = self; }; }); (self: super: { my = import ./lib { inherit pkgs inputs; lib = self; }; });
in {
in
rec {
packages = forEachPkgs (pkgs: import ./pkgs { inherit pkgs; });
devShells = forEachPkgs (pkgs: import ./shell.nix { inherit pkgs; });
overlays = import ./overlays { inherit inputs; };
nixosModules = import ./modules/nixos;
homeManagerModules = import ./modules/home-manager;
lib = lib.my; lib = lib.my;
overlay =
final: prev: {
unstable = pkgs';
my = self.packages."${system}";
};
overlays =
mapModules ./overlays import;
packages."${system}" =
mapModules ./packages (p: pkgs.callPackage p {});
nixosModules =
{ dotfiles = import ./.; } // mapModulesRec ./modules import;
# packages = forEachPkgs (pkgs: import ./pkgs { inherit pkgs; });
# devShells = forEachPkgs (pkgs: import ./shell.nix { inherit pkgs; });
devShell."${system}" =
import ./shell.nix { inherit pkgs; };
# overlays = import ./overlays { inherit inputs; };
# nixosModules = import ./modules/nixos;
homeManagerModules = import ./modules/home-manager;
# NixOS configuration entrypoint # NixOS configuration entrypoint
# Available through 'nixos-rebuild --flake .#your-hostname' # Available through 'nixos-rebuild --flake .#your-hostname'
nixosConfigurations = { nixosConfigurations = {
Go3 = nixpkgs.lib.nixosSystem { Go3 = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs; }; specialArgs = { inherit inputs ; };
modules = [ modules = [
./hosts/WSL/Go3 ./hosts/WSL/Go3
]; ];
}; };
StuPC = nixpkgs.lib.nixosSystem { StuPC = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs; }; specialArgs = { inherit inputs ; };
modules = [ modules = [
./hosts/WSL/StuPC ./hosts/WSL/StuPC
]; ];
@@ -92,7 +113,7 @@
# FIXME replace with your username@hostname # FIXME replace with your username@hostname
"sstent@Go3" = home-manager.lib.homeManagerConfiguration { "sstent@Go3" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
extraSpecialArgs = { inherit inputs outputs lib; hostName = "Go3"; }; extraSpecialArgs = { inherit inputs lib; hostName = "Go3"; };
modules = [ modules = [
# > Our main home-manager configuration file < # > Our main home-manager configuration file <
./home-manager/users/sstent ./home-manager/users/sstent
@@ -101,7 +122,7 @@
}; };
"sstent@StuPC" = home-manager.lib.homeManagerConfiguration { "sstent@StuPC" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
extraSpecialArgs = { inherit inputs outputs; hostName = "StuPC";}; extraSpecialArgs = { inherit inputs ; hostName = "StuPC";};
modules = [ modules = [
# > Our main home-manager configuration file < # > Our main home-manager configuration file <
./home-manager/users/sstent ./home-manager/users/sstent

View File

@@ -1,123 +1,123 @@
{lib, ...}: let # {lib, ...}: let
inherit # inherit
(builtins) # (builtins)
attrNames # attrNames
attrValues # attrValues
foldl' # foldl'
isPath # isPath
pathExists # pathExists
readDir # readDir
toString # toString
; # ;
inherit # inherit
(lib) # (lib)
flatten # flatten
filterAttrs # filterAttrs
forEach # forEach
getAttrFromPath # getAttrFromPath
hasPrefix # hasPrefix
hasSuffix # hasSuffix
id # id
mapAttrs' # mapAttrs'
mapAttrsToList # mapAttrsToList
mkIf # mkIf
nameValuePair # nameValuePair
removeSuffix # removeSuffix
; # ;
in rec { # in rec {
## Mapping Functions ## # ## Mapping Functions ##
array = list: func: forEach list (name: getAttrFromPath [name] func); # array = list: func: forEach list (name: getAttrFromPath [name] func);
filter = name: func: attrs: filterAttrs name (mapAttrs' func attrs); # filter = name: func: attrs: filterAttrs name (mapAttrs' func attrs);
list = func: foldl' (x: y: x + y + " ") "" (attrNames func); # list = func: foldl' (x: y: x + y + " ") "" (attrNames func);
## Files Map # ## Files Map
# Top Level # # Top Level
files = dir: func: extension: # files = dir: func: extension:
filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let # filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let
path = "${toString dir}/${name}"; # path = "${toString dir}/${name}";
in # in
if # if
(type == "directory" || type == "symlink") # (type == "directory" || type == "symlink")
&& ( # && (
if (extension == ".nix") # if (extension == ".nix")
then pathExists "${path}/default.nix" # then pathExists "${path}/default.nix"
else true # else true
) # )
then nameValuePair name (func path) # then nameValuePair name (func path)
else if # else if
type # type
== "regular" # == "regular"
&& ( # && (
if (extension == ".nix") # if (extension == ".nix")
then name != "default.nix" # then name != "default.nix"
else true # else true
) # )
&& hasSuffix extension name # && hasSuffix extension name
then nameValuePair (removeSuffix extension name) (func path) # then nameValuePair (removeSuffix extension name) (func path)
else nameValuePair "" null) (readDir dir); # else nameValuePair "" null) (readDir dir);
# Recursive # # Recursive
files' = dir: func: extension: # files' = dir: func: extension:
filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let # filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let
path = "${toString dir}/${name}"; # path = "${toString dir}/${name}";
in # in
if (type == "directory" || type == "symlink") # if (type == "directory" || type == "symlink")
then nameValuePair name (files' path func) # then nameValuePair name (files' path func)
else if # else if
type # type
== "regular" # == "regular"
&& ( # && (
if (extension == ".nix") # if (extension == ".nix")
then name != "default.nix" # then name != "default.nix"
else true # else true
) # )
&& hasSuffix extension name # && hasSuffix extension name
then nameValuePair (removeSuffix extension name) (func path) # then nameValuePair (removeSuffix extension name) (func path)
else nameValuePair "" null) (readDir dir); # else nameValuePair "" null) (readDir dir);
# Package Patches # # Package Patches
patches = patch: # patches = patch:
if isPath patch # if isPath patch
then # then
flatten (mapAttrsToList (name: type: # flatten (mapAttrsToList (name: type:
if # if
type # type
== "regular" # == "regular"
&& (hasSuffix ".diff" name || hasSuffix ".patch" name) # && (hasSuffix ".diff" name || hasSuffix ".patch" name)
then patch + "/${name}" # then patch + "/${name}"
else null) (readDir patch)) # else null) (readDir patch))
else patch; # else patch;
# Module Imports # # Module Imports
module = dir: attrValues (modules dir id); # module = dir: attrValues (modules dir id);
module' = dir: attrNames (modules dir id); # module' = dir: attrNames (modules dir id);
modules = dir: func: files dir func ".nix"; # modules = dir: func: files dir func ".nix";
modules' = dir: func: files' dir func ".nix"; # modules' = dir: func: files' dir func ".nix";
# 'sops' Encrypted Secrets # # 'sops' Encrypted Secrets
secrets = dir: neededForUsers: # secrets = dir: neededForUsers:
filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: # filter (name: type: type != null && !(hasPrefix "_" name)) (name: type:
if type == "regular" && hasSuffix ".secret" name # if type == "regular" && hasSuffix ".secret" name
then # then
nameValuePair name { # nameValuePair name {
sopsFile = dir + "/${name}"; # sopsFile = dir + "/${name}";
format = "binary"; # format = "binary";
inherit neededForUsers; # inherit neededForUsers;
} # }
else nameValuePair "" null) (readDir dir); # else nameValuePair "" null) (readDir dir);
# 'sops' Encrypted Secrets # # 'sops' Encrypted Secrets
hm_secrets = dir: out_dir: # hm_secrets = dir: out_dir:
filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: # filter (name: type: type != null && !(hasPrefix "_" name)) (name: type:
if type == "regular" && hasSuffix ".age" name # if type == "regular" && hasSuffix ".age" name
then # then
nameValuePair name { # nameValuePair name {
sopsFile = dir + "/${name}"; # sopsFile = dir + "/${name}";
format = "binary"; # format = "binary";
path = out_dir + "/${name}"; # path = out_dir + "/${name}";
} # }
else nameValuePair "" null) (readDir dir); # else nameValuePair "" null) (readDir dir);
} # }