FlakeInputName generates a name for the input that will be used in the generated flake.nix to import this package. This name must be unique in that flake so we attach a hash to (quasi) ensure uniqueness. Input name will be different from raw package name
()
| 213 | // flake so we attach a hash to (quasi) ensure uniqueness. |
| 214 | // Input name will be different from raw package name |
| 215 | func (p *Package) FlakeInputName() string { |
| 216 | _ = p.resolve() |
| 217 | |
| 218 | result := "" |
| 219 | switch p.installable.Ref.Type { |
| 220 | case flake.TypePath: |
| 221 | result = filepath.Base(p.installable.Ref.Path) + "-" + p.Hash() |
| 222 | case flake.TypeGitHub: |
| 223 | isNixOS := strings.ToLower(p.installable.Ref.Owner) == "nixos" |
| 224 | isNixpkgs := isNixOS && strings.ToLower(p.installable.Ref.Repo) == "nixpkgs" |
| 225 | if isNixpkgs && p.IsDevboxPackage { |
| 226 | commitHash := nix.HashFromNixPkgsURL(p.installable.Ref.String()) |
| 227 | result = "nixpkgs-" + commitHash[:min(6, len(commitHash))] |
| 228 | } else { |
| 229 | result = "gh-" + p.installable.Ref.Owner + "-" + p.installable.Ref.Repo |
| 230 | if p.installable.Ref.Rev != "" { |
| 231 | result += "-" + p.installable.Ref.Rev |
| 232 | } else if p.installable.Ref.Ref != "" { |
| 233 | result += "-" + p.installable.Ref.Ref |
| 234 | } |
| 235 | } |
| 236 | default: |
| 237 | result = p.installable.Ref.String() + "-" + p.Hash() |
| 238 | } |
| 239 | |
| 240 | // replace all non-alphanumeric with dashes |
| 241 | return inputNameRegex.ReplaceAllString(result, "-") |
| 242 | } |
| 243 | |
| 244 | // URLForFlakeInput returns the input url to be used in a flake.nix file. This |
| 245 | // input can be used to import the package. |