diff --git a/flake.lock b/flake.lock index a29097f..4f1a787 100644 --- a/flake.lock +++ b/flake.lock @@ -61,6 +61,21 @@ "type": "github" } }, + "flake-utils_3": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -246,6 +261,7 @@ "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "sops-nix": "sops-nix", + "utils": "utils_2", "vscode-server": "vscode-server" } }, @@ -283,6 +299,24 @@ "type": "github" } }, + "utils_2": { + "inputs": { + "flake-utils": "flake-utils_3" + }, + "locked": { + "lastModified": 1657226504, + "narHash": "sha256-GIYNjuq4mJlFgqKsZ+YrgzWm0IpA4axA3MCrdKYj7gs=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a", + "type": "github" + }, + "original": { + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "type": "github" + } + }, "vscode-server": { "inputs": { "nixpkgs": "nixpkgs_3" diff --git a/flake.nix b/flake.nix index aa3924a..9e6594a 100644 --- a/flake.nix +++ b/flake.nix @@ -28,6 +28,7 @@ vscode-server.url = "github:msteen/nixos-vscode-server"; # homeage = {url = "github:jordanisaacs/homeage"; inputs.nixpkgs.follows = "nixpkgs";}; + # Nix Library Functions library = { type = "github"; owner = "nix-community"; @@ -35,71 +36,47 @@ ref = "master"; rev = "af5239f892ae6e1c8bb560b11ed874cebbd10696"; }; - + # Source Filter Functions filter.url = "github:numtide/nix-filter"; ignore = { url = "github:hercules-ci/gitignore.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + # Flake Utility Functions + utils.url = "github:gytis-ivaskevicius/flake-utils-plus"; + }; - outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, home-manager,... }: + + outputs = { self, nixpkgs, home-manager,library, ignore, filter,... }@inputs: let - inherit (lib.my) mapModules mapModulesRec mapHosts; + inherit (self) outputs; + 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 - (self: super: { my = import ./lib { inherit pkgs inputs; lib = self; }; }); - in { - 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; + 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; + # NixOS configuration entrypoint # Available through 'nixos-rebuild --flake .#your-hostname' nixosConfigurations = { Go3 = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs ; }; + specialArgs = { inherit inputs outputs; }; modules = [ ./hosts/WSL/Go3 ]; }; StuPC = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs ; }; + specialArgs = { inherit inputs outputs; }; modules = [ ./hosts/WSL/StuPC ]; @@ -113,7 +90,7 @@ # FIXME replace with your username@hostname "sstent@Go3" = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance - extraSpecialArgs = { inherit inputs lib; hostName = "Go3"; }; + extraSpecialArgs = { inherit inputs outputs; hostName = "Go3"; }; modules = [ # > Our main home-manager configuration file < ./home-manager/users/sstent @@ -122,7 +99,7 @@ }; "sstent@StuPC" = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance - extraSpecialArgs = { inherit inputs ; hostName = "StuPC";}; + extraSpecialArgs = { inherit inputs outputs; hostName = "StuPC";}; modules = [ # > Our main home-manager configuration file < ./home-manager/users/sstent diff --git a/home-manager/global/keybase.nix b/home-manager/global/keybase.nix index 62ccc3f..0e5fd74 100644 --- a/home-manager/global/keybase.nix +++ b/home-manager/global/keybase.nix @@ -1,11 +1,53 @@ -{ config, pkgs, lib, inputs, hostName, outputs, ... }: +{ config, pkgs, inputs, lib, hostName, util, ... }: with lib; -with lib.my; let + inherit + (builtins) + # attrNames + # attrValues + # foldl' + # isPath + # pathExists + readDir + # toString + ; + + inherit + (lib) + # flatten + filterAttrs + # forEach + # getAttrFromPath + # hasPrefix + # hasSuffix + # id + # mapAttrs' + # mapAttrsToList + # mkIf + # nameValuePair + # removeSuffix + ; cfg = config.custom.keybase; username = config.home.username; secretstore = config._secretstore; +# map = import "${inputs.self}/lib/map.nix"; + + # 'sops' Encrypted Secrets + hm_secrets = dir: out_dir: + filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: + if type == "regular" + then + nameValuePair name { + sopsFile = dir + "/${name}"; + format = "binary"; + path = out_dir + "/${name}"; + + } + else nameValuePair "" null) (readDir dir); + + filter = name: func: attrs: filterAttrs name (mapAttrs' func attrs); + in { # imports = [ @@ -28,7 +70,7 @@ in { systemd.user.services.kbfs.Unit.After = [ "sops-nix.service" ]; sops = { - secrets = map.hm_secrets "${secretstore}/user_dotfiles/${username}@${hostName}/keybase/" "${config.xdg.configHome}/keybase/"; + secrets = hm_secrets "${secretstore}/user_dotfiles/${username}@${hostName}/keybase/" "${config.xdg.configHome}/keybase/"; }; }; } diff --git a/lib/default.nix b/lib/default.nix index 564d6bd..5349379 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -19,10 +19,10 @@ let inherit (lib) makeExtensible attrValues foldr; inherit (modules) mapModules; - # modules = import ./modules.nix { - # inherit lib; - # self.attrs = import ./attrs.nix { inherit lib; self = {}; }; - # }; + modules = import ./modules.nix { + inherit lib; + self.attrs = import ./attrs.nix { inherit lib; self = {}; }; + }; mylib = makeExtensible (self: with self; mapModules ./. diff --git a/lib/map.nix b/lib/map.nix index eeb039b..4a4aa12 100644 --- a/lib/map.nix +++ b/lib/map.nix @@ -1,123 +1,123 @@ -# {lib, ...}: let -# inherit -# (builtins) -# attrNames -# attrValues -# foldl' -# isPath -# pathExists -# readDir -# toString -# ; +{lib, ...}: let + inherit + (builtins) + attrNames + attrValues + foldl' + isPath + pathExists + readDir + toString + ; -# inherit -# (lib) -# flatten -# filterAttrs -# forEach -# getAttrFromPath -# hasPrefix -# hasSuffix -# id -# mapAttrs' -# mapAttrsToList -# mkIf -# nameValuePair -# removeSuffix -# ; -# in rec { -# ## Mapping Functions ## -# array = list: func: forEach list (name: getAttrFromPath [name] func); -# filter = name: func: attrs: filterAttrs name (mapAttrs' func attrs); -# list = func: foldl' (x: y: x + y + " ") "" (attrNames func); + inherit + (lib) + flatten + filterAttrs + forEach + getAttrFromPath + hasPrefix + hasSuffix + id + mapAttrs' + mapAttrsToList + mkIf + nameValuePair + removeSuffix + ; +in rec { + ## Mapping Functions ## + array = list: func: forEach list (name: getAttrFromPath [name] func); + filter = name: func: attrs: filterAttrs name (mapAttrs' func attrs); + list = func: foldl' (x: y: x + y + " ") "" (attrNames func); -# ## Files Map -# # Top Level -# files = dir: func: extension: -# filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let -# path = "${toString dir}/${name}"; -# in -# if -# (type == "directory" || type == "symlink") -# && ( -# if (extension == ".nix") -# then pathExists "${path}/default.nix" -# else true -# ) -# then nameValuePair name (func path) -# else if -# type -# == "regular" -# && ( -# if (extension == ".nix") -# then name != "default.nix" -# else true -# ) -# && hasSuffix extension name -# then nameValuePair (removeSuffix extension name) (func path) -# else nameValuePair "" null) (readDir dir); + ## Files Map + # Top Level + files = dir: func: extension: + filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let + path = "${toString dir}/${name}"; + in + if + (type == "directory" || type == "symlink") + && ( + if (extension == ".nix") + then pathExists "${path}/default.nix" + else true + ) + then nameValuePair name (func path) + else if + type + == "regular" + && ( + if (extension == ".nix") + then name != "default.nix" + else true + ) + && hasSuffix extension name + then nameValuePair (removeSuffix extension name) (func path) + else nameValuePair "" null) (readDir dir); -# # Recursive -# files' = dir: func: extension: -# filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let -# path = "${toString dir}/${name}"; -# in -# if (type == "directory" || type == "symlink") -# then nameValuePair name (files' path func) -# else if -# type -# == "regular" -# && ( -# if (extension == ".nix") -# then name != "default.nix" -# else true -# ) -# && hasSuffix extension name -# then nameValuePair (removeSuffix extension name) (func path) -# else nameValuePair "" null) (readDir dir); + # Recursive + files' = dir: func: extension: + filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let + path = "${toString dir}/${name}"; + in + if (type == "directory" || type == "symlink") + then nameValuePair name (files' path func) + else if + type + == "regular" + && ( + if (extension == ".nix") + then name != "default.nix" + else true + ) + && hasSuffix extension name + then nameValuePair (removeSuffix extension name) (func path) + else nameValuePair "" null) (readDir dir); -# # Package Patches -# patches = patch: -# if isPath patch -# then -# flatten (mapAttrsToList (name: type: -# if -# type -# == "regular" -# && (hasSuffix ".diff" name || hasSuffix ".patch" name) -# then patch + "/${name}" -# else null) (readDir patch)) -# else patch; + # Package Patches + patches = patch: + if isPath patch + then + flatten (mapAttrsToList (name: type: + if + type + == "regular" + && (hasSuffix ".diff" name || hasSuffix ".patch" name) + then patch + "/${name}" + else null) (readDir patch)) + else patch; -# # Module Imports -# module = dir: attrValues (modules dir id); -# module' = dir: attrNames (modules dir id); -# modules = dir: func: files dir func ".nix"; -# modules' = dir: func: files' dir func ".nix"; + # Module Imports + module = dir: attrValues (modules dir id); + module' = dir: attrNames (modules dir id); + modules = dir: func: files dir func ".nix"; + modules' = dir: func: files' dir func ".nix"; -# # 'sops' Encrypted Secrets -# secrets = dir: neededForUsers: -# filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: -# if type == "regular" && hasSuffix ".secret" name -# then -# nameValuePair name { -# sopsFile = dir + "/${name}"; -# format = "binary"; -# inherit neededForUsers; -# } -# else nameValuePair "" null) (readDir dir); + # 'sops' Encrypted Secrets + secrets = dir: neededForUsers: + filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: + if type == "regular" && hasSuffix ".secret" name + then + nameValuePair name { + sopsFile = dir + "/${name}"; + format = "binary"; + inherit neededForUsers; + } + else nameValuePair "" null) (readDir dir); -# # 'sops' Encrypted Secrets -# hm_secrets = dir: out_dir: -# filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: -# if type == "regular" && hasSuffix ".age" name -# then -# nameValuePair name { -# sopsFile = dir + "/${name}"; -# format = "binary"; -# path = out_dir + "/${name}"; + # 'sops' Encrypted Secrets + hm_secrets = dir: out_dir: + filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: + if type == "regular" && hasSuffix ".age" name + then + nameValuePair name { + sopsFile = dir + "/${name}"; + format = "binary"; + path = out_dir + "/${name}"; -# } -# else nameValuePair "" null) (readDir dir); -# } \ No newline at end of file + } + else nameValuePair "" null) (readDir dir); +} \ No newline at end of file