diff --git a/README.md b/README.md index 9fb1abf..7873ebf 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ * simple-shell: Some shells; * hello-versions: Choosing some package version; * samples: A directory with found exicting recipes! +* flake-basic: A really basic flake +* flake-basic-platform: A slighly more complex flake, with more targets +* flake-mkDerivation: A flake with a ... mkDerivation +* flake-rust-devshell: A flake with a rust overlay ## Building, running, deleting @@ -63,4 +67,4 @@ It will be needed to wipe the profile history and the `result` link to be able t * https://nix.dev/tutorials/nixos/building-and-running-docker-images.html * https://mitchellh.com/writing/nix-with-dockerfiles * https://jameswillia.ms/posts/go-nix-containers.html - \ No newline at end of file + diff --git a/flake-mkDerivation/flake.lock b/flake-mkDerivation/flake.lock new file mode 100644 index 0000000..994fb9c --- /dev/null +++ b/flake-mkDerivation/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710631334, + "narHash": "sha256-rL5LSYd85kplL5othxK5lmAtjyMOBg390sGBTb3LRMM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c75037bbf9093a2acb617804ee46320d6d1fea5a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake-mkDerivation/flake.nix b/flake-mkDerivation/flake.nix new file mode 100644 index 0000000..b78eeec --- /dev/null +++ b/flake-mkDerivation/flake.nix @@ -0,0 +1,54 @@ +# Source: https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10#a-flake-with-derivation +# nix build .#packages.x86_64-linux.shaka-packager +# nix build .#shaka-packager +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + name = "simple"; + src = ./.; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + packages.default = derivation { + inherit system name src; + builder = with pkgs; "${bash}/bin/bash"; + args = [ "-c" "echo foo > $out" ]; + }; + packages.shaka-packager = + let + version = "2.6.1"; + inherit (pkgs) stdenv lib; + in + stdenv.mkDerivation + { + name = "shaka-packager-${version}"; + + # https://nixos.wiki/wiki/Packaging/Binaries + src = pkgs.fetchurl { + url = + "https://github.com/shaka-project/shaka-packager/releases/download/v${version}/packager-linux-x64"; + sha256 = "sha256-MoMX6PEtvPmloXJwRpnC2lHlT+tozsV4dmbCqweyyI0="; + }; + + dontUnpack = true; + sourceRoot = "."; + + installPhase = '' + install -m755 -D $src $out/bin/shaka-packager + ''; + + meta = with nixpkgs.lib; { + homepage = "https://shaka-project.github.io/shaka-packager/html/"; + description = + "Media packaging framework for VOD and Live DASH and HLS applications"; + platforms = platforms.linux; + }; + }; + } + ); +} \ No newline at end of file diff --git a/flake-multi-platform/README.md b/flake-multi-platform/README.md index 08876ac..224af98 100644 --- a/flake-multi-platform/README.md +++ b/flake-multi-platform/README.md @@ -1,5 +1,7 @@ # flake-multi-platform +## Targets + ``` > nix build ... @@ -17,3 +19,11 @@ git+file:///home/mycroft/dev/nix-samples?dir=flake-multi-platform └───x86_64-linux └───default: package 'simple' ``` + +## Building + +``` +> nix build . +> nix build .#default +> nix build .#packages.x86_64-linux +``` diff --git a/flake-rust-devshell/flake.lock b/flake-rust-devshell/flake.lock new file mode 100644 index 0000000..3992879 --- /dev/null +++ b/flake-rust-devshell/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710631334, + "narHash": "sha256-rL5LSYd85kplL5othxK5lmAtjyMOBg390sGBTb3LRMM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c75037bbf9093a2acb617804ee46320d6d1fea5a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1710727870, + "narHash": "sha256-Ulsx+t4SnRmjMJx4eF2Li+3rBGYhZp0XNShVjIheCfg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a1b17cacfa7a6ed18f553a195a047f4e73e95da9", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake-rust-devshell/flake.nix b/flake-rust-devshell/flake.nix new file mode 100644 index 0000000..be757b5 --- /dev/null +++ b/flake-rust-devshell/flake.nix @@ -0,0 +1,32 @@ +# https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10#a-flake-with-derivation +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem + (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + in + with pkgs; + { + devShells.default = mkShell { + # buildInputs = [ rust-bin.stable.latest.default ]; + buildInputs = [ rustToolchain ]; + }; + } + ); +} \ No newline at end of file diff --git a/flake-rust-devshell/rust-toolchain.toml b/flake-rust-devshell/rust-toolchain.toml new file mode 100644 index 0000000..ecef085 --- /dev/null +++ b/flake-rust-devshell/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly-2020-07-10" +components = [ "rustfmt", "rustc-dev" ] +targets = [ "x86_64-unknown-linux-gnu" ] +profile = "minimal"