mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-10-26 04:42:43 +03:00
WIP Migrates device configuration into the options system.
This commit is contained in:
parent
7a4b625cf7
commit
844313903e
10
README.md
10
README.md
@ -10,13 +10,21 @@ WIP notes
|
||||
---------
|
||||
|
||||
```
|
||||
nix-build bootimg.nix --arg device_name '"asus-z00t"'
|
||||
nix-build --argstr device asus-z00t -A all
|
||||
# Maybe `nix copy ./result --to ssh://another-host`
|
||||
adb wait-for-device && adb reboot bootloader
|
||||
fastboot boot result # or full path
|
||||
# getting adb and fastboot working is left as an exercise to the reader.
|
||||
```
|
||||
|
||||
Alternatively, helpers under `bin` can be used. They mostly pave over
|
||||
the nix CLI to provide one-liners and one-parameter helpers.
|
||||
|
||||
```
|
||||
# Builds -A all for device_name $1
|
||||
bin/build asus-z00t
|
||||
```
|
||||
|
||||
|
||||
Goals
|
||||
-----
|
||||
|
19
bin/build
19
bin/build
@ -1,23 +1,28 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -p ruby -i ruby
|
||||
|
||||
require "shellwords"
|
||||
|
||||
# Given a device name, instantiates `nix-build` to build
|
||||
# everything needed to boot on that device.
|
||||
|
||||
ROOT = File.join(__dir__, "..")
|
||||
# Which file builds the basic building block for a whole device build.
|
||||
ENTRY_POINT = File.join(ROOT, "bootimg.nix")
|
||||
|
||||
unless ARGV.count == 1 then
|
||||
if ARGV.count < 1 then
|
||||
puts "Usage: bin/build <device-name>"
|
||||
exit 1
|
||||
end
|
||||
|
||||
DEVICE = ARGV.shift
|
||||
|
||||
system(
|
||||
"nix-build", ENTRY_POINT,
|
||||
"--arg", "device_name", "\"#{DEVICE}\"",
|
||||
)
|
||||
cmd = [
|
||||
"nix-build", "-A", "all",
|
||||
"--argstr", "device", DEVICE,
|
||||
*ARGV
|
||||
]
|
||||
|
||||
puts " $ #{cmd.shelljoin}"
|
||||
|
||||
system(*cmd)
|
||||
|
||||
# vim: ft=ruby
|
||||
|
23
bootimg.nix
23
bootimg.nix
@ -1,21 +1,22 @@
|
||||
{
|
||||
device_name
|
||||
device_config
|
||||
}:
|
||||
let
|
||||
pkgs = (import ./overlay);
|
||||
in
|
||||
with pkgs;
|
||||
let
|
||||
device_config = import (./devices + ("/" + device_name)) {inherit pkgs lib;};
|
||||
linux = device_config.kernel;
|
||||
device_name = device_config.name;
|
||||
device_info = device_config.info;
|
||||
linux = device_info.kernel;
|
||||
kernel = "${linux}/Image.gz-dtb";
|
||||
dt = "${linux}/boot/dt.img";
|
||||
|
||||
# TODO : Allow appending / prepending
|
||||
cmdline = device_config.kernel_cmdline;
|
||||
cmdline = device_info.kernel_cmdline;
|
||||
|
||||
# TODO : make configurable?
|
||||
initrd = callPackage ./rootfs.nix { inherit device_config; };
|
||||
initrd = callPackage ./initrd.nix { inherit device_name device_info; };
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "nixos-mobile_${device_name}_boot.img";
|
||||
@ -35,12 +36,12 @@ stdenv.mkDerivation {
|
||||
--dt ${dt} \
|
||||
--ramdisk ${initrd} \
|
||||
--cmdline "${cmdline}" \
|
||||
--base ${device_config.flash_offset_base } \
|
||||
--kernel_offset ${device_config.flash_offset_kernel } \
|
||||
--second_offset ${device_config.flash_offset_second } \
|
||||
--ramdisk_offset ${device_config.flash_offset_ramdisk} \
|
||||
--tags_offset ${device_config.flash_offset_tags } \
|
||||
--pagesize ${device_config.flash_pagesize } \
|
||||
--base ${device_info.flash_offset_base } \
|
||||
--kernel_offset ${device_info.flash_offset_kernel } \
|
||||
--second_offset ${device_info.flash_offset_second } \
|
||||
--ramdisk_offset ${device_info.flash_offset_ramdisk} \
|
||||
--tags_offset ${device_info.flash_offset_tags } \
|
||||
--pagesize ${device_info.flash_pagesize } \
|
||||
-o $out
|
||||
'';
|
||||
}
|
||||
|
17
default.nix
17
default.nix
@ -1,3 +1,18 @@
|
||||
# This entry points allows calling `nix-build -A` with
|
||||
# anything defined in the overlay (or the host system).
|
||||
(import ./overlay)
|
||||
{
|
||||
device
|
||||
}:
|
||||
let
|
||||
overlay = import ./overlay;
|
||||
eval = import ./lib/eval-config.nix {
|
||||
pkgs = overlay;
|
||||
modules = [
|
||||
(import (./. + "/devices/${device}" ))
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit overlay;
|
||||
inherit (eval.config.system.build) all;
|
||||
}
|
||||
|
@ -1,23 +1,28 @@
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
config = (lib.importJSON ../postmarketOS-devices.json).asus-z00t;
|
||||
msm-fb-refresher = (import ../../quirks/qualcomm/msm-fb-refresher.nix) { inherit pkgs lib; };
|
||||
in
|
||||
config // {
|
||||
name = config.pm_name;
|
||||
kernel = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; };
|
||||
|
||||
stage-1 = {
|
||||
fb_modes = ./fb.modes;
|
||||
inherit (msm-fb-refresher.stage-1) initFramebuffer;
|
||||
packages = with pkgs; [
|
||||
strace
|
||||
]
|
||||
++ msm-fb-refresher.stage-1.packages
|
||||
;
|
||||
{
|
||||
mobile.device.name = "asus-z00t";
|
||||
mobile.device.info = (lib.importJSON ../postmarketOS-devices.json).asus-z00t // {
|
||||
# TODO : make kernel part of options.
|
||||
kernel = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; };
|
||||
# TODO : make stage-1 part of options.
|
||||
stage-1 = {
|
||||
fb_modes = ./fb.modes;
|
||||
inherit (msm-fb-refresher.stage-1) initFramebuffer;
|
||||
packages = with pkgs; [
|
||||
strace
|
||||
]
|
||||
# TODO : implement quirks
|
||||
++ msm-fb-refresher.stage-1.packages
|
||||
;
|
||||
};
|
||||
};
|
||||
mobile.hardware = {
|
||||
# This could also be pre-built option types?
|
||||
soc = "msm8939";
|
||||
screen = { width = 1080; height = 1920; };
|
||||
};
|
||||
mobile.system.type = "android-bootimg";
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
device_config,
|
||||
device_info,
|
||||
device_name,
|
||||
|
||||
stdenv,
|
||||
makeInitrd,
|
||||
@ -18,10 +19,10 @@
|
||||
|
||||
let
|
||||
inherit (lib) optionalString optionals optional;
|
||||
inherit device_name;
|
||||
|
||||
stage-1 = if device_config ? stage-1 then device_config.stage-1 else {};
|
||||
stage-1 = if device_info ? stage-1 then device_info.stage-1 else {};
|
||||
|
||||
device_name = device_config.name;
|
||||
extraUtils = mkExtraUtils {
|
||||
name = device_name;
|
||||
packages = [
|
54
lib/eval-config.nix
Normal file
54
lib/eval-config.nix
Normal file
@ -0,0 +1,54 @@
|
||||
# This file is based on <nixpkgs/nixos/lib/eval-config.nix>.
|
||||
|
||||
# From a device configuration, build an initrd.
|
||||
|
||||
{ # !!! system can be set modularly, would be nice to remove
|
||||
system ? builtins.currentSystem
|
||||
, # !!! is this argument needed any more? The pkgs argument can
|
||||
# be set modularly anyway.
|
||||
pkgs ? null
|
||||
, # !!! what do we gain by making this configurable?
|
||||
baseModules ? import ../modules/module-list.nix
|
||||
, # !!! See comment about args in lib/modules.nix
|
||||
extraArgs ? {}
|
||||
, # !!! See comment about args in lib/modules.nix
|
||||
specialArgs ? {}
|
||||
, modules
|
||||
, # !!! See comment about check in lib/modules.nix
|
||||
check ? true
|
||||
, prefix ? []
|
||||
, lib ? import <nixpkgs/lib>
|
||||
}:
|
||||
|
||||
let extraArgs_ = extraArgs; pkgs_ = pkgs;
|
||||
in
|
||||
|
||||
let
|
||||
pkgsModule = rec {
|
||||
_file = ./eval-config.nix;
|
||||
key = _file;
|
||||
config = {
|
||||
nixpkgs.localSystem = lib.mkDefault { inherit system; };
|
||||
_module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
|
||||
};
|
||||
};
|
||||
|
||||
in rec {
|
||||
|
||||
# Merge the option definitions in all modules, forming the full
|
||||
# system configuration.
|
||||
inherit (lib.evalModules {
|
||||
inherit prefix check;
|
||||
modules = modules ++ baseModules ++ [ pkgsModule ];
|
||||
args = extraArgs;
|
||||
specialArgs = { modulesPath = ../modules; } // specialArgs;
|
||||
}) config options;
|
||||
|
||||
# These are the extra arguments passed to every module. In
|
||||
# particular, Nixpkgs is passed through the "pkgs" argument.
|
||||
extraArgs = extraArgs_ // {
|
||||
inherit modules baseModules;
|
||||
};
|
||||
|
||||
inherit (config._module.args) pkgs;
|
||||
}
|
18
modules/hardware-qualcomm.nix
Normal file
18
modules/hardware-qualcomm.nix
Normal file
@ -0,0 +1,18 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.mobile = {
|
||||
hardware.qualcomm.msm8939.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "enable when SOC is msm8939";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
# TODO : more generic than msm8939.enable.
|
||||
mobile.quirks.qualcomm.msm-fb-refresher.enable = config.mobile.hardware.qualcomm.msm8939.enable;
|
||||
};
|
||||
}
|
16
modules/mobile-device.nix
Normal file
16
modules/mobile-device.nix
Normal file
@ -0,0 +1,16 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.mobile = {
|
||||
device.name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
device.info = mkOption {
|
||||
#type = types.attrSet;
|
||||
description = "system type specific informations";
|
||||
# This probably should be `internal`.
|
||||
};
|
||||
};
|
||||
}
|
10
modules/module-list.nix
Normal file
10
modules/module-list.nix
Normal file
@ -0,0 +1,10 @@
|
||||
# Keep sorted, <nixpkgs> imports first.
|
||||
[
|
||||
<nixpkgs/nixos/modules/misc/nixpkgs.nix>
|
||||
<nixpkgs/nixos/modules/misc/assertions.nix>
|
||||
./hardware-qualcomm.nix
|
||||
./mobile-device.nix
|
||||
./quirks-qualcomm.nix
|
||||
./system-build.nix
|
||||
./system-types.nix
|
||||
]
|
13
modules/quirks-qualcomm.nix
Normal file
13
modules/quirks-qualcomm.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.mobile = {
|
||||
quirks.qualcomm.msm-fb-refresher = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enables use of `msm-fb-refresher`.";
|
||||
};
|
||||
};
|
||||
}
|
13
modules/system-build.nix
Normal file
13
modules/system-build.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.system.build = mkOption {
|
||||
internal = true;
|
||||
description = ''
|
||||
Where the result will be put into.
|
||||
This ends up building `all`.
|
||||
'';
|
||||
};
|
||||
}
|
37
modules/system-types.nix
Normal file
37
modules/system-types.nix
Normal file
@ -0,0 +1,37 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
system_type = config.mobile.system.type;
|
||||
|
||||
build_types = {
|
||||
android-bootimg =
|
||||
pkgs.callPackage ../bootimg.nix { device_config = config.mobile.device; }
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.mobile = {
|
||||
system.type = mkOption {
|
||||
type = types.enum [ "android-bootimg" ];
|
||||
description = ''
|
||||
Defines the kind of system the device is.
|
||||
|
||||
The different kind of system types will define the outputs
|
||||
produced for the system.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
assertions = [
|
||||
# While the enum type is enough to implement value safety, this will help
|
||||
# when implementing new platforms and not implementing them in build_types.
|
||||
{ assertion = build_types ? system_type; message = "cannot build unexpected system type: ${system_type}.";}
|
||||
];
|
||||
system = {
|
||||
build = build_types."${system_type}";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user