diff --git a/modules/flake/checks/lib.nix b/modules/flake/checks/lib.nix index 46a82d0e..41b04193 100644 --- a/modules/flake/checks/lib.nix +++ b/modules/flake/checks/lib.nix @@ -6,48 +6,6 @@ }: let res = lib.debug.runTests { - boolToNum = { - expr = self.lib.helpers.boolToNum true; - expected = 1; - }; - - intListToStringList = { - expr = self.lib.helpers.intListToStringList [ - 1 - 2 - 3 - ]; - expected = [ - "1" - "2" - "3" - ]; - }; - - indexOf = { - expr = self.lib.helpers.indexOf [ - 1 - 2 - 3 - ] 2; - expected = 1; - }; - - containsStrings = { - expr = - self.lib.helpers.containsStrings - [ - "a" - "b" - "c" - ] - [ - "a" - "b" - ]; - expected = true; - }; - giturl = { expr = self.lib.helpers.giturl { domain = "github.com"; diff --git a/modules/flake/lib/default.nix b/modules/flake/lib/default.nix index 399ce40b..9df7da69 100644 --- a/modules/flake/lib/default.nix +++ b/modules/flake/lib/default.nix @@ -17,19 +17,9 @@ lib.fixedPoints.makeExtensible (final: { # we have to rexport the functions we want to use, but don't want to refer to the whole lib # "path". e.g. gardenLib.hardware.isx86Linux can be shortened to gardenLib.isx86Linux # NOTE: never rexport templates - inherit (final.hardware) isx86Linux ldTernary; - inherit (final.helpers) - mkPubs - giturl - filterNixFiles - importNixFiles - importNixFilesAndDirs - boolToNum - containsStrings - indexOf - intListToStringList - ; + inherit (final.hardware) isx86Linux; + inherit (final.helpers) mkPubs giturl; inherit (final.secrets) mkSecret; - inherit (final.services) mkGraphicalService mkServiceOption; - inherit (final.validators) ifOneEnabled anyHome; + inherit (final.services) mkServiceOption; + inherit (final.validators) anyHome; }) diff --git a/modules/flake/lib/hardware.nix b/modules/flake/lib/hardware.nix index a58fa4f9..b9c19c4d 100644 --- a/modules/flake/lib/hardware.nix +++ b/modules/flake/lib/hardware.nix @@ -20,38 +20,7 @@ let ``` */ isx86Linux = pkgs: pkgs.stdenv.hostPlatform.isLinux && pkgs.stdenv.hostPlatform.isx86; - - /** - ldTernary, short for linux darwin ternary - - # Inputs - - - [pkgs] is the package set - - [l] the value to return if the host platform is linux - - [d] the value to return if the host platform is darwin - - # Type - - ``` - ldTernary :: AttrSet -> Any -> Any -> Any - ``` - - # Example - - ```nix - ldTernary pkgs "linux" "darwin" - => "linux" - ``` - */ - ldTernary = - pkgs: l: d: - if pkgs.stdenv.hostPlatform.isLinux then - l - else if pkgs.stdenv.hostPlatform.isDarwin then - d - else - throw "Unsupported system: ${pkgs.stdenv.system}"; in { - inherit isx86Linux ldTernary; + inherit isx86Linux; } diff --git a/modules/flake/lib/helpers.nix b/modules/flake/lib/helpers.nix index cc363b13..4182215e 100644 --- a/modules/flake/lib/helpers.nix +++ b/modules/flake/lib/helpers.nix @@ -1,185 +1,5 @@ { lib }: let - inherit (lib.lists) forEach filter; - inherit (lib.attrsets) filterAttrs mapAttrsToList; - inherit (lib.filesystem) listFilesRecursive; - inherit (lib.strings) hasSuffix; - - /** - filter files for the .nix suffix - - # Arguments - - - [k] they key, which is the file name - - [v] the value, which is the type of the file - - # Type - - ``` - filterNixFiles :: String -> String -> Bool - ``` - - # Example - - ```nix - filterNixFiles "default.nix" "regular" - => true - ``` - */ - filterNixFiles = k: v: v == "regular" && hasSuffix ".nix" k; - - /** - Import all file that filterNixFiles allows for - - # Arguments - - - [path] the path to the directory - - # Type - - ``` - importNixFiles :: String -> List - ``` - - # Example - - ```nix - importNixFiles ./. - => [ {...} ] - ``` - */ - importNixFiles = - path: - (forEach ( - mapAttrsToList (name: _: path + ("/" + name)) (filterAttrs filterNixFiles (builtins.readDir path)) - )) - import; - - /** - import all nix files and directories - - # Arguments - - - [dir] the directory to search for nix files - - # Type - - ``` - importNixFilesAndDirs :: String -> List - ``` - - # Example - - ```nix - importNixFilesAndDirs ./. - => [ "flake.nix" ] - ``` - */ - importNixFilesAndDirs = dir: filter (f: f != "default.nix") (listFilesRecursive dir); - - /** - return an int based on boolean value - - # Arguments - - - [bool] the boolean value - - # Type - - ``` - boolToNum :: Bool -> Int - ``` - - # Example - - ```nix - boolToNum true - => 1 - ``` - */ - boolToNum = bool: if bool then 1 else 0; - - /** - convert a list of integers to a list of string - - # Arguments - - - [list] the list of integers - - # Type - - ``` - intListToStringList :: List -> List - ``` - - # Example - - ```nix - intListToStringList [1 2 3] - => ["1" "2" "3"] - ``` - */ - intListToStringList = list: map (toString list); - - /** - a function that returns the index of an element in a list - - # Arguments - - - [list] the list to search in - - [elem] the element to search for - - # Type - - ``` - indexOf :: List -> Any -> Int - ``` - - # Example - - ```nix - indexOf [1 2 3] 2 - => 1 - ``` - */ - indexOf = - list: elem: - let - f = - f: i: - if i == (builtins.length list) then - null - else if (builtins.elemAt list i) == elem then - i - else - f f (i + 1); - in - f f 0; - - /** - a function that checks if a list contains a list of given strings - - # Arguments - - - [list] the list to search in - - [targetStrings] the list of strings to search for - - # Type - - ``` - containsStrings :: List -> List -> Bool - ``` - - # Example - - ```nix - containsStrings ["a" "b" "c"] ["a" "b"] - => true - ``` - */ - containsStrings = - list: targetStrings: builtins.all (s: builtins.any (x: x == s) list) targetStrings; - /** Create git url aliases for a given domain @@ -309,12 +129,5 @@ in mkPub mkPubs giturl - filterNixFiles - importNixFiles - importNixFilesAndDirs - boolToNum - containsStrings - indexOf - intListToStringList ; } diff --git a/modules/flake/lib/services.nix b/modules/flake/lib/services.nix index 5bdafbdf..fd292374 100644 --- a/modules/flake/lib/services.nix +++ b/modules/flake/lib/services.nix @@ -2,13 +2,6 @@ let inherit (lib.types) str; inherit (lib.options) mkOption mkEnableOption; - inherit (lib.attrsets) recursiveUpdate; - - mkGraphicalService = recursiveUpdate { - Unit.PartOf = [ "graphical-session.target" ]; - Unit.After = [ "graphical-session.target" ]; - Install.WantedBy = [ "graphical-session.target" ]; - }; /** A quick way to use my services abstraction @@ -54,5 +47,5 @@ let }; in { - inherit mkGraphicalService mkServiceOption; + inherit mkServiceOption; } diff --git a/modules/flake/lib/template/default.nix b/modules/flake/lib/template/default.nix index 2ff505fc..95237f0d 100644 --- a/modules/flake/lib/template/default.nix +++ b/modules/flake/lib/template/default.nix @@ -1,34 +1,3 @@ -let - systemd = { - LockPersonality = true; - MemoryDenyWriteExecute = true; - NoNewPrivileges = true; - PrivateDevices = true; - PrivateIPC = true; - PrivateTmp = true; - PrivateUsers = true; - ProtectClock = true; - ProtectControlGroups = true; - ProtectHome = true; - ProtectHostname = true; - ProtectKernelLogs = true; - ProtectKernelModules = true; - ProtectKernelTunables = true; - ProtectProc = "invisible"; - ProtectSystem = "strict"; - RestrictNamespaces = "uts ipc pid user cgroup"; - RestrictRealtime = true; - RestrictSUIDSGID = true; - SystemCallArchitectures = "native"; - SystemCallFilter = [ "@system-service" ]; - UMask = "0077"; - }; - - xdg = import ./xdg.nix; -in { - inherit - systemd - xdg - ; + xdg = import ./xdg.nix; }