From a217594cf3e12a6d811734a11c401e4a90921983 Mon Sep 17 00:00:00 2001 From: Jake Waksbaum Date: Sun, 23 Aug 2020 21:57:52 -0400 Subject: [PATCH 1/5] Use flakes This should let users build an SD image simply with `nix build` run from the root of the repo, or even `nix build github:samudeldr/wip-pinebook-pro'. --- README.md | 5 +--- build.sh | 16 ----------- configuration.nix | 8 +++--- default.nix | 20 +++----------- flake.lock | 43 +++++++++++++++++++++++++++++ flake.nix | 55 ++++++++++++++++++++++++++++++++++++++ nixos/sd-image-aarch64.nix | 4 +-- nixos/sd-image.nix | 4 +-- system.nix | 7 ----- 9 files changed, 111 insertions(+), 51 deletions(-) delete mode 100755 build.sh create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 system.nix diff --git a/README.md b/README.md index b59208a..f7141e4 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,10 @@ The backlight can be controlled using `light` (`programs.light.enable`). ## Image build ``` -$ ./build.sh +$ nix build $ lsblk /dev/mmcblk0 && sudo dd if=$(echo result/sd-image/*.img) of=/dev/mmcblk0 bs=8M oflag=direct status=progress ``` -The `build.sh` script transmits parameters to `nix-build`, so e.g. `-j0` can -be used. - Once built, this image is self-sufficient, meaning that it should already be booting, no need burn u-boot to it. diff --git a/build.sh b/build.sh deleted file mode 100755 index 14ffdea..0000000 --- a/build.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -u -PS4=" $ " - -# Ugh, I would have liked to do it through a simpler `nix-build`, but as this -# needs to set `NIX_PATH` for use of `` imports, this is the better -# way to go. - -set -x -exec env -i \ - NIXPKGS_ALLOW_UNFREE=1 \ - NIX_PATH="nixpkgs=channel:nixos-unstable" \ - "$(command -v nix-build)" \ - system.nix -A config.system.build.sdImage "$@" diff --git a/configuration.nix b/configuration.nix index 79bae76..462301b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -1,13 +1,13 @@ -{ config, pkgs, lib, ... }: +{ nixpkgs, config, pkgs, lib, ... }: let uboot = pkgs.uBootPinebookProExternalFirst; in { imports = [ - - - + "${nixpkgs}/nixos/modules/profiles/base.nix" + "${nixpkgs}/nixos/modules/profiles/minimal.nix" + "${nixpkgs}/nixos/modules/profiles/installation-device.nix" ./nixos/sd-image-aarch64.nix ./pinebook_pro.nix ]; diff --git a/default.nix b/default.nix index 009941d..d9ea6ca 100644 --- a/default.nix +++ b/default.nix @@ -1,17 +1,5 @@ -{ - pkgs ? import { - overlays = [ - (import ./overlay.nix) - ]; +( + import (fetchTarball https://github.com/edolstra/flake-compat/archive/master.tar.gz) { + src = ./.; } -}: - -let - pkgs' = if builtins.currentSystem == "aarch64-linux" - then pkgs - else pkgs.pkgsCross.aarch64-multiplatform - ; -in -{ - pkgs = pkgs'; -} +).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..dbac4e6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1597053966, + "narHash": "sha256-f9lbPS/GJ1His8fsDqM6gfa8kSqREU4eKiMCS5hrKg4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ec20f52e2ff61e9c36c2b894b62fc1b4bd04c71b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1597943282, + "narHash": "sha256-G/VQBlqO7YeFOSvn29RqdvABZxmQBtiRYVA6kjqWZ6o=", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "c59ea8b8a0e7f927e7291c14ea6cd1bd3a16ff38", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs-channels", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8f09639 --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + description = "WIP stuff to get started on the pinebook pro."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs-channels/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + { + overlay = final: prev: import "${self}/overlay.nix" final prev; + } // flake-utils.lib.eachDefaultSystem ( + system: + let + darwin_network_cmds_openssl_overlay = final: prev: { + darwin = prev.darwin // { + network_cmds = prev.darwin.network_cmds.override { openssl_1_0_2 = prev.openssl; }; + }; + }; + pkgsNative = import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ darwin_network_cmds_openssl_overlay self.overlay ]; + }; + pkgs = if system == "aarch64-linux" then pkgsNative else pkgsNative.pkgsCross.aarch64-multiplatform; + in + rec { + packages = rec { + inherit (pkgs) + uBootPinebookPro uBootPinebookProExternalFirst + linux_pinebookpro_latest + linux_pinebookpro_lts + pinebookpro-firmware + pinebookpro-keyboard-updater + ; + + inherit (nixosConfigurations.config.system.build) sdImage; + }; + + defaultPackage = packages.sdImage; + + nixosConfigurations = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + # Pass nixpkgs as an argument to each module so that modules from nixpkgs can be imported purely + specialArgs = { inherit nixpkgs; }; + modules = [ + { nixpkgs.config.allowUnfree = true; } + (if system == "aarch64-linux" then "${self}/configuration.nix" else "${self}/with-cross.nix") + ]; + }; + + nixosModule = import "${self}/pinebook_pro.nix"; + } + ); +} diff --git a/nixos/sd-image-aarch64.nix b/nixos/sd-image-aarch64.nix index b55bee3..fdd288e 100644 --- a/nixos/sd-image-aarch64.nix +++ b/nixos/sd-image-aarch64.nix @@ -1,8 +1,8 @@ -{ config, lib, pkgs, ... }: +{ nixpkgs, config, lib, pkgs, ... }: let extlinux-conf-builder = - import { + import "${nixpkgs}/nixos/modules/system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix" { pkgs = pkgs.buildPackages; }; in diff --git a/nixos/sd-image.nix b/nixos/sd-image.nix index 32633ca..9a33078 100644 --- a/nixos/sd-image.nix +++ b/nixos/sd-image.nix @@ -1,9 +1,9 @@ -{ config, lib, pkgs, ... }: +{ nixpkgs, config, lib, pkgs, ... }: with lib; let - rootfsImage = pkgs.callPackage ({ + rootfsImage = pkgs.callPackage "${nixpkgs}/nixos/lib/make-ext4-fs.nix" ({ inherit (config.sdImage) storePaths; #compressImage = false; populateImageCommands = config.sdImage.populateRootCommands; diff --git a/system.nix b/system.nix deleted file mode 100644 index 975a7b2..0000000 --- a/system.nix +++ /dev/null @@ -1,7 +0,0 @@ -import { - configuration = - if builtins.currentSystem == "aarch64-linux" - then builtins.toPath (./. + "/configuration.nix") - else builtins.toPath (./. + "/with-cross.nix") - ; -} From 78c96317b03e7ed0f3a74afb0229ff42ca771319 Mon Sep 17 00:00:00 2001 From: Jake Waksbaum Date: Mon, 24 Aug 2020 00:35:14 -0400 Subject: [PATCH 2/5] Move with-cross.nix functionaity into flake.nix --- flake.nix | 11 +++++++++-- with-cross.nix | 11 ----------- 2 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 with-cross.nix diff --git a/flake.nix b/flake.nix index 8f09639..b19f344 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,7 @@ } // flake-utils.lib.eachDefaultSystem ( system: let + inherit (nixpkgs) lib; darwin_network_cmds_openssl_overlay = final: prev: { darwin = prev.darwin // { network_cmds = prev.darwin.network_cmds.override { openssl_1_0_2 = prev.openssl; }; @@ -39,13 +40,19 @@ defaultPackage = packages.sdImage; - nixosConfigurations = nixpkgs.lib.nixosSystem { + nixosConfigurations = lib.nixosSystem { system = "aarch64-linux"; # Pass nixpkgs as an argument to each module so that modules from nixpkgs can be imported purely specialArgs = { inherit nixpkgs; }; modules = [ { nixpkgs.config.allowUnfree = true; } - (if system == "aarch64-linux" then "${self}/configuration.nix" else "${self}/with-cross.nix") + "${self}/configuration.nix" + ( + lib.optionalAttrs (system != "aarch64-linux") { + imports = [ "${self}/cross-hacks.nix" ]; + nixpkgs.crossSystem.system = "aarch64-linux"; + } + ) ]; }; diff --git a/with-cross.nix b/with-cross.nix deleted file mode 100644 index d0e44a3..0000000 --- a/with-cross.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ config, pkgs, lib, ... }: -{ - imports = [ - ./cross-hacks.nix - ./configuration.nix - ]; - - nixpkgs.crossSystem = { - system = "aarch64-linux"; - }; -} From 5c5a0da07a137c78f22cce5ad70a8947641f623c Mon Sep 17 00:00:00 2001 From: Jake Waksbaum Date: Mon, 31 Aug 2020 00:10:18 -0400 Subject: [PATCH 3/5] Limit systems to x86 and aarch64 --- flake.nix | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index b19f344..5f37106 100644 --- a/flake.nix +++ b/flake.nix @@ -9,19 +9,14 @@ outputs = { self, nixpkgs, flake-utils }: { overlay = final: prev: import "${self}/overlay.nix" final prev; - } // flake-utils.lib.eachDefaultSystem ( + } // flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] ( system: let inherit (nixpkgs) lib; - darwin_network_cmds_openssl_overlay = final: prev: { - darwin = prev.darwin // { - network_cmds = prev.darwin.network_cmds.override { openssl_1_0_2 = prev.openssl; }; - }; - }; pkgsNative = import nixpkgs { inherit system; config.allowUnfree = true; - overlays = [ darwin_network_cmds_openssl_overlay self.overlay ]; + overlays = [ self.overlay ]; }; pkgs = if system == "aarch64-linux" then pkgsNative else pkgsNative.pkgsCross.aarch64-multiplatform; in From 89605b0f3e6a016b9759734c209cc0a2ad5b8f2e Mon Sep 17 00:00:00 2001 From: Jake Waksbaum Date: Wed, 9 Sep 2020 21:41:28 -0400 Subject: [PATCH 4/5] Fix nixosModule The `nixosModule` attribute is not system specific, so it should itself be a module instead of `nixosModule.aarch64-linux`, etc. being modules. --- flake.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 5f37106..f2516be 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ outputs = { self, nixpkgs, flake-utils }: { overlay = final: prev: import "${self}/overlay.nix" final prev; + nixosModule = import "${self}/pinebook_pro.nix"; } // flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] ( system: let @@ -50,8 +51,6 @@ ) ]; }; - - nixosModule = import "${self}/pinebook_pro.nix"; } ); } From 2a198051a861f44853847c7b46342c0434c972ee Mon Sep 17 00:00:00 2001 From: Jake Waksbaum Date: Wed, 9 Sep 2020 21:38:56 -0400 Subject: [PATCH 5/5] Upgrade nixpkgs to 20.09 with linux 5.8 --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index dbac4e6..c825734 100644 --- a/flake.lock +++ b/flake.lock @@ -17,16 +17,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1597943282, - "narHash": "sha256-G/VQBlqO7YeFOSvn29RqdvABZxmQBtiRYVA6kjqWZ6o=", + "lastModified": 1599597582, + "narHash": "sha256-dBtZSveC7AS6ElKV1GruRN4j8QukyI27RMAuTzrZueg=", "owner": "NixOS", "repo": "nixpkgs-channels", - "rev": "c59ea8b8a0e7f927e7291c14ea6cd1bd3a16ff38", + "rev": "c411fe8ae0888994361279cf71a1bf820c4b22f4", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixos-20.09", "repo": "nixpkgs-channels", "type": "github" } diff --git a/flake.nix b/flake.nix index f2516be..fcb3e7b 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "WIP stuff to get started on the pinebook pro."; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs-channels/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs-channels/nixos-20.09"; flake-utils.url = "github:numtide/flake-utils"; };