-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathflake.nix
More file actions
100 lines (88 loc) · 2.5 KB
/
flake.nix
File metadata and controls
100 lines (88 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
{
nixpkgs,
self,
...
}:
{
lib.mkIceDOS =
{
configRoot,
stateDir ? ".state",
}:
let
inherit (builtins)
isString
pathExists
readFile
;
isFlake = value: (value._type or null) == "flake";
_configRoot =
if
(
(isFlake configRoot)
&& (pathExists "${configRoot}/flake.nix")
&& (pathExists "${configRoot}/config.toml")
)
then
configRoot
else
(throw "The value of `configRoot` is invalid. Please set `configRoot = self;`.");
_stateDir =
if (isString stateDir) then (stateDir) else (throw "The value of `stateDir` should be a string.");
inherit (fromTOML (readFile "${_configRoot}/config.toml")) icedos;
system = icedos.system.arch or "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs)
git
jq
jsonfmt
lib
nh
nix
nixfmt
rsync
toml2json
writeShellScript
;
inherit (lib) makeBinPath;
icedosBuild = toString (
writeShellScript "icedos-build" ''
set -e
export PATH="${
makeBinPath [
git
jq
jsonfmt
nh
nix
nixfmt
rsync
toml2json
]
}:$PATH"
export ICEDOS_ROOT="${self}"
export ICEDOS_CONFIG_ROOT="$PWD"
export ICEDOS_STATE_DIR="$PWD/${_stateDir}"
mkdir -p "$ICEDOS_STATE_DIR"
[ -f "$ICEDOS_STATE_DIR/build.sh" ] && rm "$ICEDOS_STATE_DIR/build.sh"
echo "#!/usr/bin/env bash" >>"$ICEDOS_STATE_DIR/build.sh"
echo "set -e" >>"$ICEDOS_STATE_DIR/build.sh"
echo "cd \"$PWD\"" >>"$ICEDOS_STATE_DIR/build.sh"
echo "nix run . -- \"\$@\"" >>"$ICEDOS_STATE_DIR/build.sh"
bash "${self}/build.sh" "$@"
''
);
in
{
apps.${system}.default = {
type = "app";
program = icedosBuild;
};
};
};
}