Skip to content

Commit 338d285

Browse files
committed
feat(build): add flag to export fully evaluated config from nix (#37)
1 parent c976904 commit 338d285

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

build.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env nix-shell
2-
#! nix-shell -i bash -p git nh nixfmt-rfc-style rsync
2+
#! nix-shell -i bash -p git jq jsonfmt nh nixfmt-rfc-style rsync
33

44
ICEDOS_DIR="/tmp/icedos"
55
CONFIG="$ICEDOS_DIR/configuration-location"
@@ -23,6 +23,10 @@ while [[ $# -gt 0 ]]; do
2323
action="build"
2424
shift
2525
;;
26+
--export-full-config)
27+
export_full_config=1
28+
shift
29+
;;
2630
--update)
2731
update="1"
2832
update_repos="1"
@@ -100,6 +104,13 @@ nixfmt "$FLAKE"
100104
rm $ICEDOS_FLAKE_INPUTS
101105
unset ICEDOS_FLAKE_INPUTS
102106

107+
if [ "$export_full_config" == "1" ]; then
108+
ICEDOS_STAGE="genflake" nix eval $trace --file "./lib/genflake.nix" evaluatedConfig | nixfmt | jq -r . > full-config.json
109+
jsonfmt ./full-config.json -w
110+
echo "Full config saved at $PWD/full-config.json"
111+
exit 0
112+
fi
113+
103114
[ "$update" == "1" ] && nix flake update
104115

105116
# Make a tmp folder and build from there

lib/genflake.nix

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let
2-
inherit (builtins) getEnv readFile;
3-
inherit ((fromTOML (readFile ../config.toml))) icedos;
2+
inherit (builtins) getEnv readFile toJSON;
3+
config = (fromTOML (readFile ../config.toml));
4+
inherit (config) icedos;
45

56
system = icedos.system.arch or "x86_64-linux";
67
pkgs = import <nixpkgs> { inherit system; };
@@ -10,10 +11,13 @@ let
1011
boolToString
1112
concatMapStrings
1213
concatStringsSep
14+
evalModules
1315
fileContents
16+
foldl'
1417
listToAttrs
1518
map
1619
pathExists
20+
recursiveUpdate
1721
;
1822

1923
icedosLib = import ../lib {
@@ -60,9 +64,28 @@ let
6064
);
6165

6266
nixosModulesText = modulesFromConfig.nixosModulesText;
67+
68+
evaluatedConfig =
69+
toJSON
70+
(evalModules {
71+
modules = [
72+
{
73+
inherit config;
74+
75+
options =
76+
let
77+
mergedOptions =
78+
foldl' (acc: cur: recursiveUpdate acc cur.options)
79+
(import ../modules/options.nix { inherit icedosLib lib; }).options
80+
modulesFromConfig.options;
81+
in
82+
mergedOptions;
83+
}
84+
];
85+
}).config;
6386
in
6487
{
65-
inherit flakeInputs;
88+
inherit flakeInputs evaluatedConfig;
6689

6790
flakeFinal = ''
6891
{

modules/options.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ in
1919
options = {
2020
icedos = {
2121
system = {
22-
arch = mkStrOption { };
22+
arch = mkStrOption { default = "x86_64-linux"; };
2323

2424
channels = mkSubmoduleListOption { default = [ ]; } {
2525
name = mkStrOption { };
@@ -34,8 +34,8 @@ in
3434

3535
repositories = mkSubmoduleListOption { } {
3636
url = mkStrOption { };
37-
fetchOptionalDependencies = mkBoolOption { };
38-
modules = mkStrListOption { };
37+
fetchOptionalDependencies = mkBoolOption { default = false; };
38+
modules = mkStrListOption { default = [ ]; };
3939
};
4040
};
4141
};

0 commit comments

Comments
 (0)