Switch to named flakes

This commit is contained in:
Manuel Thalmann 2024-09-08 17:09:01 +02:00
parent 4c55137785
commit 5879aefe04
15 changed files with 88 additions and 31 deletions

View file

@ -34,9 +34,8 @@
};
})) // {
valhalla = {
"DerGeret Windows" = import ./profiles/DerGeret/config.nix;
"der-geret Arch Linux" = import ./profiles/DerGeret/Arch/config.nix;
"manu-surface Arch Linux" = import ./profiles/ManuSurface/Arch/config.nix;
DerGeret = import ./profiles/machines/manuel/DerGeret/Arch/config.nix;
ManuSurface = import ./profiles/machines/manuel/ManuSurface/Arch/config.nix;
};
};
}

15
lib/eval-attribute.nix Normal file
View 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

View file

@ -6,7 +6,7 @@ begin
echo "$dir/install.fish"
end
CONFIG_MODULE="$dir/config.nix" \
CONFIG_NAME="DerGeret" \
ARCH_HOSTNAME="der-geret" \
USER_DISPLAYNAME="Manuel Thalmann" \
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish"

View file

@ -1,6 +1,6 @@
#!/bin/pwsh
$env:WIN_COMPUTER_NAME = "DerGeret";
$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";

View file

@ -11,7 +11,7 @@ begin
echo "$dir/install.fish"
end
CONFIG_MODULE="$(status dirname)/config.nix" \
CONFIG_NAME="ManuSurface" \
ARCH_HOSTNAME="manu-surface" \
USER_DISPLAYNAME="Manuel Thalmann" \
source "$(status dirname)/../../../../../scripts/Arch/OS/setup.fish";

View file

@ -24,7 +24,7 @@ if [ (id -u) -eq 0 ]
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
end > "$sudoConfig"
and sudo --preserve-env="CONFIG_MODULE" --user "$name" "$INSTALLER_SCRIPT"
and sudo --preserve-env="CONFIG_NAME" --user "$name" "$INSTALLER_SCRIPT"
rm "$sudoConfig"
userdel -r "$name"
else

View file

@ -39,7 +39,7 @@ function runSetup
function wrapScript -S
printf %s\n \
"cd $PROJECT_CLONE_ROOT" \
"export CONFIG_MODULE=$(string escape (getCloneFile "$CONFIG_MODULE"))" \
"export CONFIG_NAME=$(string escape (getCloneFile "$CONFIG_NAME"))" \
"$argv"
end

View file

@ -115,16 +115,29 @@ $null = New-Module {
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
if ($env:CONFIG_MODULE) {
if ($env:CONFIG_NAME) {
$output = & {
if (-not $IsWindows) {
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
fish -c ". $escapedPath; $Script";
} else {
$cleanup = { };
$projectRoot = "$PSScriptRoot/../../..";
$archisoDir = "$projectRoot/archiso";
function fish {
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";
if (-not $?) {
@ -132,6 +145,8 @@ $null = New-Module {
} else {
$output;
}
& $cleanup *> $null;
}
}

View file

@ -80,12 +80,7 @@ $null = New-Module {
$Global:ErrorActionPreference = $NonInteractive.IsPresent ? 'Continue' : 'Inquire';
if ($IsWindows) {
$env:WSLENV = "CONFIG_MODULE/p";
if ($env:CONFIG_MODULE) {
$env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE;
}
$env:WSLENV = "CONFIG_NAME";
New-Alias -Force "sudo" gsudo;
}
@ -150,7 +145,7 @@ $null = New-Module {
Start-Sleep 0.1;
}
foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) {
foreach ($name in @("INSTALLER_SCRIPT")) {
$variable = Get-Item "Env:\$name";
$path = Join-Path `

View file

@ -1,11 +1,16 @@
#!/bin/env fish
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
function getConfig -S -a property
source "$(status dirname)/eval-module.fish"
evalModule "$CONFIG_MODULE" "$property" $argv[2..]
source "$(status dirname)/eval-flake.fish"
evalFlake "$CONFIG_NAME" "$property" $argv[2..]
end
function getAttributes -S -a property

View 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

View file

@ -26,7 +26,7 @@ begin
"Terminal=false" (
printf "%s " \
"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"
)
end | sudo -u "$name" tee "$entryPoint" > /dev/null
@ -36,7 +36,7 @@ begin
rm "$entryPoint"
rm ~"$name"/.config/plasma-welcomerc
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
systemctl --user enable rclone.service
echo "Please complete the setup of your rclone configurations!"

View file

@ -2,16 +2,16 @@
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
function Start-Setup {
param($ConfigurationName)
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
$Global:InformationPreference = "Continue";
$Global:ErrorActionPreference = "Inquire";
$env:CONFIG_NAME ??= $ConfigurationName;
$null = $env:WIN_COMPUTER_NAME;
$null = $env:SETUP_SCRIPT_NAME;
$null = $env:CONFIG_MODULE;
$env:WSLENV = "CONFIG_MODULE/p";
$valhallaConfig = ConvertFrom-Json (Get-Content "$env:CONFIG_MODULE.json");
$env:WSLENV = "CONFIG_NAME";
$valhallaConfig = ConvertFrom-Json (Get-Content "$PSScriptRoot/../../../.config/$env:CONFIG_NAME.json");
[xml]$unattendedConfig = [xml]::new();
$unattendedConfig.PreserveWhitespace = $true;
@ -233,7 +233,7 @@ function Start-Setup {
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
"`$env:PWSH_PATH = $(Get-PathInjection $env:PWSH_PATH);" +
"`$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;") `
-Description "Install PowerShell Core and git and run setup script";
@ -264,4 +264,4 @@ function Start-Setup {
& "$SETUP_DRIVE\setup.exe" /Unattend:$unattendedConfigFile;
}
Start-Setup
Start-Setup @args;

View file

@ -55,7 +55,7 @@ $null = New-Module {
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection (Resolve-Path $env:BACKUP_ARCHIVE));" : "") +
"`$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;";
}

View file

@ -209,9 +209,11 @@ begin
begin
source "$dir/../scripts/Common/Scripts/config.fish"
find "$projectPath/profiles" -type f -name "*.nix" | while read -l file
set -l CONFIG_MODULE "$file"
getConfig "valhalla.windows.config" --json > "$file.json"
for name in (getProfiles | jq '.[]' --raw-output0 | string split0)
set -l CONFIG_NAME "$name"
set -l file "$projectPath/.config/$name.json"
mkdir -p (dirname $file)
getConfig "valhalla.windows.config" --json > "$file"
end
end