From 567e4eb551fc3a77d1ade38386a0238d633fad22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Tue, 7 Mar 2023 11:25:53 +0100 Subject: [PATCH] refactor: add lib.my for useful functions --- flake.nix | 41 ++++++++++++++++++++++++----------------- lib/default.nix | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 lib/default.nix diff --git a/flake.nix b/flake.nix index e6be918..6d7c237 100644 --- a/flake.nix +++ b/flake.nix @@ -104,11 +104,17 @@ channelsConfig.allowUnfree = true; + lib = nixpkgs.lib.extend + (self: super: { my = import ./lib { lib = self; }; }); + ################ ### Overlays ### ################ - overlay = import ./overlays { inherit inputs; }; + overlay = import ./overlays { + inherit inputs; + inherit (self) lib; + }; channels.nixpkgs.overlaysBuilder = channels: [ inputs.emacs.overlays.default @@ -134,22 +140,23 @@ ./modules/profiles/gaming.nix ./modules/profiles/desktop.nix ]; - - hostDefaults.modules = [ - ./modules/default.nix - self.nixosModules.base - inputs.home-manager.nixosModule - { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { inherit inputs self; }; - }; - } - inputs.hyprland.nixosModules.default - inputs.agenix.nixosModules.age - inputs.howdy.nixosModules.default - ]; + hostDefaults = { + modules = [ + ./modules/default.nix + self.nixosModules.base + inputs.home-manager.nixosModule + { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = { inherit inputs self; }; + }; + } + inputs.hyprland.nixosModules.default + inputs.agenix.nixosModules.age + inputs.howdy.nixosModules.default + ]; + }; hosts.nixos-laptop.modules = [ ./hosts/nixos-laptop diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..f2ea1c0 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,16 @@ +{ lib, ... }: + +lib.makeExtensible (self: rec { + mkDate = longDate: lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]; + mkVersionSrc = src: "unstable-" + builtins.substring 0 7 src.rev; + mkVersionInput = input: + let + date = mkDate (input.lastModifiedDate or "19700101"); + rev = input.shortRev or "dirty"; + in + "unstable-${date}_${rev}}"; +})