1
0
Fork 0
nixos-config/private.nix

35 lines
1 KiB
Nix
Raw Normal View History

2020-12-16 18:26:20 +00:00
let
2021-07-04 22:53:03 +00:00
persistPath = "/disk/persist/maralorn";
hasPersistDisk = builtins.pathExists persistPath;
2020-12-16 18:26:20 +00:00
privateExists = builtins.pathExists private/submodule-is-checked-out;
2021-07-04 22:53:03 +00:00
var = "WITH_SECRETS";
explicitUsePrivate = builtins.getEnv var == "true";
explicitNotUsePrivate = builtins.getEnv var == "false";
2020-12-16 18:26:20 +00:00
usePrivate = !explicitNotUsePrivate && (explicitUsePrivate || privateExists);
2021-05-18 14:33:28 +00:00
withSecrets = builtins.trace
2022-03-08 01:42:46 +00:00
(if usePrivate
then assert privateExists; "Building _with_ secrets!"
else "Building _without_ secrets!")
usePrivate;
in {
2020-12-16 18:26:20 +00:00
inherit withSecrets;
2022-03-08 01:42:46 +00:00
privatePath = name: let
path = "${
if hasPersistDisk
then persistPath
else "/home/maralorn"
}/git/config/private/${name}";
in
if withSecrets
then assert builtins.pathExists (./private + "/${name}"); path
else path;
2020-12-16 18:26:20 +00:00
privateValue = default: name:
2022-03-08 01:42:46 +00:00
if withSecrets
then import (./private + "/${name}.nix")
else default;
2020-12-16 18:26:20 +00:00
privateFile = name:
2022-03-08 01:42:46 +00:00
if withSecrets
then ./private + "/${name}"
else builtins.toFile "missing-secret-file-${name}" "";
2020-12-16 18:26:20 +00:00
}