Add nix init script

This commit is contained in:
Lukas Cech 2025-01-15 09:46:57 +01:00
parent d054152d36
commit 9b5a5b6e9f
4 changed files with 115 additions and 0 deletions

View File

@ -27,6 +27,9 @@ in
{ {
cat = lib.mkDefault "bat --paging=never"; cat = lib.mkDefault "bat --paging=never";
nixfix = lib.mkDefault "nix fmt ./**/*.nix"; nixfix = lib.mkDefault "nix fmt ./**/*.nix";
aws-export-credentials = lib.mkDefault "aws configure export-credentials --format env --profile";
# use curl-aws --aws-sigv4 "aws:amz:region:service"
curl-aws = lib.mkDefault "curl -H \"X-Amz-Security-Token: $AWS_SESSION_TOKEN\" --user \"$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY\"";
} }
// ( // (
if isDarwin then if isDarwin then

View File

@ -0,0 +1,53 @@
{
inputs = {
nix.url = "git+ssh://git@git.c3c.cz/C3C/nix";
};
outputs =
{ self, nix }:
{
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = nix.lib.mkDevenvShell {
inherit pkgs;
inputs = {
self = self;
nixpkgs = pkgs;
};
modules = [
{
packages = with pkgs; [
];
scripts = {
menu = {
description = "Print this menu";
exec = ''
echo "Commands:"
echo -n ${
builtins.toJSON (
builtins.mapAttrs (s: value: value.description) self.devShells.${pkgs.system}.default.config.scripts
)
}' | \
${pkgs.jq}/bin/jq -r 'to_entries | map(" \(.key)\n" + " - \(if .value == "" then "no description provided" else .value end)") | "" + .[]'
'';
};
fix = {
exec = ''
${nix.lib.cd_root}
nix fmt ./*.nix
${pkgs.golangci-lint}/bin/golangci-lint run --sort-results --out-format tab --config ${nix.lib.golangci-config-file} --fix --issues-exit-code 0 ./...
stylua ./src
'';
};
};
}
];
};
});
};
}

View File

@ -15,6 +15,9 @@ in
(import ./veracode/aws-cli.nix { (import ./veracode/aws-cli.nix {
inherit homedir lib pkgs; inherit homedir lib pkgs;
}) })
(import ./nix-init-scripts.nix {
inherit lib pkgs;
})
]; ];
home.username = username; home.username = username;

View File

@ -0,0 +1,56 @@
{ lib, pkgs, ... }:
let
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
echo "Clone $repo into ''${projectName}-nix/''${projectName}?"
read -p "continue?" answer
if [ "$answer" != "" ]; then
echo "Aborting"
exit 1
fi
mkdir -p "$projectName"-nix
cd "$projectName"-nix
git init
# Insert the nix flake
cp ${./flake-templates/c3c-flake.nix} flake.nix
chmod 644 flake.nix
echo '/.envrc' > .gitignore
echo '/.devenv' >> .gitignore
echo '/.direnv' >> .gitignore
echo 'use flake . --impure' > .envrc
git add flake.nix .gitignore
git commit -m "Setup initial flake"
direnv allow
eval "$(direnv export bash)"
git add flake.lock
git commit -m "Lock flakes"
git clone "$repo"
}
run "$@"
'';
in
{
programs.zsh.shellAliases = {
git-nix-clone = lib.mkDefault "${pkgs.writeShellScript "git-nix-clone" git-nix-clone}";
};
}