aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2022-08-05 08:19:33 +0200
committerKarel Kočí <cynerd@email.cz>2022-08-05 08:19:33 +0200
commit970c8596e86b8bb3ebff5e76e152fa5acdd65f98 (patch)
treeb3da4eb18452d94d2ec5da0abb6cb312249b3fc0
parent7c3d7e4989a83d188a013f9b1a8492f607958b6b (diff)
downloadnixos-personal-970c8596e86b8bb3ebff5e76e152fa5acdd65f98.tar.gz
nixos-personal-970c8596e86b8bb3ebff5e76e152fa5acdd65f98.tar.bz2
nixos-personal-970c8596e86b8bb3ebff5e76e152fa5acdd65f98.zip
Small rework of packages and and devices build
-rwxr-xr-xbuild-turris.sh23
-rw-r--r--devShells/default.nix1
-rw-r--r--devShells/qt.nix11
-rwxr-xr-xdevices.sh218
-rw-r--r--flake.lock6
-rw-r--r--flake.nix4
-rw-r--r--nixos/machine/errol.nix29
-rw-r--r--nixos/modules/generic.nix10
-rw-r--r--pkgs/default.nix4
9 files changed, 251 insertions, 55 deletions
diff --git a/build-turris.sh b/build-turris.sh
deleted file mode 100755
index d93da81..0000000
--- a/build-turris.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-set -eu
-omnia_hash="bd7ac5d8c08538ec1f126d34b765f0362427fe17"
-routers=( "dean" "spt-mox2" "spt-omnia" )
-
-cd "${0%/*}" || exit
-for system in "${routers[@]}"; do
- echo "Building $system"
- declare -a args
- toplevel=".config.system.build.toplevel"
- if [[ "$system" == *omnia ]]; then
- toplevel=".config.system.build.cross.x86_64-linux${toplevel}"
- args=( \
- "--override-input" "nixpkgs" "github:NixOS/nixpkgs/${omnia_hash}"
- "--override-input" "nixturris/nixpkgs" "github:NixOS/nixpkgs/${omnia_hash}"
- "--override-input" "nixturris" "/home/cynerd/projects/nixturris"
- )
- fi
- nix build \
- -o "result-${system}" \
- "${args[@]}" \
- ".#nixosConfigurations.${system}${toplevel}"
-done
diff --git a/devShells/default.nix b/devShells/default.nix
index be2d89f..c459aba 100644
--- a/devShells/default.nix
+++ b/devShells/default.nix
@@ -21,6 +21,7 @@ in {
armv6 = callDevelop ./nuttx.nix { arch = "armv6s-m"; };
armv7e = callDevelop ./nuttx.nix { arch = "armv7e-m"; fpu = "vfpv3-d16"; };
c = callDevelop ./c.nix;
+ qt = callDevelop ./qt.nix;
riscv = callDevelop ./riscv.nix;
}
diff --git a/devShells/qt.nix b/devShells/qt.nix
new file mode 100644
index 0000000..4ff64b2
--- /dev/null
+++ b/devShells/qt.nix
@@ -0,0 +1,11 @@
+{ system, nixpkgs, default }:
+let
+ pkgs = nixpkgs.legacyPackages.${system};
+
+in pkgs.mkShell {
+ packages = (with pkgs; [
+ qt5.full
+ ]);
+ inputsFrom = with pkgs; [ default ];
+ meta.platforms = nixpkgs.lib.platforms.linux;
+}
diff --git a/devices.sh b/devices.sh
new file mode 100755
index 0000000..7867593
--- /dev/null
+++ b/devices.sh
@@ -0,0 +1,218 @@
+#!/usr/bin/env bash
+set -eu
+declare -a devices
+declare -A sshmap
+################################################################################
+omnia_hash="bd7ac5d8c08538ec1f126d34b765f0362427fe17"
+## aarch64
+# Mox
+devices+=( "dean" "spt-mox2" )
+sshmap["spt-mox2"]="mox2.spt"
+# Raspberry Pi
+devices+=( "adm-mpd" )
+sshmap["adm-mpd"]="mpd.adm"
+
+## armv7
+# Omnia
+devices+=( "spt-omnia" )
+sshmap["spt-omnia"]="omnia.spt"
+# Raspberry Pi
+devices+=( "spt-mpd" )
+sshmap["spt-mpd"]="mpd.spt"
+################################################################################
+
+valid_device() {
+ local check="$1"
+ for dev in "${devices[@]}"; do
+ [ "$dev" != "$check" ] \
+ || return 0
+ done
+ return 1
+}
+
+
+build() {
+ local system="$1"
+ echo "Building $system"
+ local -a args
+ local toplevel=".config.system.build.toplevel"
+ args+=("--keep-going")
+ args+=("--override-input" "nixturris" "/home/cynerd/projects/nixturris")
+ if [[ "$system" == *omnia ]]; then
+ true
+ #toplevel=".config.system.build.cross.x86_64-linux${toplevel}"
+ #args=( \
+ # "--override-input" "nixpkgs" "github:NixOS/nixpkgs/${omnia_hash}"
+ # "--override-input" "nixturris/nixpkgs" "github:NixOS/nixpkgs/${omnia_hash}"
+ #)
+ fi
+ nix build \
+ -o "result-${system}" \
+ "${args[@]}" \
+ "${0%/*}#nixosConfigurations.${system}${toplevel}"
+}
+
+build_validate() {
+ local system="$1"
+ [ -L "result-$system" ] && [ ! -e "result-$system" ]
+}
+
+copy() {
+ local system="$1"
+ if ! build_validate "$system"; then
+ echo "System '$system' seems to be not build." >&2
+ return 1
+ fi
+ local store="$(readlink -f "result-$system")"
+ local host="${sshmap["$system"]:-$system}"
+
+ local freespace="$(ssh "$host" -- df -B 1 /nix | awk 'NR == 2 { print $4 }')"
+ local required="$(nix path-info -S "$store")"
+ if [ "$required" -ge "$freespace" ]; then
+ echo "There is not enough space to copy clousure to: $system" >&2
+ return 1
+ fi
+
+ echo "Copy closure to: $system"
+ nix copy -s --to "ssh://$host" "$store"
+}
+
+setenv() {
+ local system="$1"
+ if ! build_validate "$system"; then
+ echo "System '$system' seems to be not build." >&2
+ return 1
+ fi
+ local store="$(readlink -f "result-$system")"
+ local host="${sshmap["$system"]:-$system}"
+
+ echo "Update system: $system"
+ if [ "$(ssh "$host" -- readlink -f /nix/var/nix/profiles/system)" != "$store" ]; then
+ ssh -t "$host" -- \
+ sudo nix-env --profile /nix/var/nix/profiles/system --set "$store"
+ fi
+}
+
+boot() {
+ local system="$1"
+ setenv "$system" || return 1
+
+ local store="$(readlink -f "result-$system")"
+ local host="${sshmap["$system"]:-$system}"
+
+ echo "Setting boot system: $system"
+ ssh -t "$host" -- \
+ sudo /nix/var/nix/profiles/system/bin/switch-to-configuration boot
+}
+
+is_current() {
+ ssh "$1" -- \
+ '[ "$(readlink -f /run/current-system)" != "$(readlink -f /nix/var/nix/profiles/system)" ]'
+}
+
+switch() {
+ local system="$1"
+ setenv "$system" || return 1
+
+ local store="$(readlink -f "result-$system")"
+ local host="${sshmap["$system"]:-$system}"
+
+ if is_current "$host"; then
+ echo "Switching: $system"
+ ssh -t "$host" -- \
+ sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch
+ else
+ echo "This system is already running: $system"
+ fi
+}
+
+switch_test() {
+ local system="$1"
+ setenv "$system" || return 1
+
+ local store="$(readlink -f "result-$system")"
+ local host="${sshmap["$system"]:-$system}"
+
+ if is_current "$host"; then
+ echo "Testing: $system"
+ ssh -t "$host" -- \
+ sudo /nix/var/nix/profiles/system/bin/switch-to-configuration test
+ else
+ echo "This system is already running: $system"
+ fi
+}
+
+for_devices() {
+ for device in "${selected_devices[@]}"; do
+ for op in "$@"; do
+ if ! "$op" "$device"; then
+ echo "Operation '$op' failed for: $device" >&2
+ break
+ fi
+ done
+ done
+}
+
+
+operation="${1:-}"
+[ $# -gt 0 ] && shift
+
+declare -a selected_devices
+if [ $# -gt 0 ]; then
+ for device in "$@"; do
+ if ! valid_device "$device"; then
+ echo "No such device: $device" >&2
+ exit 2
+ fi
+ selected_devices+=("$device")
+ done
+else
+ selected_devices=("${devices[@]}")
+fi
+
+case "$operation" in
+ help|h)
+ cat <<-EOF
+ Usage $0 operation [device]...
+ Local system builder and updater for remote devices.
+
+ Operations:
+ build: build device system
+ copy: copy built system to the device
+ boot: set built system to be boot default on the device
+ switch: switch to the built system on the target device
+ test: test the built system on the target device
+ EOF
+ ;;
+ build|b|"")
+ for_devices build
+ ;;
+ copy|c)
+ for_devices copy
+ ;;
+ boot)
+ for_devices boot
+ ;;
+ switch|s)
+ for_devices switch
+ ;;
+ test|t)
+ for_devices switch_test
+ ;;
+ build-copy|bc)
+ for_devices build copy
+ ;;
+ build-switch|bs)
+ for_devices build copy switch
+ ;;
+ build-test|bt)
+ for_devices build copy switch_test
+ ;;
+ build-boot|bb)
+ for_devices build copy boot
+ ;;
+ default)
+ echo "Unknown operation: $operation" >&2
+ exit 2
+ ;;
+esac
diff --git a/flake.lock b/flake.lock
index 14b1301..53da4b1 100644
--- a/flake.lock
+++ b/flake.lock
@@ -44,11 +44,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1658937758,
- "narHash": "sha256-FxQB/tWX15Faq3GBM+qTfVzd9qJqy/3CEgBp2zpHeNc=",
+ "lastModified": 1659606041,
+ "narHash": "sha256-W4/u2ssr3fS4XOtltrsDD9w2kF4jYYZr6JyPGUW2jdI=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "8f73de28e63988da02426ebb17209e3ae07f103b",
+ "rev": "5f9b871b72b24f066b1a1e189efd0669f2888c49",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 403197d..de9c59f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -19,7 +19,7 @@
}:
with flake-utils.lib;
{
- overlays.default = final: prev: import ./pkgs { nixpkgs = prev; };
+ overlays.default = final: prev: import ./pkgs { inherit self; nixpkgs = prev; };
nixosModules = import ./nixos nixpkgs;
nixosConfigurations = let
@@ -77,7 +77,7 @@
} // eachDefaultSystem (system: {
packages = filterPackages system (flattenTree (
- import ./pkgs { nixpkgs = nixpkgs.legacyPackages."${system}"; }
+ import ./pkgs { inherit self; nixpkgs = nixpkgs.legacyPackages."${system}"; }
));
devShells = filterPackages system
(import ./devShells { inherit nixpkgs; inherit shellrc; inherit system; });
diff --git a/nixos/machine/errol.nix b/nixos/machine/errol.nix
index 5dd87a7..06e2446 100644
--- a/nixos/machine/errol.nix
+++ b/nixos/machine/errol.nix
@@ -20,8 +20,9 @@ with lib;
hardware.cpu.amd.updateMicrocode = true;
cynerd.autounlock = {
- "encroot" = "/dev/disk/by-uuid/c07e929a-6eac-4f99-accf-f7cb3431290c";
- "enchdd" = "/dev/disk/by-uuid/7fee3cda-efa0-47cd-8832-fdead9a7e6db";
+ "encroot" = "/dev/disk/by-uuid/8095988e-239b-4417-9df6-94a40e4133ed";
+ "enchdd1" = "/dev/disk/by-uuid/87f16080-5ff6-43dd-89f3-307455a46fbe";
+ "enchdd2" = "/dev/disk/by-uuid/be4a33fa-8bc6-431d-a3ac-787668f223ed";
};
fileSystems = {
"/" = {
@@ -40,7 +41,7 @@ with lib;
};
"/home2" = {
- device = "/dev/mapper/enchdd";
+ device = "/dev/mapper/enchdd1";
fsType = "btrfs";
options = ["compress=lzo" "subvol=@home"];
};
@@ -59,28 +60,6 @@ with lib;
configDir = "/home/cynerd/.config/syncthing";
};
- #environment.systemPackages = [ pkgs.laminar ];
- #users.groups.build.gid = 220;
- #users.users.build = {
- # group = "build";
- # uid = 220;
- # subUidRanges = [{ count = 65534; startUid = 20000; }];
- # subGidRanges = [{ count = 65534; startGid = 20000; }];
- # createHome = true;
- # home = "/var/build";
- #};
- #systemd.services.laminar = {
- # description = "Laminar build server";
- # after = [ "network.target" ];
- # wantedBy = [ "multi-user.target" ];
- # serviceConfig = {
- # User = "build";
- # ExecStart = "${pkgs.laminar}/bin/laminar";
- # EnvironmentFile = "/etc/laminar.conf";
- # Restart = "always";
- # };
- #};
-
};
}
diff --git a/nixos/modules/generic.nix b/nixos/modules/generic.nix
index 08b3bfa..2b3c3fd 100644
--- a/nixos/modules/generic.nix
+++ b/nixos/modules/generic.nix
@@ -11,6 +11,16 @@ with lib;
extraOptions = "experimental-features = nix-command flakes";
settings = {
auto-optimise-store = true;
+ substituters = [
+ "https://cache.nixos.org"
+ "https://thefloweringash-armv7.cachix.org"
+ "https://arm.cachix.org"
+ ];
+ trusted-public-keys = [
+ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
+ "thefloweringash-armv7.cachix.org-1:v+5yzBD2odFKeXbmC+OPWVqx4WVoIVO6UXgnSAWFtso="
+ "arm.cachix.org-1:K3XjAeWPgWkFtSS9ge5LJSLw3xgnNqyOaG7MDecmTQ8="
+ ];
};
registry = {
personal.to = {
diff --git a/pkgs/default.nix b/pkgs/default.nix
index 23f4e25..dd47ead 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -1,8 +1,8 @@
-{ nixpkgs ? <nixpkgs>, nixlib ? nixpkgs.lib }:
+{ self, nixpkgs }:
let
pkgs = nixpkgs // personalpkgs;
- callPackage = nixlib.callPackageWith pkgs;
+ callPackage = nixpkgs.lib.callPackageWith pkgs;
personalpkgs = with pkgs; {