nix-samples/flake-basic
2024-03-17 17:33:12 +01:00
..
flake.lock Initial commit 2024-03-17 17:33:12 +01:00
flake.nix Initial commit 2024-03-17 17:33:12 +01:00
README.md Initial commit 2024-03-17 17:33:12 +01:00

flakes

Do not forget to git add the flake.nix file! Or you'll face the does not exist error.

> nix flake check

> nix build

> nix flake show

Simplying

First step:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = inputs: {
    packages."x86_64-linux".default = derivation {
      name = "simple";
      builder = "${inputs.nixpkgs.legacyPackages."x86_64-linux".bash}/bin/bash";
      args = [ "-c" "echo foo > $out" ];
      src = ./.;
      system = "x86_64-linux";
    };
  };
}

Second step:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = { self, nixpkgs }: {
    packages."x86_64-linux".default = derivation {
      name = "simple";
      builder = "${nixpkgs.legacyPackages."x86_64-linux".bash}/bin/bash";
      args = [ "-c" "echo foo > $out" ];
      src = ./.;
      system = "x86_64-linux";
    };
  };
}

Third:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
    in
    {
      packages.${system}.default = derivation {
        name = "simple";
        builder = "${nixpkgs.legacyPackages.${system}.bash}/bin/bash";
        args = [ "-c" "echo foo > $out" ];
        src = ./.;
        system = system;
      };
    };
}

Fourth:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = { self, nixpkgs }:
    let
      name = "simple";
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
      src = ./.;
    in
    {
      packages.${system}.default = derivation {
        inherit name src system;
        builder = with pkgs; "${bash}/bin/bash";
        args = [ "-c" "echo foo > $out" ];
      };
    };
}