lib: init flakes.nix

This commit creates flakes.nix, which is a library containing functions
which relate to interacting with flakes. It also moves related functions
from trivial.nix into it.
This commit is contained in:
matthewcroughan 2022-04-12 18:55:41 +01:00
parent c190b08bb7
commit cad8bbe589
3 changed files with 27 additions and 17 deletions

View File

@ -11,6 +11,9 @@ let
callLibs = file: import file { lib = self; }; callLibs = file: import file { lib = self; };
in { in {
# interacting with flakes
flakes = callLibs ./flakes.nix;
# often used, or depending on very little # often used, or depending on very little
trivial = callLibs ./trivial.nix; trivial = callLibs ./trivial.nix;
fixedPoints = callLibs ./fixed-points.nix; fixedPoints = callLibs ./fixed-points.nix;
@ -59,12 +62,13 @@ let
# linux kernel configuration # linux kernel configuration
kernel = callLibs ./kernel.nix; kernel = callLibs ./kernel.nix;
inherit (self.flakes) callLocklessFlake;
inherit (builtins) add addErrorContext attrNames concatLists inherit (builtins) add addErrorContext attrNames concatLists
deepSeq elem elemAt filter genericClosure genList getAttr deepSeq elem elemAt filter genericClosure genList getAttr
hasAttr head isAttrs isBool isInt isList isString length hasAttr head isAttrs isBool isInt isList isString length
lessThan listToAttrs pathExists readFile replaceStrings seq lessThan listToAttrs pathExists readFile replaceStrings seq
stringLength sub substring tail trace; stringLength sub substring tail trace;
inherit (self.trivial) id callLocklessFlake const pipe concat or and bitAnd bitOr bitXor inherit (self.trivial) id const pipe concat or and bitAnd bitOr bitXor
bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max
importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
info showWarnings nixpkgsVersion version isInOldestRelease info showWarnings nixpkgsVersion version isInOldestRelease

22
lib/flakes.nix Normal file
View File

@ -0,0 +1,22 @@
{ lib }:
rec {
/* imports a flake.nix without acknowledging its lock file, useful for
referencing subflakes from a parent flake. The second argument allows
specifying the inputs of this flake.
Example:
callLocklessFlake {
path = ./directoryContainingFlake;
inputs = { inherit nixpkgs; };
}
*/
callLocklessFlake = { path, inputs ? { } }:
let
self = { outPath = path; } //
((import (path + "/flake.nix")).outputs (inputs // { self = self; }));
in
self;
}

View File

@ -13,22 +13,6 @@ rec {
# The value to return # The value to return
x: x; x: x;
/* imports a flake.nix without acknowledging its lock file, useful for
referencing subflakes from a parent flake. The second argument allows
specifying the inputs of this flake.
Example:
callLocklessFlake {
path = ./directoryContainingFlake;
inputs = { inherit nixpkgs; };
}
*/
callLocklessFlake = { path, inputs ? {} }: let
self = {outPath = path;} //
((import (path + "/flake.nix")).outputs (inputs // {self = self;}));
in
self;
/* The constant function /* The constant function
Ignores the second argument. If called with only one argument, Ignores the second argument. If called with only one argument,