From f227960a8342c9888f189acfd2fb08594566834e Mon Sep 17 00:00:00 2001 From: stubbfel Date: Sat, 10 Jun 2023 14:58:23 +0000 Subject: [PATCH] test --- .devcontainer/devcontainer.json | 2 +- alias.sh | 4 ++ config/flake.nix | 11 ++- flake.lock | 25 +++++-- flake.nix | 102 +++++++++++---------------- playground/example/config/flake.nix | 5 ++ playground/example/service/flake.nix | 62 ++++++++++++++++ 7 files changed, 139 insertions(+), 72 deletions(-) create mode 100644 alias.sh create mode 100644 playground/example/config/flake.nix create mode 100644 playground/example/service/flake.nix diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 83a1938..511352a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ { "name": "Alpine", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/base:alpine-3.17", + "image": "mcr.microsoft.com/devcontainers/base:alpine", "features": { "ghcr.io/devcontainers/features/nix:1": {} }, diff --git a/alias.sh b/alias.sh new file mode 100644 index 0000000..66a3c08 --- /dev/null +++ b/alias.sh @@ -0,0 +1,4 @@ +#!/bin/env sh + +alias nixe='nix --experimental-features "nix-command flakes"' +alias ulock='nixe run .#devTasks.updateFlakeLock' diff --git a/config/flake.nix b/config/flake.nix index fb25742..c65a53c 100644 --- a/config/flake.nix +++ b/config/flake.nix @@ -1,10 +1,9 @@ { inputs.nixpkgs.url = "nixpkgs/nixos-23.05"; - outputs = { self, nixpkgs }: - let - supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); - in rec { nixpkgs = nixpkgsFor; }; + outputs = { self, nixpkgs }: rec { + supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + }; } diff --git a/flake.lock b/flake.lock index bcb4a4e..d2ab926 100644 --- a/flake.lock +++ b/flake.lock @@ -1,23 +1,38 @@ { "nodes": { + "config": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1, + "narHash": "sha256-x1tXOK1tiPQabKK5TOzHQ0HxtFobkEoxwWPvuo6YYvc=", + "path": "/nix/store/1cvr44p1k6r0qq7fydsp7x3yhpwgm0v9-source/config", + "type": "path" + }, + "original": { + "path": "/nix/store/1cvr44p1k6r0qq7fydsp7x3yhpwgm0v9-source/config", + "type": "path" + } + }, "nixpkgs": { "locked": { - "lastModified": 1668595291, - "narHash": "sha256-j8cyfbtT5sAYPYwbERgTDzfD48ZernL0/V668eGpXAM=", + "lastModified": 1686331006, + "narHash": "sha256-hElRDWUNG655aqF0awu+h5cmDN+I/dQcChRt2tGuGGU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6474d93e007e4d165bcf48e7f87de2175c93d10b", + "rev": "85bcb95aa83be667e562e781e9d186c57a07d757", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-22.05-small", + "ref": "nixos-23.05", "type": "indirect" } }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "config": "config" } } }, diff --git a/flake.nix b/flake.nix index 3b7dc80..bc8ddd4 100644 --- a/flake.nix +++ b/flake.nix @@ -1,76 +1,58 @@ { description = ""; - inputs.nixpkgs.url = "nixpkgs/nixos-22.05-small"; - - outputs = { self, nixpkgs }: + inputs = { + config.url = "./config"; + playground.url = "./playground/example/service"; + }; + outputs = { self, config, playground }: let - name = "develnixos.new"; version = "0.0.1"; - supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); - devTaskScripts = forAllSystems (system: - { - autoTag = nixpkgsFor.${system}.writeScript "auto_tag.sh" '' - git tag --force v${version} - git push origin v${version} - ''; - }); - in - rec { - packages = forAllSystems (system: - { - default = nixpkgsFor.${system}.stdenv.mkDerivation { - name = name; - src = self; - buildPhase = "echo nothing todo"; - installPhase = "mkdir -p $out/bin; install -t $out/bin src/hello.sh"; - }; - }); + name = "develnixos"; + + forAllSystems = config.forAllSystems; + nixpkgsFor = config.nixpkgsFor; + devTaskScripts = forAllSystems (system: { + autoTag = nixpkgsFor.${system}.writeScript "auto_tag.sh" '' + git tag --force v${version} + git push origin v${version} + ''; + }); + in rec { + packages = playground.packages; 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"; }; - autoTag = { type = "app"; program = "${devTaskScripts.${system}.autoTag}"; }; - }; - }); - - devShells = forAllSystems (system: - { - default = nixpkgsFor.${system}.mkShell { - name = "dev-shell"; - packages = [ ]; - shellHook = '' - alias nixe="nix --experimental-features 'nix-command flakes'" + 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"; + }; + autoTag = { + type = "app"; + program = "${devTaskScripts.${system}.autoTag}"; + }; }; }); - hydraJobs = { - tarball = nixpkgsFor.x86_64-linux.releaseTools.sourceTarball { - name = name; - src = self; - version = version; - officialRelease = true; - bootstrapBuildInputs = [ ]; - distPhase = '' - mkdir $out/tarballs - tar -czvf $out/tarballs/${name}-${version}.tar.gz * + devShells = forAllSystems (system: { + default = nixpkgsFor.${system}.mkShell { + name = "dev-shell"; + packages = [ nixpkgsFor.${system}.nixfmt ]; + shellHook = '' + . ./alias.sh ''; }; + }); - runCommandHook = { - recurseForDerivations = { }; - autoTag = devTaskScripts.x86_64-linux.autoTag; - }; - }; }; } diff --git a/playground/example/config/flake.nix b/playground/example/config/flake.nix new file mode 100644 index 0000000..7e5ef79 --- /dev/null +++ b/playground/example/config/flake.nix @@ -0,0 +1,5 @@ +{ + inputs = { config.url = "./config"; }; + + outputs = { self, config }: config; +} diff --git a/playground/example/service/flake.nix b/playground/example/service/flake.nix new file mode 100644 index 0000000..afd9b10 --- /dev/null +++ b/playground/example/service/flake.nix @@ -0,0 +1,62 @@ +{ + description = ""; + inputs = { config.url = "./config"; }; + outputs = { self, config }: + let + version = "0.0.1"; + name = "develnixos"; + + forAllSystems = config.forAllSystems; + nixpkgsFor = config.nixpkgsFor; + devTaskScripts = forAllSystems (system: { + autoTag = nixpkgsFor.${system}.writeScript "auto_tag.sh" '' + git tag --force v${version} + git push origin v${version} + ''; + }); + in rec { + packages = forAllSystems (system: { + default = nixpkgsFor.${system}.stdenv.mkDerivation { + name = name; + 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"; + }; + autoTag = { + type = "app"; + program = "${devTaskScripts.${system}.autoTag}"; + }; + }; + }); + + devShells = forAllSystems (system: { + default = nixpkgsFor.${system}.mkShell { + name = "dev-shell"; + packages = [ nixpkgsFor.${system}.nixfmt ]; + shellHook = '' + . ./alias.sh + ''; + }; + }); + + }; +}