2023-08-09 23:27:37 +02:00
|
|
|
## Base options
|
|
|
|
## ============
|
|
|
|
|
|
|
|
|
2024-10-05 11:50:12 +02:00
|
|
|
{ lib, pkgs, utils, config, ...}:
|
2022-09-26 12:46:09 +02:00
|
|
|
let
|
2024-09-27 10:17:34 +02:00
|
|
|
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep mapAttrsToList;
|
2022-09-26 19:27:43 +02:00
|
|
|
inherit (pkgs.pseudofile) dir symlink;
|
2023-03-07 23:02:24 +01:00
|
|
|
inherit (pkgs.liminix.networking) address interface;
|
|
|
|
inherit (pkgs.liminix.services) bundle;
|
2022-09-26 19:27:43 +02:00
|
|
|
|
2024-09-17 16:35:33 +02:00
|
|
|
# TODO: escape shell argument.
|
|
|
|
exportVar = name: value: "export ${name}=\"${value}\"";
|
2023-07-14 21:22:29 +02:00
|
|
|
type_service = pkgs.liminix.lib.types.service;
|
2022-09-26 12:46:09 +02:00
|
|
|
|
2022-09-25 12:22:15 +02:00
|
|
|
in {
|
|
|
|
options = {
|
2022-09-27 17:17:55 +02:00
|
|
|
defaultProfile = {
|
|
|
|
packages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2023-08-12 21:11:43 +02:00
|
|
|
description = ''
|
|
|
|
List of packages which are available in a login shell. (This
|
|
|
|
is analogous to systemPackages in NixOS, but we don't symlink into
|
|
|
|
/run/current-system, we just add the paths in /etc/profile
|
|
|
|
'';
|
2022-09-27 17:17:55 +02:00
|
|
|
};
|
2024-09-17 16:35:33 +02:00
|
|
|
|
|
|
|
environmentVariables = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = ''
|
|
|
|
Attribute set of environment variables to make available
|
|
|
|
in a login shell.
|
|
|
|
|
|
|
|
The value is assumed to be escaped and the name to be valid.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
prompt = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$(whoami)@$(hostname) # ";
|
|
|
|
description = ''
|
|
|
|
Prompt string (PS1) for the shell.
|
|
|
|
'';
|
|
|
|
};
|
2022-09-25 12:22:15 +02:00
|
|
|
};
|
2024-10-05 11:50:12 +02:00
|
|
|
|
|
|
|
# deprecated
|
2022-09-25 12:22:15 +02:00
|
|
|
services = mkOption {
|
2022-09-26 12:46:09 +02:00
|
|
|
type = types.attrsOf type_service;
|
2022-09-25 12:22:15 +02:00
|
|
|
};
|
2024-10-05 11:50:12 +02:00
|
|
|
|
2024-03-16 21:23:18 +01:00
|
|
|
system.callService = mkOption {
|
|
|
|
type = types.functionTo (types.functionTo types.anything);
|
|
|
|
};
|
|
|
|
|
2023-08-12 21:11:43 +02:00
|
|
|
filesystem = mkOption {
|
|
|
|
type = types.anything;
|
|
|
|
description = ''
|
|
|
|
Skeleton filesystem, represented as nested attrset. Consult the
|
|
|
|
source code if you need to add to this
|
|
|
|
'';
|
|
|
|
# internal = true; # probably a good case to make this internal
|
|
|
|
};
|
2023-04-10 20:59:09 +02:00
|
|
|
rootfsType = mkOption {
|
|
|
|
default = "squashfs";
|
2023-11-06 22:52:31 +01:00
|
|
|
type = types.enum [
|
2024-01-07 17:43:43 +01:00
|
|
|
"btrfs"
|
2023-11-06 22:52:31 +01:00
|
|
|
"ext4"
|
|
|
|
"jffs2"
|
|
|
|
"squashfs"
|
|
|
|
"ubifs"
|
|
|
|
];
|
2023-04-10 20:59:09 +02:00
|
|
|
};
|
2024-01-08 19:54:49 +01:00
|
|
|
rootOptions = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2023-02-18 16:13:19 +01:00
|
|
|
boot = {
|
|
|
|
commandLine = mkOption {
|
|
|
|
type = types.listOf types.nonEmptyStr;
|
|
|
|
default = [];
|
2023-08-12 21:11:43 +02:00
|
|
|
description = "Kernel command line";
|
2023-02-18 16:13:19 +01:00
|
|
|
};
|
2024-02-17 02:16:57 +01:00
|
|
|
commandLineDtbNode = mkOption {
|
|
|
|
type = types.enum [ "bootargs" "bootargs-override" ];
|
|
|
|
default = "bootargs";
|
|
|
|
description = "Kernel command line's devicetree node";
|
|
|
|
};
|
2023-10-08 23:35:30 +02:00
|
|
|
imageFormat = mkOption {
|
|
|
|
type = types.enum ["fit" "uimage"];
|
|
|
|
default = "uimage";
|
|
|
|
};
|
2023-03-18 15:45:51 +01:00
|
|
|
tftp = {
|
2024-09-16 18:14:39 +02:00
|
|
|
commandLine = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = config.boot.commandLine;
|
|
|
|
description = ''
|
|
|
|
TFTP-specific command line.
|
|
|
|
Defaults to the classical one if unset.
|
|
|
|
'';
|
|
|
|
};
|
2023-08-12 21:11:43 +02:00
|
|
|
loadAddress = mkOption {
|
2023-11-12 19:37:33 +01:00
|
|
|
type = types.ints.unsigned;
|
2023-08-12 21:11:43 +02:00
|
|
|
description = ''
|
|
|
|
RAM address at which to load data when transferring via
|
|
|
|
TFTP. This is not the address of the flash storage,
|
|
|
|
nor the kernel load address: it should be set to some part
|
|
|
|
of RAM that's not used for anything else and suitable for
|
|
|
|
temporary storage.
|
|
|
|
'';
|
|
|
|
};
|
2023-03-18 15:45:51 +01:00
|
|
|
# These names match the uboot environment variables. I reserve
|
|
|
|
# the right to change them if I think of better ones.
|
2023-08-12 21:11:43 +02:00
|
|
|
ipaddr = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Our IP address to use when creating scripts to
|
|
|
|
boot or flash from U-Boot. Not relevant in normal operation
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
serverip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
IP address of the TFTP server. Not relevant in normal operation
|
|
|
|
'';
|
|
|
|
};
|
2023-03-18 15:45:51 +01:00
|
|
|
};
|
2023-02-10 19:20:01 +01:00
|
|
|
};
|
2022-09-25 12:22:15 +02:00
|
|
|
};
|
2022-09-26 21:45:00 +02:00
|
|
|
config = {
|
2024-09-16 18:14:39 +02:00
|
|
|
# By default, we enable cross-compilation support.
|
|
|
|
nixpkgs.buildPlatform = lib.mkDefault builtins.currentSystem;
|
|
|
|
|
2024-09-17 16:35:33 +02:00
|
|
|
# Set the useful PS1 prompt by default.
|
|
|
|
defaultProfile.environmentVariables.PS1 = lib.mkDefault config.defaultProfile.prompt;
|
2024-10-06 23:27:48 +02:00
|
|
|
defaultProfile.packages = with pkgs; [
|
|
|
|
# execline
|
|
|
|
systemd
|
|
|
|
];
|
2022-09-28 22:31:15 +02:00
|
|
|
|
2022-10-07 01:21:04 +02:00
|
|
|
boot.commandLine = [
|
2023-09-20 18:27:04 +02:00
|
|
|
"panic=10 oops=panic init=/bin/init loglevel=8"
|
2023-04-26 23:16:15 +02:00
|
|
|
"root=${config.hardware.rootDevice}"
|
2023-04-10 20:59:09 +02:00
|
|
|
"rootfstype=${config.rootfsType}"
|
2022-10-15 17:11:40 +02:00
|
|
|
"fw_devlink=off"
|
2024-04-21 17:26:31 +02:00
|
|
|
]
|
|
|
|
++ (map (mtd: "ubi.mtd=${mtd}") config.hardware.ubi.mtds)
|
|
|
|
++ lib.optional (config.rootOptions != null) "rootflags=${config.rootOptions}"
|
2024-08-26 20:01:34 +02:00
|
|
|
++ lib.optional (config.hardware.alternativeRootDevice != null) "rootalt=${config.hardware.alternativeRootDevice}";
|
2024-01-08 19:54:49 +01:00
|
|
|
|
2024-08-26 17:53:08 +02:00
|
|
|
boot.tftp.commandLine = [
|
|
|
|
"panic=10 oops=panic init=/bin/init loglevel=8"
|
|
|
|
"fw_devlink=off"
|
|
|
|
"rootfstype=${config.rootfsType}"
|
|
|
|
];
|
|
|
|
|
2024-03-16 21:23:18 +01:00
|
|
|
system.callService = path : parameters :
|
|
|
|
let
|
|
|
|
typeChecked = caller: type: value:
|
|
|
|
let
|
|
|
|
inherit (lib) types mergeDefinitions;
|
|
|
|
defs = [{ file = caller; inherit value; }];
|
|
|
|
type' = types.submodule { options = type; };
|
|
|
|
in (mergeDefinitions [] type' defs).mergedValue;
|
|
|
|
cp = lib.callPackageWith(pkgs // { svc = config.system.service; });
|
|
|
|
pkg = cp path {};
|
|
|
|
checkTypes = t : p : typeChecked (builtins.toString path) t p;
|
|
|
|
in {
|
|
|
|
inherit parameters;
|
|
|
|
build = { dependencies ? [], ... } @ args :
|
|
|
|
let
|
|
|
|
s = pkg (checkTypes parameters
|
|
|
|
(builtins.removeAttrs args ["dependencies"]));
|
|
|
|
in s.overrideAttrs (o: {
|
|
|
|
dependencies = (builtins.map (d: d.name) dependencies) ++ o.dependencies;
|
|
|
|
buildInputs = dependencies ++ o.buildInputs;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-09-28 22:31:15 +02:00
|
|
|
users.root = {
|
|
|
|
uid = 0; gid= 0; gecos = "Root of all evaluation";
|
2023-03-18 15:46:50 +01:00
|
|
|
dir = "/home/root/";
|
2023-03-04 01:24:48 +01:00
|
|
|
passwd = lib.mkDefault "";
|
2022-09-28 22:31:15 +02:00
|
|
|
shell = "/bin/sh";
|
|
|
|
};
|
2023-02-25 21:33:18 +01:00
|
|
|
groups = {
|
|
|
|
root = {
|
|
|
|
gid = 0; usernames = ["root"];
|
|
|
|
};
|
2023-02-25 23:53:06 +01:00
|
|
|
system = {
|
|
|
|
gid = 1; usernames = ["root"];
|
|
|
|
};
|
2022-09-28 22:31:15 +02:00
|
|
|
};
|
|
|
|
|
2022-09-27 17:33:58 +02:00
|
|
|
filesystem = dir {
|
2022-09-27 15:06:07 +02:00
|
|
|
dev =
|
|
|
|
let node = type: major: minor: mode : { inherit type major minor mode; };
|
|
|
|
in dir {
|
|
|
|
null = node "c" "1" "3" "0666";
|
|
|
|
zero = node "c" "1" "5" "0666";
|
|
|
|
tty = node "c" "5" "0" "0666";
|
|
|
|
console = node "c" "5" "1" "0600";
|
|
|
|
pts = dir {};
|
|
|
|
};
|
2023-05-21 18:08:32 +02:00
|
|
|
etc = let
|
2022-09-26 21:45:00 +02:00
|
|
|
profile = symlink
|
|
|
|
(pkgs.writeScript ".profile" ''
|
2024-09-17 16:35:33 +02:00
|
|
|
PATH=${lib.makeBinPath config.defaultProfile.packages}:/bin
|
2022-09-26 21:45:00 +02:00
|
|
|
export PATH
|
2024-09-27 10:17:34 +02:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList exportVar config.defaultProfile.environmentVariables)}
|
2024-09-17 16:35:33 +02:00
|
|
|
'');
|
2023-05-21 18:08:32 +02:00
|
|
|
in dir {
|
|
|
|
inherit profile;
|
|
|
|
ashrc = profile;
|
2022-09-26 21:45:00 +02:00
|
|
|
};
|
2023-05-21 18:08:32 +02:00
|
|
|
|
2022-09-27 15:06:07 +02:00
|
|
|
proc = dir {};
|
|
|
|
run = dir {};
|
|
|
|
sys = dir {};
|
2024-01-05 00:22:02 +01:00
|
|
|
tmp = dir {};
|
2022-09-26 21:45:00 +02:00
|
|
|
};
|
|
|
|
};
|
2022-09-25 12:22:15 +02:00
|
|
|
}
|