Refactor nix init scripts

This commit is contained in:
Lukas Cech 2025-01-23 13:03:52 +01:00
parent 28a44e36fa
commit 46f71fabdd
4 changed files with 95 additions and 69 deletions

View File

@ -229,7 +229,7 @@ in
character = { character = {
success_symbol = "[](bold green)"; success_symbol = "[](bold green)";
error_symbol = "[](bold red)"; error_symbol = "[!](bold red)";
}; };
}; };
}; };

View File

@ -3,7 +3,9 @@
nix.url = "git+ssh://git@git.investbay.dev/devops/nix?branch=main"; nix.url = "git+ssh://git@git.investbay.dev/devops/nix?branch=main";
}; };
outputs = { self, nix }: { outputs =
{ self, nix }:
{
formatter = nix.formatter; formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: { devShells = nix.lib.forAllSystems (pkgs: {
@ -14,7 +16,7 @@
]; ];
commands = []; commands = [ ];
}; };
}); });
}; };

View File

@ -3,7 +3,9 @@
nix.url = "git+ssh://git@bitbucket.org/yourpass/nix"; nix.url = "git+ssh://git@bitbucket.org/yourpass/nix";
}; };
outputs = { self, nix }: { outputs =
{ self, nix }:
{
formatter = nix.formatter; formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: { devShells = nix.lib.forAllSystems (pkgs: {
@ -14,7 +16,7 @@
]; ];
commands = []; commands = [ ];
}; };
}); });
}; };

View File

@ -1,6 +1,11 @@
{ lib, pkgs, ... }: { lib, pkgs, ... }:
let let
flake-dir = {flake, impure ? false}: pkgs.writeShellScript "nix-prepare" '' flake-dir =
{
flake,
impure ? false,
}:
pkgs.writeShellScript "nix-prepare" ''
run() { run() {
local dir="$1" local dir="$1"
echo "Preparing nix environment in $dir" echo "Preparing nix environment in $dir"
@ -38,7 +43,12 @@ let
run "$@" run "$@"
''; '';
git-flake-dir-clone = { flake, impure? false}: pkgs.writeShellScript "git-nix-clone" '' git-flake-dir-clone =
{
flake,
impure ? false,
}:
pkgs.writeShellScript "git-nix-clone" ''
# Input is a git repository such as git@github.com:group/project-name.git # Input is a git repository such as git@github.com:group/project-name.git
run() { run() {
local repo="$1" local repo="$1"
@ -49,7 +59,7 @@ let
exit 1 exit 1
fi fi
${flake-dir {inherit flake impure;}} "$projectName"-nix ${flake-dir { inherit flake impure; }} "$projectName"-nix
git clone "$repo" "$projectName"-nix"/$projectName" git clone "$repo" "$projectName"-nix"/$projectName"
} }
@ -59,10 +69,22 @@ let
in in
{ {
programs.zsh.shellAliases = { programs.zsh.shellAliases = {
git-c3c-clone = lib.mkDefault "${git-flake-dir-clone { flake = ./flake-templates/c3c-flake.nix; impure = false;}}"; git-c3c-clone = lib.mkDefault "${git-flake-dir-clone {
flake-dir-c3c = lib.mkDefault "${flake-dir { flake = ./flake-templates/c3c-flake.nix; impure = false;}}"; flake = ./flake-templates/c3c-flake.nix;
flake-dir-yp = lib.mkDefault "${flake-dir { flake = ./flake-templates/yp-flake.nix; impure = false;}}"; impure = true;
flake-dir-investbay = lib.mkDefault "${flake-dir { flake = ./flake-templates/investbay-flake.nix; impure = false;}}"; }}";
flake-dir-c3c = lib.mkDefault "${flake-dir {
flake = ./flake-templates/c3c-flake.nix;
impure = true;
}}";
flake-dir-yp = lib.mkDefault "${flake-dir {
flake = ./flake-templates/yp-flake.nix;
impure = false;
}}";
flake-dir-investbay = lib.mkDefault "${flake-dir {
flake = ./flake-templates/investbay-flake.nix;
impure = false;
}}";
}; };
} }