Switch to named flakes
This commit is contained in:
parent
d9266b5bf8
commit
5a1b1cd8c1
15 changed files with 88 additions and 31 deletions
|
@ -34,9 +34,8 @@
|
||||||
};
|
};
|
||||||
})) // {
|
})) // {
|
||||||
valhalla = {
|
valhalla = {
|
||||||
"DerGeret Windows" = import ./profiles/DerGeret/config.nix;
|
DerGeret = import ./profiles/machines/manuel/DerGeret/Arch/config.nix;
|
||||||
"der-geret Arch Linux" = import ./profiles/DerGeret/Arch/config.nix;
|
ManuSurface = import ./profiles/machines/manuel/ManuSurface/Arch/config.nix;
|
||||||
"manu-surface Arch Linux" = import ./profiles/ManuSurface/Arch/config.nix;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
15
lib/eval-attribute.nix
Normal file
15
lib/eval-attribute.nix
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
let
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
|
nixpkgs = import <nixpkgs> { config = {}; overlay = []; };
|
||||||
|
property = (builtins.getEnv "PROPERTY");
|
||||||
|
processor = if (builtins.stringLength property > 0)
|
||||||
|
then
|
||||||
|
(_: lib.attrsets.getAttrFromPath (lib.strings.splitString "." property) _)
|
||||||
|
else
|
||||||
|
(_: _);
|
||||||
|
in
|
||||||
|
_: processor (lib.evalModules {
|
||||||
|
modules = [
|
||||||
|
_
|
||||||
|
];
|
||||||
|
}).config
|
|
@ -6,7 +6,7 @@ begin
|
||||||
echo "$dir/install.fish"
|
echo "$dir/install.fish"
|
||||||
end
|
end
|
||||||
|
|
||||||
CONFIG_MODULE="$dir/config.nix" \
|
CONFIG_NAME="DerGeret" \
|
||||||
ARCH_HOSTNAME="der-geret" \
|
ARCH_HOSTNAME="der-geret" \
|
||||||
USER_DISPLAYNAME="Manuel Thalmann" \
|
USER_DISPLAYNAME="Manuel Thalmann" \
|
||||||
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish"
|
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/pwsh
|
#!/bin/pwsh
|
||||||
$env:WIN_COMPUTER_NAME = "DerGeret";
|
$env:WIN_COMPUTER_NAME = "DerGeret";
|
||||||
$env:SETUP_SCRIPT_NAME = "$PSScriptRoot/Restore.ps1";
|
$env:SETUP_SCRIPT_NAME = "$PSScriptRoot/Restore.ps1";
|
||||||
$env:CONFIG_MODULE = "$PSScriptRoot/../config.nix";
|
$env:CONFIG_NAME = $env:WIN_COMPUTER_NAME;
|
||||||
|
|
||||||
. "$PSScriptRoot/../../../../../scripts/Windows/OS/Setup.ps1";
|
. "$PSScriptRoot/../../../../../scripts/Windows/OS/Setup.ps1";
|
||||||
|
|
|
@ -11,7 +11,7 @@ begin
|
||||||
echo "$dir/install.fish"
|
echo "$dir/install.fish"
|
||||||
end
|
end
|
||||||
|
|
||||||
CONFIG_MODULE="$(status dirname)/config.nix" \
|
CONFIG_NAME="ManuSurface" \
|
||||||
ARCH_HOSTNAME="manu-surface" \
|
ARCH_HOSTNAME="manu-surface" \
|
||||||
USER_DISPLAYNAME="Manuel Thalmann" \
|
USER_DISPLAYNAME="Manuel Thalmann" \
|
||||||
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish";
|
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish";
|
||||||
|
|
|
@ -24,7 +24,7 @@ if [ (id -u) -eq 0 ]
|
||||||
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
|
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
|
||||||
end > "$sudoConfig"
|
end > "$sudoConfig"
|
||||||
|
|
||||||
and sudo --preserve-env="CONFIG_MODULE" --user "$name" "$INSTALLER_SCRIPT"
|
and sudo --preserve-env="CONFIG_NAME" --user "$name" "$INSTALLER_SCRIPT"
|
||||||
rm "$sudoConfig"
|
rm "$sudoConfig"
|
||||||
userdel -r "$name"
|
userdel -r "$name"
|
||||||
else
|
else
|
||||||
|
|
|
@ -39,7 +39,7 @@ function runSetup
|
||||||
function wrapScript -S
|
function wrapScript -S
|
||||||
printf %s\n \
|
printf %s\n \
|
||||||
"cd $PROJECT_CLONE_ROOT" \
|
"cd $PROJECT_CLONE_ROOT" \
|
||||||
"export CONFIG_MODULE=$(string escape (getCloneFile "$CONFIG_MODULE"))" \
|
"export CONFIG_NAME=$(string escape (getCloneFile "$CONFIG_NAME"))" \
|
||||||
"$argv"
|
"$argv"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -115,16 +115,29 @@ $null = New-Module {
|
||||||
|
|
||||||
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
|
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
|
||||||
|
|
||||||
if ($env:CONFIG_MODULE) {
|
if ($env:CONFIG_NAME) {
|
||||||
$output = & {
|
$output = & {
|
||||||
if (-not $IsWindows) {
|
if (-not $IsWindows) {
|
||||||
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
|
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
|
||||||
fish -c ". $escapedPath; $Script";
|
fish -c ". $escapedPath; $Script";
|
||||||
} else {
|
} else {
|
||||||
|
$cleanup = { };
|
||||||
|
$projectRoot = "$PSScriptRoot/../../..";
|
||||||
|
$archisoDir = "$projectRoot/archiso";
|
||||||
|
|
||||||
function fish {
|
function fish {
|
||||||
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
|
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish -- $args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Test-Path -PathType Container "$archisoDir") {
|
||||||
|
$git = {
|
||||||
|
git -C "$projectRoot" -c safe.directory="$("$(Resolve-Path $projectRoot)".Replace("\", "/"))" @args;
|
||||||
|
};
|
||||||
|
|
||||||
|
& $git rm -r --cached "$archisoDir" *> $null;
|
||||||
|
$cleanup = { & $git restore --staged "$archisoDir" };
|
||||||
|
}
|
||||||
|
|
||||||
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
|
$output = fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script";
|
||||||
|
|
||||||
if (-not $?) {
|
if (-not $?) {
|
||||||
|
@ -132,6 +145,8 @@ $null = New-Module {
|
||||||
} else {
|
} else {
|
||||||
$output;
|
$output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& $cleanup *> $null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,12 +80,7 @@ $null = New-Module {
|
||||||
$Global:ErrorActionPreference = $NonInteractive.IsPresent ? 'Continue' : 'Inquire';
|
$Global:ErrorActionPreference = $NonInteractive.IsPresent ? 'Continue' : 'Inquire';
|
||||||
|
|
||||||
if ($IsWindows) {
|
if ($IsWindows) {
|
||||||
$env:WSLENV = "CONFIG_MODULE/p";
|
$env:WSLENV = "CONFIG_NAME";
|
||||||
|
|
||||||
if ($env:CONFIG_MODULE) {
|
|
||||||
$env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE;
|
|
||||||
}
|
|
||||||
|
|
||||||
New-Alias -Force "sudo" gsudo;
|
New-Alias -Force "sudo" gsudo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +145,7 @@ $null = New-Module {
|
||||||
Start-Sleep 0.1;
|
Start-Sleep 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) {
|
foreach ($name in @("INSTALLER_SCRIPT")) {
|
||||||
$variable = Get-Item "Env:\$name";
|
$variable = Get-Item "Env:\$name";
|
||||||
|
|
||||||
$path = Join-Path `
|
$path = Join-Path `
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
#!/bin/env fish
|
#!/bin/env fish
|
||||||
function isConfigured -S
|
function isConfigured -S
|
||||||
set -q "$CONFIG_MODULE"
|
set -q CONFIG_NAME
|
||||||
|
end
|
||||||
|
|
||||||
|
function getProfiles -S
|
||||||
|
source "$(status dirname)/eval-flake.fish";
|
||||||
|
evalFlake "" "" --apply "builtins.attrNames" --json
|
||||||
end
|
end
|
||||||
|
|
||||||
function getConfig -S -a property
|
function getConfig -S -a property
|
||||||
source "$(status dirname)/eval-module.fish"
|
source "$(status dirname)/eval-flake.fish"
|
||||||
evalModule "$CONFIG_MODULE" "$property" $argv[2..]
|
evalFlake "$CONFIG_NAME" "$property" $argv[2..]
|
||||||
end
|
end
|
||||||
|
|
||||||
function getAttributes -S -a property
|
function getAttributes -S -a property
|
||||||
|
|
26
scripts/Common/Scripts/eval-flake.fish
Executable file
26
scripts/Common/Scripts/eval-flake.fish
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/env fish
|
||||||
|
function evalFlake --argument-names config property
|
||||||
|
set -l argv $argv[3..]
|
||||||
|
argparse --ignore-unknown "apply=" "json" -- $argv
|
||||||
|
|
||||||
|
if [ -z "$_flag_json" ]
|
||||||
|
set -a argv --raw
|
||||||
|
else
|
||||||
|
set -a argv --json
|
||||||
|
end
|
||||||
|
|
||||||
|
if [ -z "$_flag_apply" ]
|
||||||
|
set _flag_apply "_: _"
|
||||||
|
end
|
||||||
|
|
||||||
|
if [ -n "$config" ]
|
||||||
|
set config ".$config"
|
||||||
|
set _flag_apply "_: ($_flag_apply) ((import $(status dirname)/../../../lib/eval-attribute.nix) _)"
|
||||||
|
end
|
||||||
|
|
||||||
|
PROPERTY="$property" \
|
||||||
|
nix eval --impure --extra-experimental-features "nix-command flakes" \
|
||||||
|
--apply "$_flag_apply" \
|
||||||
|
"$(realpath (status dirname))/../../..#valhalla$config" \
|
||||||
|
$argv
|
||||||
|
end
|
|
@ -26,7 +26,7 @@ begin
|
||||||
"Terminal=false" (
|
"Terminal=false" (
|
||||||
printf "%s " \
|
printf "%s " \
|
||||||
"Exec=env" \
|
"Exec=env" \
|
||||||
"CONFIG_MODULE=$(echo "$CONFIG_MODULE" | string escape)" \
|
"CONFIG_NAME=$(echo "$CONFIG_NAME" | string escape)" \
|
||||||
"konsole -e fish $(realpath (status filename) | string escape) userConfig"
|
"konsole -e fish $(realpath (status filename) | string escape) userConfig"
|
||||||
)
|
)
|
||||||
end | sudo -u "$name" tee "$entryPoint" > /dev/null
|
end | sudo -u "$name" tee "$entryPoint" > /dev/null
|
||||||
|
@ -36,7 +36,7 @@ begin
|
||||||
rm "$entryPoint"
|
rm "$entryPoint"
|
||||||
rm ~"$name"/.config/plasma-welcomerc
|
rm ~"$name"/.config/plasma-welcomerc
|
||||||
else if [ -n "$name" ] && [ "$name" != "$USER" ]
|
else if [ -n "$name" ] && [ "$name" != "$USER" ]
|
||||||
sudo -Eu "$name" CONFIG_MODULE="$CONFIG_MODULE" fish "$(status filename)" userConfig
|
sudo -Eu "$name" CONFIG_NAME="$CONFIG_NAME" fish "$(status filename)" userConfig
|
||||||
else
|
else
|
||||||
systemctl --user enable rclone.service
|
systemctl --user enable rclone.service
|
||||||
echo "Please complete the setup of your rclone configurations!"
|
echo "Please complete the setup of your rclone configurations!"
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
|
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
|
||||||
|
|
||||||
function Start-Setup {
|
function Start-Setup {
|
||||||
|
param($ConfigurationName)
|
||||||
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
|
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
|
||||||
$Global:InformationPreference = "Continue";
|
$Global:InformationPreference = "Continue";
|
||||||
$Global:ErrorActionPreference = "Inquire";
|
$Global:ErrorActionPreference = "Inquire";
|
||||||
|
$env:CONFIG_NAME ??= $ConfigurationName;
|
||||||
$null = $env:WIN_COMPUTER_NAME;
|
$null = $env:WIN_COMPUTER_NAME;
|
||||||
$null = $env:SETUP_SCRIPT_NAME;
|
$null = $env:SETUP_SCRIPT_NAME;
|
||||||
$null = $env:CONFIG_MODULE;
|
$env:WSLENV = "CONFIG_NAME";
|
||||||
$env:WSLENV = "CONFIG_MODULE/p";
|
|
||||||
|
|
||||||
$valhallaConfig = ConvertFrom-Json (Get-Content "$env:CONFIG_MODULE.json");
|
|
||||||
|
|
||||||
|
$valhallaConfig = ConvertFrom-Json (Get-Content "$PSScriptRoot/../../../.config/$env:CONFIG_NAME.json");
|
||||||
[xml]$unattendedConfig = [xml]::new();
|
[xml]$unattendedConfig = [xml]::new();
|
||||||
$unattendedConfig.PreserveWhitespace = $true;
|
$unattendedConfig.PreserveWhitespace = $true;
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ function Start-Setup {
|
||||||
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
|
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
|
||||||
"`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" +
|
"`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" +
|
||||||
"`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" +
|
"`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" +
|
||||||
"`$env:CONFIG_MODULE = $(Get-ScriptPathInjection $env:CONFIG_MODULE);" +
|
"`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
|
||||||
"& (Join-Path `$env:PWSH_PATH pwsh) `$env:INSTALLER_SCRIPT;") `
|
"& (Join-Path `$env:PWSH_PATH pwsh) `$env:INSTALLER_SCRIPT;") `
|
||||||
-Description "Install PowerShell Core and git and run setup script";
|
-Description "Install PowerShell Core and git and run setup script";
|
||||||
|
|
||||||
|
@ -264,4 +264,4 @@ function Start-Setup {
|
||||||
& "$SETUP_DRIVE\setup.exe" /Unattend:$unattendedConfigFile;
|
& "$SETUP_DRIVE\setup.exe" /Unattend:$unattendedConfigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
Start-Setup
|
Start-Setup @args;
|
||||||
|
|
|
@ -55,7 +55,7 @@ $null = New-Module {
|
||||||
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
|
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
|
||||||
($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection (Resolve-Path $env:BACKUP_ARCHIVE));" : "") +
|
($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection (Resolve-Path $env:BACKUP_ARCHIVE));" : "") +
|
||||||
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
|
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
|
||||||
"`$env:CONFIG_MODULE = $(ConvertTo-Injection (Resolve-Path $env:CONFIG_MODULE));" +
|
"`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
|
||||||
"& `$env:INSTALLER_SCRIPT;";
|
"& `$env:INSTALLER_SCRIPT;";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,9 +209,11 @@ begin
|
||||||
begin
|
begin
|
||||||
source "$dir/../scripts/Common/Scripts/config.fish"
|
source "$dir/../scripts/Common/Scripts/config.fish"
|
||||||
|
|
||||||
find "$projectPath/profiles" -type f -name "*.nix" | while read -l file
|
for name in (getProfiles | jq '.[]' --raw-output0 | string split0)
|
||||||
set -l CONFIG_MODULE "$file"
|
set -l CONFIG_NAME "$name"
|
||||||
getConfig "valhalla.windows.config" --json > "$file.json"
|
set -l file "$projectPath/.config/$name.json"
|
||||||
|
mkdir -p (dirname $file)
|
||||||
|
getConfig "valhalla.windows.config" --json > "$file"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue