mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +00:00
lib: reformat code
This commit is contained in:
parent
2f93b33e0c
commit
171d8f797d
@ -4,6 +4,5 @@
|
||||
|
||||
{ dir, name ? baseNameOf dir, keyfiles, profile }@args:
|
||||
|
||||
runCommand "dconf-${name}" {
|
||||
nativeBuildInputs = [ (lib.getBin dconf) ];
|
||||
} "dconf compile $out ${dir}"
|
||||
runCommand "dconf-${name}" { nativeBuildInputs = [ (lib.getBin dconf) ]; }
|
||||
"dconf compile $out ${dir}"
|
||||
|
@ -18,14 +18,7 @@
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
{
|
||||
hugo,
|
||||
go,
|
||||
cacert,
|
||||
git,
|
||||
lib,
|
||||
stdenv,
|
||||
}:
|
||||
{ hugo, go, cacert, git, lib, stdenv, }:
|
||||
|
||||
# A modified Go builder for generating a website with Hugo. Since it relies on
|
||||
# Hugo modules (which is basically wrapper around Go modules), this can be used
|
||||
@ -34,11 +27,9 @@
|
||||
# Take note, this doesn't work for Hugo projects with remote resources
|
||||
# right in the content since Hugo allows network access when generating
|
||||
# the website.
|
||||
{
|
||||
name ? "${args'.pname}-${args'.version}",
|
||||
{ name ? "${args'.pname}-${args'.version}",
|
||||
|
||||
nativeBuildInputs ? [ ],
|
||||
passthru ? { },
|
||||
nativeBuildInputs ? [ ], passthru ? { },
|
||||
|
||||
# A function to override the goModules derivation
|
||||
overrideModAttrs ? (_oldAttrs: { }),
|
||||
@ -50,12 +41,10 @@
|
||||
#
|
||||
# if vendorHash is null, then we won't fetch any dependencies and
|
||||
# rely on the vendor folder within the source.
|
||||
vendorHash ? throw (
|
||||
if args' ? vendorSha256 then
|
||||
vendorHash ? throw (if args' ? vendorSha256 then
|
||||
"buildHugoSite: Expect vendorHash instead of vendorSha256"
|
||||
else
|
||||
"buildHugoSite: vendorHash is missing"
|
||||
),
|
||||
"buildHugoSite: vendorHash is missing"),
|
||||
|
||||
# Whether to delete the vendor folder supplied with the source.
|
||||
deleteVendor ? false,
|
||||
@ -81,32 +70,22 @@
|
||||
|
||||
GOFLAGS ? [ ],
|
||||
|
||||
...
|
||||
}@args':
|
||||
... }@args':
|
||||
|
||||
let
|
||||
args = removeAttrs args' [
|
||||
"overrideModAttrs"
|
||||
"vendorSha256"
|
||||
"vendorHash"
|
||||
];
|
||||
args = removeAttrs args' [ "overrideModAttrs" "vendorSha256" "vendorHash" ];
|
||||
|
||||
GO111MODULE = "on";
|
||||
GOTOOLCHAIN = "local";
|
||||
|
||||
hugoModules =
|
||||
if (vendorHash == null) then
|
||||
hugoModules = if (vendorHash == null) then
|
||||
""
|
||||
else
|
||||
(stdenv.mkDerivation {
|
||||
name = "${name}-hugo-modules";
|
||||
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
||||
hugo
|
||||
go
|
||||
git
|
||||
cacert
|
||||
];
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ])
|
||||
++ [ hugo go git cacert ];
|
||||
|
||||
inherit (args) src;
|
||||
inherit (go) GOOS GOARCH;
|
||||
@ -126,14 +105,10 @@ let
|
||||
setSourceRoot = args.setSourceRoot or "";
|
||||
env = args.env or { };
|
||||
|
||||
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
|
||||
"GIT_PROXY_COMMAND"
|
||||
"SOCKS_SERVER"
|
||||
"GOPROXY"
|
||||
];
|
||||
impureEnvVars = lib.fetchers.proxyImpureEnvVars
|
||||
++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" "GOPROXY" ];
|
||||
|
||||
configurePhase =
|
||||
args.modConfigurePhase or ''
|
||||
configurePhase = args.modConfigurePhase or ''
|
||||
runHook preConfigure
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
export GOPATH="$TMPDIR/go"
|
||||
@ -141,61 +116,45 @@ let
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
buildPhase =
|
||||
args.modBuildPhase or (
|
||||
''
|
||||
buildPhase = args.modBuildPhase or (''
|
||||
runHook preBuild
|
||||
''
|
||||
+ lib.optionalString deleteVendor ''
|
||||
'' + lib.optionalString deleteVendor ''
|
||||
if [ ! -d _vendor ]; then
|
||||
echo "_vendor folder does not exist, 'deleteVendor' is not needed"
|
||||
exit 10
|
||||
else
|
||||
rm -rf _vendor
|
||||
fi
|
||||
''
|
||||
+ ''
|
||||
'' + ''
|
||||
if [ -d _vendor ]; then
|
||||
echo "_vendor folder exists, please set 'vendorHash = null;' in your expression"
|
||||
exit 10
|
||||
fi
|
||||
|
||||
${
|
||||
if proxyVendor then
|
||||
''
|
||||
${if proxyVendor then ''
|
||||
mkdir -p "''${GOPATH}/pkg/mod/cache/download"
|
||||
hugo mod vendor
|
||||
''
|
||||
else
|
||||
''
|
||||
'' else ''
|
||||
if (( "''${NIX_DEBUG:-0}" >= 1 )); then
|
||||
hugoModVendorFlags+=(-v)
|
||||
fi
|
||||
hugo mod vendor "''${hugoModVendorFlags[@]}"
|
||||
''
|
||||
}
|
||||
''}
|
||||
|
||||
mkdir -p _vendor
|
||||
|
||||
runHook postBuild
|
||||
''
|
||||
);
|
||||
'');
|
||||
|
||||
installPhase =
|
||||
args.modInstallPhase or ''
|
||||
installPhase = args.modInstallPhase or ''
|
||||
runHook preInstall
|
||||
|
||||
${
|
||||
if proxyVendor then
|
||||
''
|
||||
${if proxyVendor then ''
|
||||
rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb"
|
||||
cp -r --reflink=auto "''${GOPATH}/pkg/mod/cache/download" $out
|
||||
''
|
||||
else
|
||||
''
|
||||
'' else ''
|
||||
cp -r --reflink=auto _vendor $out
|
||||
''
|
||||
}
|
||||
''}
|
||||
|
||||
if ! [ "$(ls -A $out)" ]; then
|
||||
echo "_vendor folder is empty, please set 'vendorHash = null;' in your expression"
|
||||
@ -212,43 +171,27 @@ let
|
||||
# Handle empty vendorHash; avoid
|
||||
# error: empty hash requires explicit hash algorithm
|
||||
outputHashAlgo = if vendorHash == "" then "sha256" else null;
|
||||
}).overrideAttrs
|
||||
overrideModAttrs;
|
||||
}).overrideAttrs overrideModAttrs;
|
||||
|
||||
package = stdenv.mkDerivation (
|
||||
args
|
||||
// {
|
||||
nativeBuildInputs = [
|
||||
hugo
|
||||
git
|
||||
go
|
||||
] ++ nativeBuildInputs;
|
||||
package = stdenv.mkDerivation (args // {
|
||||
nativeBuildInputs = [ hugo git go ] ++ nativeBuildInputs;
|
||||
|
||||
inherit (go) GOOS GOARCH;
|
||||
|
||||
GOFLAGS =
|
||||
GOFLAGS
|
||||
++
|
||||
lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS)
|
||||
GOFLAGS = GOFLAGS ++ lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS)
|
||||
"use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS"
|
||||
(lib.optional (!proxyVendor) "-mod=vendor")
|
||||
++
|
||||
lib.warnIf (builtins.elem "-trimpath" GOFLAGS)
|
||||
++ lib.warnIf (builtins.elem "-trimpath" GOFLAGS)
|
||||
"`-trimpath` is added by default to GOFLAGS by buildHugoSite when allowGoReference isn't set to true"
|
||||
(lib.optional (!allowGoReference) "-trimpath");
|
||||
inherit
|
||||
CGO_ENABLED
|
||||
enableParallelBuilding
|
||||
GO111MODULE
|
||||
GOTOOLCHAIN
|
||||
;
|
||||
inherit CGO_ENABLED enableParallelBuilding GO111MODULE GOTOOLCHAIN;
|
||||
|
||||
# If not set to an explicit value, set the buildid empty for reproducibility.
|
||||
ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid=";
|
||||
ldflags = ldflags
|
||||
++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags)
|
||||
"-buildid=";
|
||||
|
||||
configurePhase =
|
||||
args.configurePhase or (
|
||||
''
|
||||
configurePhase = args.configurePhase or (''
|
||||
runHook preConfigure
|
||||
|
||||
export GOCACHE=$TMPDIR/go-cache
|
||||
@ -256,21 +199,14 @@ let
|
||||
export GOPROXY=off
|
||||
export GOSUMDB=off
|
||||
cd "$modRoot"
|
||||
''
|
||||
+ lib.optionalString (vendorHash != null) ''
|
||||
${
|
||||
if proxyVendor then
|
||||
''
|
||||
'' + lib.optionalString (vendorHash != null) ''
|
||||
${if proxyVendor then ''
|
||||
export GOPROXY=file://${hugoModules}
|
||||
''
|
||||
else
|
||||
''
|
||||
'' else ''
|
||||
rm -rf _vendor
|
||||
cp -r --reflink=auto ${hugoModules} _vendor
|
||||
''
|
||||
}
|
||||
''
|
||||
+ ''
|
||||
''}
|
||||
'' + ''
|
||||
|
||||
# currently pie is only enabled by default in pkgsMusl
|
||||
# this will respect the `hardening{Disable,Enable}` flags if set
|
||||
@ -279,26 +215,22 @@ let
|
||||
fi
|
||||
|
||||
runHook postConfigure
|
||||
''
|
||||
);
|
||||
'');
|
||||
|
||||
buildPhase =
|
||||
args.buildPhase or ''
|
||||
buildPhase = args.buildPhase or ''
|
||||
runHook preBuild
|
||||
hugo "''${buildFlags[@]}" --destination public
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
doCheck = args.doCheck or true;
|
||||
checkPhase =
|
||||
args.checkPhase or ''
|
||||
checkPhase = args.checkPhase or ''
|
||||
runHook preCheck
|
||||
|
||||
runHook postCheck
|
||||
'';
|
||||
|
||||
installPhase =
|
||||
args.installPhase or ''
|
||||
installPhase = args.installPhase or ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p $out
|
||||
@ -311,20 +243,11 @@ let
|
||||
|
||||
disallowedReferences = lib.optional (!allowGoReference) go;
|
||||
|
||||
passthru = passthru // {
|
||||
inherit
|
||||
go
|
||||
hugo
|
||||
hugoModules
|
||||
vendorHash
|
||||
;
|
||||
};
|
||||
passthru = passthru // { inherit go hugo hugoModules vendorHash; };
|
||||
|
||||
meta = {
|
||||
# Add default meta information
|
||||
platforms = go.meta.platforms or lib.platforms.all;
|
||||
} // meta;
|
||||
}
|
||||
);
|
||||
in
|
||||
package
|
||||
});
|
||||
in package
|
||||
|
@ -19,11 +19,12 @@
|
||||
removedAssociations ? { },
|
||||
|
||||
# Set of applications to be opened associated with the MIME type.
|
||||
defaultApplications ? { },
|
||||
}:
|
||||
defaultApplications ? { }, }:
|
||||
|
||||
writeTextFile {
|
||||
name = "xdg-mime-associations${lib.optionalString (desktopName != "") "-${desktopName}"}";
|
||||
name = "xdg-mime-associations${
|
||||
lib.optionalString (desktopName != "") "-${desktopName}"
|
||||
}";
|
||||
text =
|
||||
# Non-desktop-specific mimeapps.list are only allowed to specify
|
||||
# default applications.
|
||||
@ -33,6 +34,8 @@ writeTextFile {
|
||||
"Added Associations" = addedAssociations;
|
||||
"Removed Associations" = removedAssociations;
|
||||
}));
|
||||
destination = "/share/applications/${lib.optionalString (desktopName != "") "${desktopName}-"}mimeapps.list";
|
||||
destination = "/share/applications/${
|
||||
lib.optionalString (desktopName != "") "${desktopName}-"
|
||||
}mimeapps.list";
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,7 @@
|
||||
validate ? true,
|
||||
|
||||
# Destination path relative to the output path.
|
||||
destination ? "/share/applications/${name}.desktop",
|
||||
}:
|
||||
destination ? "/share/applications/${name}.desktop", }:
|
||||
|
||||
writeTextFile {
|
||||
name = "xdg-desktop-entry-${name}";
|
||||
@ -26,14 +25,14 @@ writeTextFile {
|
||||
listsAsDuplicateKeys = false;
|
||||
mkKeyValue = lib.generators.mkKeyValueDefault {
|
||||
mkValueString = v:
|
||||
if lib.isList v then lib.concatStringsSep ";" v
|
||||
else lib.generators.mkValueStringDefault { } v;
|
||||
if lib.isList v then
|
||||
lib.concatStringsSep ";" v
|
||||
else
|
||||
lib.generators.mkValueStringDefault { } v;
|
||||
} "=";
|
||||
} config;
|
||||
inherit destination;
|
||||
checkPhase =
|
||||
lib.optionalString validate
|
||||
''
|
||||
checkPhase = lib.optionalString validate ''
|
||||
${lib.getExe' desktop-file-utils "desktop-file-validate"} "$target"
|
||||
'';
|
||||
}
|
||||
|
@ -4,14 +4,16 @@
|
||||
configuration. Similarly, the given desktop name is assumed to be already
|
||||
in its suitable form of a lowercase ASCII.
|
||||
*/
|
||||
{
|
||||
desktopName ? "common",
|
||||
{ desktopName ? "common",
|
||||
|
||||
# Nix-representable data to be exported as the portal configuration.
|
||||
config,
|
||||
}:
|
||||
config, }:
|
||||
writeTextFile {
|
||||
name = "xdg-portal-config${lib.optionalString (desktopName != "common") "-${desktopName}"}";
|
||||
name = "xdg-portal-config${
|
||||
lib.optionalString (desktopName != "common") "-${desktopName}"
|
||||
}";
|
||||
text = lib.generators.toINI { } config;
|
||||
destination = "/share/xdg-desktop-portal/${lib.optionalString (desktopName != "common") "${desktopName}-"}portals.conf";
|
||||
destination = "/share/xdg-desktop-portal/${
|
||||
lib.optionalString (desktopName != "common") "${desktopName}-"
|
||||
}portals.conf";
|
||||
}
|
||||
|
@ -55,8 +55,7 @@
|
||||
=> /nix/store/HASH-mustache-render-template
|
||||
*/
|
||||
renderMustacheTemplate = { template, context, extraArgs ? { } }:
|
||||
let
|
||||
extraArgs' = lib.cli.toGNUCommandLineShell { } extraArgs;
|
||||
let extraArgs' = lib.cli.toGNUCommandLineShell { } extraArgs;
|
||||
in pkgs.runCommand "mustache-render-template" {
|
||||
nativeBuildInputs = with pkgs; [ mustache-go ];
|
||||
context = builtins.toJSON context;
|
||||
|
@ -14,39 +14,30 @@
|
||||
|
||||
let
|
||||
# A set of nixos-generators modules including our custom ones.
|
||||
nixosGeneratorModules =
|
||||
let
|
||||
nixosGeneratorModules = let
|
||||
officialFormats = builtins.readDir "${sources.nixos-generators}/formats";
|
||||
unofficialFormats = builtins.readDir ../modules/nixos-generators;
|
||||
formats = officialFormats // unofficialFormats;
|
||||
in
|
||||
lib.mapAttrs' (n: _: lib.nameValuePair (lib.removeSuffix ".nix" n) {
|
||||
in lib.mapAttrs' (n: _:
|
||||
lib.nameValuePair (lib.removeSuffix ".nix" n) {
|
||||
imports = [
|
||||
"${sources.nixos-generators}/format-module.nix"
|
||||
(
|
||||
if (lib.hasAttr n officialFormats)
|
||||
then "${sources.nixos-generators}/formats/${n}"
|
||||
else "${../modules/nixos-generators}/${n}"
|
||||
)
|
||||
(if (lib.hasAttr n officialFormats) then
|
||||
"${sources.nixos-generators}/formats/${n}"
|
||||
else
|
||||
"${../modules/nixos-generators}/${n}")
|
||||
];
|
||||
}) formats;
|
||||
in
|
||||
rec {
|
||||
mkNixosSystem = {
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
system,
|
||||
extraModules ? [ ],
|
||||
specialArgs ? { },
|
||||
}:
|
||||
in rec {
|
||||
mkNixosSystem =
|
||||
{ pkgs, lib ? pkgs.lib, system, extraModules ? [ ], specialArgs ? { }, }:
|
||||
let
|
||||
nixosModules = ../modules/nixos;
|
||||
|
||||
# Evaluating the system ourselves (which is trivial) instead of relying
|
||||
# on nixpkgs.lib.nixosSystem flake output.
|
||||
nixosSystem = args: import "${pkgs.path}/nixos/lib/eval-config.nix" args;
|
||||
in
|
||||
(lib.makeOverridable nixosSystem) {
|
||||
in (lib.makeOverridable nixosSystem) {
|
||||
inherit pkgs;
|
||||
specialArgs = specialArgs // {
|
||||
foodogsquaredUtils = import ./utils/nixos.nix { inherit lib; };
|
||||
@ -55,9 +46,7 @@ rec {
|
||||
modules = extraModules ++ [
|
||||
nixosModules
|
||||
../modules/nixos/_private
|
||||
({ lib, ... }: {
|
||||
nixpkgs.hostPlatform = lib.mkForce system;
|
||||
})
|
||||
({ lib, ... }: { nixpkgs.hostPlatform = lib.mkForce system; })
|
||||
];
|
||||
|
||||
# Since we're setting it through nixpkgs.hostPlatform, we'll have to pass
|
||||
@ -66,44 +55,27 @@ rec {
|
||||
};
|
||||
|
||||
# A very very thin wrapper around `mkNixosSystem` to build with the given format.
|
||||
mkNixosImage = {
|
||||
pkgs,
|
||||
system,
|
||||
lib ? pkgs.lib,
|
||||
extraModules ? [ ],
|
||||
specialArgs ? { },
|
||||
format ? "iso",
|
||||
}:
|
||||
mkNixosImage = { pkgs, system, lib ? pkgs.lib, extraModules ? [ ]
|
||||
, specialArgs ? { }, format ? "iso", }:
|
||||
let
|
||||
extraModules' = extraModules ++ [ nixosGeneratorModules.${format} ];
|
||||
nixosSystem = mkNixosSystem {
|
||||
inherit pkgs lib system specialArgs;
|
||||
extraModules = extraModules';
|
||||
};
|
||||
in
|
||||
nixosSystem.config.system.build.${nixosSystem.config.formatAttr};
|
||||
in nixosSystem.config.system.build.${nixosSystem.config.formatAttr};
|
||||
|
||||
mkHome = {
|
||||
pkgs,
|
||||
homeManagerSrc,
|
||||
lib ? pkgs.lib,
|
||||
modules ? [ ],
|
||||
specialArgs ? { },
|
||||
}:
|
||||
let
|
||||
homeModules = ../modules/home-manager;
|
||||
in
|
||||
import "${homeManagerSrc}/modules" {
|
||||
mkHome =
|
||||
{ pkgs, homeManagerSrc, lib ? pkgs.lib, modules ? [ ], specialArgs ? { }, }:
|
||||
let homeModules = ../modules/home-manager;
|
||||
in import "${homeManagerSrc}/modules" {
|
||||
inherit pkgs lib;
|
||||
check = true;
|
||||
extraSpecialArgs = specialArgs // {
|
||||
foodogsquaredModulesPath = builtins.toString homeModules;
|
||||
};
|
||||
configuration = { lib, ... }: {
|
||||
imports = modules ++ [
|
||||
homeModules
|
||||
../modules/home-manager/_private
|
||||
];
|
||||
imports = modules ++ [ homeModules ../modules/home-manager/_private ];
|
||||
|
||||
config = {
|
||||
programs.home-manager.path = homeManagerSrc;
|
||||
@ -113,25 +85,17 @@ rec {
|
||||
};
|
||||
};
|
||||
|
||||
mkWrapper = {
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
wrapperManagerSrc,
|
||||
modules ? [ ],
|
||||
specialArgs ? { },
|
||||
}:
|
||||
mkWrapper = { pkgs, lib ? pkgs.lib, wrapperManagerSrc, modules ? [ ]
|
||||
, specialArgs ? { }, }:
|
||||
let
|
||||
wrapperManagerModules = ../modules/wrapper-manager;
|
||||
wrapperManager = import wrapperManagerSrc { };
|
||||
in
|
||||
wrapperManager.lib.build {
|
||||
in wrapperManager.lib.build {
|
||||
inherit pkgs lib;
|
||||
specialArgs = specialArgs // {
|
||||
foodogsquaredModulesPath = builtins.toString wrapperManagerModules;
|
||||
};
|
||||
modules = modules ++ [
|
||||
wrapperManagerModules
|
||||
../modules/wrapper-manager/_private
|
||||
];
|
||||
modules = modules
|
||||
++ [ wrapperManagerModules ../modules/wrapper-manager/_private ];
|
||||
};
|
||||
}
|
||||
|
@ -2,8 +2,7 @@
|
||||
{ pkgs, lib, self }:
|
||||
|
||||
rec {
|
||||
/*
|
||||
Checks if there is the `osConfig` attribute and get the attribute path from
|
||||
/* Checks if there is the `osConfig` attribute and get the attribute path from
|
||||
its system configuration.
|
||||
*/
|
||||
hasNixOSConfigAttr =
|
||||
@ -26,11 +25,10 @@ rec {
|
||||
|
||||
# The default value when `attrPath` is missing.
|
||||
default:
|
||||
attrs ? darwinConfig && pkgs.lib.attrByPath attrPath default attrs.darwinConfig;
|
||||
attrs ? darwinConfig
|
||||
&& pkgs.lib.attrByPath attrPath default attrs.darwinConfig;
|
||||
|
||||
/*
|
||||
A quick function to check if the optional NixOS system module is enabled.
|
||||
*/
|
||||
# A quick function to check if the optional NixOS system module is enabled.
|
||||
hasOSModuleEnabled =
|
||||
# The configuration attribute set of the home-manager configuration.
|
||||
attrs:
|
||||
|
@ -5,12 +5,10 @@
|
||||
# Checks if the NixOS configuration is part of the nixos-generator build.
|
||||
# Typically, we just check if there's a certain attribute that is imported
|
||||
# from it.
|
||||
hasNixosFormat = config:
|
||||
lib.hasAttrByPath [ "formatAttr" ] config;
|
||||
hasNixosFormat = config: lib.hasAttrByPath [ "formatAttr" ] config;
|
||||
|
||||
# Checks if the NixOS config is being built for a particular format.
|
||||
isFormat = config: format:
|
||||
(config.formatAttr or "") == format;
|
||||
isFormat = config: format: (config.formatAttr or "") == format;
|
||||
|
||||
# Create a separate environment similar to NixOS `system.path`. This is
|
||||
# typically used to create isolated environments for custom desktop sessions
|
||||
@ -21,8 +19,7 @@
|
||||
pkgs.buildEnv (args // {
|
||||
inherit (config.environment) pathsToLink extraOutputsToInstall;
|
||||
ignoreCollisions = true;
|
||||
postBuild =
|
||||
''
|
||||
postBuild = ''
|
||||
# Remove wrapped binaries, they shouldn't be accessible via PATH.
|
||||
find $out/bin -maxdepth 1 -name ".*-wrapped" -type l -delete
|
||||
|
||||
@ -44,26 +41,24 @@
|
||||
|
||||
# Create a range object (as [start, end) in notation) that is typically used
|
||||
# in module options that accept them.
|
||||
makeRange = start: range:
|
||||
{ from = start; to = start + range; };
|
||||
makeRange = start: range: {
|
||||
from = start;
|
||||
to = start + range;
|
||||
};
|
||||
|
||||
# Create a range object (as [start + 1, end + 1] in notation) that is typically used
|
||||
# in module options that accept them except that the starting port is included.
|
||||
makeRange' = start: range:
|
||||
let
|
||||
start' = start + 1;
|
||||
in
|
||||
{ from = start'; to = start' + range; };
|
||||
let start' = start + 1;
|
||||
in {
|
||||
from = start';
|
||||
to = start' + range;
|
||||
};
|
||||
|
||||
/*
|
||||
A specific function that checks if specific filesystem setups are set.
|
||||
*/
|
||||
# A specific function that checks if specific filesystem setups are set.
|
||||
isFilesystemSet = config: setupName:
|
||||
config.suites.filesystem.setups.${setupName}.enable or false;
|
||||
|
||||
/*
|
||||
Get the path from the state variable.
|
||||
*/
|
||||
getFilesystem = config: setupName:
|
||||
config.state.paths.${setupName};
|
||||
# Get the path from the state variable.
|
||||
getFilesystem = config: setupName: config.state.paths.${setupName};
|
||||
}
|
||||
|
@ -18,13 +18,8 @@
|
||||
}
|
||||
*/
|
||||
getSecrets = sopsFile: secrets:
|
||||
let
|
||||
getKey = key: { inherit key sopsFile; };
|
||||
in
|
||||
lib.mapAttrs
|
||||
(path: attrs:
|
||||
(getKey path) // attrs)
|
||||
secrets;
|
||||
let getKey = key: { inherit key sopsFile; };
|
||||
in lib.mapAttrs (path: attrs: (getKey path) // attrs) secrets;
|
||||
|
||||
/* Prepend a prefix for the given secrets. This allows a workflow for
|
||||
separate sops file.
|
||||
@ -44,10 +39,7 @@
|
||||
}))
|
||||
*/
|
||||
attachSopsPathPrefix = prefix: secrets:
|
||||
lib.mapAttrs'
|
||||
(key: settings:
|
||||
lib.nameValuePair
|
||||
"${prefix}/${key}"
|
||||
({ inherit key; } // settings))
|
||||
lib.mapAttrs' (key: settings:
|
||||
lib.nameValuePair "${prefix}/${key}" ({ inherit key; } // settings))
|
||||
secrets;
|
||||
}
|
||||
|
@ -5,11 +5,8 @@ rec {
|
||||
containing all of the addons properly placed as a system resource folder.
|
||||
*/
|
||||
wrapBlenderAddons = { blenderPackage, addons }:
|
||||
let
|
||||
blenderVersion = lib.versions.majorMinor blenderPackage.version;
|
||||
in
|
||||
pkgs.runCommand "blender-system-resources"
|
||||
{
|
||||
let blenderVersion = lib.versions.majorMinor blenderPackage.version;
|
||||
in pkgs.runCommand "blender-system-resources" {
|
||||
passAsFile = [ "paths" ];
|
||||
paths = addons ++ [ blenderPackage ];
|
||||
nativeBuildInputs = with pkgs; [ outils ];
|
||||
@ -24,11 +21,10 @@ rec {
|
||||
done
|
||||
'';
|
||||
|
||||
makeBlenderWrapper = module@{ blenderPackage, blenderArgs ? [ ] , addons ? [ ], ... }:
|
||||
let
|
||||
blenderAddons = wrapBlenderAddons { inherit blenderPackage addons; };
|
||||
in
|
||||
lib.mkMerge [
|
||||
makeBlenderWrapper =
|
||||
module@{ blenderPackage, blenderArgs ? [ ], addons ? [ ], ... }:
|
||||
let blenderAddons = wrapBlenderAddons { inherit blenderPackage addons; };
|
||||
in lib.mkMerge [
|
||||
{
|
||||
arg0 = lib.getExe' blenderPackage "blender";
|
||||
prependArgs = lib.mkBefore blenderArgs;
|
||||
@ -41,48 +37,49 @@ rec {
|
||||
(lib.removeAttrs module [ "blenderPackage" "blenderArgs" "addons" ])
|
||||
];
|
||||
|
||||
/* Create a configuration module for quickly wrapping with Boxxy.
|
||||
*/
|
||||
makeBoxxyWrapper = module@{ boxxyArgs, wraparound, wraparoundArgs ? [], ... }:
|
||||
# Create a configuration module for quickly wrapping with Boxxy.
|
||||
makeBoxxyWrapper =
|
||||
module@{ boxxyArgs, wraparound, wraparoundArgs ? [ ], ... }:
|
||||
lib.mkMerge [
|
||||
{
|
||||
arg0 = lib.getExe' pkgs.boxxy "boxxy";
|
||||
prependArgs = lib.mkBefore (boxxyArgs ++ [ "--" wraparound ] ++ wraparoundArgs);
|
||||
prependArgs =
|
||||
lib.mkBefore (boxxyArgs ++ [ "--" wraparound ] ++ wraparoundArgs);
|
||||
}
|
||||
|
||||
(builtins.removeAttrs module [ "boxxyArgs" "wraparound" "wraparoundArgs" ])
|
||||
(builtins.removeAttrs module [
|
||||
"boxxyArgs"
|
||||
"wraparound"
|
||||
"wraparoundArgs"
|
||||
])
|
||||
];
|
||||
|
||||
/* Given the path to the source code, the attribute path, and the executable
|
||||
name, return the store path to one of its executables.
|
||||
*/
|
||||
getNixglExecutable = { src, variant ? [ "auto" "nixGLDefault" ], nixglProgram ? "nixGL" }:
|
||||
getNixglExecutable =
|
||||
{ src, variant ? [ "auto" "nixGLDefault" ], nixglProgram ? "nixGL" }:
|
||||
let
|
||||
nixgl = import src { inherit pkgs; };
|
||||
nixglPkg = lib.getAttrFromPath variant nixgl;
|
||||
in
|
||||
lib.getExe' nixglPkg nixglProgram;
|
||||
in lib.getExe' nixglPkg nixglProgram;
|
||||
|
||||
/* Create a configuration module for quickly wrapping with NixGL.
|
||||
*/
|
||||
makeNixglWrapper = {
|
||||
nixglSrc,
|
||||
nixglArgs,
|
||||
nixglVariant,
|
||||
nixglExecutable,
|
||||
wraparound,
|
||||
wraparoundArgs ? [],
|
||||
...
|
||||
}@module:
|
||||
# Create a configuration module for quickly wrapping with NixGL.
|
||||
makeNixglWrapper = { nixglSrc, nixglArgs, nixglVariant, nixglExecutable
|
||||
, wraparound, wraparoundArgs ? [ ], ... }@module:
|
||||
lib.mkMerge [
|
||||
{
|
||||
arg0 = getNixglExecutable nixglSrc nixglVariant nixglExecutable;
|
||||
prependArgs = lib.mkBefore (nixglArgs ++ [ "--" wraparound ] ++ wraparoundArgs);
|
||||
prependArgs =
|
||||
lib.mkBefore (nixglArgs ++ [ "--" wraparound ] ++ wraparoundArgs);
|
||||
}
|
||||
|
||||
(builtins.removeAttrs module [
|
||||
"nixglArgs" "nixglVariant" "nixglExecutable"
|
||||
"wraparound" "wraparoundArgs"
|
||||
"nixglArgs"
|
||||
"nixglVariant"
|
||||
"nixglExecutable"
|
||||
"wraparound"
|
||||
"wraparoundArgs"
|
||||
])
|
||||
];
|
||||
}
|
||||
|
@ -1,27 +1,20 @@
|
||||
{ stdenvNoCC, lib, fetchzip, fetchurl, curl }:
|
||||
|
||||
{
|
||||
id,
|
||||
file ? "",
|
||||
formats ? [ ],
|
||||
hash ? "",
|
||||
name ? "internet-archive-${id}",
|
||||
{ id, file ? "", formats ? [ ], hash ? "", name ? "internet-archive-${id}",
|
||||
}@args:
|
||||
|
||||
let
|
||||
isFormatIndiciated = formats != [ ];
|
||||
url =
|
||||
if isFormatIndiciated
|
||||
then "https://archive.org/compress/${lib.escapeURL id}/formats=${lib.concatStringsSep "," formats}"
|
||||
else "https://archive.org/download/${lib.escapeURL id}/${lib.escapeURL file}";
|
||||
url = if isFormatIndiciated then
|
||||
"https://archive.org/compress/${lib.escapeURL id}/formats=${
|
||||
lib.concatStringsSep "," formats
|
||||
}"
|
||||
else
|
||||
"https://archive.org/download/${lib.escapeURL id}/${lib.escapeURL file}";
|
||||
|
||||
args' = lib.removeAttrs args [ "id" "file" "formats" ] // {
|
||||
inherit url hash name;
|
||||
};
|
||||
|
||||
fetcher =
|
||||
if isFormatIndiciated
|
||||
then fetchzip
|
||||
else fetchurl;
|
||||
in
|
||||
fetcher args'
|
||||
fetcher = if isFormatIndiciated then fetchzip else fetchurl;
|
||||
in fetcher args'
|
||||
|
@ -1,15 +1,8 @@
|
||||
{ fetchzip, lib }:
|
||||
|
||||
{
|
||||
fileId,
|
||||
pid,
|
||||
ext ? "gz",
|
||||
...
|
||||
}@args:
|
||||
{ fileId, pid, ext ? "gz", ... }@args:
|
||||
|
||||
let
|
||||
args' = lib.removeAttrs args [ "fileId" "pid" "ext" ];
|
||||
in
|
||||
fetchzip (args' // {
|
||||
let args' = lib.removeAttrs args [ "fileId" "pid" "ext" ];
|
||||
in fetchzip (args' // {
|
||||
url = "https://www.ugee.com/download/file/id/${fileId}/pid/${pid}/ext/${ext}";
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
# No, this is not a flake of the library set, it is a library subset for
|
||||
# flake-related shtick. This should be used VERY RARELY in most parts of the
|
||||
# configuration because they are set up to be usable both in flakes- and
|
||||
# non-flakes-enabled environment.
|
||||
# configuration because they are set up to be usable both in flakes and
|
||||
# flake-less environment.
|
||||
#
|
||||
# Take note it has a very strict design constraint of not relying on the
|
||||
# `inputs` attribute of the flake output. Instead, we're relying on the
|
||||
@ -22,6 +22,5 @@ rec {
|
||||
fetchTree = metadata: inputName:
|
||||
builtins.fetchTree metadata.nodes.${inputName}.locked;
|
||||
|
||||
fetchInput = metadata: inputName:
|
||||
(fetchTree metadata inputName).outPath;
|
||||
fetchInput = metadata: inputName: (fetchTree metadata inputName).outPath;
|
||||
}
|
||||
|
13
lib/math.nix
13
lib/math.nix
@ -11,8 +11,7 @@ rec {
|
||||
abs (1 / 5)
|
||||
=> 0.2
|
||||
*/
|
||||
abs = number:
|
||||
if number < 0 then -(number) else number;
|
||||
abs = number: if number < 0 then -(number) else number;
|
||||
/* Exponentiates the given base with the exponent.
|
||||
|
||||
Example:
|
||||
@ -28,10 +27,10 @@ rec {
|
||||
let
|
||||
absValue = abs exponent;
|
||||
iter = product: counter: maxCount:
|
||||
if counter > maxCount
|
||||
then product
|
||||
else iter (product * base) (counter + 1) maxCount;
|
||||
if counter > maxCount then
|
||||
product
|
||||
else
|
||||
iter (product * base) (counter + 1) maxCount;
|
||||
value = iter 1 1 absValue;
|
||||
in
|
||||
if exponent < 0 then (1 / value) else value;
|
||||
in if exponent < 0 then (1 / value) else value;
|
||||
}
|
||||
|
@ -33,14 +33,15 @@ rec {
|
||||
=> { ok = { a = 4; }; notOk = { b = 2; c = 6; }; }
|
||||
*/
|
||||
filterAttrs' = f: attrs:
|
||||
lib.foldlAttrs (acc: name: value: let
|
||||
isOk = f name value;
|
||||
lib.foldlAttrs (acc: name: value:
|
||||
let isOk = f name value;
|
||||
in {
|
||||
ok = acc.ok // lib.optionalAttrs isOk { ${name} = value; };
|
||||
notOk = acc.notOk // lib.optionalAttrs (!isOk) { ${name} = value; };
|
||||
})
|
||||
{ ok = { }; notOk = { }; }
|
||||
attrs;
|
||||
}) {
|
||||
ok = { };
|
||||
notOk = { };
|
||||
} attrs;
|
||||
|
||||
/* Convenient function for converting bits to bytes.
|
||||
|
||||
@ -87,8 +88,7 @@ rec {
|
||||
r = -27;
|
||||
q = -30;
|
||||
};
|
||||
in
|
||||
prefixes.${c};
|
||||
in prefixes.${c};
|
||||
|
||||
/* Gives the multiplier for the metric units.
|
||||
|
||||
@ -99,8 +99,7 @@ rec {
|
||||
metricPrefixMultiplier "G"
|
||||
=> 1000000000
|
||||
*/
|
||||
metricPrefixMultiplier = c:
|
||||
self.math.pow 10 (SIPrefixExponent c);
|
||||
metricPrefixMultiplier = c: self.math.pow 10 (SIPrefixExponent c);
|
||||
|
||||
/* Gives the exponent with the associated binary prefix.
|
||||
|
||||
@ -126,8 +125,7 @@ rec {
|
||||
M = 20;
|
||||
K = 10;
|
||||
};
|
||||
in
|
||||
prefixes.${c};
|
||||
in prefixes.${c};
|
||||
|
||||
/* Gives the multiplier for the given byte unit. Essentially returns the
|
||||
value in number of bytes.
|
||||
@ -139,8 +137,7 @@ rec {
|
||||
binaryPrefixMultiplier "G"
|
||||
=> 1.099511628×10¹²
|
||||
*/
|
||||
binaryPrefixMultiplier = c:
|
||||
self.math.pow 2 (binaryPrefixExponent c);
|
||||
binaryPrefixMultiplier = c: self.math.pow 2 (binaryPrefixExponent c);
|
||||
|
||||
/* Parse the given string containing the size into its appropriate value.
|
||||
Returns the value in number of bytes.
|
||||
@ -157,23 +154,22 @@ rec {
|
||||
*/
|
||||
parseBytesSizeIntoInt = str:
|
||||
let
|
||||
matches = builtins.match "([[:digit:]]+)[[:space:]]*([[:alpha:]]{1})(i?[B|b])" str;
|
||||
matches =
|
||||
builtins.match "([[:digit:]]+)[[:space:]]*([[:alpha:]]{1})(i?[B|b])"
|
||||
str;
|
||||
numeral = lib.toInt (lib.lists.head matches);
|
||||
prefix = lib.lists.elemAt matches 1;
|
||||
suffix = lib.lists.last matches;
|
||||
isBinary = lib.hasPrefix "i" suffix;
|
||||
|
||||
multiplier =
|
||||
let
|
||||
multiplierFn = if isBinary then binaryPrefixMultiplier else metricPrefixMultiplier;
|
||||
in
|
||||
multiplierFn prefix;
|
||||
multiplier = let
|
||||
multiplierFn =
|
||||
if isBinary then binaryPrefixMultiplier else metricPrefixMultiplier;
|
||||
in multiplierFn prefix;
|
||||
bitDivider = if lib.hasSuffix "b" suffix then 8 else 1;
|
||||
in
|
||||
numeral * multiplier / bitDivider;
|
||||
in numeral * multiplier / bitDivider;
|
||||
|
||||
/*
|
||||
Given an attrset of unit size object, return the size in bytes.
|
||||
/* Given an attrset of unit size object, return the size in bytes.
|
||||
|
||||
Example:
|
||||
unitsToInt { size = 4; prefix = "G"; type = "binary"; }
|
||||
@ -184,10 +180,11 @@ rec {
|
||||
*/
|
||||
unitsToInt = { size, prefix, type ? "binary" }:
|
||||
let
|
||||
multiplierFn =
|
||||
if type == "binary" then binaryPrefixMultiplier
|
||||
else if type == "metric" then metricPrefixMultiplier
|
||||
else builtins.throw "no multiplier type ${type}";
|
||||
in
|
||||
size * (multiplierFn prefix);
|
||||
multiplierFn = if type == "binary" then
|
||||
binaryPrefixMultiplier
|
||||
else if type == "metric" then
|
||||
metricPrefixMultiplier
|
||||
else
|
||||
builtins.throw "no multiplier type ${type}";
|
||||
in size * (multiplierFn prefix);
|
||||
}
|
||||
|
@ -3,10 +3,8 @@
|
||||
{
|
||||
# This is only used for home-manager users without a NixOS user counterpart.
|
||||
mapHomeManagerUser = user: settings:
|
||||
let
|
||||
homeDirectory = "/home/${user}";
|
||||
in
|
||||
({ lib, ... }: {
|
||||
let homeDirectory = "/home/${user}";
|
||||
in ({ lib, ... }: {
|
||||
home-manager.users."${user}" = { ... }: {
|
||||
imports = [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user