From 9b5f39d7f2e808a63958c638bdec7d6547a94a1f Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 23 Jul 2023 22:16:59 +0200 Subject: [PATCH] hive.nix: Switch dgn-lib to nix-lib --- hive.nix | 4 ++-- lib/default.nix | 31 ++-------------------------- lib/trivial.nix | 50 ---------------------------------------------- npins/sources.json | 13 ++++++++++++ 4 files changed, 17 insertions(+), 81 deletions(-) delete mode 100644 lib/trivial.nix diff --git a/hive.nix b/hive.nix index e6ddf7b..9d3f78e 100644 --- a/hive.nix +++ b/hive.nix @@ -2,7 +2,7 @@ let sources = import ./npins; metadata = import ./meta; - lib = import ./lib/trivial.nix; + lib = import (sources.nix-lib + "/trivial.nix"); mkNode = node: { name, nodes, ... }: { # Import the base configuration for each node @@ -35,7 +35,7 @@ let mkNixpkgs' = node: import (mkNixpkgs node) { }; mkArgs = node: { - dgn-lib = import ./lib { inherit ((mkNixpkgs' node)) lib; }; + dgn-lib = import sources.nix-lib { inherit ((mkNixpkgs' node)) lib; keysRoot = ./keys; }; }; nodes = builtins.attrNames metadata.nodes; diff --git a/lib/default.nix b/lib/default.nix index 99b2785..7947fed 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,34 +1,7 @@ { lib, ... }: let - trivial = import ./trivial.nix; + sources = import ../npins; in -trivial // (with trivial; rec { - recursiveFuse = builtins.foldl' lib.recursiveUpdate { }; - - mkImport = root: file: - let path = mkRel root file; in - path + (lib.optionalString (!lib.pathIsDirectory path) ".nix"); - - mkImports = root: builtins.map (mkImport root); - - getKeys = name: builtins.filter - (k: k != "") - (lib.splitString "\n" (builtins.readFile (mkRel ../keys "${name}.keys"))); - - /* List version of getKeys */ - getAllKeys = names: builtins.concatLists (builtins.map getKeys names); - - getKeyFiles = builtins.map (compose (n: "${n}.keys") (mkRel ../keys)); - - getNodeKeys = node: - let - meta = import ../meta; - names = builtins.foldl' - (names: group: names ++ meta.members.groups.${group}) - (meta.nodes.${node}.admins ++ [ "/machines/${node}" ]) - (meta.nodes.${node}.adminGroups ++ [ "root" ]); - in - getAllKeys names; -}) +import sources.nix-lib { inherit lib; keysRoot = ../keys; } diff --git a/lib/trivial.nix b/lib/trivial.nix deleted file mode 100644 index cd848c0..0000000 --- a/lib/trivial.nix +++ /dev/null @@ -1,50 +0,0 @@ -rec { - /* Fuses a list of attribute sets into a single attribute set. - - Example: - x = [ { a = 1; } { b = 2; } ] - fuseAttrs x - => { a = 1; b = 2; } - */ - fuseAttrs = builtins.foldl' (attrs: x: attrs // x) { }; - - /* Maps then fuses a list of attribute sets into a single attribute set. - - Example: - x = [ "a" "b" ] - mapFuse (c: { ${c} = 42; }) x - => { a = 42; b = 42; } - */ - mapFuse = f: attrsList: fuseAttrs (builtins.map f attrsList); - - /* Equivalent of lib.singleton but for an attribute set. - - Example: - singleAttr "a" 1 - => { a = 1; } - */ - singleAttr = name: value: { ${name} = value; }; - - /* Enables a list of modules. */ - enableAttrs' = enable: mapFuse (m: { ${m}.${enable} = true; }); - - enableModules = enableAttrs' "enable"; - - mapSingleFuse = f: mapFuse (x: singleAttr x (f x)); - - setDefault = default: mapFuse (name: { ${name} = default; }); - - /* Creates a relative path as a string - - Example: - mkRel /home/test/ "file.txt" - => "/home/test/file.txt" - */ - mkRel = path: file: path + "/${file}"; - - compose = f: g: (x: g (f x)); - - mkBaseSecrets = root: mapFuse (secret: { ${secret}.file = mkRel root secret; }); - - getSecrets = dir: builtins.attrNames (import (mkRel dir "secrets.nix")); -} diff --git a/npins/sources.json b/npins/sources.json index 0194d75..95265af 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -41,6 +41,19 @@ "url": null, "hash": "1bashjbh71dqs32yld7ihw2vz0vrad73pc35crf3qck8ssgpzv7d" }, + "nix-lib": { + "type": "GitRelease", + "repository": { + "type": "Git", + "url": "https://git.hubrecht.ovh/hubrecht/nix-lib" + }, + "pre_releases": false, + "version_upper_bound": null, + "version": "0.1.1", + "revision": "5db2443e2cb18335375ad84ffbc066a239c054de", + "url": null, + "hash": "18xzi2yn2vk7zq79pgz8z2s1ijhyjcx5866mp21rrdi9gz37yiif" + }, "nixos-23.05": { "type": "Channel", "name": "nixos-23.05",