Refactor nix init scripts
This commit is contained in:
parent
28a44e36fa
commit
46f71fabdd
@ -229,7 +229,7 @@ in
|
||||
|
||||
character = {
|
||||
success_symbol = "[›](bold green)";
|
||||
error_symbol = "[›](bold red)";
|
||||
error_symbol = "[!](bold red)";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -3,19 +3,21 @@
|
||||
nix.url = "git+ssh://git@git.investbay.dev/devops/nix?branch=main";
|
||||
};
|
||||
|
||||
outputs = { self, nix }: {
|
||||
formatter = nix.formatter;
|
||||
outputs =
|
||||
{ self, nix }:
|
||||
{
|
||||
formatter = nix.formatter;
|
||||
|
||||
devShells = nix.lib.forAllSystems (pkgs: {
|
||||
default = pkgs.devshell.mkShell {
|
||||
name = "investbay";
|
||||
devShells = nix.lib.forAllSystems (pkgs: {
|
||||
default = pkgs.devshell.mkShell {
|
||||
name = "investbay";
|
||||
|
||||
packages = with pkgs; [
|
||||
packages = with pkgs; [
|
||||
|
||||
];
|
||||
];
|
||||
|
||||
commands = [];
|
||||
};
|
||||
});
|
||||
};
|
||||
commands = [ ];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -3,19 +3,21 @@
|
||||
nix.url = "git+ssh://git@bitbucket.org/yourpass/nix";
|
||||
};
|
||||
|
||||
outputs = { self, nix }: {
|
||||
formatter = nix.formatter;
|
||||
outputs =
|
||||
{ self, nix }:
|
||||
{
|
||||
formatter = nix.formatter;
|
||||
|
||||
devShells = nix.lib.forAllSystems (pkgs: {
|
||||
default = pkgs.devshell.mkShell {
|
||||
name = "yp";
|
||||
devShells = nix.lib.forAllSystems (pkgs: {
|
||||
default = pkgs.devshell.mkShell {
|
||||
name = "yp";
|
||||
|
||||
packages = with pkgs; [
|
||||
packages = with pkgs; [
|
||||
|
||||
];
|
||||
];
|
||||
|
||||
commands = [];
|
||||
};
|
||||
});
|
||||
};
|
||||
commands = [ ];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,68 +1,90 @@
|
||||
{ lib, pkgs, ... }:
|
||||
let
|
||||
flake-dir = {flake, impure ? false}: pkgs.writeShellScript "nix-prepare" ''
|
||||
run() {
|
||||
local dir="$1"
|
||||
echo "Preparing nix environment in $dir"
|
||||
flake-dir =
|
||||
{
|
||||
flake,
|
||||
impure ? false,
|
||||
}:
|
||||
pkgs.writeShellScript "nix-prepare" ''
|
||||
run() {
|
||||
local dir="$1"
|
||||
echo "Preparing nix environment in $dir"
|
||||
|
||||
if [ "$dir" = "" ]; then
|
||||
echo "Usage: nix-prepare <dir>"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$dir" = "" ]; then
|
||||
echo "Usage: nix-prepare <dir>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p $dir
|
||||
cd $dir
|
||||
mkdir -p $dir
|
||||
cd $dir
|
||||
|
||||
git init
|
||||
git init
|
||||
|
||||
# Insert the nix flake
|
||||
cp ${flake} flake.nix
|
||||
chmod 644 flake.nix
|
||||
# Insert the nix flake
|
||||
cp ${flake} flake.nix
|
||||
chmod 644 flake.nix
|
||||
|
||||
echo '/*' > .gitignore
|
||||
echo '!/.gitignore' >> .gitignore
|
||||
echo '!/flake.nix' >> .gitignore
|
||||
echo '!/flake.lock' >> .gitignore
|
||||
echo 'use flake .${(if impure then " --impure" else "")}' > .envrc
|
||||
echo '/*' > .gitignore
|
||||
echo '!/.gitignore' >> .gitignore
|
||||
echo '!/flake.nix' >> .gitignore
|
||||
echo '!/flake.lock' >> .gitignore
|
||||
echo 'use flake .${(if impure then " --impure" else "")}' > .envrc
|
||||
|
||||
git add flake.nix .gitignore
|
||||
git commit -m "Setup initial flake"
|
||||
git add flake.nix .gitignore
|
||||
git commit -m "Setup initial flake"
|
||||
|
||||
direnv allow
|
||||
eval "$(direnv export bash)"
|
||||
direnv allow
|
||||
eval "$(direnv export bash)"
|
||||
|
||||
git add flake.lock
|
||||
git commit -m "Lock flakes"
|
||||
}
|
||||
git add flake.lock
|
||||
git commit -m "Lock flakes"
|
||||
}
|
||||
|
||||
run "$@"
|
||||
'';
|
||||
run "$@"
|
||||
'';
|
||||
|
||||
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
|
||||
run() {
|
||||
local repo="$1"
|
||||
local projectName=$(echo "$repo" | sed 's/.*\///' | sed 's/\.git//')
|
||||
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
|
||||
run() {
|
||||
local repo="$1"
|
||||
local projectName=$(echo "$repo" | sed 's/.*\///' | sed 's/\.git//')
|
||||
|
||||
if [ "$repo" = "" ]; then
|
||||
echo "Usage: git-nix-clone <repo>"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$repo" = "" ]; then
|
||||
echo "Usage: git-nix-clone <repo>"
|
||||
exit 1
|
||||
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"
|
||||
}
|
||||
|
||||
run "$@"
|
||||
'';
|
||||
run "$@"
|
||||
'';
|
||||
in
|
||||
{
|
||||
programs.zsh.shellAliases = {
|
||||
git-c3c-clone = lib.mkDefault "${git-flake-dir-clone { flake = ./flake-templates/c3c-flake.nix; impure = false;}}";
|
||||
flake-dir-c3c = lib.mkDefault "${flake-dir { flake = ./flake-templates/c3c-flake.nix; impure = false;}}";
|
||||
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;}}";
|
||||
git-c3c-clone = lib.mkDefault "${git-flake-dir-clone {
|
||||
flake = ./flake-templates/c3c-flake.nix;
|
||||
impure = true;
|
||||
}}";
|
||||
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;
|
||||
}}";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user