From 146b6b54d15c7d3e723db597d2c36102bd780348 Mon Sep 17 00:00:00 2001 From: stubbfelnewpc Date: Tue, 1 Nov 2022 13:41:22 +0000 Subject: [PATCH] init --- .devcontainer/Dockerfile | 14 +++++++ .devcontainer/devcontainer.json | 30 ++++++++++++++ .gitignore | 1 + .vscode/settings.json | 9 +++++ CHANGELOG | 1 + LICENSE | 9 +++++ README.md | 12 ++++++ flake.lock | 26 ++++++++++++ flake.nix | 72 +++++++++++++++++++++++++++++++++ src/hello.sh | 3 ++ 10 files changed, 177 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 CHANGELOG create mode 100644 LICENSE create mode 100644 README.md create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 src/hello.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..142c3f6 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,14 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ubuntu/.devcontainer/base.Dockerfile + +# [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 +ARG VARIANT="jammy" +FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} + +RUN mkdir /nix \ + && chown vscode /nix \ + && su vscode -c "sh <(curl -L https://nixos.org/nix/install) --no-daemon" + +RUN su vscode -c "/home/vscode/.nix-profile/bin/nix-env -i nixpkgs-fmt" + +RUN echo 'nix --experimental-features "nix-command flakes" develop' > /usr/bin/devShell \ + && chmod +x /usr/bin/devShell diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..7547a14 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ubuntu +{ + "name": "Ubuntu", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04 + // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon. + "args": { "VARIANT": "ubuntu-22.04" } + }, + "extensions": [ + "donjayamanne.githistory", + "jnoortheen.nix-ide", + "ms-azuretools.vscode-docker", + "eamodio.gitlens", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker" + ], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "docker-from-docker": "latest" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2f5dd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3ca342b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "terminal.integrated.profiles.linux": { + "dev": { + "path": "/usr/bin/devShell", + "icon": "terminal-bash" + } + }, + "terminal.integrated.defaultProfile.linux": "dev" +} \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/CHANGELOG @@ -0,0 +1 @@ +# Changelog diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..04d8fab --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2022 stubbfel + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c065c2e --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# + +## Packages + +```sh +nixe run "git+https://gitlab.com/codeguesser/code_guesser.sh.git?ref=flake&dir=pkgs/nix" examples/example.c + +nixe run ./pkgs/nix examples/example.c + +nixe run "gitlab:codeguesser/code_guesser.sh/flake?dir=pkgs/nix" examples/example.c + +``` \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8de3b17 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1667254466, + "narHash": "sha256-YrMQzDVOo+uz5gg1REj2q/uVhJE3WcpkqGiMzh3Da3o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1b4722674c315de0e191d0d79790b4eac51570a1", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-22.05-small", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e7fd664 --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + description = "template flake"; + inputs.nixpkgs.url = "nixpkgs/nixos-22.05-small"; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in + rec { + packages = forAllSystems (system: + { + default = nixpkgsFor.${system}.stdenv.mkDerivation { + name = "hello"; + src = self; + buildPhase = "echo nothing todo"; + installPhase = "mkdir -p $out/bin; install -t $out/bin src/hello.sh"; + }; + }); + + apps = forAllSystems (system: + let + updateLockScript = nixpkgsFor.${system}.writeShellScriptBin "update_flake_lock.sh" '' + nix --experimental-features 'nix-command flakes' flake lock --update-input nixpkgs + nix --experimental-features 'nix-command flakes' build + ''; + in + { + default = { type = "app"; program = "${packages.${system}.default}/bin/hello.sh"; }; + devTasks = { + updateFlakeLock = { type = "app"; program = "${updateLockScript}/bin/update_flake_lock.sh"; }; + }; + }); + + + + devShells = forAllSystems (system: + { + default = nixpkgsFor.${system}.mkShell { + name = "dev-shell"; + packages = [ ]; + shellHook = '' + alias nixe="nix --experimental-features 'nix-command flakes'" + ''; + }; + }); + + hydraJobs = { + tarball = nixpkgsFor.x86_64-linux.releaseTools.sourceTarball rec { + name = "example.sh"; + src = self; + version = "0.0.1"; + officialRelease = true; + bootstrapBuildInputs = [ ]; + distPhase = '' + mkdir $out/tarballs + tar -czvf $out/tarballs/${name}-${version}.tar.gz * + ''; + }; + + runCommandHook = { + recurseForDerivations = { }; + example = forAllSystems (system: + nixpkgsFor.${system}.writeShellScriptBin "example_hook.sh" '' + echo foo + '' + ); + }; + }; + }; +} diff --git a/src/hello.sh b/src/hello.sh new file mode 100755 index 0000000..2202fe7 --- /dev/null +++ b/src/hello.sh @@ -0,0 +1,3 @@ +#!/bin/env bash + +echo "hello world" \ No newline at end of file