Add nix init script
This commit is contained in:
parent
d054152d36
commit
5ace96b3c0
@ -27,6 +27,9 @@ in
|
||||
{
|
||||
cat = lib.mkDefault "bat --paging=never";
|
||||
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
|
||||
|
||||
53
home-manager/flake-templates/c3c-flake.nix
Normal file
53
home-manager/flake-templates/c3c-flake.nix
Normal 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
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
@ -15,6 +15,9 @@ in
|
||||
(import ./veracode/aws-cli.nix {
|
||||
inherit homedir lib pkgs;
|
||||
})
|
||||
(import ./nix-init-scripts.nix {
|
||||
inherit lib pkgs;
|
||||
})
|
||||
];
|
||||
|
||||
home.username = username;
|
||||
|
||||
56
home-manager/nix-init-scripts.nix
Normal file
56
home-manager/nix-init-scripts.nix
Normal 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 '/*' > .gitignore
|
||||
echo '!/flake.nix' >> .gitignore
|
||||
echo '!/flake.lock' >> .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}";
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user