Separate global and OS-specific config

This commit is contained in:
Manuel Thalmann 2024-09-22 17:50:05 +02:00
parent c46caf27a4
commit b6329693d6
15 changed files with 101 additions and 61 deletions

View file

@ -9,8 +9,8 @@ begin
function configureSW -V dir function configureSW -V dir
source "$dir/../../../Common/Scripts/config.fish" source "$dir/../../../Common/Scripts/config.fish"
set -l label (getConfig valhalla.boot.label) set -l label (getOSConfig boot.label)
set -l efiDir (getConfig valhalla.boot.efiMountPoint) set -l efiDir (getOSConfig boot.efiMountPoint)
set -l bootNums (efibootmgr | sed "/$label/{ s/^.*Boot\([[:digit:]]\+\)\*.*\$/\1/; p; }; d") set -l bootNums (efibootmgr | sed "/$label/{ s/^.*Boot\([[:digit:]]\+\)\*.*\$/\1/; p; }; d")
for bootNum in $bootNums for bootNum in $bootNums

View file

@ -4,7 +4,7 @@ begin
source "$dir/../../Common/OS/setup.fish" source "$dir/../../Common/OS/setup.fish"
source "$dir/../../Common/Scripts/config.fish" source "$dir/../../Common/Scripts/config.fish"
set -l mountDir (getConfig valhalla.partition.rootDir) set -l mountDir (getOSConfig partition.rootDir)
function runChroot -S function runChroot -S
arch-chroot $argv arch-chroot $argv
@ -15,7 +15,7 @@ begin
end end
function installDrivers -V mountDir function installDrivers -V mountDir
if isEnabled valhalla.linux.hardware.surfaceBook if isOSEnabled hardware.surfaceBook
pacstrap -K "$mountDir" linux-firmware-marvell; pacstrap -K "$mountDir" linux-firmware-marvell;
end end
end end
@ -33,11 +33,11 @@ begin
set -l relativeDir (realpath --relative-to "$dir/../../.." "$dir") set -l relativeDir (realpath --relative-to "$dir/../../.." "$dir")
set -l tempDir "$PROJECT_CLONE_ROOT/$relativeDir" set -l tempDir "$PROJECT_CLONE_ROOT/$relativeDir"
if set -l keyMap (getConfig valhalla.keyMap) if set -l keyMap (getOSConfig keyMap)
loadkeys "$keyMap" loadkeys "$keyMap"
end end
and if set -l timezone (getConfig valhalla.timeZone) and if set -l timezone (getOSConfig timeZone)
timedatectl set-timezone "$timezone" timedatectl set-timezone "$timezone"
end end
@ -63,7 +63,7 @@ begin
and arch-chroot "$mountDir" hwclock --systohc and arch-chroot "$mountDir" hwclock --systohc
and begin and begin
getConfig valhalla.i18n.localeSettings --json | \ getOSConfig i18n.localeSettings --json | \
jq --raw-output '[.[] | split(".") | .[0]] | unique | join("\\\\|")' jq --raw-output '[.[] | split(".") | .[0]] | unique | join("\\\\|")'
end | begin end | begin
read LOCALES read LOCALES
@ -72,7 +72,7 @@ begin
end end
and begin and begin
getConfig valhalla.i18n.localeSettings --json | \ getOSConfig i18n.localeSettings --json | \
jq --raw-output '[keys[] as $key | "\($key)=\(.[$key])"] | join("\n")' jq --raw-output '[keys[] as $key | "\($key)=\(.[$key])"] | join("\n")'
end | arch-chroot "$mountDir" tee /etc/locale.conf > /dev/null end | arch-chroot "$mountDir" tee /etc/locale.conf > /dev/null
@ -80,13 +80,13 @@ begin
echo "KEYMAP=$keyMap" | arch-chroot "$mountDir" tee /etc/vconsole.conf > /dev/null echo "KEYMAP=$keyMap" | arch-chroot "$mountDir" tee /etc/vconsole.conf > /dev/null
end end
and echo (getConfig valhalla.hostname) | arch-chroot "$mountDir" tee /etc/hostname > /dev/null and echo (getOSConfig hostname) | arch-chroot "$mountDir" tee /etc/hostname > /dev/null
and arch-chroot "$mountDir" mkinitcpio -P and arch-chroot "$mountDir" mkinitcpio -P
and runHook installDrivers "Installing drivers..." || true and runHook installDrivers "Installing drivers..." || true
and runInOS fish "$tempDir/../Software/GRUB/main.fish" and runInOS fish "$tempDir/../Software/GRUB/main.fish"
and if set -l keyLayout (getConfig valhalla.keyboardLayout) and if set -l keyLayout (getOSConfig keyboardLayout)
set -l serviceName set-keymap.service set -l serviceName set-keymap.service
and set -l serviceFile "$mountDir/etc/systemd/system/$serviceName" and set -l serviceFile "$mountDir/etc/systemd/system/$serviceName"
and cp "$dir/$serviceName" "$serviceFile" and cp "$dir/$serviceName" "$serviceFile"

View file

@ -14,23 +14,23 @@ function deploySoftware -d "Deploys a the specified software action" -a action
end end
) )
if isEnabled valhalla.linux.secureBoot if isOSEnabled secureBoot
source "$dir/../Config/SecureBoot/main.fish" $argv source "$dir/../Config/SecureBoot/main.fish" $argv
end end
and if isEnabled valhalla.linux.hardware.surfaceBook and if isOSEnabled hardware.surfaceBook
source "$dir/../Drivers/SurfaceBook2/main.fish" $argv source "$dir/../Drivers/SurfaceBook2/main.fish" $argv
end end
and if isEnabled valhalla.linux.hardware.nvidiaGPU and if isOSEnabled hardware.nvidiaGPU
source "$dir/../Software/nvidia-dkms/main.fish" $argv source "$dir/../Software/nvidia-dkms/main.fish" $argv
end end
and if isEnabled valhalla.linux.hardware.xoneReceiver and if isOSEnabled hardware.xoneReceiver
source "$dir/../Software/xone/main.fish" $argv source "$dir/../Software/xone/main.fish" $argv
end end
and for component in (getConfig valhalla.linux.hardware.components --json | jq '.[]' --raw-output0 | string split0) and for component in (getOSConfig hardware.components --json | jq '.[]' --raw-output0 | string split0)
if [ "$component" = "Logitech G903" ] if [ "$component" = "Logitech G903" ]
source "$dir/../../Common/Drivers/Logitech G903/main.fish" $argv source "$dir/../../Common/Drivers/Logitech G903/main.fish" $argv
end end

View file

@ -11,7 +11,7 @@ begin
function configureSW -V dir function configureSW -V dir
. "$dir/../../../Common/Scripts/config.fish" . "$dir/../../../Common/Scripts/config.fish"
if isEnabled valhalla.hidpi if isOSEnabled hidpi
begin begin
printf %s\n \ printf %s\n \
"#!/bin/bash" \ "#!/bin/bash" \

View file

@ -4,7 +4,7 @@ source "$dir/../Scripts/config.fish"
source "$dir/../Scripts/hooks.fish" source "$dir/../Scripts/hooks.fish"
if [ (id -u) -eq 0 ] if [ (id -u) -eq 0 ]
set -l name (getConfig valhalla.setupUser.name) set -l name (getOSConfig setupUser.name)
set -l sudoConfig "/etc/sudoers.d/PortValhalla" set -l sudoConfig "/etc/sudoers.d/PortValhalla"
rm ~/.bash_profile rm ~/.bash_profile
@ -16,7 +16,7 @@ if [ (id -u) -eq 0 ]
--no-user-group \ --no-user-group \
--groups nix-users \ --groups nix-users \
--create-home \ --create-home \
--uid (getConfig valhalla.setupUser.id --json) \ --uid (getOSConfig setupUser.id --json) \
"$name" "$name"
end end

View file

@ -3,7 +3,7 @@ function runSetup
set -l dir (status dirname) set -l dir (status dirname)
source "$dir/../Scripts/config.fish" source "$dir/../Scripts/config.fish"
source "$dir/../Scripts/hooks.fish" source "$dir/../Scripts/hooks.fish"
set -l mountDir (getConfig valhalla.partition.rootDir) set -l mountDir (getOSConfig partition.rootDir)
set -l projectRoot (realpath "$dir/../../..") set -l projectRoot (realpath "$dir/../../..")
set -l projectName (basename "$projectRoot") set -l projectName (basename "$projectRoot")
set -l PROJECT_CLONE_ROOT "/opt/$(basename "$projectName")" set -l PROJECT_CLONE_ROOT "/opt/$(basename "$projectName")"
@ -43,7 +43,7 @@ function runSetup
"$argv" "$argv"
end end
getConfig valhalla.partition.script > "$script" getOSConfig partition.script > "$script"
and "$script" and "$script"
and rm "$script" and rm "$script"

View file

@ -5,13 +5,13 @@ set -l users (getUsers)
for name in (echo "$users" | jq '.[]' --raw-output0 | string split0) for name in (echo "$users" | jq '.[]' --raw-output0 | string split0)
function getUserConfig -V name -a config function getUserInfo -V name -a config
getConfig "valhalla.linux.users.$name.$config" $argv[2..] getUserConfig "$name" "$config" $argv[2..]
end end
set -l groups (getUserConfig groups --apply 'builtins.concatStringsSep ","'); set -l groups (getUserInfo groups --apply 'builtins.concatStringsSep ","');
set -l displayName (getUserConfig displayName --json) set -l displayName (getUserInfo displayName --json)
set -l shell (getUserConfig defaultShell --json) set -l shell (getUserInfo defaultShell --json)
sudo useradd --create-home ( sudo useradd --create-home (
if echo "$displayName" | jq --exit-status > /dev/null if echo "$displayName" | jq --exit-status > /dev/null

View file

@ -226,7 +226,10 @@ $null = New-Module {
Gets a configuration option. Gets a configuration option.
.PARAMETER Name .PARAMETER Name
The name of the option to get. The name of the configuration value to get.
.PARAMETER ArgumentList
The arguments to send to the configuration script.
#> #>
function Get-Config { function Get-Config {
param( param(
@ -242,16 +245,36 @@ $null = New-Module {
.SYNOPSIS .SYNOPSIS
Gets the name of the config root. Gets the name of the config root.
#> #>
function Get-ConfigRootName { function Get-OSConfigRoot {
return "valhalla.$($IsWindows ? "windows" : "linux")"; return "valhalla.$($IsWindows ? "windows" : "linux")";
} }
<#
.SYNOPSIS
Gets the configuration value for the current operating system.
.PARAMETER Name
The name of the configuration value to get.
.PARAMETER ArgumentList
The arguments to send to the configuration script.
#>
function Get-OSConfig {
param(
[string] $Name,
[Parameter(ValueFromRemainingArguments)]
[string[]] $ArgumentList
)
return Get-Config -Name "$(Get-OSConfigRoot).$Name" @PSBoundParameters;
}
<# <#
.SYNOPSIS .SYNOPSIS
Gets the name of the user root. Gets the name of the user root.
#> #>
function Get-UserRootName { function Get-UserConfigRoot {
return "$(Get-ConfigRootName).$($IsWindows ? "winUsers" : "users")"; return "$(Get-OSConfigRoot).$($IsWindows ? "winUsers" : "users")";
} }
<# <#
@ -272,7 +295,7 @@ $null = New-Module {
) )
if ((Get-Users) -contains $UserName) { if ((Get-Users) -contains $UserName) {
Get-Config "$(Get-UserRootName).$UserName.$Name"; Get-Config "$(Get-UserConfigRoot).$UserName.$Name";
} else { } else {
return $null; return $null;
} }
@ -300,7 +323,7 @@ $null = New-Module {
function Get-Users { function Get-Users {
[OutputType([string[]])] [OutputType([string[]])]
param() param()
Get-Attributes "$(Get-UserRootName)"; Get-Attributes "$(Get-UserConfigRoot)";
} }
<# <#
@ -310,7 +333,7 @@ $null = New-Module {
function Get-SetupUser { function Get-SetupUser {
[OutputType([string])] [OutputType([string])]
param() param()
Get-Config "$(Get-ConfigRootName).setupUser.name"; Get-OSConfig "setupUser.name";
} }
<# <#

View file

@ -13,22 +13,46 @@ function getConfig -S -a property
evalFlake "$CONFIG_NAME" "$property" $argv[2..] evalFlake "$CONFIG_NAME" "$property" $argv[2..]
end end
function getOSConfigRoot
echo "valhalla.linux"
end
function getOSConfig -S -a property
getConfig "$(getOSConfigRoot).$property" $argv[2..]
end
function getAttributes -S -a property function getAttributes -S -a property
getConfig "$property" --apply "builtins.attrNames" --json getConfig "$property" --apply "builtins.attrNames" --json
end end
function getUsers -S function getUsers -S
getAttributes "valhalla.users" getAttributes "$(getOSConfigRoot).users"
end
function getUserConfig -S -a name property
getOSConfig "users.$name.$property" $argv[3..]
end end
function isSet -S -a property function isSet -S -a property
not test "$(getConfig "$property" --json)" = "null" not test "$(getConfig "$property" --json)" = "null"
end end
function isOSSet -S -a property
isSet "$(getOSConfigRoot).$property"
end
function isUserSet -S -a name property
isOSSet "users.$name.$property"
end
function isEnabled -S -a property function isEnabled -S -a property
getConfig "$property" --json | jq --exit-status > /dev/null getConfig "$property" --json | jq --exit-status > /dev/null
end end
function collectionActive -S -a name function isOSEnabled -S -a property
[ "$(getConfig "valhalla.software.$name" --json)" = "true" ] isEnabled "$(getOSConfigRoot).$property"
end
function collectionActive -S -a name
[ "$(getOSConfig "software.$name" --json)" = "true" ]
end end

View file

@ -5,13 +5,13 @@ begin
source "$dir/../../Scripts/software.fish" source "$dir/../../Scripts/software.fish"
function configureSW function configureSW
set -l efiDir (getConfig valhalla.boot.efiMountPoint) set -l efiDir (getOSConfig boot.efiMountPoint)
sudo sed -i \ sudo sed -i \
-e "s/#\(GRUB_DISABLE_OS_PROBER\)/\1/" \ -e "s/#\(GRUB_DISABLE_OS_PROBER\)/\1/" \
/etc/default/grub /etc/default/grub
sudo grub-install --target=x86_64-efi --efi-directory="$efiDir" --bootloader-id="$(getConfig valhalla.boot.label)" sudo grub-install --target=x86_64-efi --efi-directory="$efiDir" --bootloader-id="$(getOSConfig boot.label)"
sudo grub-mkconfig -o "$efiDir/grub/grub.cfg" sudo grub-mkconfig -o "$efiDir/grub/grub.cfg"
end end

View file

@ -17,18 +17,19 @@ param (
[string] $User [string] $User
) )
$root = "valhalla"; $getConfig = $null;
if ($User) { if ($User) {
$root = "$root$($IsWindows ? ".windows" : '').users.$User"; $getConfig = { Get-UserConfig -UserName $User @args };
$sudoArgs = @("-u", $User); $sudoArgs = @("-u", $User);
$configArgs = @("--global"); $configArgs = @("--global");
} else { } else {
$getConfig = { Get-OSConfig @args };
$sudoArgs = @(); $sudoArgs = @();
$configArgs = @("--system"); $configArgs = @("--system");
} }
$config = Get-Config "$root.git"; $config = & $getConfig "git";
<# <#
.SYNOPSIS .SYNOPSIS

View file

@ -9,8 +9,8 @@ begin
function userConfig -V dir -a name function userConfig -V dir -a name
source "$dir/../../Scripts/config.fish" source "$dir/../../Scripts/config.fish"
set -l key "valhalla.linux.users.$name.rclone.configurations" set -l key "rclone.configurations"
set -l configs (getConfig "$key" --apply "builtins.attrNames" --json) set -l configs (getUserConfig "$name" "$key" --apply "builtins.attrNames" --json)
if [ (echo "$configs" | jq "length") -gt 0 ] if [ (echo "$configs" | jq "length") -gt 0 ]
if [ "$XDG_SESSION_TYPE" = "tty" ] if [ "$XDG_SESSION_TYPE" = "tty" ]
@ -89,10 +89,10 @@ begin
set -l configKey "$key.$config" set -l configKey "$key.$config"
set -l duration "$configKey.cacheDuration" set -l duration "$configKey.cacheDuration"
set -l serviceName "rclone@$config:$(getConfig "$configKey.dirName")" set -l serviceName "rclone@$config:$(getUserConfig "$name" "$configKey.dirName")"
if isSet "$duration" if isUserSet "$name" "$duration"
set serviceName "$serviceName:$(getConfig "$duration")" set serviceName "$serviceName:$(getUserConfig "$name" "$duration")"
end end
echo "Please create a remote called `$config`." echo "Please create a remote called `$config`."

View file

@ -25,8 +25,8 @@ function Deploy-SoftwareAction {
$install = $true; $install = $true;
} }
$hardware = Get-Config "valhalla.hardware"; $hardware = Get-OSConfig "hardware";
$collections = Get-Config "valhalla.windows.software"; $collections = Get-OSConfig "software";
# Drivers # Drivers
& { & {
@ -107,7 +107,7 @@ function Deploy-SoftwareAction {
& "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments; & "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments;
& "$softwarePath/Oh My Posh/Manage.ps1" @arguments; & "$softwarePath/Oh My Posh/Manage.ps1" @arguments;
if (Get-Config "valhalla.windows.dualboot") { if (Get-OSConfig "dualboot") {
& "$softwarePath/Ext4Fsd/Main.ps1" @arguments; & "$softwarePath/Ext4Fsd/Main.ps1" @arguments;
} }

View file

@ -44,19 +44,11 @@ param(
$dir = New-TemporaryDirectory; $dir = New-TemporaryDirectory;
Push-Location $dir; Push-Location $dir;
function Get-WinConfig {
param(
[string] $Name
)
Get-Config "valhalla.windows.$Name";
}
# Copy keyboard layout # Copy keyboard layout
# ToDo: Why not NewUser? Investiagte! # ToDo: Why not NewUser? Investiagte!
Copy-UserInternationalSettingsToSystem -WelcomeScreen $True -NewUser $False; Copy-UserInternationalSettingsToSystem -WelcomeScreen $True -NewUser $False;
if (Get-WinConfig "legacyIconSpacing") { if (Get-OSConfig "legacyIconSpacing") {
Write-Host "Setting up old-school Desktop Icon spacing"; Write-Host "Setting up old-school Desktop Icon spacing";
Edit-DefaultUserKey { Edit-DefaultUserKey {
@ -73,7 +65,7 @@ param(
}; };
} }
if (-not (Get-WinConfig "dynamicLighting")) { if (-not (Get-OSConfig "dynamicLighting")) {
Write-Host "Disabling Dynamic Lighting"; Write-Host "Disabling Dynamic Lighting";
Edit-DefaultUserKey { Edit-DefaultUserKey {
@ -87,7 +79,7 @@ param(
}; };
} }
if (-not (Get-WinConfig "adware")) { if (-not (Get-OSConfig "adware")) {
$startLayoutFile = "start.json"; $startLayoutFile = "start.json";
Write-Host "Removing adware"; Write-Host "Removing adware";
@ -151,7 +143,7 @@ param(
$startLayout | ConvertTo-Json -Compress | Set-Content "$env:SystemDrive\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.json"; $startLayout | ConvertTo-Json -Compress | Set-Content "$env:SystemDrive\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.json";
} }
if (Get-WinConfig "showFileExt") { if (Get-OSConfig "showFileExt") {
Edit-DefaultUserKey { Edit-DefaultUserKey {
param ( param (
[RegistryKey] $Key [RegistryKey] $Key

View file

@ -18,7 +18,7 @@ param (
Start-SoftwareInstaller @Parameters ` Start-SoftwareInstaller @Parameters `
-Installer { -Installer {
$params = "/WindowsTerminalProfile"; $params = "/WindowsTerminalProfile";
$defaultBranch = Get-Config "valhalla.git.defaultBranch"; $defaultBranch = Get-OSConfig "git.defaultBranch";
if ($defaultBranch) { if ($defaultBranch) {
$params += " /DefaultBranchName:`"$defaultBranch`""; $params += " /DefaultBranchName:`"$defaultBranch`"";